Commit bbe21d53 authored by HFJ's avatar HFJ

add udm post-normal

parent acf97707
......@@ -25,6 +25,7 @@ First of all, you need to download and install the libraries listed [here](#libr
Once the libraries are installed, in order to compile and run the server please follow the steps below:
```bash
cd src
mkdir build
cd build
cmake ..
......@@ -35,9 +36,8 @@ Once compiled run the server:
```bash
cd build
./api-server
or ./ausf -c ../etc/ausf.conf -o -r
or ./ausf -c ../../etc/ausf.conf -o -r
./ausf -c ../../etc/ausf.conf -o -r
#or ./ausf -c ../etc/ausf.conf -o -r
```
## Libraries required
......
......@@ -26,22 +26,27 @@ AUSF =
INTERFACES:{
SBI_AUSF:{
INTERFACE_NAME = "ens33"; #interface for providing ausf service
IPV4_ADDRESS = "192.168.21.133/24";#"192.168.61.141/24"; #address for intercafe (cidr)
IPV4_ADDRESS = "192.168.21.136/24"; #"192.168.61.141/24"; #address for intercafe (cidr)
PORT = 8282; #ausf service port
PPID = 60;
};
NUDM:{
INTERFACE_NAME = "ens33"; #interface for providing udm service
IPV4_ADDRESS = "192.168.21.133/24"; #address for intercafe (cidr)
IPV4_ADDRESS = "192.168.21.136/24"; #address for intercafe (cidr)
PORT = 8181; #udm service port
#PPID = 60;
};
NUDR:{
INTERFACE_NAME = "ens33"; #interface for request for udr service
IPV4_ADDRESS = "192.168.21.133/24"; #udr address (cidr)
PORT = 8080; #udr port
VERSION = "v2";
NAMF:{
INTERFACE_NAME = "ens33"; #interface for request for amf service
IPV4_ADDRESS = "192.168.21.136/24"; #amf address (cidr)
PORT = 8383; #amf port
};
# NUDR:{
# INTERFACE_NAME = "ens33"; #interface for request for udr service
# IPV4_ADDRESS = "192.168.21.133/24"; #udr address (cidr)
# PORT = 8080; #udr port
# VERSION = "v2";
# };
};
# CORE_CONFIGURATION:{
......
......@@ -23,6 +23,7 @@
#include "sha256.hpp"
#include "UEAuthenticationCtx.h"
#include "ConfirmationDataResponse.h"
#include "AuthenticationInfo.h"
#include <typeinfo>
#include <map>
......@@ -165,72 +166,72 @@ void DefaultApiImpl::ue_authentications_post(
/*----------------------getting params-------------*/
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";
std::string supi = authenticationInfo.getSupiOrSuci();
//uint64_t _imsi = fromString<uint64_t>(imsi);
std::string snn = authenticationInfo.getServingNetworkName(); //serving network name
std::string supi = authenticationInfo.getSupiOrSuci(); //supi
/* -----------5g he av from udm-----------------*/
//UDM GET interface ----- get authentication related info--------------------
std::string udm_ip = std::string(inet_ntoa (*((struct in_addr *)&ausf_cfg.nudm.addr4))); //need to change to nudm
std::string udm_port = std::to_string(ausf_cfg.nudm.port);
std::string udmUri;
std::string Method;
std::string Response;
//UDM POST interface ----- get authentication related info--------------------
udmUri = "http://" + udm_ip+ ":" + udm_port + "/nudm-ueau/v1/" + supi + "/security-information/generate-auth-data";
//udmUri = "http://192.168.21.134:8181/nudm-ueau/v1/imsi-460011111111111/security-information/generate-auth-data";
Logger::ausf_server().debug("POST Request:" + udmUri);
Method = "POST";
//form udm request body AuthInso
nlohmann::json AuthInfo = {}; //model AuthenticationInfo do not have ausfInstanceId field
AuthInfo["servingNetworkName"] = snn;
AuthInfo["ausfInstanceId"] = "400346f4-087e-40b1-a4cd-00566953999d"; //fixed, may need to change
Curl::curl_http_client(udmUri, Method, AuthInfo.dump() , Response);
nlohmann::json response_data = {};
try
{
response_data = nlohmann::json::parse(Response.c_str());
}
catch (nlohmann::json::exception &e)
{
Logger::ausf_server().info("Could not get Json content from UDM response");
//TODO: error handling
}
cout << response_data.dump() << endl;
// std::string udm_ip = std::string(inet_ntoa (*((struct in_addr *)&ausf_cfg.nudr.addr4))); //need to change to nudr
// std::string udm_port = std::to_string(ausf_cfg.nudr.port);
// std::string udmUri;
// std::string Method;
// std::string Response;
// //UDM GET interface ----- get authentication related info--------------------
// udmUri = "http://192.168.21.134:8181/nudm-ueau/v1/imsi-460011111111111/security-information/generate-auth-data";
// Logger::ausf_server().debug("POST Request:" + udmUri);
// Method = "POST";
// nlohmann::json AuthInfo = {};
// AuthInfo["servingNetworkName"] = "5G:mnc001.mcc460.3gppnetwork.org";
// AuthInfo["ausfInstanceId"] = "400346f4-087e-40b1-a4cd-00566953999d";
// Curl::curl_http_client(udmUri, Method, AuthInfo.dump() , Response);
// nlohmann::json response_data = {};
// try
// {
// response_data = nlohmann::json::parse(Response.c_str());
// }
// catch (nlohmann::json::exception &e)
// {
// Logger::ausf_server().info("Could not get Json content from UDR response");
// //TODO: error handling
// }
// cout << response_data.dump() << endl;
//args
//uint8_t rand[] = {0x23, 0x55, 0x3c, 0xbe, 0x96, 0x37, 0xa8, 0x9d, 0x21, 0x8a, 0xe6, 0x4d, 0xae, 0x47, 0xbf, 0x35};
uint8_t rand[] = {0};
uint8_t opc[] = {0xcd, 0x63, 0xcb, 0x71, 0x95, 0x4a, 0x9f, 0x4e, 0x48, 0xa5, 0x99, 0x4e, 0x37, 0xa0, 0x2b, 0xaf};
uint8_t key[] = {0x46, 0x5b, 0x5c, 0xe8, 0xb1, 0x99, 0xb4, 0x9f, 0xaa, 0x5f, 0x0a, 0x2e, 0xe2, 0x38, 0xa6, 0xbc};
uint8_t sqn[] = {0xff, 0x9b, 0xb4, 0xd0, 0xb6, 0x07};
uint8_t amf[] = {0xb9, 0xb9};
uint8_t mac_a[8] = {0};
uint8_t ck[16] = {0};
uint8_t ik[16] = {0};
uint8_t ak[6] = {0};
uint8_t xres[8] = {0};
uint8_t xresStar[16] = {0};
std::string authType_udm = response_data.at("authType");
Logger::ausf_server().debug("authType %s",authType_udm.c_str());
std::string autn_udm = response_data["authenticationVector"].at("autn");
Logger::ausf_server().debug("autn_udm %s",autn_udm.c_str());
std::string avType_udm = response_data["authenticationVector"].at("avType");
Logger::ausf_server().debug("avType_udm %s",avType_udm.c_str());
std::string kausf_udm = response_data["authenticationVector"].at("kausf");
Logger::ausf_server().debug("kausf_udm %s",kausf_udm.c_str());
std::string rand_udm = response_data["authenticationVector"].at("rand");
Logger::ausf_server().debug("rand_udm %s",rand_udm.c_str());
std::string xresStar_udm = response_data["authenticationVector"].at("xresStar");
Logger::ausf_server().debug("xresStar_udm %s",autn_udm.c_str());
//------------------5G HE AV-----------------------------------------------------
uint8_t autn[16] = {0};
uint8_t rand[16] = {0};
uint8_t xresStar[16] = {0};
uint8_t kausf[32] = {0};
// 5GAKA functions
Authentication_5gaka::generate_random(rand, 16); //generate rand
Authentication_5gaka::f1(opc, key, rand, sqn, amf, mac_a);
Authentication_5gaka::f2345(opc, key, rand, xres, ck, ik, ak); // to compute XRES, CK, IK, AK
Authentication_5gaka::generate_autn(sqn, ak, amf, mac_a, autn); // generate AUTN
Authentication_5gaka::annex_a_4_33501(ck, ik, xres, rand, snn, xresStar);//generate xres*
Authentication_5gaka::derive_kausf(ck, ik, snn, sqn, ak, kausf); //derive Kausf
conv::hex_str_to_uint8(autn_udm.c_str(),autn); //autn
conv::hex_str_to_uint8(rand_udm.c_str(),rand); //rand
conv::hex_str_to_uint8(xresStar_udm.c_str(),xresStar); //xres*
conv::hex_str_to_uint8(kausf_udm.c_str(),kausf); //kausf
/*----------------------generating 5G AV from 5G HE AV--------------------------*/
/* HXRES* <-- XRES* */
......@@ -248,12 +249,11 @@ void DefaultApiImpl::ue_authentications_post(
uint8_t kausf_ausf[32] = {0};
uint8_t hxresStar[16] = {0};
//getting params from udm 5G HE AV
//getting params from udm 5G HE AV------may be simplified
memcpy(xresStar_ausf,xresStar,16); //xres*
memcpy(XRES_STAR,xresStar,16); //xres* for 5g-aka-confirmation
memcpy(rand_ausf,rand,16); //rand
memcpy(autn_ausf,autn,16); //autn
memcpy(kausf_ausf,kausf,32); //autn
memcpy(kausf_ausf,kausf,32); //kausf
//generate_Hxres*
Authentication_5gaka::generate_Hxres(rand_ausf,xresStar_ausf,hxresStar);
......@@ -275,6 +275,9 @@ void DefaultApiImpl::ue_authentications_post(
//store kausf_tmp in ausf
KAUSF_TMP = conv::uint8_to_hex_string(kausf_ausf,32);
//store xres* for 5g-aka-confirmation
memcpy(XRES_STAR,xresStar,16);
/*----------------ausf --> seaf-----------*/
//---forming response
// convert uint8_t to string
......@@ -287,7 +290,7 @@ void DefaultApiImpl::ue_authentications_post(
UEAuthenticationCtx UEAuthCtx;
//-------authType(string)
UEAuthCtx.setAuthType("5G_AKA");
UEAuthCtx.setAuthType(authType_udm);
//-------_links(std::map)
std::map<std::string, LinksValueSchema> ausf_links;
......@@ -297,7 +300,7 @@ void DefaultApiImpl::ue_authentications_post(
std::string authCtxId_s;
authCtxId_s = autn_s; // authCtxId = autn
std::string ausf_ip = std::string(inet_ntoa (*((struct in_addr *)&ausf_cfg.nudr.addr4)));
std::string ausf_ip = std::string(inet_ntoa (*((struct in_addr *)&ausf_cfg.sbi.addr4)));
std::string ausf_port = std::to_string(ausf_cfg.sbi.port);
resourceURI = "http://" + ausf_ip + ":" + ausf_port + "/nausf-auth/v1/ue-authentications/" + authCtxId_s + "/5g-aka-confirmation";
......
......@@ -137,10 +137,13 @@ int ausf_config::load(const std::string &config_file) {
const Setting &sbi_ausf_cfg = new_if_cfg[AUSF_CONFIG_STRING_INTERFACE_SBI_AUSF];
load_interface(sbi_ausf_cfg, sbi);
const Setting &nudr_cfg = new_if_cfg[AUSF_CONFIG_STRING_INTERFACE_NUDR];
load_interface(nudr_cfg, nudr);
const Setting &nudm_cfg = new_if_cfg[AUSF_CONFIG_STRING_INTERFACE_NUDM];
load_interface(nudm_cfg, nudm);
// const Setting &udr_addr_pool = nudr_cfg[AUSF_CONFIG_STRING_UDR_INSTANCES_POOL];
const Setting &namf_cfg = new_if_cfg[AUSF_CONFIG_STRING_INTERFACE_NAMF];
load_interface(namf_cfg, namf);
// const Setting &udr_addr_pool = nudm_cfg[AUSF_CONFIG_STRING_UDR_INSTANCES_POOL];
// int count = udr_addr_pool.getLength();
// for (int i = 0; i < count; i++) {
// const Setting &udr_addr_item = udr_addr_pool[i];
......@@ -218,12 +221,17 @@ void ausf_config::display() {
Logger::config().info(" ip ...................: %s", inet_ntoa(sbi.addr4));
Logger::config().info(" port .................: %d", sbi.port);
// Logger::config().info("- Nudr Networking:");
// Logger::config().info(" iface ................: %s", nudr.if_name.c_str());
// Logger::config().info(" ip ...................: %s", inet_ntoa(nudr.addr4));
// Logger::config().info(" port .................: %d", nudr.port);
Logger::config().info("- Nudm Networking:");
Logger::config().info(" iface ................: %s", nudm.if_name.c_str());
Logger::config().info(" ip ...................: %s", inet_ntoa(nudm.addr4));
Logger::config().info(" port .................: %d", nudm.port);
Logger::config().info("- Namf Networking:");
Logger::config().info(" iface ................: %s", namf.if_name.c_str());
Logger::config().info(" ip ...................: %s", inet_ntoa(namf.addr4));
Logger::config().info(" port .................: %d", namf.port);
// Logger::config().info(" HTTP2 port ............: %d", nudr_http2_port);
// Logger::config().info(" HTTP2 port ............: %d", nudm_http2_port);
// Logger::config().info("- Remote udr Pool.....................................: ");
// for (int i = 0; i < udr_pool.size(); i++) {
......
......@@ -52,18 +52,19 @@
#define AUSF_CONFIG_STRING_INTERFACES "INTERFACES"
#define AUSF_CONFIG_STRING_INTERFACE_SBI_AUSF "SBI_AUSF"
#define AUSF_CONFIG_STRING_INTERFACE_NUDR "NUDR"
#define AUSF_CONFIG_STRING_INTERFACE_NUDM "NUDM"
#define AUSF_CONFIG_STRING_INTERFACE_NAMF "NAMF"
#define AUSF_CONFIG_STRING_INTERFACE_NAME "INTERFACE_NAME"
#define AUSF_CONFIG_STRING_IPV4_ADDRESS "IPV4_ADDRESS"
#define AUSF_CONFIG_STRING_PORT "PORT"
#define AUSF_CONFIG_STRING_PPID "PPID"
// #define AUSF_CONFIG_STRING_UDR_INSTANCES_POOL "UDR_INSTANCES_POOL"
// #define AUSF_CONFIG_STRING_UDR_INSTANCE_ID "UDR_INSTANCE_ID"
// #define AUSF_CONFIG_STRING_UDR_INSTANCE_PORT "PORT"
// #define AUSF_CONFIG_STRING_UDR_INSTANCE_VERSION "VERSION"
// #define AUSF_CONFIG_STRING_UDR_INSTANCE_SELECTED "SELECTED"
// #define AUSF_CONFIG_STRING_UDM_INSTANCES_POOL "UDM_INSTANCES_POOL"
// #define AUSF_CONFIG_STRING_UDM_INSTANCE_ID "UDM_INSTANCE_ID"
// #define AUSF_CONFIG_STRING_UDM_INSTANCE_PORT "PORT"
// #define AUSF_CONFIG_STRING_UDM_INSTANCE_VERSION "VERSION"
// #define AUSF_CONFIG_STRING_UDM_INSTANCE_SELECTED "SELECTED"
// #define AUSF_CONFIG_STRING_STATISTICS_TIMER_INTERVAL "STATISTICS_TIMER_INTERVAL"
......@@ -150,7 +151,8 @@ class ausf_config {
std::string AUSF_Name;
interface_cfg_t sbi;
interface_cfg_t nudr;
interface_cfg_t nudm;
interface_cfg_t namf;
//unsigned int statistics_interval;
//std::vector<plmn_item_t> plmn_list;
......
......@@ -21,7 +21,7 @@
/*! \file curl.cpp
\brief
\author Hongxin WANG, BUPT
\author Fengjiao He, BUPT
\date 2021
\email: contact@openairinterface.org
*/
......@@ -55,7 +55,7 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
if (curl) {
CURLcode res = {};
struct curl_slist *headers = nullptr;
if (!Method.compare("POST") || !Method.compare("PATCH")){
if (!Method.compare("POST") || !Method.compare("PUT") || !Method.compare("PATCH")){
std::string content_type = "Content-Type: application/json";
headers = curl_slist_append(headers, content_type.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
......@@ -63,6 +63,10 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
curl_easy_setopt(curl, CURLOPT_URL, remoteUri.c_str());
if (!Method.compare("POST"))
curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
else if(!Method.compare("PUT"))
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PUT");
else if(!Method.compare("DELETE"))
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "DELETE");
else if(!Method.compare("PATCH"))
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");
else
......@@ -81,7 +85,7 @@ void Curl::curl_http_client(std::string remoteUri, std::string Method,
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &callback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, httpData.get());
curl_easy_setopt(curl, CURLOPT_HEADERDATA, httpHeaderData.get());
if (!Method.compare("POST") || !Method.compare("PATCH")){
if (!Method.compare("POST") || !Method.compare("PUT") || !Method.compare("PATCH")){
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, msgBody.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data);
}
......
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