Add a return value to hasher_t.allocate_hash()
This commit is contained in:
@@ -1164,8 +1164,13 @@ METHOD(ike_sa_manager_t, checkout_by_message, ike_sa_t*,
|
||||
u_int64_t our_spi;
|
||||
chunk_t hash;
|
||||
|
||||
this->hasher->allocate_hash(this->hasher,
|
||||
message->get_packet_data(message), &hash);
|
||||
if (!this->hasher->allocate_hash(this->hasher,
|
||||
message->get_packet_data(message), &hash))
|
||||
{
|
||||
DBG1(DBG_MGR, "ignoring message, failed to hash message");
|
||||
id->destroy(id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ensure this is not a retransmit of an already handled init message */
|
||||
switch (check_and_put_init_hash(this, hash, &our_spi))
|
||||
|
||||
@@ -554,7 +554,11 @@ METHOD(keymat_v1_t, derive_ike_keys, bool,
|
||||
|
||||
/* initial IV = hash(g^xi | g^xr) */
|
||||
data = chunk_cata("cc", g_xi, g_xr);
|
||||
this->hasher->allocate_hash(this->hasher, data, &this->phase1_iv.iv);
|
||||
if (!this->hasher->allocate_hash(this->hasher, data, &this->phase1_iv.iv))
|
||||
{
|
||||
chunk_free(&dh_me);
|
||||
return FALSE;
|
||||
}
|
||||
if (this->phase1_iv.iv.len > this->aead->get_block_size(this->aead))
|
||||
{
|
||||
this->phase1_iv.iv.len = this->aead->get_block_size(this->aead);
|
||||
@@ -975,10 +979,15 @@ static bool generate_iv(private_keymat_v1_t *this, iv_data_t *iv)
|
||||
else
|
||||
{
|
||||
/* initial phase 2 IV = hash(last_phase1_block | mid) */
|
||||
u_int32_t net = htonl(iv->mid);
|
||||
chunk_t data = chunk_cata("cc", this->phase1_iv.iv,
|
||||
chunk_from_thing(net));
|
||||
this->hasher->allocate_hash(this->hasher, data, &iv->iv);
|
||||
u_int32_t net;;
|
||||
chunk_t data;
|
||||
|
||||
net = htonl(iv->mid);
|
||||
data = chunk_cata("cc", this->phase1_iv.iv, chunk_from_thing(net));
|
||||
if (!this->hasher->allocate_hash(this->hasher, data, &iv->iv))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
if (iv->iv.len > this->aead->get_block_size(this->aead))
|
||||
{
|
||||
iv->iv.len = this->aead->get_block_size(this->aead);
|
||||
|
||||
@@ -100,7 +100,11 @@ static chunk_t generate_natd_hash(private_isakmp_natd_t *this,
|
||||
natd_chunk = chunk_cata("cccc", chunk_from_thing(spi_i),
|
||||
chunk_from_thing(spi_r), host->get_address(host),
|
||||
chunk_from_thing(port));
|
||||
hasher->allocate_hash(hasher, natd_chunk, &natd_hash);
|
||||
if (!hasher->allocate_hash(hasher, natd_chunk, &natd_hash))
|
||||
{
|
||||
DBG1(DBG_IKE, "creating NAT-D payload hash failed");
|
||||
return chunk_empty;
|
||||
}
|
||||
DBG3(DBG_IKE, "natd_chunk %B", &natd_chunk);
|
||||
DBG3(DBG_IKE, "natd_hash %B", &natd_hash);
|
||||
|
||||
@@ -154,6 +158,10 @@ static hash_payload_t *build_natd_payload(private_isakmp_natd_t *this, bool src,
|
||||
ike_sa_id_t *ike_sa_id = this->ike_sa->get_id(this->ike_sa);
|
||||
hash = generate_natd_hash(this, ike_sa_id, host);
|
||||
}
|
||||
if (!hash.len)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
payload = hash_payload_create(NAT_D_V1);
|
||||
payload->set_hash(payload, hash);
|
||||
chunk_free(&hash);
|
||||
@@ -171,14 +179,20 @@ static void add_natd_payloads(private_isakmp_natd_t *this, message_t *message)
|
||||
/* destination has to be added first */
|
||||
host = message->get_destination(message);
|
||||
payload = build_natd_payload(this, FALSE, host);
|
||||
message->add_payload(message, (payload_t*)payload);
|
||||
if (payload)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)payload);
|
||||
}
|
||||
|
||||
/* source is added second, compared with IKEv2 we always know the source,
|
||||
* as these payloads are added in the second Phase 1 exchange or the
|
||||
* response to the first */
|
||||
host = message->get_source(message);
|
||||
payload = build_natd_payload(this, TRUE, host);
|
||||
message->add_payload(message, (payload_t*)payload);
|
||||
if (payload)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)payload);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -839,7 +839,10 @@ static chunk_t build_signature(private_connect_manager_t *this,
|
||||
/* signature = SHA1( MID | ME_CONNECTID | ME_ENDPOINT | ME_CONNECTKEY ) */
|
||||
sig_chunk = chunk_cat("cccc", mid_chunk, check->connect_id,
|
||||
check->endpoint_raw, key_chunk);
|
||||
this->hasher->allocate_hash(this->hasher, sig_chunk, &sig_hash);
|
||||
if (!this->hasher->allocate_hash(this->hasher, sig_chunk, &sig_hash))
|
||||
{
|
||||
sig_hash = chunk_empty;
|
||||
}
|
||||
DBG3(DBG_IKE, "sig_chunk %#B", &sig_chunk);
|
||||
DBG3(DBG_IKE, "sig_hash %#B", &sig_hash);
|
||||
|
||||
|
||||
@@ -78,7 +78,12 @@ static cert_payload_t *build_cert_payload(private_ike_cert_post_t *this,
|
||||
hasher->destroy(hasher);
|
||||
return NULL;
|
||||
}
|
||||
hasher->allocate_hash(hasher, encoded, &hash);
|
||||
if (!hasher->allocate_hash(hasher, encoded, &hash))
|
||||
{
|
||||
hasher->destroy(hasher);
|
||||
chunk_free(&encoded);
|
||||
return cert_payload_create_from_cert(CERTIFICATE, cert);
|
||||
}
|
||||
chunk_free(&encoded);
|
||||
hasher->destroy(hasher);
|
||||
id = identification_create_from_encoding(ID_KEY_ID, hash);
|
||||
|
||||
@@ -104,7 +104,10 @@ static chunk_t generate_natd_hash(private_ike_natd_t *this,
|
||||
|
||||
/* natd_hash = SHA1( spi_i | spi_r | address | port ) */
|
||||
natd_chunk = chunk_cat("cccc", spi_i_chunk, spi_r_chunk, addr_chunk, port_chunk);
|
||||
this->hasher->allocate_hash(this->hasher, natd_chunk, &natd_hash);
|
||||
if (!this->hasher->allocate_hash(this->hasher, natd_chunk, &natd_hash))
|
||||
{
|
||||
natd_hash = chunk_empty;
|
||||
}
|
||||
DBG3(DBG_IKE, "natd_chunk %B", &natd_chunk);
|
||||
DBG3(DBG_IKE, "natd_hash %B", &natd_hash);
|
||||
|
||||
@@ -152,6 +155,10 @@ static notify_payload_t *build_natd_payload(private_ike_natd_t *this,
|
||||
{
|
||||
hash = generate_natd_hash(this, ike_sa_id, host);
|
||||
}
|
||||
if (!hash.len)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
notify = notify_payload_create(NOTIFY);
|
||||
notify->set_notify_type(notify, type);
|
||||
notify->set_notification_data(notify, hash);
|
||||
@@ -298,7 +305,10 @@ METHOD(task_t, build_i, status_t,
|
||||
/* destination is always set */
|
||||
host = message->get_destination(message);
|
||||
notify = build_natd_payload(this, NAT_DETECTION_DESTINATION_IP, host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
|
||||
/* source may be any, we have 3 possibilities to get our source address:
|
||||
* 1. It is defined in the config => use the one of the IKE_SA
|
||||
@@ -309,7 +319,10 @@ METHOD(task_t, build_i, status_t,
|
||||
if (!host->is_anyaddr(host) || ike_cfg->force_encap(ike_cfg))
|
||||
{ /* 1. or if we force UDP encap, as it doesn't matter if it's %any */
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -319,7 +332,10 @@ METHOD(task_t, build_i, status_t,
|
||||
{ /* 2. */
|
||||
host->set_port(host, ike_cfg->get_my_port(ike_cfg));
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
host->destroy(host);
|
||||
}
|
||||
else
|
||||
@@ -333,7 +349,10 @@ METHOD(task_t, build_i, status_t,
|
||||
host->set_port(host, ike_cfg->get_my_port(ike_cfg));
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, host);
|
||||
host->destroy(host);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
}
|
||||
@@ -365,11 +384,16 @@ METHOD(task_t, build_r, status_t,
|
||||
/* initiator seems to support NAT detection, add response */
|
||||
me = message->get_source(message);
|
||||
notify = build_natd_payload(this, NAT_DETECTION_SOURCE_IP, me);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
other = message->get_destination(message);
|
||||
notify = build_natd_payload(this, NAT_DETECTION_DESTINATION_IP, other);
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
if (notify)
|
||||
{
|
||||
message->add_payload(message, (payload_t*)notify);
|
||||
}
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user