Added an identity getter to XAuth methods to query the actually used identity

This commit is contained in:
Martin Willi
2012-03-20 17:31:23 +01:00
parent 5f6a37eb9b
commit 7a7efbf9d8
2 changed files with 23 additions and 12 deletions
@@ -98,7 +98,7 @@ METHOD(xauth_method_t, process_server, status_t,
configuration_attribute_t *attr; configuration_attribute_t *attr;
enumerator_t *enumerator; enumerator_t *enumerator;
shared_key_t *shared; shared_key_t *shared;
identification_t *id = NULL, *peer; identification_t *id;
chunk_t user = chunk_empty, pass = chunk_empty; chunk_t user = chunk_empty, pass = chunk_empty;
status_t status = SUCCESS; status_t status = SUCCESS;
@@ -132,31 +132,33 @@ METHOD(xauth_method_t, process_server, status_t,
DBG1(DBG_IKE, "failed to parse provided XAuth username"); DBG1(DBG_IKE, "failed to parse provided XAuth username");
return FAILED; return FAILED;
} }
this->peer->destroy(this->peer);
this->peer = id;
} }
peer = id ?: this->peer; shared = lib->credmgr->get_shared(lib->credmgr, SHARED_EAP,
shared = lib->credmgr->get_shared(lib->credmgr, SHARED_EAP, this->server, this->server, this->peer);
peer);
if (!shared) if (!shared)
{ {
DBG1(DBG_IKE, "no XAuth secret found for '%Y' - '%Y'", this->server, DBG1(DBG_IKE, "no XAuth secret found for '%Y' - '%Y'",
peer); this->server, this->peer);
status = FAILED; status = FAILED;
} }
else if (!chunk_equals(shared->get_key(shared), pass)) else if (!chunk_equals(shared->get_key(shared), pass))
{ {
DBG1(DBG_IKE, "failed to authenticate '%Y' with XAuth", peer); DBG1(DBG_IKE, "failed to authenticate '%Y' with XAuth", this->peer);
status = FAILED; status = FAILED;
} }
else
{
DBG2(DBG_IKE, "authentication of '%Y' with XAuth successful", peer);
}
DESTROY_IF(shared); DESTROY_IF(shared);
DESTROY_IF(id);
return status; return status;
} }
METHOD(xauth_method_t, get_identity, identification_t*,
private_xauth_generic_t *this)
{
return this->peer;
}
METHOD(xauth_method_t, destroy, void, METHOD(xauth_method_t, destroy, void,
private_xauth_generic_t *this) private_xauth_generic_t *this)
{ {
@@ -178,6 +180,7 @@ xauth_generic_t *xauth_generic_create_peer(identification_t *server,
.xauth_method = { .xauth_method = {
.initiate = _initiate_peer, .initiate = _initiate_peer,
.process = _process_peer, .process = _process_peer,
.get_identity = _get_identity,
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
@@ -201,6 +204,7 @@ xauth_generic_t *xauth_generic_create_server(identification_t *server,
.xauth_method = { .xauth_method = {
.initiate = _initiate_server, .initiate = _initiate_server,
.process = _process_server, .process = _process_server,
.get_identity = _get_identity,
.destroy = _destroy, .destroy = _destroy,
}, },
}, },
@@ -80,6 +80,13 @@ struct xauth_method_t {
status_t (*process) (xauth_method_t *this, cp_payload_t *in, status_t (*process) (xauth_method_t *this, cp_payload_t *in,
cp_payload_t **out); cp_payload_t **out);
/**
* Get the XAuth username received as XAuth initiator.
*
* @return used XAuth username, pointer to internal data
*/
identification_t* (*get_identity)(xauth_method_t *this);
/** /**
* Destroys a eap_method_t object. * Destroys a eap_method_t object.
*/ */