Commit eb05f8d6 authored by Tien-Thinh Nguyen's avatar Tien-Thinh Nguyen

support multiple UEs

parent 36cfa8c5
......@@ -78,6 +78,26 @@ ausf_app::~ausf_app() {
Logger::ausf_app().debug("Delete AUSF_APP instance...");
}
//------------------------------------------------------------------------------
bool ausf_app::is_supi_2_security_context(const std::string& supi) const {
std::shared_lock lock(m_supi2security_context);
return bool{supi2security_context.count(supi) > 0};
}
//------------------------------------------------------------------------------
std::shared_ptr<security_context> ausf_app::supi_2_security_context(
const std::string& supi) const {
std::shared_lock lock(m_supi2security_context);
return supi2security_context.at(supi);
}
//------------------------------------------------------------------------------
void ausf_app::set_supi_2_security_context(
const std::string& supi, std::shared_ptr<security_context> sc) {
std::unique_lock lock(m_supi2security_context);
supi2security_context[supi] = sc;
}
//------------------------------------------------------------------------------
void ausf_app::handle_ue_authentications(
const AuthenticationInfo& authenticationInfo, nlohmann::json& json_data,
......@@ -93,6 +113,7 @@ void ausf_app::handle_ue_authentications(
std::string snn =
authenticationInfo.getServingNetworkName(); // serving network name
std::string supi = authenticationInfo.getSupiOrSuci(); // supi
// TODO: supi64_t supi64 = {};
Logger::ausf_server().info("servingNetworkName %s", snn.c_str());
Logger::ausf_server().info("supiOrSuci %s", supi.c_str());
......@@ -238,6 +259,41 @@ void ausf_app::handle_ue_authentications(
KAUSF_TMP =
conv::uint8_to_hex_string(kausf_ausf, 32); // store kausf_tmp in ausf
// Store the security context
std::shared_ptr<security_context> sc = {};
if (is_supi_2_security_context(supi)) {
Logger::ausf_app().debug("Update SMF context with SUPI: ", supi);
sc = supi_2_security_context(supi);
sc->supi_ausf = supi; // TODO: setter/getter
memcpy(sc->ausf_av_s.rand, rand_ausf, 16); // store 5g av in ausf
memcpy(sc->ausf_av_s.autn, autn_ausf, 16);
memcpy(sc->ausf_av_s.hxresStar, hxresStar, 16);
memcpy(sc->ausf_av_s.kseaf, kseaf, 32);
memcpy(sc->xres_star, xresStar, 16); // store xres* in ausf
sc->supi_ausf = authenticationInfo.getSupiOrSuci(); // store supi in ausf
sc->serving_nn = snn; // store snn in ausf
sc->auth_type = authType_udm; // store authType in ausf
sc->kausf_tmp =
conv::uint8_to_hex_string(kausf_ausf, 32); // store kausf_tmp in ausf
} else {
Logger::ausf_app().debug("Create a new security context with SUPI ", supi);
// sc = std::shared_ptr<security_context>(new security_context());
sc = std::make_shared<security_context>();
sc->supi_ausf = supi; // TODO: setter/getter
memcpy(sc->ausf_av_s.rand, rand_ausf, 16); // store 5g av in ausf
memcpy(sc->ausf_av_s.autn, autn_ausf, 16);
memcpy(sc->ausf_av_s.hxresStar, hxresStar, 16);
memcpy(sc->ausf_av_s.kseaf, kseaf, 32);
memcpy(sc->xres_star, xresStar, 16); // store xres* in ausf
sc->supi_ausf = authenticationInfo.getSupiOrSuci(); // store supi in ausf
sc->serving_nn = snn; // store snn in ausf
sc->auth_type = authType_udm; // store authType in ausf
sc->kausf_tmp =
conv::uint8_to_hex_string(kausf_ausf, 32); // store kausf_tmp in ausf
set_supi_2_security_context(supi, sc);
}
/*----------------ausf --> seaf-----------*/
//---form UEAuthenticationCtx
UEAuthenticationCtx UEAuthCtx;
......
......@@ -35,6 +35,8 @@
#include "UEAuthenticationCtx.h"
#include "ConfirmationData.h"
#include "ausf.h"
#include <map>
#include <shared_mutex>
namespace oai {
namespace ausf {
......@@ -42,6 +44,26 @@ namespace app {
using namespace oai::ausf_server::model;
class security_context {
public:
security_context() : xres_star() {
// supi = {};
ausf_av_s = {};
supi_ausf = "";
auth_type = "";
serving_nn = "";
kausf_tmp = "";
}
// supi64_t supi;
AUSF_AV_s ausf_av_s;
uint8_t xres_star[16]; // store xres*
std::string supi_ausf; // store supi
std::string auth_type; // store authType
std::string serving_nn; // store serving network name
std::string kausf_tmp; // store Kausf(string)
};
// class ausf_config;
class ausf_app {
public:
......@@ -59,6 +81,12 @@ class ausf_app {
const std::string& authCtxId, const ConfirmationData& confirmation_data,
nlohmann::json& json_data, uint16_t& http_response_code);
bool is_supi_2_security_context(const std::string& supi) const;
std::shared_ptr<security_context> supi_2_security_context(
const std::string& supi) const;
void set_supi_2_security_context(
const std::string& supi, std::shared_ptr<security_context> sc);
private:
AUSF_AV_s ausf_av_s;
// stored temporarily
......@@ -67,6 +95,13 @@ class ausf_app {
std::string AUTH_TYPE; // store authType
std::string SERVING_NN; // store serving network name
std::string KAUSF_TMP; // store Kausf(string)
std::map<supi64_t, std::shared_ptr<security_context>> imsi2security_context;
mutable std::shared_mutex m_imsi2security_context;
std::map<std::string, std::shared_ptr<security_context>>
supi2security_context;
mutable std::shared_mutex m_supi2security_context;
};
} // namespace app
} // namespace ausf
......
......@@ -81,4 +81,6 @@ typedef struct {
uint8_t kseaf[32];
} AUSF_AV_s;
typedef uint64_t supi64_t;
#endif
......@@ -199,3 +199,13 @@ void conv::hex_str_to_uint8(const char* string, uint8_t* des) {
index++;
}
}
uint64_t supi_to_u64(std::string& supi) {
uint64_t uint_supi;
try {
uint_supi = std::stoull(supi, nullptr, 10);
} catch (const std::exception& e) {
}
return uint_supi;
}
......@@ -57,5 +57,6 @@ class conv {
const uint8_t digit1, const uint8_t digit2, const uint8_t digit3);
static std::string uint8_to_hex_string(const uint8_t* v, const size_t s);
static void hex_str_to_uint8(const char* string, uint8_t* des);
static uint64_t supi_to_u64(std::string& supi);
};
#endif /* FILE_CONVERSIONS_HPP_SEEN */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment