Commit 1ae2e757 authored by HFJ's avatar HFJ

5gaka auth+confirm without algo

parent 2456a500
......@@ -30,6 +30,7 @@ include_directories(5gaka)
include_directories(common)
include_directories(libngap)
################### code frrom amf cmakelists###########################
find_package(PkgConfig REQUIRED)
......@@ -85,3 +86,9 @@ add_executable(${PROJECT_NAME} ${SRCS} )
add_dependencies(${PROJECT_NAME} PISTACHE NLOHMANN)
target_link_libraries(${PROJECT_NAME} LOG OPTIONS pistache pthread gmp ${NETTLE_LIBRARIES})
#include_directories(utils)
#include_directories(utils/bstr)
# ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.c
# ${CMAKE_CURRENT_SOURCE_DIR}/utils/*.cpp
# ${CMAKE_CURRENT_SOURCE_DIR}/utils/bstr/*.c
\ No newline at end of file
......@@ -97,17 +97,21 @@ void DefaultApi::rg_authentications_post_handler(const Pistache::Rest::Request &
void DefaultApi::ue_authentications_auth_ctx_id5g_aka_confirmation_put_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
// Getting the path params
auto authCtxId = request.param(":authCtxId").as<std::string>();
cout << "5gaka confirmation received with authctxID %s" << authCtxId.c_str() << endl;
cout << "5gaka confirmation received with authctxID" << authCtxId.c_str() << endl;
cout << request.body().c_str() << endl;
// Getting the body param
ConfirmationData confirmationData;
try {
cout << "--try module"<< endl;
nlohmann::json::parse(request.body()).get_to(confirmationData);
cout << "json parsed" << endl;
this->ue_authentications_auth_ctx_id5g_aka_confirmation_put(authCtxId, confirmationData, response);
} catch (nlohmann::detail::exception &e) {
//send a 400 error
cout << "**400 error"<< endl;
response.send(Pistache::Http::Code::Bad_Request, e.what());
return;
} catch (Pistache::Http::HttpError &e) {
......@@ -115,6 +119,7 @@ void DefaultApi::ue_authentications_auth_ctx_id5g_aka_confirmation_put_handler(c
return;
} catch (std::exception &e) {
//send a 500 error
cout << "**500 error"<< endl;
response.send(Pistache::Http::Code::Internal_Server_Error, e.what());
return;
}
......@@ -145,12 +150,8 @@ void DefaultApi::ue_authentications_deregister_post_handler(const Pistache::Rest
}
void DefaultApi::ue_authentications_post_handler(const Pistache::Rest::Request &request, Pistache::Http::ResponseWriter response) {
cout << "------------ue authentications post handler---------"<< endl;
if(!request.body().c_str()){
cout << "empty request body" << endl;
}
// Getting the body param
// Getting the body param
AuthenticationInfo authenticationInfo;
......
......@@ -13,6 +13,9 @@
#include "DefaultApiImpl.h"
#include <iostream>
#include "authentication_algorithms_with_5gaka.hpp"
#include "OCTET_STRING.h"
#include "comUt.hpp"
using namespace std;
......@@ -34,14 +37,71 @@ void DefaultApiImpl::rg_authentications_post(const RgAuthenticationInfo &rgAuthe
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void DefaultApiImpl::ue_authentications_auth_ctx_id5g_aka_confirmation_put(const std::string &authCtxId, const ConfirmationData &confirmationData, Pistache::Http::ResponseWriter &response) {
cout << "------------ue_authentications_auth_ctx_id5g_aka_confirmation_put---------"<< endl;
//---------------------getting params---------------------------------
cout << "handling 5gaka confirmation -- put" << endl;
cout << "authCtxId" << authCtxId.c_str() << endl; // authCtxId
cout << "resStar" << confirmationData.getResStar().c_str() << endl; //resStar
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void DefaultApiImpl::ue_authentications_deregister_post(const DeregistrationInfo &deregistrationInfo, Pistache::Http::ResponseWriter &response) {
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
void DefaultApiImpl::ue_authentications_post(const AuthenticationInfo &authenticationInfo, Pistache::Http::ResponseWriter &response) {
cout << "handling 5gaka authentication -- post" << endl;
cout << "------------ue_authentications_post---------"<< endl;
//----------------------getting params-------------------------------------
cout << "servingNetworkName " << authenticationInfo.getServingNetworkName().c_str() << endl; //servingNetworkName
cout << "supiOrSuci " << authenticationInfo.getSupiOrSuci().c_str() << endl; //supiOrSuci
//----------------------generating xres*-------------
cout << "--algorithm test"<< endl;
uint8_t opc[16] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
uint8_t key[16] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};
uint8_t rand[16] = {0x5b, 0x2e, 0x1c, 0x24, 0x28, 0xc7, 0x56, 0x28, 0xe4, 0x43, 0xb0, 0xac, 0x89, 0x5d, 0x5b, 0x73};
uint8_t res[8], ck[16], ik[16], ak[6];
Authentication_5gaka::f2345(opc, key, rand, res, ck, ik, ak);
std::string snn = "5G:mnc001.mcc110.3gppnetwork.org";
OCTET_STRING_t netName;
OCTET_STRING_fromBuf(&netName, snn.c_str(), snn.length());
uint8_t S[100];
S[0] = 0x6B;
memcpy (&S[1], netName.buf, netName.size);
// cout << "snn length(0x%x)" << netName.size << endl;
printf("snn length(0x%x)\n", (unsigned int)netName.size);
S[1+netName.size] = (netName.size & 0xff00)>>8;
S[2+netName.size] = (netName.size & 0x00ff);
for(int i=0; i<16; i++)
S[3+netName.size+i] = rand[i];
S[19+netName.size] = 0x00;
S[20+netName.size] = 0x10;
for(int i=0; i<8; i++)
S[21+netName.size+i] = res[i];
S[29+netName.size] = 0x00;
S[30+netName.size] = 0x08;
uint8_t ckik[32];
memcpy (&key[0], ck, 16);
memcpy (&key[16], ik, 16);//KEY
uint8_t out[32], output[16];
Authentication_5gaka::kdf(ckik, 32, S, 31+netName.size, out, 32);
for(int i=0; i<16; i++)
output[i] = out[16+i];
print_buffer("amf_n1", "XRES*", output, 16);
//cout << "xres* %s" << output << endl;
//----------------------generating 5g av--------------------------
cout << "--handling 5gaka authentication -- post" << endl;
response.send(Pistache::Http::Code::Ok, "Do some magic\n");
}
......
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