Commit acf97707 authored by HFJ's avatar HFJ

udm disabled

parent 39a15212
......@@ -30,7 +30,7 @@ AUSF =
PORT = 8282; #ausf service port
PPID = 60;
};
SBI_UDM:{
NUDM:{
INTERFACE_NAME = "ens33"; #interface for providing udm service
IPV4_ADDRESS = "192.168.21.133/24"; #address for intercafe (cidr)
PORT = 8181; #udm service port
......
......@@ -107,7 +107,7 @@ void Sha256::finalResult(unsigned char *digest) {
SHA2_UNPACK32(m_h[i], &digest[i << 2]);
}
}
#if 0
std::string sha256(std::string input)
{
unsigned char digest[Sha256::DIGEST_SIZE];
......@@ -116,7 +116,7 @@ std::string sha256(std::string input)
Sha256 ctx = Sha256();
ctx.init();
ctx.update( (unsigned char*)input.c_str(), input.length());
ctx.final(digest);
ctx.finalResult(digest);
char buf[2*Sha256::DIGEST_SIZE+1];
buf[2*Sha256::DIGEST_SIZE] = 0;
......@@ -124,4 +124,4 @@ std::string sha256(std::string input)
sprintf(buf+i*2, "%02x", digest[i]);
return std::string(buf);
}
#endif
......@@ -27,7 +27,7 @@ protected:
uint32 m_h[8];
};
// std::string sha256(std::string input);
std::string sha256(std::string input);
#define SHA2_SHFR(x, n) (x >> n)
#define SHA2_ROTR(x, n) ((x >> n) | (x << ((sizeof(x) << 3) - n)))
......
......@@ -92,7 +92,7 @@ file(GLOB SRCS
add_executable(${PROJECT_NAME} ${SRCS} )
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} LOG OPTIONS pistache pthread gmp config++ ${NETTLE_LIBRARIES})
target_link_libraries(${PROJECT_NAME} LOG OPTIONS pistache pthread gmp config++ ${NETTLE_LIBRARIES} curl)
################################### not used##################################
......
......@@ -27,6 +27,7 @@
#include <typeinfo>
#include <map>
#include "ausf_config.hpp"
#include "curl.hpp"
using namespace config;
extern ausf_config ausf_cfg;
......@@ -171,6 +172,40 @@ void DefaultApiImpl::ue_authentications_post(
//uint64_t _imsi = fromString<uint64_t>(imsi);
/* -----------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.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};
......@@ -269,7 +304,7 @@ void DefaultApiImpl::ue_authentications_post(
ausf_Href.setHref(resourceURI); //"/nausf-auth/v1/ue-authentications/640110987654321/5g-aka-confirmation"
// cout << ausf_Href.getHref().c_str() << endl;
ausf_links["5g_aka_confirmation_put"] = ausf_Href;
ausf_links["5G_AKA"] = ausf_Href;
UEAuthCtx.setLinks(ausf_links);
//----------5gAuthData(Av5gAka):rand autn hxresStar
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file curl.cpp
\brief
\author Hongxin WANG, BUPT
\date 2021
\email: contact@openairinterface.org
*/
#include "curl.hpp"
using namespace config;
extern ausf_config ausf_cfg;
std::size_t callback(const char *in, std::size_t size, std::size_t num,
std::string *out) {
const std::size_t totalBytes(size * num);
out->append(in, totalBytes);
return totalBytes;
}
void Curl::curl_http_client(std::string remoteUri, std::string Method,
std::string msgBody, std::string &Response) {
Logger::ausf_server().info("Send HTTP message with body %s", msgBody.c_str());
uint32_t str_len = msgBody.length();
char *body_data = (char *)malloc(str_len + 1);
memset(body_data, 0, str_len + 1);
memcpy((void *)body_data, (void *)msgBody.c_str(), str_len);
curl_global_init(CURL_GLOBAL_ALL);
CURL *curl = curl_easy_init();
if (curl) {
CURLcode res = {};
struct curl_slist *headers = nullptr;
if (!Method.compare("POST") || !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);
}
curl_easy_setopt(curl, CURLOPT_URL, remoteUri.c_str());
if (!Method.compare("POST"))
curl_easy_setopt(curl, CURLOPT_HTTPPOST, 1);
else if(!Method.compare("PATCH"))
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "PATCH");
else
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
curl_easy_setopt(curl, CURLOPT_TIMEOUT_MS, CURL_TIMEOUT_MS);
curl_easy_setopt(curl, CURLOPT_TCP_KEEPALIVE, 1);
curl_easy_setopt(curl, CURLOPT_INTERFACE, ausf_cfg.sbi.if_name.c_str());
Logger::ausf_server().info("[CURL] request sent by interface " + ausf_cfg.sbi.if_name);
// Response information.
long httpCode = {0};
std::unique_ptr<std::string> httpData(new std::string());
std::unique_ptr<std::string> httpHeaderData(new std::string());
// Hook up data handling function.
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")){
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, msgBody.length());
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body_data);
}
res = curl_easy_perform(curl);
curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &httpCode);
// get the response
std::string response = *httpData.get();
std::string json_data_response = "";
std::string resMsg = "";
bool is_response_ok = true;
Logger::ausf_server().info("Get response with httpcode (%d)", httpCode);
if (httpCode == 0) {
Logger::ausf_server().info("Cannot get response when calling %s", remoteUri.c_str());
// free curl before returning
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
return;
}
nlohmann::json response_data = {};
if (httpCode != 200 && httpCode != 201 && httpCode != 204) {
is_response_ok = false;
if (response.size() < 1) {
Logger::ausf_server().info("There's no content in the response");
// TODO: send context response error
return;
}
Logger::ausf_server().info("Wrong response code");
return;
}
else { //httpCode = 200 || httpCode = 201 || httpCode = 204
/*
//store location of the created context
std::string header_response = *httpHeaderData.get();
std::string CRLF = "\r\n";
std::size_t location_pos = header_response.find("Location");
if (location_pos != std::string::npos)
{
std::size_t crlf_pos = header_response.find(CRLF, location_pos);
if (crlf_pos != std::string::npos)
{
std::string location = header_response.substr(location_pos + 10,
crlf_pos - (location_pos + 10)); printf("Location of the created SMF
context: %s", location.c_str());
}
}
try
{
response_data = nlohmann::json::parse(response);
}
catch (nlohmann::json::exception &e)
{
printf("Could not get Json content from the response");
//Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout";
}*/
Response = *httpData.get();
}
if (!is_response_ok) {
try {
response_data = nlohmann::json::parse(json_data_response);
} catch (nlohmann::json::exception &e) {
Logger::ausf_server().info("Could not get Json content from the response");
// Set the default Cause
response_data["error"]["cause"] = "504 Gateway Timeout";
}
Logger::ausf_server().info("Get response with jsonData: %s", json_data_response.c_str());
std::string cause = response_data["error"]["cause"];
Logger::ausf_server().info("Call Network Function services failure");
Logger::ausf_server().info("Cause value: %s", cause.c_str());
}
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
}
curl_global_cleanup();
if (body_data) {
free(body_data);
body_data = NULL;
}
fflush(stdout);
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this
*file except in compliance with the License. You may obtain a copy of the
*License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
/*! \file curl.hpp
\brief
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _CURL_H_
#define _CURL_H_
// extern "C"{
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <string>
#include <unistd.h>
//}
#include <curl/curl.h>
#include <nlohmann/json.hpp>
#include "bstrlib.h"
#include "logger.hpp"
#include "ausf_config.hpp"
#define CURL_TIMEOUT_MS 100L
class Curl {
public:
/****** curl function ********/
static void curl_http_client(std::string remoteUri, std::string Method,
std::string msgBody, std::string &Response);
private:
};
#endif
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