Commit 3cce2ae2 authored by HFJ's avatar HFJ

algorithm done

parent e053ef56
......@@ -41,7 +41,7 @@ typedef struct {
uint8_t kausf[32];
} _5G_HE_AV_t; // clause 6.3.6.2.5, ts33.501
typedef struct {
typedef struct _5G_AV_s{
uint8_t avType;
uint8_t rand[16];
uint8_t hxres[16];
......
......@@ -40,6 +40,15 @@ using namespace org::openapitools::server::model;
uint8_t XRES_STAR[16]; //store xres*
uint8_t KSEAF[32];
typedef struct {
uint8_t rand[16];
uint8_t autn[16];
uint8_t hxresStar[16];
uint8_t kseaf[32];
} AUSF_AV_s;
AUSF_AV_s ausf_av_s;
DefaultApiImpl::DefaultApiImpl(std::shared_ptr<Pistache::Rest::Router> rtr)
: DefaultApi(rtr) {}
......@@ -70,52 +79,75 @@ void DefaultApiImpl::ue_authentications_auth_ctx_id5g_aka_confirmation_put(
conv::hex_str_to_uint8(confirmationData.getResStar().c_str(), resStar); //string->uint8, res*(uint8)
cout << "\nres*" << endl;
for (int i = 0; i < 16; i++)printf("%x ", resStar[i]);
cout << endl;
/*---------------------认证确认-amf--------------------------------*/
ConfirmationDataResponse confirmResponse;
//1.验证AV是否过期: 认证成功后,AUSF将存储 KAUSF ?
bool is_auth_vectors_present = true;
//2.将接收到的RES*与存储的XRES*进行比较:RES*与XRES*相等,AUSF将从家庭网络角度认为认证成功
//get stored xres* -----
uint8_t xresStar[16] = {0};
memcpy(xresStar,XRES_STAR,16); //xres* stored for 5g-aka-confirmation
cout << "\nxres*" << endl;
for (int i = 0; i < 16; i++)printf("%x ", xresStar[i]);
cout << endl;
cout << "\nstring xres*" << endl;
cout << conv::uint8_to_hex_string(xresStar,16);
cout << endl;
//res* verification
bool authResult = true;
for (int i = 0; i < 16; i++)
{
if (xresStar[i] != resStar[i])
authResult = false;
}
confirmResponse.setAuthResult(authResult);
//av up to date?
if(!authResult) //fail
if(!is_auth_vectors_present) //AV expired
{
Logger::ausf_server().error("Authentication failure with authCtxId %s: res* != xres*",authCtxId.c_str());
Logger::ausf_server().error("Authentication failure by home network with authCtxId %s: AV expired",authCtxId.c_str());
confirmResponse.setAuthResult(is_auth_vectors_present); //向SEAF指示,从本地网络角度认证否成功
}
else //success
else //AV valid
{
Logger::ausf_server().info("Authentication successful by home network!");
// confirmResponse.setKseaf();
Logger::ausf_server().info("AV is up to date, handling received res*...");
//2.将接收到的RES*与存储的XRES*进行比较:RES*与XRES*相等,AUSF将从家庭网络角度认为认证成功
//get stored xres* -----
uint8_t xresStar[16] = {0};
memcpy(xresStar,XRES_STAR,16); //xres* stored for 5g-aka-confirmation
cout << "\nxres*" << endl;
for (int i = 0; i < 16; i++)printf("%x ", xresStar[i]);
cout << endl;
}
cout << "\nstring xres*" << endl;
cout << conv::uint8_to_hex_string(xresStar,16);
cout << endl;
//3.向SEAF指示,从本地网络角度认证是否成功
//4.将KSEAF 发送给SEAF
//res* verification
bool authResult = true;
for (int i = 0; i < 16; i++)
{
if (xresStar[i] != resStar[i])
authResult = false;
}
confirmResponse.setAuthResult(authResult); //3.向SEAF指示,从本地网络角度认证是否成功
if(!authResult) //fail
{
Logger::ausf_server().error("Authentication failure by home network with authCtxId %s: res* != xres*",authCtxId.c_str());
}
else //success
{
Logger::ausf_server().info("Authentication successful by home network!");
//4.send KSEAF to SEAF
string kseaf_s;
kseaf_s = conv::uint8_to_hex_string(ausf_av_s.kseaf, 32); // convert uint8_t to string
confirmResponse.setKseaf(kseaf_s);
//supi ignored
}
}
cout << "kseafIsSet" << confirmResponse.kseafIsSet() << endl;
cout << "supiIsSet " << confirmResponse.supiIsSet() << endl;
/*----------------ausf --> seaf-----------*/
//---forming response
nlohmann::json confirmResponse_json;
to_json(confirmResponse_json, confirmResponse);
cout << confirmResponse_json << endl;
Logger::ausf_server().info("Send 5g-aka-confirmation response to SEAF");
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
response.send(Pistache::Http::Code::Ok, confirmResponse_json.dump());
}
void DefaultApiImpl::ue_authentications_deregister_post(
......@@ -131,8 +163,8 @@ void DefaultApiImpl::ue_authentications_post(
Logger::ausf_server().debug("--ue_authentications_post--");
/*----------------------getting params-------------*/
Logger::ausf_server().info("servingNetworkName %s", authenticationInfo.getServingNetworkName());
Logger::ausf_server().info("supiOrSuci %s", authenticationInfo.getSupiOrSuci());
Logger::ausf_server().info("servingNetworkName %s", authenticationInfo.getServingNetworkName().c_str());
Logger::ausf_server().info("supiOrSuci %s", authenticationInfo.getSupiOrSuci().c_str());
//std::string snn = "5G:mnc001.mcc460.3gppnetwork.org";
std::string snn = authenticationInfo.getServingNetworkName();
//std::string imsi = "imsi-460010123456789";
......@@ -253,6 +285,21 @@ void DefaultApiImpl::ue_authentications_post(
for (int i = 0; i < 32; i++)printf("%x ", kseaf[i]);
cout << endl;
//store 5g av in ausf
memcpy(ausf_av_s.rand,rand_ausf,16);
memcpy(ausf_av_s.autn,autn_ausf,16);
memcpy(ausf_av_s.hxresStar,hxresStar,16);
memcpy(ausf_av_s.kseaf,kseaf,32);
cout << "\nausf_av_s.rand" << std::endl;
for (int i = 0; i < 16; i++)printf("%x ", ausf_av_s.rand[i]);
cout << "\nausf_av_s.autn" << std::endl;
for (int i = 0; i < 16; i++)printf("%x ", ausf_av_s.autn[i]);
cout << "\nausf_av_s.hxresStar" << std::endl;
for (int i = 0; i < 16; i++)printf("%x ", ausf_av_s.hxresStar[i]);
cout << "\nausf_av_s.kseaf" << std::endl;
for (int i = 0; i < 32; i++)printf("%x ", ausf_av_s.kseaf[i]);
cout << endl;
......@@ -273,10 +320,11 @@ void DefaultApiImpl::ue_authentications_post(
AuthResponse.setAutn(autn_s);
AuthResponse.setHxresStar(hxresStar_s);
nlohmann::json AuthResponse_json;
to_json(AuthResponse_json,AuthResponse);
cout << AuthResponse_json;
cout << AuthResponse_json << endl;
Logger::ausf_server().info("Send response to SEAF");
......
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