Making the SQN readable from the csv database file

master
David Rupprecht 7 years ago
parent e8985dbdbc
commit 1aced47d6a

@ -56,6 +56,7 @@ typedef struct{
uint8_t key[16];
uint8_t op[16];
uint8_t amf[2];
uint8_t sqn[6];
}hss_ue_ctx_t;
enum hss_auth_algo {
@ -74,9 +75,8 @@ public:
bool set_auth_algo(std::string auth_algo);
bool read_db_file(std::string db_file);
void get_sqn(uint8_t sqn[6]);
void gen_rand(uint8_t rand_[16]);
bool get_k_amf_op(uint64_t imsi, uint8_t *k, uint8_t *amf, uint8_t *op);
bool get_k_amf_op_sqn(uint64_t imsi, uint8_t *k, uint8_t *amf, uint8_t *op, uint8_t *sqn);
bool gen_auth_info_answer(uint64_t imsi, uint8_t *k_asme, uint8_t *autn, uint8_t *rand, uint8_t *xres);
bool gen_auth_info_answer_milenage(uint64_t imsi, uint8_t *k_asme, uint8_t *autn, uint8_t *rand, uint8_t *xres);
bool gen_auth_info_answer_xor(uint64_t imsi, uint8_t *k_asme, uint8_t *autn, uint8_t *rand, uint8_t *xres);
@ -90,7 +90,6 @@ private:
virtual ~hss();
static hss *m_instance;
uint64_t m_sqn; //48 bits
srslte::byte_buffer_pool *m_pool;
std::ifstream m_db_file;

@ -39,8 +39,6 @@ hss* hss::m_instance = NULL;
boost::mutex hss_instance_mutex;
hss::hss()
// :m_sqn(0x112233445566)
:m_sqn(0)
{
m_pool = srslte::byte_buffer_pool::get_instance();
return;
@ -152,7 +150,7 @@ hss::read_db_file(std::string db_filename)
if(line[0] != '#')
{
std::vector<std::string> split = split_string(line,',');
if(split.size()!=5)
if(split.size()!=6)
{
m_hss_log->error("Error parsing UE database\n");
return false;
@ -163,11 +161,13 @@ hss::read_db_file(std::string db_filename)
get_uint_vec_from_hex_str(split[2],ue_ctx->key,16);
get_uint_vec_from_hex_str(split[3],ue_ctx->op,16);
get_uint_vec_from_hex_str(split[4],ue_ctx->amf,2);
get_uint_vec_from_hex_str(split[5],ue_ctx->sqn,6);
m_hss_log->debug("Added user from DB, IMSI: %015lu\n", ue_ctx->imsi);
m_hss_log->debug_hex(ue_ctx->key, 16, "User Key : ");
m_hss_log->debug_hex(ue_ctx->op, 16, "User OP : ");
m_hss_log->debug_hex(ue_ctx->amf, 2, "AMF : ");
m_hss_log->debug_hex(ue_ctx->sqn, 6, "SQN : ");
m_imsi_to_ue_ctx.insert(std::pair<uint64_t,hss_ue_ctx_t*>(ue_ctx->imsi,ue_ctx));
}
@ -207,12 +207,11 @@ hss::gen_auth_info_answer_milenage(uint64_t imsi, uint8_t *k_asme, uint8_t *autn
uint8_t mac[8];
if(!get_k_amf_op(imsi,k,amf,op))
if(!get_k_amf_op_sqn(imsi, k, amf, op, sqn))
{
return false;
}
gen_rand(rand);
get_sqn(sqn);
security_milenage_f2345( k,
op,
@ -289,12 +288,11 @@ hss::gen_auth_info_answer_xor(uint64_t imsi, uint8_t *k_asme, uint8_t *autn, uin
int i = 0;
if(!get_k_amf_op(imsi,k,amf,op))
if(!get_k_amf_op_sqn(imsi, k, amf, op, sqn))
{
return false;
}
gen_rand(rand);
get_sqn(sqn);
// Use RAND and K to compute RES, CK, IK and AK
for(i=0; i<16; i++) {
@ -381,7 +379,7 @@ hss::gen_auth_info_answer_xor(uint64_t imsi, uint8_t *k_asme, uint8_t *autn, uin
bool
hss::get_k_amf_op(uint64_t imsi, uint8_t *k, uint8_t *amf, uint8_t *op )
hss::get_k_amf_op_sqn(uint64_t imsi, uint8_t *k, uint8_t *amf, uint8_t *op, uint8_t *sqn)
{
/*
@ -401,20 +399,11 @@ hss::get_k_amf_op(uint64_t imsi, uint8_t *k, uint8_t *amf, uint8_t *op )
memcpy(k, ue_ctx->key, 16);
memcpy(amf, ue_ctx->amf, 2);
memcpy(op, ue_ctx->op, 16);
memcpy(sqn, ue_ctx->sqn, 6);
return true;
}
void
hss::get_sqn(uint8_t sqn[6])
{
for (int i=0; i<6; i++)
{
sqn[i] = ((uint8_t *)&m_sqn)[i];
}
m_sqn++;
return; //TODO See TS 33.102, Annex C
}
void
hss::gen_rand(uint8_t rand_[16])

@ -6,8 +6,9 @@
# IMSI: UE's IMSI value
# Key: UE's key, where other keys are derived from. Stored in hexadecimal
# OP: Operator's code, sotred in hexadecimal
# AMF: Authentication management feild, stored in hexadecimal
# AMF: Authentication management field, stored in hexadecimal
# SQN: UE's Sequence number for freshness of the authentication
#
# Note: Lines starting by '#' are ignored
ue1,001010123456789,00112233445566778899aabbccddeeff,63BFA50EE6523365FF14C1F45F88737D,9001
ue2,001010123456780,00112233445566778899aabbccddeeaa,63BFA50EE6523365FF14C1F45F88737D,2000
ue1,001010123456789,00112233445566778899aabbccddeeff,63BFA50EE6523365FF14C1F45F88737D,9001,000000001234
ue2,001010123456780,00112233445566778899aabbccddeeaa,63BFA50EE6523365FF14C1F45F88737D,2000,000000001235

Loading…
Cancel
Save