Moved some helper setters/getters to hss_ue_ctx_t to remove more useless lookups.

master
Pedro Alvarez 5 years ago
parent 88c7988813
commit 3d4f300b6f

@ -53,6 +53,7 @@ typedef struct {
enum hss_auth_algo { HSS_ALGO_XOR, HSS_ALGO_MILENAGE }; enum hss_auth_algo { HSS_ALGO_XOR, HSS_ALGO_MILENAGE };
typedef struct { typedef struct {
// Members
std::string name; std::string name;
uint64_t imsi; uint64_t imsi;
enum hss_auth_algo algo; enum hss_auth_algo algo;
@ -65,6 +66,11 @@ typedef struct {
uint16_t qci; uint16_t qci;
uint8_t last_rand[16]; uint8_t last_rand[16];
std::string static_ip_addr; std::string static_ip_addr;
// Helper getters/setters
void set_sqn(uint8_t* sqn_);
void set_last_rand(uint8_t* rand_);
void get_last_rand(uint8_t* rand_);
} hss_ue_ctx_t; } hss_ue_ctx_t;
class hss : public hss_interface_nas class hss : public hss_interface_nas
@ -95,8 +101,8 @@ private:
void gen_auth_info_answer_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* k_asme, uint8_t* autn, uint8_t* rand, uint8_t* xres); void gen_auth_info_answer_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* k_asme, uint8_t* autn, uint8_t* rand, uint8_t* xres);
void gen_auth_info_answer_xor(hss_ue_ctx_t* ue_ctx, uint8_t* k_asme, uint8_t* autn, uint8_t* rand, uint8_t* xres); void gen_auth_info_answer_xor(hss_ue_ctx_t* ue_ctx, uint8_t* k_asme, uint8_t* autn, uint8_t* rand, uint8_t* xres);
bool resync_sqn_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* auts); void resync_sqn_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* auts);
bool resync_sqn_xor(hss_ue_ctx_t* ue_ctx, uint8_t* auts); void resync_sqn_xor(hss_ue_ctx_t* ue_ctx, uint8_t* auts);
std::vector<std::string> split_string(const std::string& str, char delimiter); std::vector<std::string> split_string(const std::string& str, char delimiter);
void get_uint_vec_from_hex_str(const std::string& key_str, uint8_t* key, uint len); void get_uint_vec_from_hex_str(const std::string& key_str, uint8_t* key, uint len);
@ -104,10 +110,6 @@ private:
void increment_ue_sqn(hss_ue_ctx_t* ue_ctx); void increment_ue_sqn(hss_ue_ctx_t* ue_ctx);
void increment_seq_after_resync(hss_ue_ctx_t* ue_ctx); void increment_seq_after_resync(hss_ue_ctx_t* ue_ctx);
void increment_sqn(uint8_t* sqn, uint8_t* next_sqn); void increment_sqn(uint8_t* sqn, uint8_t* next_sqn);
void set_sqn(uint64_t imsi, uint8_t* sqn);
void set_last_rand(uint64_t imsi, uint8_t* rand);
void get_last_rand(uint64_t imsi, uint8_t* rand);
bool set_auth_algo(std::string auth_algo); bool set_auth_algo(std::string auth_algo);
bool read_db_file(std::string db_file); bool read_db_file(std::string db_file);
@ -127,5 +129,19 @@ private:
std::map<std::string, uint64_t> m_ip_to_imsi; std::map<std::string, uint64_t> m_ip_to_imsi;
}; };
inline void hss_ue_ctx_t::set_sqn(uint8_t* sqn_)
{
memcpy(sqn, sqn_, 6);
}
inline void hss_ue_ctx_t::set_last_rand(uint8_t* last_rand_)
{
memcpy(last_rand, last_rand_, 16);
}
inline void hss_ue_ctx_t::get_last_rand(uint8_t* last_rand_)
{
memcpy(last_rand_, last_rand, 16);
}
} // namespace srsepc } // namespace srsepc
#endif // SRSEPC_HSS_H #endif // SRSEPC_HSS_H

