Add typelen parameter to chunk_to_sequence function
The parameter is used to initialize the given sequence to zero.
This commit is contained in:
committed by
Tobias Brunner
parent
270b321e97
commit
0f0165c81f
@@ -145,7 +145,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
|
|||||||
else if (nonce_loc_id != 0 && esa.dh_id == 0)
|
else if (nonce_loc_id != 0 && esa.dh_id == 0)
|
||||||
{
|
{
|
||||||
nonce_type nc_rem;
|
nonce_type nc_rem;
|
||||||
chunk_to_sequence(nonce_rem, &nc_rem);
|
chunk_to_sequence(nonce_rem, &nc_rem, sizeof(nonce_type));
|
||||||
if (ike_esa_create_no_pfs(esa_id, esa.isa_id, 1, 1, nonce_loc_id,
|
if (ike_esa_create_no_pfs(esa_id, esa.isa_id, 1, 1, nonce_loc_id,
|
||||||
nc_rem, initiator, ntohl(spi_loc),
|
nc_rem, initiator, ntohl(spi_loc),
|
||||||
ntohl(spi_rem)) != TKM_OK)
|
ntohl(spi_rem)) != TKM_OK)
|
||||||
@@ -159,7 +159,7 @@ METHOD(kernel_ipsec_t, add_sa, status_t,
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
nonce_type nc_rem;
|
nonce_type nc_rem;
|
||||||
chunk_to_sequence(nonce_rem, &nc_rem);
|
chunk_to_sequence(nonce_rem, &nc_rem, sizeof(nonce_type));
|
||||||
if (ike_esa_create(esa_id, esa.isa_id, 1, 1, esa.dh_id, nonce_loc_id,
|
if (ike_esa_create(esa_id, esa.isa_id, 1, 1, esa.dh_id, nonce_loc_id,
|
||||||
nc_rem, initiator, ntohl(spi_loc),
|
nc_rem, initiator, ntohl(spi_loc),
|
||||||
ntohl(spi_rem)) != TKM_OK)
|
ntohl(spi_rem)) != TKM_OK)
|
||||||
|
|||||||
@@ -219,13 +219,13 @@ METHOD(keymat_v2_t, derive_ike_keys, bool,
|
|||||||
|
|
||||||
if (this->initiator)
|
if (this->initiator)
|
||||||
{
|
{
|
||||||
chunk_to_sequence(&nonce_r, &nonce_rem);
|
chunk_to_sequence(&nonce_r, &nonce_rem, sizeof(nonce_type));
|
||||||
spi_loc = id->get_initiator_spi(id);
|
spi_loc = id->get_initiator_spi(id);
|
||||||
spi_rem = id->get_responder_spi(id);
|
spi_rem = id->get_responder_spi(id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
chunk_to_sequence(&nonce_i, &nonce_rem);
|
chunk_to_sequence(&nonce_i, &nonce_rem, sizeof(nonce_type));
|
||||||
spi_loc = id->get_responder_spi(id);
|
spi_loc = id->get_responder_spi(id);
|
||||||
spi_rem = id->get_initiator_spi(id);
|
spi_rem = id->get_initiator_spi(id);
|
||||||
}
|
}
|
||||||
@@ -390,14 +390,14 @@ METHOD(keymat_v2_t, get_psk_sig, bool,
|
|||||||
|
|
||||||
signature_type signature;
|
signature_type signature;
|
||||||
init_message_type msg;
|
init_message_type msg;
|
||||||
chunk_to_sequence(&ike_sa_init, &msg);
|
chunk_to_sequence(&ike_sa_init, &msg, sizeof(init_message_type));
|
||||||
|
|
||||||
chunk_t idx_chunk, chunk = chunk_alloca(4);
|
chunk_t idx_chunk, chunk = chunk_alloca(4);
|
||||||
chunk.ptr[0] = id->get_type(id);
|
chunk.ptr[0] = id->get_type(id);
|
||||||
memcpy(chunk.ptr + 1, reserved, 3);
|
memcpy(chunk.ptr + 1, reserved, 3);
|
||||||
idx_chunk = chunk_cata("cc", chunk, id->get_encoding(id));
|
idx_chunk = chunk_cata("cc", chunk, id->get_encoding(id));
|
||||||
idx_type idx;
|
idx_type idx;
|
||||||
chunk_to_sequence(&idx_chunk, &idx);
|
chunk_to_sequence(&idx_chunk, &idx, sizeof(idx_type));
|
||||||
|
|
||||||
if (ike_isa_sign_psk(this->isa_ctx_id, msg, idx, verify == TRUE, &signature)
|
if (ike_isa_sign_psk(this->isa_ctx_id, msg, idx, verify == TRUE, &signature)
|
||||||
!= TKM_OK)
|
!= TKM_OK)
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ METHOD(listener_t, authorize, bool,
|
|||||||
}
|
}
|
||||||
|
|
||||||
signature_type signature;
|
signature_type signature;
|
||||||
chunk_to_sequence(auth, &signature);
|
chunk_to_sequence(auth, &signature, sizeof(signature_type));
|
||||||
if (ike_isa_auth_psk(isa_id, signature) != TKM_OK)
|
if (ike_isa_auth_psk(isa_id, signature) != TKM_OK)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IKE, "TKM based authentication failed"
|
DBG1(DBG_IKE, "TKM based authentication failed"
|
||||||
|
|||||||
@@ -30,8 +30,10 @@ void sequence_to_chunk(const byte_t * const first, const uint32_t len,
|
|||||||
memcpy(chunk->ptr, first, len);
|
memcpy(chunk->ptr, first, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void chunk_to_sequence(const chunk_t * const chunk, void *sequence)
|
void chunk_to_sequence(const chunk_t * const chunk, void *sequence,
|
||||||
|
const uint32_t typelen)
|
||||||
{
|
{
|
||||||
|
memset(sequence, 0, typelen);
|
||||||
sequence_type *seq = sequence;
|
sequence_type *seq = sequence;
|
||||||
seq->size = chunk->len;
|
seq->size = chunk->len;
|
||||||
memcpy(seq->data, chunk->ptr, seq->size);
|
memcpy(seq->data, chunk->ptr, seq->size);
|
||||||
|
|||||||
@@ -35,7 +35,9 @@ void sequence_to_chunk(const byte_t * const first, const uint32_t len,
|
|||||||
*
|
*
|
||||||
* @param chunk pointer to chunk struct
|
* @param chunk pointer to chunk struct
|
||||||
* @param sequence pointer to variable-length sequence
|
* @param sequence pointer to variable-length sequence
|
||||||
|
* @param typelen length of sequence type
|
||||||
*/
|
*/
|
||||||
void chunk_to_sequence(const chunk_t * const chunk, void *sequence);
|
void chunk_to_sequence(const chunk_t * const chunk, void *sequence,
|
||||||
|
const uint32_t typelen);
|
||||||
|
|
||||||
#endif /** TKM_UTILS_H_ */
|
#endif /** TKM_UTILS_H_ */
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ START_TEST(test_chunk_to_sequence)
|
|||||||
chunk_t chunk = chunk_from_thing("ABCDEFGH");
|
chunk_t chunk = chunk_from_thing("ABCDEFGH");
|
||||||
key_type key;
|
key_type key;
|
||||||
|
|
||||||
chunk_to_sequence(&chunk, &key);
|
chunk_to_sequence(&chunk, &key, sizeof(key_type));
|
||||||
fail_if(key.size != chunk.len, "Seq size mismatch");
|
fail_if(key.size != chunk.len, "Seq size mismatch");
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|||||||
Reference in New Issue
Block a user