add test code, finished authentication

This commit is contained in:
Laurent
2020-09-21 15:11:02 +02:00
parent 693364ddc5
commit 93550b1cb0
12 changed files with 355 additions and 215 deletions

View File

@@ -22,6 +22,7 @@
*/
#include <openair3/UICC/usim_interface.h>
#include <openair3/NAS/COMMON/milenage.h>
#define UICC_SECTION "uicc"
#define UICC_CONFIG_HELP_OPTIONS " list of comma separated options to interface a simulated (real UICC to be developped). Available options: \n"\
@@ -42,29 +43,50 @@
};
const char *hexTable="0123456789abcdef";
static inline void to_hex(char *in, uint8_t *out, bool swap) {
if (swap)
for (size_t i=0; in[i]!=0; i++) {
out+=hexTable[in[i] & 0xf];
out+=hexTable[in[i]>>4 & 0xf];
} else {
for (size_t i=0; in[i]!=0; i++) {
out+=hexTable[in[i]>>4 & 0xf];
out+=hexTable[in[i] & 0xf];
}
static inline uint8_t mkDigit(unsigned char in) {
for (int i=0; i<16; i++)
if (in==hexTable[i])
return i;
LOG_E(SIM,"Impossible hexa input: %c\n",in);
return 0;
}
static inline void to_hex(char *in, uint8_t *out, int size) {
for (size_t i=0; in[i]!=0 && i < size*2 ; i+=2) {
*out++=(mkDigit(in[i]) << 4) | mkDigit(in[i+1]);
}
}
uicc_t *init_uicc(char *sectionName) {
uicc_t *uicc=(uicc_t *)calloc(sizeof(uicc_t),1);
paramdef_t uicc_params[] = UICC_PARAMS_DESC;
// here we call usim simulation, but calling actual usim is quite simple
// the code is in open-cells.com => program_uicc open source
// we can read the IMSI from the USIM
// key, OPc, sqn, amf don't need to be read from the true USIM
int ret = config_get( uicc_params,sizeof(uicc_params)/sizeof(paramdef_t),sectionName);
AssertFatal(ret >= 0, "configuration couldn't be performed");
LOG_I(HW, "UICC simulation: IMSI=%s, Ki=%s, OPc=%s\n", uicc->imsiStr, uicc->keyStr, uicc->opcStr);
to_hex(uicc->keyStr,uicc->key, false);
to_hex(uicc->opcStr,uicc->opc, false);
to_hex(uicc->sqnStr,uicc->sqn, false);
to_hex(uicc->amfStr,uicc->amf, false);
LOG_I(SIM, "UICC simulation: IMSI=%s, Ki=%s, OPc=%s\n", uicc->imsiStr, uicc->keyStr, uicc->opcStr);
to_hex(uicc->keyStr,uicc->key, sizeof(uicc->key) );
to_hex(uicc->opcStr,uicc->opc, sizeof(uicc->opc) );
to_hex(uicc->sqnStr,uicc->sqn, sizeof(uicc->sqn) );
to_hex(uicc->amfStr,uicc->amf, sizeof(uicc->amf) );
return uicc;
}
void uicc_milenage_generate(uint8_t *autn, uicc_t *uicc) {
// here we call usim simulation, but calling actual usim is quite simple
// the code is in open-cells.com => program_uicc open source
milenage_generate(uicc->opc, uicc->amf, uicc->key,
uicc->sqn, uicc->rand, autn, uicc->ik, uicc->ck, uicc->milenage_res);
log_dump(SIM,uicc->opc,sizeof(uicc->opc), LOG_DUMP_CHAR,"opc:");
log_dump(SIM,uicc->amf,sizeof(uicc->amf), LOG_DUMP_CHAR,"amf:");
log_dump(SIM,uicc->key,sizeof(uicc->key), LOG_DUMP_CHAR,"key:");
log_dump(SIM,uicc->sqn,sizeof(uicc->sqn), LOG_DUMP_CHAR,"sqn:");
log_dump(SIM,uicc->rand,sizeof(uicc->rand), LOG_DUMP_CHAR,"rand:");
log_dump(SIM,uicc->ik,sizeof(uicc->ik), LOG_DUMP_CHAR,"milenage output ik:");
log_dump(SIM,uicc->ck,sizeof(uicc->ck), LOG_DUMP_CHAR,"milenage output ck:");
log_dump(SIM,uicc->milenage_res,sizeof(uicc->milenage_res), LOG_DUMP_CHAR,"milenage output res:");
log_dump(SIM,autn,sizeof(autn), LOG_DUMP_CHAR,"milenage output autn:");
}

View File

@@ -35,6 +35,14 @@
#include <common/config/config_userapi.h>
#include "common_lib.h"
/* 3GPP glossary
RES RESponse
XRES eXpected RESponse
HRES Hash RESponse
HXRES Hash eXpected RESponse
So, RES can be either milenage res, or received response, so hash of milenage res
*/
typedef struct {
char *imsiStr;
char *keyStr;
@@ -48,10 +56,16 @@ typedef struct {
int nmc_size;
uint8_t rand[16];
uint8_t autn[16];
uint8_t ak[6];
uint8_t akstar[6];
uint8_t ck[16];
uint8_t ik[16];
uint8_t milenage_res[8];
} uicc_t;
/*
* Read the configuration file, section name variable to be able to manage several UICC
*/
uicc_t *init_uicc(char *sectionName);
void uicc_milenage_generate(uint8_t * autn, uicc_t *uicc);
#endif