@ -328,7 +328,7 @@ void hss::gen_auth_info_answer_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* k_asme, u
m_hss_log->debug_hex(autn, 16, "User AUTN: "); m_hss_log->debug_hex(autn, 16, "User AUTN: ");
// Set last RAND // Set last RAND
memcpy(ue_ctx->last_rand, rand, 16); ue_ctx->set_last_rand(rand);
return; return;
} }
@ -423,7 +423,7 @@ void hss::gen_auth_info_answer_xor(hss_ue_ctx_t* ue_ctx, uint8_t* k_asme, uint8_
m_hss_log->debug_hex(autn, 8, "User AUTN: "); m_hss_log->debug_hex(autn, 8, "User AUTN: ");
// Set last RAND // Set last RAND
memcpy(ue_ctx->last_rand, rand, 16); ue_ctx->set_last_rand(rand);
return; return;
} }
@ -468,28 +468,27 @@ bool hss::resync_sqn(uint64_t imsi, uint8_t* auts)
return false; return false;
} }
bool ret = false; //FIXME
switch (ue_ctx->algo) { switch (ue_ctx->algo) {
case HSS_ALGO_XOR: case HSS_ALGO_XOR:
ret = resync_sqn_xor(ue_ctx, auts); resync_sqn_xor(ue_ctx, auts);
break; break;
case HSS_ALGO_MILENAGE: case HSS_ALGO_MILENAGE:
ret = resync_sqn_milenage(ue_ctx, auts); resync_sqn_milenage(ue_ctx, auts);
break; break;
} }
increment_seq_after_resync(ue_ctx); increment_seq_after_resync(ue_ctx);
return ret; return true;
} }
bool hss::resync_sqn_xor(hss_ue_ctx_t* ue_ctx, uint8_t* auts) void hss::resync_sqn_xor(hss_ue_ctx_t* ue_ctx, uint8_t* auts)
{ {
m_hss_log->error("XOR SQN synchronization not supported yet\n"); m_hss_log->error("XOR SQN synchronization not supported yet\n");
m_hss_log->console("XOR SQNs synchronization not supported yet\n"); m_hss_log->console("XOR SQNs synchronization not supported yet\n");
return false; return;
} }
bool hss::resync_sqn_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* auts) void hss::resync_sqn_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* auts)
{ {
// Get K, AMF, OPC and SQN // Get K, AMF, OPC and SQN
uint8_t *k = ue_ctx->key; uint8_t *k = ue_ctx->key;
@ -503,7 +502,7 @@ bool hss::resync_sqn_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* auts)
uint8_t mac_s[8]; uint8_t mac_s[8];
uint8_t sqn_ms_xor_ak[6]; uint8_t sqn_ms_xor_ak[6];
get_last_rand(ue_ctx->imsi, last_rand); ue_ctx->get_last_rand(last_rand);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
sqn_ms_xor_ak[i] = auts[i]; sqn_ms_xor_ak[i] = auts[i];
@ -538,8 +537,8 @@ bool hss::resync_sqn_milenage(hss_ue_ctx_t* ue_ctx, uint8_t* auts)
srslte::security_milenage_f1_star(k, opc, last_rand, sqn_ms, dummy_amf, mac_s_tmp); srslte::security_milenage_f1_star(k, opc, last_rand, sqn_ms, dummy_amf, mac_s_tmp);
m_hss_log->debug_hex(mac_s_tmp, 8, "MAC calc : "); m_hss_log->debug_hex(mac_s_tmp, 8, "MAC calc : ");
set_sqn(ue_ctx->imsi, sqn_ms); ue_ctx->set_sqn(sqn_ms);
return true; return;
} }
void hss::increment_ue_sqn(hss_ue_ctx_t* ue_ctx) void hss::increment_ue_sqn(hss_ue_ctx_t* ue_ctx)
@ -609,33 +608,6 @@ void hss::increment_seq_after_resync(hss_ue_ctx_t* ue_ctx)
return; return;
} }
void hss::set_sqn(uint64_t imsi, uint8_t* sqn)
{
hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
if (ue_ctx == nullptr) {
return;
}
memcpy(ue_ctx->sqn, sqn, 6);
}
void hss::set_last_rand(uint64_t imsi, uint8_t* rand)
{
hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
if (ue_ctx == nullptr) {
return;
}
memcpy(ue_ctx->last_rand, rand, 16);
}
void hss::get_last_rand(uint64_t imsi, uint8_t* rand)
{
hss_ue_ctx_t* ue_ctx = get_ue_ctx(imsi);
if (ue_ctx == nullptr) {
return;
}
memcpy(rand, ue_ctx->last_rand, 16);
}
void hss::gen_rand(uint8_t rand_[16]) void hss::gen_rand(uint8_t rand_[16])
{ {
for (int i = 0; i < 16; i++) { for (int i = 0; i < 16; i++) {

Loading…
Cancel
Save