merged the modularization branch (credentials) back to trunk
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,141 +0,0 @@
|
||||
/**
|
||||
* @file eap_aka.h
|
||||
*
|
||||
* @brief Interface of eap_aka_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef EAP_AKA_H_
|
||||
#define EAP_AKA_H_
|
||||
|
||||
typedef struct eap_aka_t eap_aka_t;
|
||||
typedef enum aka_subtype_t aka_subtype_t;
|
||||
typedef enum aka_attribute_t aka_attribute_t;
|
||||
|
||||
#include <sa/authenticators/eap/eap_method.h>
|
||||
|
||||
|
||||
/**
|
||||
* Subtypes of AKA messages
|
||||
*/
|
||||
enum aka_subtype_t {
|
||||
AKA_CHALLENGE = 1,
|
||||
AKA_AUTHENTICATION_REJECT = 2,
|
||||
AKA_SYNCHRONIZATION_FAILURE = 4,
|
||||
AKA_IDENTITY = 5,
|
||||
AKA_NOTIFICATION = 12,
|
||||
AKA_REAUTHENTICATION = 13,
|
||||
AKA_CLIENT_ERROR = 14,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum names for aka_subtype_t
|
||||
*/
|
||||
extern enum_name_t *aka_subtype_names;
|
||||
|
||||
/**
|
||||
* Attribute types in AKA messages
|
||||
*/
|
||||
enum aka_attribute_t {
|
||||
/** defines the end of attribute list */
|
||||
AT_END = -1,
|
||||
AT_RAND = 1,
|
||||
AT_AUTN = 2,
|
||||
AT_RES = 3,
|
||||
AT_AUTS = 4,
|
||||
AT_PADDING = 6,
|
||||
AT_NONCE_MT = 7,
|
||||
AT_PERMANENT_ID_REQ = 10,
|
||||
AT_MAC = 11,
|
||||
AT_NOTIFICATION = 12,
|
||||
AT_ANY_ID_REQ = 13,
|
||||
AT_IDENTITY = 14,
|
||||
AT_VERSION_LIST = 15,
|
||||
AT_SELECTED_VERSION = 16,
|
||||
AT_FULLAUTH_ID_REQ = 17,
|
||||
AT_COUNTER = 19,
|
||||
AT_COUNTER_TOO_SMALL = 20,
|
||||
AT_NONCE_S = 21,
|
||||
AT_CLIENT_ERROR_CODE = 22,
|
||||
AT_IV = 129,
|
||||
AT_ENCR_DATA = 130,
|
||||
AT_NEXT_PSEUDONYM = 132,
|
||||
AT_NEXT_REAUTH_ID = 133,
|
||||
AT_CHECKCODE = 134,
|
||||
AT_RESULT_IND = 135,
|
||||
};
|
||||
|
||||
/**
|
||||
* enum names for aka_attribute_t
|
||||
*/
|
||||
extern enum_name_t *aka_attribute_names;
|
||||
|
||||
/** check SEQ values as client for validity, disabled by default */
|
||||
#ifndef SEQ_CHECK
|
||||
# define SEQ_CHECK 0
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Implementation of the eap_method_t interface using EAP-AKA.
|
||||
*
|
||||
* EAP-AKA uses 3rd generation mobile phone standard authentication
|
||||
* mechanism for authentication. It is a mutual authentication
|
||||
* mechanism which establishs a shared key and therefore supports EAP_ONLY
|
||||
* authentication. This implementation follows the standard of the
|
||||
* 3GPP2 (S.S0055) and not the one of 3GGP.
|
||||
* The shared key used for authentication is from ipsec.secrets. The
|
||||
* peers ID is used to query it.
|
||||
* The AKA mechanism uses sequence numbers to detect replay attacks. The
|
||||
* peer stores the sequence number normally in a USIM and accepts
|
||||
* incremental sequence numbers (incremental for lifetime of the USIM). To
|
||||
* prevent a complex sequence number management, this implementation uses
|
||||
* a sequence number derived from time. It is initialized to the startup
|
||||
* time of the daemon. As long as the (UTC) time of the system is not
|
||||
* turned back while the daemon is not running, this method is secure.
|
||||
* To enable time based SEQs, #define SEQ_CHECK as 1. Default is to accept
|
||||
* any SEQ numbers. This allows an attacker to do replay attacks. But since
|
||||
* the server has proven his identity via IKE, such an attack is only
|
||||
* possible between server and AAA (if any).
|
||||
*
|
||||
* @b Constructors:
|
||||
* - eap_aka_create()
|
||||
* - eap_client_create() using eap_method EAP_AKA
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
struct eap_aka_t {
|
||||
|
||||
/**
|
||||
* Implemented eap_method_t interface.
|
||||
*/
|
||||
eap_method_t eap_method_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates the EAP method EAP-AKA.
|
||||
*
|
||||
* @param server ID of the EAP server
|
||||
* @param peer ID of the EAP client
|
||||
* @return eap_aka_t object
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
eap_aka_t *eap_create(eap_role_t role,
|
||||
identification_t *server, identification_t *peer);
|
||||
|
||||
#endif /* EAP_AKA_H_ */
|
||||
@@ -1,135 +0,0 @@
|
||||
/**
|
||||
* @file eap_identity.c
|
||||
*
|
||||
* @brief Implementation of eap_identity_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "eap_identity.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <library.h>
|
||||
|
||||
typedef struct private_eap_identity_t private_eap_identity_t;
|
||||
|
||||
/**
|
||||
* Private data of an eap_identity_t object.
|
||||
*/
|
||||
struct private_eap_identity_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
eap_identity_t public;
|
||||
|
||||
/**
|
||||
* ID of the peer
|
||||
*/
|
||||
identification_t *peer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.process for the peer
|
||||
*/
|
||||
static status_t process(private_eap_identity_t *this,
|
||||
eap_payload_t *in, eap_payload_t **out)
|
||||
{
|
||||
chunk_t id, hdr;
|
||||
|
||||
hdr = chunk_alloca(5);
|
||||
id = this->peer->get_encoding(this->peer);
|
||||
|
||||
*(hdr.ptr + 0) = EAP_RESPONSE;
|
||||
*(hdr.ptr + 1) = in->get_identifier(in);
|
||||
*(u_int16_t*)(hdr.ptr + 2) = htons(hdr.len + id.len);
|
||||
*(hdr.ptr + 4) = EAP_IDENTITY;
|
||||
|
||||
*out = eap_payload_create_data(chunk_cata("cc", hdr, id));
|
||||
return SUCCESS;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.initiate for the peer
|
||||
*/
|
||||
static status_t initiate(private_eap_identity_t *this, eap_payload_t **out)
|
||||
{
|
||||
/* peer never initiates */
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.get_type.
|
||||
*/
|
||||
static eap_type_t get_type(private_eap_identity_t *this)
|
||||
{
|
||||
return EAP_IDENTITY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.get_msk.
|
||||
*/
|
||||
static status_t get_msk(private_eap_identity_t *this, chunk_t *msk)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.is_mutual.
|
||||
*/
|
||||
static bool is_mutual(private_eap_identity_t *this)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.destroy.
|
||||
*/
|
||||
static void destroy(private_eap_identity_t *this)
|
||||
{
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
eap_identity_t *eap_create(eap_role_t role,
|
||||
identification_t *server, identification_t *peer)
|
||||
{
|
||||
private_eap_identity_t *this;
|
||||
|
||||
if (role != EAP_PEER)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
this = malloc_thing(private_eap_identity_t);
|
||||
|
||||
/* public functions */
|
||||
this->public.eap_method_interface.initiate = (status_t(*)(eap_method_t*,eap_payload_t**))initiate;
|
||||
this->public.eap_method_interface.process = (status_t(*)(eap_method_t*,eap_payload_t*,eap_payload_t**))process;
|
||||
this->public.eap_method_interface.get_type = (eap_type_t(*)(eap_method_t*))get_type;
|
||||
this->public.eap_method_interface.is_mutual = (bool(*)(eap_method_t*))is_mutual;
|
||||
this->public.eap_method_interface.get_msk = (status_t(*)(eap_method_t*,chunk_t*))get_msk;
|
||||
this->public.eap_method_interface.destroy = (void(*)(eap_method_t*))destroy;
|
||||
|
||||
/* private data */
|
||||
this->peer = peer;
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/**
|
||||
* @file eap_identity.h
|
||||
*
|
||||
* @brief Interface of eap_identity_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef EAP_IDENTITY_H_
|
||||
#define EAP_IDENTITY_H_
|
||||
|
||||
typedef struct eap_identity_t eap_identity_t;
|
||||
|
||||
#include <sa/authenticators/eap/eap_method.h>
|
||||
|
||||
/**
|
||||
* @brief Implementation of the eap_method_t interface using EAP Identity.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - eap_identity_create()
|
||||
* - eap_client_create() using eap_method EAP_IDENTITY
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
struct eap_identity_t {
|
||||
|
||||
/**
|
||||
* Implemented eap_method_t interface.
|
||||
*/
|
||||
eap_method_t eap_method_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates the EAP method EAP Identity.
|
||||
*
|
||||
* @param server ID of the EAP server
|
||||
* @param peer ID of the EAP client
|
||||
* @return eap_identity_t object
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
eap_identity_t *eap_create(eap_role_t role,
|
||||
identification_t *server, identification_t *peer);
|
||||
|
||||
#endif /* EAP_IDENTITY_H_ */
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include "eap_manager.h"
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include <utils/linked_list.h>
|
||||
|
||||
typedef struct private_eap_manager_t private_eap_manager_t;
|
||||
typedef struct eap_entry_t eap_entry_t;
|
||||
|
||||
/**
|
||||
* EAP constructor entry
|
||||
*/
|
||||
struct eap_entry_t {
|
||||
|
||||
/**
|
||||
* EAP method type, vendor specific if vendor is set
|
||||
*/
|
||||
eap_type_t type;
|
||||
|
||||
/**
|
||||
* vendor ID, 0 for default EAP methods
|
||||
*/
|
||||
u_int32_t vendor;
|
||||
|
||||
/**
|
||||
* Role of the method returned by the constructor, EAP_SERVER or EAP_PEER
|
||||
*/
|
||||
eap_role_t role;
|
||||
|
||||
/**
|
||||
* constructor function to create instance
|
||||
*/
|
||||
eap_constructor_t constructor;
|
||||
};
|
||||
|
||||
/**
|
||||
* private data of eap_manager
|
||||
*/
|
||||
struct private_eap_manager_t {
|
||||
|
||||
/**
|
||||
* public functions
|
||||
*/
|
||||
eap_manager_t public;
|
||||
|
||||
/**
|
||||
* list of eap_entry_t's
|
||||
*/
|
||||
linked_list_t *methods;
|
||||
|
||||
/**
|
||||
* mutex to lock methods
|
||||
*/
|
||||
pthread_mutex_t mutex;
|
||||
};
|
||||
|
||||
/**
|
||||
* Implementation of eap_manager_t.add_method.
|
||||
*/
|
||||
static void add_method(private_eap_manager_t *this, eap_type_t type,
|
||||
u_int32_t vendor, eap_role_t role,
|
||||
eap_constructor_t constructor)
|
||||
{
|
||||
eap_entry_t *entry = malloc_thing(eap_entry_t);
|
||||
|
||||
entry->type = type;
|
||||
entry->vendor = vendor;
|
||||
entry->role = role;
|
||||
entry->constructor = constructor;
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
this->methods->insert_last(this->methods, entry);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_manager_t.remove_method.
|
||||
*/
|
||||
static void remove_method(private_eap_manager_t *this, eap_constructor_t constructor)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
eap_entry_t *entry;
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
enumerator = this->methods->create_enumerator(this->methods);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
if (constructor == entry->constructor)
|
||||
{
|
||||
this->methods->remove_at(this->methods, enumerator);
|
||||
free(entry);
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_manager_t.create_instance.
|
||||
*/
|
||||
static eap_method_t* create_instance(private_eap_manager_t *this,
|
||||
eap_type_t type, u_int32_t vendor,
|
||||
eap_role_t role, identification_t *server,
|
||||
identification_t *peer)
|
||||
{
|
||||
enumerator_t *enumerator;
|
||||
eap_entry_t *entry;
|
||||
eap_method_t *method = NULL;
|
||||
|
||||
pthread_mutex_lock(&this->mutex);
|
||||
enumerator = this->methods->create_enumerator(this->methods);
|
||||
while (enumerator->enumerate(enumerator, &entry))
|
||||
{
|
||||
if (type == entry->type && vendor == entry->vendor &&
|
||||
role == entry->role)
|
||||
{
|
||||
method = entry->constructor(server, peer);
|
||||
if (method)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
enumerator->destroy(enumerator);
|
||||
pthread_mutex_unlock(&this->mutex);
|
||||
return method;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of 2008_t.destroy
|
||||
*/
|
||||
static void destroy(private_eap_manager_t *this)
|
||||
{
|
||||
this->methods->destroy_function(this->methods, free);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* see header file
|
||||
*/
|
||||
eap_manager_t *eap_manager_create()
|
||||
{
|
||||
private_eap_manager_t *this = malloc_thing(private_eap_manager_t);
|
||||
|
||||
this->public.add_method = (void(*)(eap_manager_t*, eap_type_t type, u_int32_t vendor, eap_role_t role, eap_constructor_t constructor))add_method;
|
||||
this->public.remove_method = (void(*)(eap_manager_t*, eap_constructor_t constructor))remove_method;
|
||||
this->public.create_instance = (eap_method_t*(*)(eap_manager_t*, eap_type_t type, u_int32_t vendor, eap_role_t role, identification_t*,identification_t*))create_instance;
|
||||
this->public.destroy = (void(*)(eap_manager_t*))destroy;
|
||||
|
||||
this->methods = linked_list_create();
|
||||
pthread_mutex_init(&this->mutex, NULL);
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (C) 2008 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup eap_manager eap_manager
|
||||
* @{ @ingroup eap
|
||||
*/
|
||||
|
||||
#ifndef EAP_MANAGER_H_
|
||||
#define EAP_MANAGER_H_
|
||||
|
||||
#include <sa/authenticators/eap/eap_method.h>
|
||||
|
||||
typedef struct eap_manager_t eap_manager_t;
|
||||
|
||||
/**
|
||||
* The EAP manager manages all EAP implementations and creates instances.
|
||||
*
|
||||
* A plugin registers it's implemented EAP method at the manager by
|
||||
* providing type and a contructor function. The manager then instanciates
|
||||
* eap_method_t instances through the provided constructor to handle
|
||||
* EAP authentication.
|
||||
*/
|
||||
struct eap_manager_t {
|
||||
|
||||
/**
|
||||
* Register a EAP method implementation.
|
||||
*
|
||||
* @param method vendor specific method, if vendor != 0
|
||||
* @param vendor vendor ID, 0 for non-vendor (default) EAP methods
|
||||
* @param role EAP role of the registered method
|
||||
* @param constructor constructor function, returns an eap_method_t
|
||||
*/
|
||||
void (*add_method)(eap_manager_t *this, eap_type_t type, u_int32_t vendor,
|
||||
eap_role_t role, eap_constructor_t constructor);
|
||||
|
||||
/**
|
||||
* Unregister a EAP method implementation using it's constructor.
|
||||
*
|
||||
* @param constructor constructor function to remove, as added in add_method
|
||||
*/
|
||||
void (*remove_method)(eap_manager_t *this, eap_constructor_t constructor);
|
||||
|
||||
/**
|
||||
* Create a new EAP method instance.
|
||||
*
|
||||
* @param type type of the EAP method
|
||||
* @param vendor vendor ID, 0 for non-vendor (default) EAP methods
|
||||
* @param role role of EAP method, either EAP_SERVER or EAP_PEER
|
||||
* @param server identity of the server
|
||||
* @param peer identity of the peer (client)
|
||||
* @return EAP method instance, NULL if no constructor found
|
||||
*/
|
||||
eap_method_t* (*create_instance)(eap_manager_t *this, eap_type_t type,
|
||||
u_int32_t vendor, eap_role_t role,
|
||||
identification_t *server,
|
||||
identification_t *peer);
|
||||
|
||||
/**
|
||||
* Destroy a eap_manager instance.
|
||||
*/
|
||||
void (*destroy)(eap_manager_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a eap_manager instance.
|
||||
*/
|
||||
eap_manager_t *eap_manager_create();
|
||||
|
||||
#endif /* EAP_MANAGER_H_ @}*/
|
||||
@@ -1,282 +0,0 @@
|
||||
/**
|
||||
* @file eap_md5.c
|
||||
*
|
||||
* @brief Implementation of eap_md5_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include "eap_md5.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <library.h>
|
||||
|
||||
typedef struct private_eap_md5_t private_eap_md5_t;
|
||||
|
||||
/**
|
||||
* Private data of an eap_md5_t object.
|
||||
*/
|
||||
struct private_eap_md5_t {
|
||||
|
||||
/**
|
||||
* Public authenticator_t interface.
|
||||
*/
|
||||
eap_md5_t public;
|
||||
|
||||
/**
|
||||
* ID of the server
|
||||
*/
|
||||
identification_t *server;
|
||||
|
||||
/**
|
||||
* ID of the peer
|
||||
*/
|
||||
identification_t *peer;
|
||||
|
||||
/**
|
||||
* challenge sent by the server
|
||||
*/
|
||||
chunk_t challenge;
|
||||
|
||||
/**
|
||||
* EAP message identififier
|
||||
*/
|
||||
u_int8_t identifier;
|
||||
};
|
||||
|
||||
typedef struct eap_md5_header_t eap_md5_header_t;
|
||||
|
||||
/**
|
||||
* packed eap MD5 header struct
|
||||
*/
|
||||
struct eap_md5_header_t {
|
||||
/** EAP code (REQUEST/RESPONSE) */
|
||||
u_int8_t code;
|
||||
/** unique message identifier */
|
||||
u_int8_t identifier;
|
||||
/** length of whole message */
|
||||
u_int16_t length;
|
||||
/** EAP type */
|
||||
u_int8_t type;
|
||||
/** length of value (challenge) */
|
||||
u_int8_t value_size;
|
||||
/** actual value */
|
||||
u_int8_t value[];
|
||||
} __attribute__((__packed__));
|
||||
|
||||
#define CHALLENGE_LEN 16
|
||||
#define PAYLOAD_LEN (CHALLENGE_LEN + sizeof(eap_md5_header_t))
|
||||
|
||||
/**
|
||||
* Hash the challenge string, create response
|
||||
*/
|
||||
static status_t hash_challenge(private_eap_md5_t *this, chunk_t *response)
|
||||
{
|
||||
chunk_t concat, secret;
|
||||
hasher_t *hasher;
|
||||
|
||||
if (charon->credentials->get_eap_key(charon->credentials, this->server,
|
||||
this->peer, &secret) != SUCCESS)
|
||||
{
|
||||
DBG1(DBG_IKE, "no EAP key found for hosts '%D' - '%D'",
|
||||
this->server, this->peer);
|
||||
return NOT_FOUND;
|
||||
}
|
||||
concat = chunk_cata("cmc", chunk_from_thing(this->identifier),
|
||||
secret, this->challenge);
|
||||
hasher = hasher_create(HASH_MD5);
|
||||
hasher->allocate_hash(hasher, concat, response);
|
||||
hasher->destroy(hasher);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.initiate for the peer
|
||||
*/
|
||||
static status_t initiate_peer(private_eap_md5_t *this, eap_payload_t **out)
|
||||
{
|
||||
/* peer never initiates */
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.initiate for the server
|
||||
*/
|
||||
static status_t initiate_server(private_eap_md5_t *this, eap_payload_t **out)
|
||||
{
|
||||
randomizer_t *randomizer;
|
||||
status_t status;
|
||||
eap_md5_header_t *req;
|
||||
|
||||
randomizer = randomizer_create();
|
||||
status = randomizer->allocate_pseudo_random_bytes(randomizer, CHALLENGE_LEN,
|
||||
&this->challenge);
|
||||
randomizer->destroy(randomizer);
|
||||
if (status != SUCCESS)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
req = alloca(PAYLOAD_LEN);
|
||||
req->length = htons(PAYLOAD_LEN);
|
||||
req->code = EAP_REQUEST;
|
||||
req->identifier = this->identifier;
|
||||
req->type = EAP_MD5;
|
||||
req->value_size = this->challenge.len;
|
||||
memcpy(req->value, this->challenge.ptr, this->challenge.len);
|
||||
|
||||
*out = eap_payload_create_data(chunk_create((void*)req, PAYLOAD_LEN));
|
||||
return NEED_MORE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.process for the peer
|
||||
*/
|
||||
static status_t process_peer(private_eap_md5_t *this,
|
||||
eap_payload_t *in, eap_payload_t **out)
|
||||
{
|
||||
chunk_t response;
|
||||
chunk_t data;
|
||||
eap_md5_header_t *req;
|
||||
|
||||
this->identifier = in->get_identifier(in);
|
||||
data = in->get_data(in);
|
||||
this->challenge = chunk_clone(chunk_skip(data, 6));
|
||||
if (data.len < 6 || this->challenge.len < *(data.ptr + 5))
|
||||
{
|
||||
DBG1(DBG_IKE, "received invalid EAP-MD5 message");
|
||||
return FAILED;
|
||||
}
|
||||
if (hash_challenge(this, &response) != SUCCESS)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
req = alloca(PAYLOAD_LEN);
|
||||
req->length = htons(PAYLOAD_LEN);
|
||||
req->code = EAP_RESPONSE;
|
||||
req->identifier = this->identifier;
|
||||
req->type = EAP_MD5;
|
||||
req->value_size = response.len;
|
||||
memcpy(req->value, response.ptr, response.len);
|
||||
chunk_free(&response);
|
||||
|
||||
*out = eap_payload_create_data(chunk_create((void*)req, PAYLOAD_LEN));
|
||||
return NEED_MORE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.process for the server
|
||||
*/
|
||||
static status_t process_server(private_eap_md5_t *this,
|
||||
eap_payload_t *in, eap_payload_t **out)
|
||||
{
|
||||
chunk_t response, expected;
|
||||
chunk_t data;
|
||||
|
||||
if (this->identifier != in->get_identifier(in))
|
||||
{
|
||||
DBG1(DBG_IKE, "received invalid EAP-MD5 message");
|
||||
return FAILED;
|
||||
}
|
||||
if (hash_challenge(this, &expected) != SUCCESS)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
data = in->get_data(in);
|
||||
response = chunk_skip(data, 6);
|
||||
|
||||
if (response.len < expected.len ||
|
||||
!memeq(response.ptr, expected.ptr, expected.len))
|
||||
{
|
||||
chunk_free(&expected);
|
||||
DBG1(DBG_IKE, "EAP-MD5 verification failed");
|
||||
return FAILED;
|
||||
}
|
||||
chunk_free(&expected);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.get_type.
|
||||
*/
|
||||
static eap_type_t get_type(private_eap_md5_t *this, u_int32_t *vendor)
|
||||
{
|
||||
*vendor = 0;
|
||||
return EAP_MD5;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.get_msk.
|
||||
*/
|
||||
static status_t get_msk(private_eap_md5_t *this, chunk_t *msk)
|
||||
{
|
||||
return FAILED;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.is_mutual.
|
||||
*/
|
||||
static bool is_mutual(private_eap_md5_t *this)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of eap_method_t.destroy.
|
||||
*/
|
||||
static void destroy(private_eap_md5_t *this)
|
||||
{
|
||||
chunk_free(&this->challenge);
|
||||
free(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
eap_md5_t *eap_create(eap_role_t role,
|
||||
identification_t *server, identification_t *peer)
|
||||
{
|
||||
private_eap_md5_t *this = malloc_thing(private_eap_md5_t);
|
||||
|
||||
/* public functions */
|
||||
switch (role)
|
||||
{
|
||||
case EAP_SERVER:
|
||||
this->public.eap_method_interface.initiate = (status_t(*)(eap_method_t*,eap_payload_t**))initiate_server;
|
||||
this->public.eap_method_interface.process = (status_t(*)(eap_method_t*,eap_payload_t*,eap_payload_t**))process_server;
|
||||
break;
|
||||
case EAP_PEER:
|
||||
this->public.eap_method_interface.initiate = (status_t(*)(eap_method_t*,eap_payload_t**))initiate_peer;
|
||||
this->public.eap_method_interface.process = (status_t(*)(eap_method_t*,eap_payload_t*,eap_payload_t**))process_peer;
|
||||
break;
|
||||
default:
|
||||
free(this);
|
||||
return NULL;
|
||||
}
|
||||
this->public.eap_method_interface.get_type = (eap_type_t(*)(eap_method_t*,u_int32_t*))get_type;
|
||||
this->public.eap_method_interface.is_mutual = (bool(*)(eap_method_t*))is_mutual;
|
||||
this->public.eap_method_interface.get_msk = (status_t(*)(eap_method_t*,chunk_t*))get_msk;
|
||||
this->public.eap_method_interface.destroy = (void(*)(eap_method_t*))destroy;
|
||||
|
||||
/* private data */
|
||||
this->peer = peer;
|
||||
this->server = server;
|
||||
this->challenge = chunk_empty;
|
||||
this->identifier = random();
|
||||
|
||||
return &this->public;
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/**
|
||||
* @file eap_md5.h
|
||||
*
|
||||
* @brief Interface of eap_md5_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef EAP_MD5_H_
|
||||
#define EAP_MD5_H_
|
||||
|
||||
typedef struct eap_md5_t eap_md5_t;
|
||||
|
||||
#include <sa/authenticators/eap/eap_method.h>
|
||||
|
||||
/**
|
||||
* @brief Implementation of the eap_method_t interface using EAP-MD5 (CHAP).
|
||||
*
|
||||
* @b Constructors:
|
||||
* - eap_md5_create()
|
||||
* - eap_client_create() using eap_method EAP_MD5
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
struct eap_md5_t {
|
||||
|
||||
/**
|
||||
* Implemented eap_method_t interface.
|
||||
*/
|
||||
eap_method_t eap_method_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates the EAP method EAP-MD5.
|
||||
*
|
||||
* @param server ID of the EAP server
|
||||
* @param peer ID of the EAP client
|
||||
* @return eap_md5_t object
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
eap_md5_t *eap_create(eap_role_t role,
|
||||
identification_t *server, identification_t *peer);
|
||||
|
||||
#endif /* EAP_MD5_H_ */
|
||||
@@ -1,10 +1,3 @@
|
||||
/**
|
||||
* @file eap_method.c
|
||||
*
|
||||
* @brief Generic constructor for eap_methods.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -18,22 +11,12 @@
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <dirent.h>
|
||||
#include <error.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#include "eap_method.h"
|
||||
|
||||
#include <daemon.h>
|
||||
#include <library.h>
|
||||
#include <utils/linked_list.h>
|
||||
#include <utils/identification.h>
|
||||
|
||||
|
||||
ENUM_BEGIN(eap_type_names, EAP_IDENTITY, EAP_TOKEN_CARD,
|
||||
"EAP_IDENTITY",
|
||||
"EAP_NOTIFICATION",
|
||||
@@ -62,171 +45,3 @@ ENUM(eap_role_names, EAP_SERVER, EAP_PEER,
|
||||
"EAP_PEER",
|
||||
);
|
||||
|
||||
|
||||
typedef struct module_entry_t module_entry_t;
|
||||
|
||||
/**
|
||||
* Representation of a loaded module: EAP type, library handle, constructor
|
||||
*/
|
||||
struct module_entry_t {
|
||||
eap_type_t type;
|
||||
u_int32_t vendor;
|
||||
void *handle;
|
||||
eap_constructor_t constructor;
|
||||
};
|
||||
|
||||
/** List of module_entry_t's */
|
||||
static linked_list_t *modules = NULL;
|
||||
|
||||
/**
|
||||
* unload modules at daemon shutdown
|
||||
*/
|
||||
void eap_method_unload()
|
||||
{
|
||||
if (modules)
|
||||
{
|
||||
module_entry_t *entry;
|
||||
|
||||
while (modules->remove_last(modules, (void**)&entry) == SUCCESS)
|
||||
{
|
||||
DBG2(DBG_CFG, "unloaded module EAP module %d-%d",
|
||||
entry->type, entry->vendor);
|
||||
dlclose(entry->handle);
|
||||
free(entry);
|
||||
}
|
||||
modules->destroy(modules);
|
||||
modules = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load EAP modules at daemon startup
|
||||
*/
|
||||
void eap_method_load(char *directory)
|
||||
{
|
||||
struct dirent* entry;
|
||||
DIR* dir;
|
||||
|
||||
eap_method_unload();
|
||||
modules = linked_list_create();
|
||||
|
||||
dir = opendir(directory);
|
||||
if (dir == NULL)
|
||||
{
|
||||
DBG1(DBG_CFG, "error opening EAP modules directory %s", directory);
|
||||
return;
|
||||
}
|
||||
|
||||
DBG1(DBG_CFG, "loading EAP modules from '%s'", directory);
|
||||
|
||||
while ((entry = readdir(dir)) != NULL)
|
||||
{
|
||||
char file[256];
|
||||
module_entry_t module, *loaded_module;
|
||||
eap_method_t *method;
|
||||
identification_t *id;
|
||||
char *ending;
|
||||
|
||||
snprintf(file, sizeof(file), "%s/%s", directory, entry->d_name);
|
||||
|
||||
ending = entry->d_name + strlen(entry->d_name) - 3;
|
||||
if (ending <= entry->d_name || !streq(ending, ".so"))
|
||||
{
|
||||
/* skip anything which does not look like a library */
|
||||
DBG2(DBG_CFG, " skipping %s, doesn't look like a library",
|
||||
entry->d_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* try to load the library */
|
||||
module.handle = dlopen(file, RTLD_LAZY);
|
||||
if (module.handle == NULL)
|
||||
{
|
||||
DBG1(DBG_CFG, " opening EAP module %s failed: %s", entry->d_name,
|
||||
dlerror());
|
||||
continue;
|
||||
}
|
||||
module.constructor = dlsym(module.handle, "eap_create");
|
||||
if (module.constructor == NULL)
|
||||
{
|
||||
DBG1(DBG_CFG, " EAP module %s has no eap_create() function, skipped",
|
||||
entry->d_name);
|
||||
dlclose(module.handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* get the type implemented in the method, create an instance for it */
|
||||
id = identification_create_from_string("[email protected]");
|
||||
method = module.constructor(EAP_SERVER, id, id);
|
||||
if (method == NULL)
|
||||
{
|
||||
method = module.constructor(EAP_PEER, id, id);
|
||||
}
|
||||
id->destroy(id);
|
||||
if (method == NULL)
|
||||
{
|
||||
DBG1(DBG_CFG, " unable to create instance of EAP method %s, skipped",
|
||||
entry->d_name);
|
||||
dlclose(module.handle);
|
||||
continue;
|
||||
}
|
||||
module.type = method->get_type(method, &module.vendor);
|
||||
method->destroy(method);
|
||||
|
||||
if (module.vendor)
|
||||
{
|
||||
DBG1(DBG_CFG, " loaded EAP method %d, vendor %d successfully from %s",
|
||||
module.type, module.vendor, entry->d_name);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(DBG_CFG, " loaded EAP method %N successfully from %s",
|
||||
eap_type_names, module.type, entry->d_name);
|
||||
}
|
||||
|
||||
loaded_module = malloc_thing(module_entry_t);
|
||||
memcpy(loaded_module, &module, sizeof(module));
|
||||
modules->insert_last(modules, loaded_module);
|
||||
}
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header.
|
||||
*/
|
||||
eap_method_t *eap_method_create(eap_type_t type, u_int32_t vendor, eap_role_t role,
|
||||
identification_t *server, identification_t *peer)
|
||||
{
|
||||
eap_method_t *method = NULL;
|
||||
iterator_t *iterator;
|
||||
module_entry_t *entry;
|
||||
|
||||
iterator = modules->create_iterator(modules, TRUE);
|
||||
while (iterator->iterate(iterator, (void**)&entry))
|
||||
{
|
||||
if (entry->type == type && entry->vendor == vendor)
|
||||
{
|
||||
method = entry->constructor(role, server, peer);
|
||||
if (method)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
iterator->destroy(iterator);
|
||||
|
||||
if (method == NULL)
|
||||
{
|
||||
if (vendor)
|
||||
{
|
||||
DBG1(DBG_CFG, "no vendor %d specific EAP module found for method "
|
||||
"%d %N", vendor, type, eap_role_names, role);
|
||||
}
|
||||
else
|
||||
{
|
||||
DBG1(DBG_CFG, "no EAP module found for %N %N",
|
||||
eap_type_names, type, eap_role_names, role);
|
||||
}
|
||||
}
|
||||
return method;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,3 @@
|
||||
/**
|
||||
* @file eap_method.h
|
||||
*
|
||||
* @brief Interface eap_method_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2006 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
@@ -18,6 +11,13 @@
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*
|
||||
* $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* @defgroup eap_method eap_method
|
||||
* @{ @ingroup eap
|
||||
*/
|
||||
|
||||
#ifndef EAP_METHOD_H_
|
||||
@@ -34,8 +34,6 @@ typedef enum eap_code_t eap_code_t;
|
||||
|
||||
/**
|
||||
* Role of an eap_method, SERVER or PEER (client)
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
enum eap_role_t {
|
||||
EAP_SERVER,
|
||||
@@ -43,15 +41,11 @@ enum eap_role_t {
|
||||
};
|
||||
/**
|
||||
* enum names for eap_role_t.
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
extern enum_name_t *eap_role_names;
|
||||
|
||||
/**
|
||||
* EAP types, defines the EAP method implementation
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
enum eap_type_t {
|
||||
EAP_IDENTITY = 1,
|
||||
@@ -68,15 +62,11 @@ enum eap_type_t {
|
||||
|
||||
/**
|
||||
* enum names for eap_type_t.
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
extern enum_name_t *eap_type_names;
|
||||
|
||||
/**
|
||||
* EAP code, type of an EAP message
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
enum eap_code_t {
|
||||
EAP_REQUEST = 1,
|
||||
@@ -87,14 +77,12 @@ enum eap_code_t {
|
||||
|
||||
/**
|
||||
* enum names for eap_code_t.
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
extern enum_name_t *eap_code_names;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Interface of an EAP method for server and client side.
|
||||
* Interface of an EAP method for server and client side.
|
||||
*
|
||||
* An EAP method initiates an EAP exchange and processes requests and
|
||||
* responses. An EAP method may need multiple exchanges before succeeding, and
|
||||
@@ -107,22 +95,16 @@ extern enum_name_t *eap_code_names;
|
||||
* authentication. Even if a mutual EAP method is used, the traditional
|
||||
* AUTH payloads are required. Only these include the nonces and messages from
|
||||
* ike_sa_init and therefore prevent man in the middle attacks.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - eap_method_create()
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
struct eap_method_t {
|
||||
|
||||
/**
|
||||
* @brief Initiate the EAP exchange.
|
||||
* Initiate the EAP exchange.
|
||||
*
|
||||
* initiate() is only useable for server implementations, as clients only
|
||||
* reply to server requests.
|
||||
* A eap_payload is created in "out" if result is NEED_MORE.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param out eap_payload to send to the client
|
||||
* @return
|
||||
* - NEED_MORE, if an other exchange is required
|
||||
@@ -131,11 +113,10 @@ struct eap_method_t {
|
||||
status_t (*initiate) (eap_method_t *this, eap_payload_t **out);
|
||||
|
||||
/**
|
||||
* @brief Process a received EAP message.
|
||||
* Process a received EAP message.
|
||||
*
|
||||
* A eap_payload is created in "out" if result is NEED_MORE.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param in eap_payload response received
|
||||
* @param out created eap_payload to send
|
||||
* @return
|
||||
@@ -147,31 +128,28 @@ struct eap_method_t {
|
||||
eap_payload_t **out);
|
||||
|
||||
/**
|
||||
* @brief Get the EAP type implemented in this method.
|
||||
* Get the EAP type implemented in this method.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param vendor pointer receiving vendor identifier for type, 0 for none
|
||||
* @return type of the EAP method
|
||||
*/
|
||||
eap_type_t (*get_type) (eap_method_t *this, u_int32_t *vendor);
|
||||
|
||||
/**
|
||||
* @brief Check if this EAP method authenticates the server.
|
||||
* Check if this EAP method authenticates the server.
|
||||
*
|
||||
* Some EAP methods provide mutual authentication and
|
||||
* allow authentication using only EAP, if the peer supports it.
|
||||
*
|
||||
* @param this calling object
|
||||
* @return TRUE if methods provides mutual authentication
|
||||
*/
|
||||
bool (*is_mutual) (eap_method_t *this);
|
||||
|
||||
/**
|
||||
* @brief Get the MSK established by this EAP method.
|
||||
* Get the MSK established by this EAP method.
|
||||
*
|
||||
* Not all EAP methods establish a shared secret.
|
||||
*
|
||||
* @param this calling object
|
||||
* @param msk chunk receiving internal stored MSK
|
||||
* @return
|
||||
* - SUCCESS, or
|
||||
@@ -180,68 +158,25 @@ struct eap_method_t {
|
||||
status_t (*get_msk) (eap_method_t *this, chunk_t *msk);
|
||||
|
||||
/**
|
||||
* @brief Destroys a eap_method_t object.
|
||||
*
|
||||
* @param this calling object
|
||||
* Destroys a eap_method_t object.
|
||||
*/
|
||||
void (*destroy) (eap_method_t *this);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates an EAP method for a specific type and role.
|
||||
*
|
||||
* @param eap_type EAP type to use
|
||||
* @param eap_vendor vendor identifier if a vendor specifc EAP type is used
|
||||
* @param role role of the eap_method, server or peer
|
||||
* @param server ID of acting server
|
||||
* @param peer ID of involved peer (client)
|
||||
* @return eap_method_t object
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
eap_method_t *eap_method_create(eap_type_t eap_type, u_int32_t eap_vendor,
|
||||
eap_role_t role, identification_t *server,
|
||||
identification_t *peer);
|
||||
|
||||
/**
|
||||
* @brief (Re-)Load all EAP modules in the EAP modules directory.
|
||||
*
|
||||
* For security reasons, the directory and all it's modules must be owned
|
||||
* by root and must not be writeable by someone else.
|
||||
*
|
||||
* @param dir directory of the EAP modules
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
void eap_method_load(char *directory);
|
||||
|
||||
/**
|
||||
* @brief Unload all loaded EAP modules
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
void eap_method_unload();
|
||||
|
||||
/**
|
||||
* @brief Constructor definition for a pluggable EAP module.
|
||||
* Constructor definition for a pluggable EAP method.
|
||||
*
|
||||
* Each EAP module must define a constructor function which will return
|
||||
* an initialized object with the methods defined in eap_method_t. The
|
||||
* constructor must be named eap_create() and it's signature must be equal
|
||||
* to that of eap_constructor_t.
|
||||
* A module may implement only a single role. If it does not support the role
|
||||
* requested, NULL should be returned. Multiple modules are allowed of the
|
||||
* same EAP type to support seperate implementations of peer/server.
|
||||
* an initialized object with the methods defined in eap_method_t.
|
||||
* Constructors for server and peers are identical, to support both roles
|
||||
* of a EAP method, a plugin needs register two constructors in the
|
||||
* eap_manager_t.
|
||||
*
|
||||
* @param role role the module will play, peer or server
|
||||
* @param server ID of the server to use for credential lookup
|
||||
* @param peer ID of the peer to use for credential lookup
|
||||
* @return implementation of the eap_method_t interface
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
typedef eap_method_t *(*eap_constructor_t)(eap_role_t role,
|
||||
identification_t *server,
|
||||
typedef eap_method_t *(*eap_constructor_t)(identification_t *server,
|
||||
identification_t *peer);
|
||||
|
||||
#endif /* EAP_METHOD_H_ */
|
||||
#endif /* EAP_METHOD_H_ @} */
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,114 +0,0 @@
|
||||
/**
|
||||
* @file eap_sim.h
|
||||
*
|
||||
* @brief Interface of eap_sim_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#ifndef EAP_SIM_H_
|
||||
#define EAP_SIM_H_
|
||||
|
||||
typedef struct eap_sim_t eap_sim_t;
|
||||
|
||||
#include <sa/authenticators/eap/eap_method.h>
|
||||
|
||||
/** the library containing with the triplet functions */
|
||||
#ifndef SIM_READER_LIB
|
||||
#error SIM_READER_LIB not specified, use --with-sim-reader option
|
||||
#endif /* SIM_READER_LIB */
|
||||
|
||||
/**
|
||||
* @brief Cardreaders SIM function.
|
||||
*
|
||||
* @param rand RAND to run algo with
|
||||
* @param rand_length length of value in rand
|
||||
* @param sres buffer to get SRES
|
||||
* @param sres_length size of buffer in sres, returns bytes written to SRES
|
||||
* @param kc buffer to get Kc
|
||||
* @param kc_length size of buffer in Kc, returns bytes written to Kc
|
||||
* @return zero on success
|
||||
*/
|
||||
typedef int (*sim_algo_t)(const unsigned char *rand, int rand_length,
|
||||
unsigned char *sres, int *sres_length,
|
||||
unsigned char *kc, int *kc_length);
|
||||
|
||||
#ifndef SIM_READER_ALG
|
||||
/** the SIM_READER_LIB's algorithm, uses sim_algo_t signature */
|
||||
#define SIM_READER_ALG "sim_run_alg"
|
||||
#endif /* SIM_READER_ALG */
|
||||
|
||||
/**
|
||||
* @brief Function to get a SIM triplet.
|
||||
*
|
||||
* @param identity identity (imsi) to get a triplet for
|
||||
* @param rand buffer to get RAND
|
||||
* @param rand_length size of buffer in rand, returns bytes written to RAND
|
||||
* @param sres buffer to get SRES
|
||||
* @param sres_length size of buffer in sres, returns bytes written to SRES
|
||||
* @param kc buffer to get Kc
|
||||
* @param kc_length size of buffer in Kc, returns bytes written to Kc
|
||||
* @return zero on success
|
||||
*/
|
||||
typedef int (*sim_get_triplet_t)(char *identity,
|
||||
unsigned char *rand, int *rand_length,
|
||||
unsigned char *sres, int *sres_length,
|
||||
unsigned char *kc, int *kc_length);
|
||||
|
||||
#ifndef SIM_READER_GET_TRIPLET
|
||||
/** the SIM_READER_LIB's get-triplet function, uses sim_get_triplet_t signature */
|
||||
#define SIM_READER_GET_TRIPLET "sim_get_triplet"
|
||||
#endif /* SIM_READER_GET_TRIPLET */
|
||||
|
||||
/**
|
||||
* @brief Implementation of the eap_method_t interface using EAP-SIM.
|
||||
*
|
||||
* This EAP-SIM client implementation uses another pluggable library to
|
||||
* access the SIM card/triplet provider. This module is specified using the
|
||||
* SIM_READER_LIB definition. It has to privde a sim_run_alg() function to
|
||||
* calculate a triplet (client), and/or a sim_get_triplet() function to get
|
||||
* a triplet (server). These functions are named to the SIM_READER_ALG and
|
||||
* the SIM_READER_GET_TRIPLET definitions.
|
||||
*
|
||||
* @b Constructors:
|
||||
* - eap_create() of this module
|
||||
* - eap_client_create() using eap_method EAP_SIM
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
struct eap_sim_t {
|
||||
|
||||
/**
|
||||
* Implemented eap_method_t interface.
|
||||
*/
|
||||
eap_method_t eap_method_interface;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Creates the EAP method EAP-SIM.
|
||||
*
|
||||
* @param role role of the module, client/server
|
||||
* @param server ID of the EAP server
|
||||
* @param peer ID of the EAP client
|
||||
* @return eap_sim_t object
|
||||
*
|
||||
* @ingroup eap
|
||||
*/
|
||||
eap_sim_t *eap_create(eap_role_t role,
|
||||
identification_t *server, identification_t *peer);
|
||||
|
||||
#endif /* EAP_SIM_H_ */
|
||||
@@ -1,288 +0,0 @@
|
||||
/**
|
||||
* @file eap_sim.h
|
||||
*
|
||||
* @brief Interface of eap_sim_t.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2007 Martin Willi
|
||||
* Hochschule fuer Technik Rapperswil
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <daemon.h>
|
||||
|
||||
#define IMSI_LEN 64
|
||||
#define RAND_LEN 16
|
||||
#define SRES_LEN 4
|
||||
#define KC_LEN 8
|
||||
|
||||
typedef struct triplet_t triplet_t;
|
||||
|
||||
struct triplet_t {
|
||||
unsigned char imsi[IMSI_LEN];
|
||||
unsigned char rand[RAND_LEN];
|
||||
unsigned char sres[SRES_LEN];
|
||||
unsigned char kc[KC_LEN];
|
||||
};
|
||||
|
||||
static triplet_t *triplets = NULL;
|
||||
static int triplet_count = 0;
|
||||
|
||||
#define TRIPLET_FILE IPSEC_CONFDIR "/ipsec.d/triplets.dat"
|
||||
|
||||
/**
|
||||
* convert a single HEX char to its integer value
|
||||
*/
|
||||
static int hexchr(char chr)
|
||||
{
|
||||
switch (chr)
|
||||
{
|
||||
case '0'...'9':
|
||||
return chr - '0';
|
||||
case 'A'...'F':
|
||||
return 10 + chr - 'A';
|
||||
case 'a'...'f':
|
||||
return 10 + chr - 'a';
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* convert a HEX string into a char array bin, limited by array length len
|
||||
*/
|
||||
static void hex2bin(char *hex, unsigned char *bin, size_t len)
|
||||
{
|
||||
char *pos;
|
||||
int i, even = 1;
|
||||
|
||||
pos = hex - 1;
|
||||
/* find the end, as we convert bottom up */
|
||||
while (TRUE)
|
||||
{
|
||||
switch (*(pos+1))
|
||||
{
|
||||
case '0'...'9':
|
||||
case 'A'...'F':
|
||||
case 'a'...'f':
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
/* convert two hex chars into a single bin byte */
|
||||
for (i = 0; pos >= hex && i < len; pos--)
|
||||
{
|
||||
if (even)
|
||||
{
|
||||
bin[len - 1 - i] = hexchr(*pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
bin[len - 1 - i] |= 16 * hexchr(*pos);
|
||||
i++;
|
||||
}
|
||||
even = !even;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* free up allocated triplets
|
||||
*/
|
||||
static void __attribute__ ((destructor)) free_triplets()
|
||||
{
|
||||
free(triplets);
|
||||
}
|
||||
|
||||
/**
|
||||
* read the triplets from the file, using freeradius triplet file syntax:
|
||||
* http://www.freeradius.org/radiusd/doc/rlm_sim_triplets
|
||||
*/
|
||||
static void __attribute__ ((constructor)) read_triplets()
|
||||
{
|
||||
char line[512], *data[4], *pos;
|
||||
FILE *file;
|
||||
int i, nr = 0;
|
||||
triplet_t *triplet;
|
||||
|
||||
file = fopen(TRIPLET_FILE, "r");
|
||||
if (file == NULL)
|
||||
{
|
||||
DBG1(DBG_CFG, "opening triplet file %s failed: %s",
|
||||
TRIPLET_FILE, strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (triplets)
|
||||
{
|
||||
free(triplets);
|
||||
triplets = NULL;
|
||||
triplet_count = 0;
|
||||
}
|
||||
|
||||
/* read line by line */
|
||||
while (fgets(line, sizeof(line), file))
|
||||
{
|
||||
nr++;
|
||||
/* skip comments, empty lines */
|
||||
switch (line[0])
|
||||
{
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '#':
|
||||
case '\0':
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
/* read comma separated values */
|
||||
pos = line;
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
data[i] = pos;
|
||||
pos = strchr(pos, ',');
|
||||
if (pos)
|
||||
{
|
||||
*pos = '\0';
|
||||
pos++;
|
||||
}
|
||||
else if (i != 3)
|
||||
{
|
||||
DBG1(DBG_CFG, "error in triplet file, line %d", nr);
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* allocate new triplet */
|
||||
triplet_count++;
|
||||
triplets = realloc(triplets, triplet_count * sizeof(triplet_t));
|
||||
triplet = &triplets[triplet_count - 1];
|
||||
memset(triplet, 0, sizeof(triplet_t));
|
||||
|
||||
/* convert/copy triplet data */
|
||||
for (i = 0; i < IMSI_LEN - 1; i++)
|
||||
{
|
||||
switch (data[0][i])
|
||||
{
|
||||
case '\n':
|
||||
case '\r':
|
||||
case '\0':
|
||||
break;
|
||||
default:
|
||||
triplet->imsi[i] = data[0][i];
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
hex2bin(data[1], triplet->rand, RAND_LEN);
|
||||
hex2bin(data[2], triplet->sres, SRES_LEN);
|
||||
hex2bin(data[3], triplet->kc, KC_LEN);
|
||||
|
||||
DBG4(DBG_CFG, "triplet: imsi %b\nrand %b\nsres %b\nkc %b",
|
||||
triplet->imsi, IMSI_LEN, triplet->rand, RAND_LEN,
|
||||
triplet->sres, SRES_LEN, triplet->kc, KC_LEN);
|
||||
}
|
||||
fclose(file);
|
||||
DBG2(DBG_CFG, "read %d triplets from %s", triplet_count, TRIPLET_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run the sim algorithm, see eap_sim.h
|
||||
*/
|
||||
int sim_run_alg(const unsigned char *rand, int rand_length,
|
||||
unsigned char *sres, int *sres_length,
|
||||
unsigned char *kc, int *kc_length)
|
||||
{
|
||||
int current;
|
||||
|
||||
if (rand_length != RAND_LEN ||
|
||||
*sres_length < SRES_LEN ||
|
||||
*kc_length < KC_LEN)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
for (current = 0; current < triplet_count; current++)
|
||||
{
|
||||
if (memcmp(triplets[current].rand, rand, RAND_LEN) == 0)
|
||||
{
|
||||
memcpy(sres, triplets[current].sres, SRES_LEN);
|
||||
memcpy(kc, triplets[current].kc, KC_LEN);
|
||||
*sres_length = SRES_LEN;
|
||||
*kc_length = KC_LEN;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single triplet, see_eap_sim.h
|
||||
*/
|
||||
int sim_get_triplet(char *imsi,
|
||||
unsigned char *rand, int *rand_length,
|
||||
unsigned char *sres, int *sres_length,
|
||||
unsigned char *kc, int *kc_length)
|
||||
{
|
||||
int current;
|
||||
triplet_t *triplet;
|
||||
static int skip = -1;
|
||||
|
||||
DBG2(DBG_CFG, "getting triplet for %s", imsi);
|
||||
|
||||
if (*rand_length < RAND_LEN ||
|
||||
*sres_length < SRES_LEN ||
|
||||
*kc_length < KC_LEN)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (triplet_count == 0)
|
||||
{
|
||||
return 2;
|
||||
}
|
||||
for (current = 0; current < triplet_count; current++)
|
||||
{
|
||||
triplet = &triplets[current];
|
||||
|
||||
if (streq(imsi, triplet->imsi))
|
||||
{
|
||||
/* skip triplet if already used */
|
||||
if (skip >= current)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*rand_length = RAND_LEN;
|
||||
*sres_length = SRES_LEN;
|
||||
*kc_length = KC_LEN;
|
||||
memcpy(rand, triplet->rand, RAND_LEN);
|
||||
memcpy(sres, triplet->sres, SRES_LEN);
|
||||
memcpy(kc, triplet->kc, KC_LEN);
|
||||
/* remember used triplet */
|
||||
skip = current;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (skip > -1)
|
||||
{
|
||||
/* no triplet left, reuse triplets */
|
||||
skip = -1;
|
||||
return sim_get_triplet(imsi, rand, rand_length,
|
||||
sres, sres_length, kc, kc_length);
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user