Add a return value to keymat_v2_t.get_auth_octets()

This commit is contained in:
Martin Willi
2012-07-16 14:53:34 +02:00
parent 2baae8e3ea
commit bb1e0c59e1
5 changed files with 37 additions and 21 deletions
+6 -2
View File
@@ -237,8 +237,12 @@ static bool build_auth(private_pretend_auth_t *this,
return FALSE; return FALSE;
} }
keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa); keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa);
octets = keymat->get_auth_octets(keymat, TRUE, this->ike_init, if (!keymat->get_auth_octets(keymat, TRUE, this->ike_init,
this->nonce, this->id, this->reserved); this->nonce, this->id, this->reserved, &octets))
{
private->destroy(private);
return FALSE;
}
if (!private->sign(private, scheme, octets, &auth_data)) if (!private->sign(private, scheme, octets, &auth_data))
{ {
chunk_free(&octets); chunk_free(&octets);
+7 -2
View File
@@ -136,8 +136,13 @@ static bool rebuild_auth(private_rebuild_auth_t *this, ike_sa_t *ike_sa,
return FALSE; return FALSE;
} }
keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa); keymat = (keymat_v2_t*)ike_sa->get_keymat(ike_sa);
octets = keymat->get_auth_octets(keymat, FALSE, this->ike_init, if (!keymat->get_auth_octets(keymat, FALSE, this->ike_init,
this->nonce, id, reserved); this->nonce, id, reserved, &octets))
{
private->destroy(private);
id->destroy(id);
return FALSE;
}
if (!private->sign(private, scheme, octets, &auth_data)) if (!private->sign(private, scheme, octets, &auth_data))
{ {
chunk_free(&octets); chunk_free(&octets);
@@ -57,7 +57,7 @@ struct private_pubkey_authenticator_t {
METHOD(authenticator_t, build, status_t, METHOD(authenticator_t, build, status_t,
private_pubkey_authenticator_t *this, message_t *message) private_pubkey_authenticator_t *this, message_t *message)
{ {
chunk_t octets, auth_data; chunk_t octets = chunk_empty, auth_data;
status_t status = FAILED; status_t status = FAILED;
private_key_t *private; private_key_t *private;
identification_t *id; identification_t *id;
@@ -112,9 +112,9 @@ METHOD(authenticator_t, build, status_t,
return status; return status;
} }
keymat = (keymat_v2_t*)this->ike_sa->get_keymat(this->ike_sa); keymat = (keymat_v2_t*)this->ike_sa->get_keymat(this->ike_sa);
octets = keymat->get_auth_octets(keymat, FALSE, this->ike_sa_init, if (keymat->get_auth_octets(keymat, FALSE, this->ike_sa_init,
this->nonce, id, this->reserved); this->nonce, id, this->reserved, &octets) &&
if (private->sign(private, scheme, octets, &auth_data)) private->sign(private, scheme, octets, &auth_data))
{ {
auth_payload = auth_payload_create(); auth_payload = auth_payload_create();
auth_payload->set_auth_method(auth_payload, auth_method); auth_payload->set_auth_method(auth_payload, auth_method);
@@ -176,8 +176,11 @@ METHOD(authenticator_t, process, status_t,
auth_data = auth_payload->get_data(auth_payload); auth_data = auth_payload->get_data(auth_payload);
id = this->ike_sa->get_other_id(this->ike_sa); id = this->ike_sa->get_other_id(this->ike_sa);
keymat = (keymat_v2_t*)this->ike_sa->get_keymat(this->ike_sa); keymat = (keymat_v2_t*)this->ike_sa->get_keymat(this->ike_sa);
octets = keymat->get_auth_octets(keymat, TRUE, this->ike_sa_init, if (!keymat->get_auth_octets(keymat, TRUE, this->ike_sa_init,
this->nonce, id, this->reserved); this->nonce, id, this->reserved, &octets))
{
return FAILED;
}
auth = this->ike_sa->get_auth_cfg(this->ike_sa, FALSE); auth = this->ike_sa->get_auth_cfg(this->ike_sa, FALSE);
enumerator = lib->credmgr->create_public_enumerator(lib->credmgr, enumerator = lib->credmgr->create_public_enumerator(lib->credmgr,
key_type, id, auth); key_type, id, auth);
+10 -7
View File
@@ -576,11 +576,11 @@ METHOD(keymat_t, get_aead, aead_t*,
return in ? this->aead_in : this->aead_out; return in ? this->aead_in : this->aead_out;
} }
METHOD(keymat_v2_t, get_auth_octets, chunk_t, METHOD(keymat_v2_t, get_auth_octets, bool,
private_keymat_v2_t *this, bool verify, chunk_t ike_sa_init, private_keymat_v2_t *this, bool verify, chunk_t ike_sa_init,
chunk_t nonce, identification_t *id, char reserved[3]) chunk_t nonce, identification_t *id, char reserved[3], chunk_t *octets)
{ {
chunk_t chunk, idx, octets; chunk_t chunk, idx;
chunk_t skp; chunk_t skp;
skp = verify ? this->skp_verify : this->skp_build; skp = verify ? this->skp_verify : this->skp_build;
@@ -595,9 +595,9 @@ METHOD(keymat_v2_t, get_auth_octets, chunk_t,
this->prf->set_key(this->prf, skp); this->prf->set_key(this->prf, skp);
this->prf->allocate_bytes(this->prf, idx, &chunk); this->prf->allocate_bytes(this->prf, idx, &chunk);
octets = chunk_cat("ccm", ike_sa_init, nonce, chunk); *octets = chunk_cat("ccm", ike_sa_init, nonce, chunk);
DBG3(DBG_IKE, "octets = message + nonce + prf(Sk_px, IDx') %B", &octets); DBG3(DBG_IKE, "octets = message + nonce + prf(Sk_px, IDx') %B", octets);
return octets; return TRUE;
} }
/** /**
@@ -616,7 +616,10 @@ METHOD(keymat_v2_t, get_psk_sig, bool,
{ /* EAP uses SK_p if no MSK has been established */ { /* EAP uses SK_p if no MSK has been established */
secret = verify ? this->skp_verify : this->skp_build; secret = verify ? this->skp_verify : this->skp_build;
} }
octets = get_auth_octets(this, verify, ike_sa_init, nonce, id, reserved); if (!get_auth_octets(this, verify, ike_sa_init, nonce, id, reserved, &octets))
{
return FALSE;
}
/* AUTH = prf(prf(Shared Secret,"Key Pad for IKEv2"), <msg octets>) */ /* AUTH = prf(prf(Shared Secret,"Key Pad for IKEv2"), <msg octets>) */
key_pad = chunk_create(IKEV2_KEY_PAD, IKEV2_KEY_PAD_LENGTH); key_pad = chunk_create(IKEV2_KEY_PAD, IKEV2_KEY_PAD_LENGTH);
this->prf->set_key(this->prf, secret); this->prf->set_key(this->prf, secret);
+5 -4
View File
@@ -99,11 +99,12 @@ struct keymat_v2_t {
* @param nonce nonce value * @param nonce nonce value
* @param id identity * @param id identity
* @param reserved reserved bytes of id_payload * @param reserved reserved bytes of id_payload
* @return authentication octets * @param octests chunk receiving allocated auth octets
* @return TRUE if octets created successfully
*/ */
chunk_t (*get_auth_octets)(keymat_v2_t *this, bool verify, bool (*get_auth_octets)(keymat_v2_t *this, bool verify, chunk_t ike_sa_init,
chunk_t ike_sa_init, chunk_t nonce, chunk_t nonce, identification_t *id,
identification_t *id, char reserved[3]); char reserved[3], chunk_t *octets);
/** /**
* Build the shared secret signature used for PSK and EAP authentication. * Build the shared secret signature used for PSK and EAP authentication.
* *