Support signing of RADIUS accounting messages

This commit is contained in:
Martin Willi 2012-01-30 19:13:20 +01:00
parent 370de553f8
commit a69aff5f17
3 changed files with 26 additions and 10 deletions

View File

@ -272,8 +272,20 @@ METHOD(radius_message_t, add, void,
} }
METHOD(radius_message_t, sign, void, METHOD(radius_message_t, sign, void,
private_radius_message_t *this, rng_t *rng, signer_t *signer) private_radius_message_t *this, rng_t *rng, signer_t *signer,
hasher_t *hasher, chunk_t secret)
{ {
if (this->msg->code == RMC_ACCOUNTING_REQUEST)
{
chunk_t msg;
memset(this->msg->authenticator, 0, sizeof(this->msg->authenticator));
msg = chunk_create((u_char*)this->msg, ntohs(this->msg->length));
hasher->get_hash(hasher, msg, NULL);
hasher->get_hash(hasher, secret, this->msg->authenticator);
}
else
{
char buf[HASH_SIZE_MD5]; char buf[HASH_SIZE_MD5];
/* build Request-Authenticator */ /* build Request-Authenticator */
@ -285,6 +297,7 @@ METHOD(radius_message_t, sign, void,
signer->get_signature(signer, signer->get_signature(signer,
chunk_create((u_char*)this->msg, ntohs(this->msg->length)), chunk_create((u_char*)this->msg, ntohs(this->msg->length)),
((u_char*)this->msg) + ntohs(this->msg->length) - HASH_SIZE_MD5); ((u_char*)this->msg) + ntohs(this->msg->length) - HASH_SIZE_MD5);
}
} }
METHOD(radius_message_t, verify, bool, METHOD(radius_message_t, verify, bool,

View File

@ -238,8 +238,11 @@ struct radius_message_t {
* *
* @param rng RNG to create Request-Authenticator * @param rng RNG to create Request-Authenticator
* @param signer HMAC-MD5 signer with secret set * @param signer HMAC-MD5 signer with secret set
* @param hasher MD5 hasher
* @param secret shared RADIUS secret
*/ */
void (*sign)(radius_message_t *this, rng_t *rng, signer_t *signer); void (*sign)(radius_message_t *this, rng_t *rng, signer_t *signer,
hasher_t *hasher, chunk_t secret);
/** /**
* Verify the integrity of a received RADIUS response. * Verify the integrity of a received RADIUS response.

View File

@ -132,7 +132,7 @@ METHOD(radius_socket_t, request, radius_message_t*,
/* set Message Identifier */ /* set Message Identifier */
request->set_identifier(request, this->identifier++); request->set_identifier(request, this->identifier++);
/* sign the request */ /* sign the request */
request->sign(request, this->rng, this->signer); request->sign(request, this->rng, this->signer, this->hasher, this->secret);
if (!check_connection(this)) if (!check_connection(this))
{ {