use a nonce for a PA-TNC message identifier

This commit is contained in:
Andreas Steffen
2012-07-16 18:08:49 +02:00
parent 358dbe4835
commit e51c527e68
4 changed files with 26 additions and 9 deletions
+5 -1
View File
@@ -525,7 +525,11 @@ METHOD(imc_agent_t, send_message, TNC_Result,
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
/* build and send the PA-TNC message via the IF-IMC interface */ /* build and send the PA-TNC message via the IF-IMC interface */
pa_tnc_msg->build(pa_tnc_msg); if (!pa_tnc_msg->build(pa_tnc_msg))
{
pa_tnc_msg->destroy(pa_tnc_msg);
return TNC_RESULT_FATAL;
}
msg = pa_tnc_msg->get_encoding(pa_tnc_msg); msg = pa_tnc_msg->get_encoding(pa_tnc_msg);
if (state->has_long(state) && this->send_message_long) if (state->has_long(state) && this->send_message_long)
+5 -1
View File
@@ -547,7 +547,11 @@ METHOD(imv_agent_t, send_message, TNC_Result,
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
/* build and send the PA-TNC message via the IF-IMV interface */ /* build and send the PA-TNC message via the IF-IMV interface */
pa_tnc_msg->build(pa_tnc_msg); if (!pa_tnc_msg->build(pa_tnc_msg))
{
pa_tnc_msg->destroy(pa_tnc_msg);
return TNC_RESULT_FATAL;
}
msg = pa_tnc_msg->get_encoding(pa_tnc_msg); msg = pa_tnc_msg->get_encoding(pa_tnc_msg);
if (state->has_long(state) && this->send_message_long) if (state->has_long(state) && this->send_message_long)
+13 -6
View File
@@ -131,7 +131,7 @@ METHOD(pa_tnc_msg_t, add_attribute, bool,
return TRUE; return TRUE;
} }
METHOD(pa_tnc_msg_t, build, void, METHOD(pa_tnc_msg_t, build, bool,
private_pa_tnc_msg_t *this) private_pa_tnc_msg_t *this)
{ {
bio_writer_t *writer; bio_writer_t *writer;
@@ -142,12 +142,17 @@ METHOD(pa_tnc_msg_t, build, void,
u_int32_t type; u_int32_t type;
u_int8_t flags; u_int8_t flags;
chunk_t value; chunk_t value;
rng_t *rng; nonce_gen_t *ng;
/* create a random message identifier */ /* generate a nonce as a message identifier */
rng = lib->crypto->create_rng(lib->crypto, RNG_WEAK); ng = lib->crypto->create_nonce_gen(lib->crypto);
rng->get_bytes(rng, sizeof(this->identifier), (u_int8_t*)&this->identifier); if (!ng || !ng->get_nonce(ng, 4, (u_int8_t*)&this->identifier))
rng->destroy(rng); {
DBG1(DBG_TNC, "failed to generate random PA-TNC message identifier");
DESTROY_IF(ng);
return FALSE;
}
ng->destroy(ng);
DBG2(DBG_TNC, "creating PA-TNC message with ID 0x%08x", this->identifier); DBG2(DBG_TNC, "creating PA-TNC message with ID 0x%08x", this->identifier);
/* build message header */ /* build message header */
@@ -193,6 +198,8 @@ METHOD(pa_tnc_msg_t, build, void,
free(this->encoding.ptr); free(this->encoding.ptr);
this->encoding = chunk_clone(writer->get_buf(writer)); this->encoding = chunk_clone(writer->get_buf(writer));
writer->destroy(writer); writer->destroy(writer);
return TRUE;
} }
METHOD(pa_tnc_msg_t, process, status_t, METHOD(pa_tnc_msg_t, process, status_t,
+3 -1
View File
@@ -52,8 +52,10 @@ struct pa_tnc_msg_t {
/** /**
* Build the PA-TNC message * Build the PA-TNC message
*
* @return TRUE if PA-TNC message was built successfully
*/ */
void (*build)(pa_tnc_msg_t *this); bool (*build)(pa_tnc_msg_t *this);
/** /**
* Process the PA-TNC message * Process the PA-TNC message