Commit 6649664a authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update Authentication Request

parent 2921bc4d
...@@ -2116,11 +2116,12 @@ bool amf_n1::start_authentication_procedure( ...@@ -2116,11 +2116,12 @@ bool amf_n1::start_authentication_procedure(
abba[0] = 0x00; abba[0] = 0x00;
abba[1] = 0x00; abba[1] = 0x00;
auth_request->setABBA(2, abba); auth_request->setABBA(2, abba);
uint8_t* rand = nc->_5g_av[vindex].rand; // uint8_t* rand = nc->_5g_av[vindex].rand;
if (rand) auth_request->setAuthentication_Parameter_RAND(rand); auth_request->setAuthentication_Parameter_RAND(nc->_5g_av[vindex].rand);
Logger::amf_n1().debug("Sending Authentication Request with RAND"); Logger::amf_n1().debug("Sending Authentication Request with RAND");
printf("0x"); printf("0x");
for (int i = 0; i < 16; i++) printf("%x", rand[i]); for (int i = 0; i < kAuthenticationParameterRandValueLength; i++)
printf("%x", nc->_5g_av[vindex].rand[i]);
printf("\n"); printf("\n");
uint8_t* autn = nc->_5g_av[vindex].autn; uint8_t* autn = nc->_5g_av[vindex].autn;
......
...@@ -19,92 +19,87 @@ ...@@ -19,92 +19,87 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "Authentication_Parameter_AUTN.hpp" #include "Authentication_Parameter_AUTN.hpp"
#include "3gpp_24.501.hpp"
#include "common_defs.h"
#include "logger.hpp" #include "logger.hpp"
using namespace nas; using namespace nas;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Authentication_Parameter_AUTN::Authentication_Parameter_AUTN(uint8_t iei) Authentication_Parameter_AUTN::Authentication_Parameter_AUTN(uint8_t iei)
: _value() { : Type4NasIe(iei), _value() {
_iei = iei; SetLengthIndicator(0);
SetIeName(kAuthenticationParameterAutnIeName);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Authentication_Parameter_AUTN::Authentication_Parameter_AUTN( Authentication_Parameter_AUTN::Authentication_Parameter_AUTN(
const uint8_t iei, uint8_t* value) { const uint8_t iei, uint8_t value[kAuthenticationParameterAutnValueLength])
_iei = iei; : Type4NasIe(iei) {
for (int i = 0; i < 16; i++) { for (int i = 0; i < kAuthenticationParameterAutnValueLength; i++) {
this->_value[i] = value[i]; this->_value[i] = value[i];
} }
SetLengthIndicator(kAuthenticationParameterAutnValueLength);
SetIeName(kAuthenticationParameterAutnIeName);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Authentication_Parameter_AUTN::Authentication_Parameter_AUTN() Authentication_Parameter_AUTN::Authentication_Parameter_AUTN()
: _iei(), _value() {} : Type4NasIe(), _value() {
SetLengthIndicator(0);
SetIeName(kAuthenticationParameterAutnIeName);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Authentication_Parameter_AUTN::~Authentication_Parameter_AUTN() {} Authentication_Parameter_AUTN::~Authentication_Parameter_AUTN() {}
//------------------------------------------------------------------------------
uint8_t* Authentication_Parameter_AUTN::getValue() {
// for (int j = 0; j < 16; j++) {
// Logger::nas_mm().debug("decoded Authentication_Response_Parameter
// value(0x%2x)", _value[j]);
//}
return _value;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int Authentication_Parameter_AUTN::Encode(uint8_t* buf, int len) { int Authentication_Parameter_AUTN::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug( Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
"Encoding Authentication_Parameter_AUTN IEI (0x%x)", _iei); int ie_len = GetIeLength();
if (len < 18) {
Logger::nas_mm().error("len is less than 18"); if (len < ie_len) {
return 0; Logger::nas_mm().error("Len is less than %d", ie_len);
return KEncodeDecodeError;
} }
int encoded_size = 0; int encoded_size = 0;
if (_iei) { // IEI and Length
*(buf + encoded_size) = _iei; int encoded_header_size = Type4NasIe::Encode(buf + encoded_size, len);
encoded_size++; if (encoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
*(buf + encoded_size) = 16; encoded_size += encoded_header_size;
encoded_size++;
for (int i = 0; i < 16; i++) { if (GetLengthIndicator() != kAuthenticationParameterAutnValueLength)
*(buf + encoded_size) = _value[i]; return KEncodeDecodeError;
encoded_size++;
} for (int i = 0; i < kAuthenticationParameterAutnValueLength; i++) {
return encoded_size; ENCODE_U8(buf + encoded_size, _value[i], encoded_size);
} else {
// *(buf + encoded_size) = length - 1; encoded_size++;
// *(buf + encoded_size) = _value; encoded_size++; encoded_size++;
} }
Logger::nas_mm().debug( Logger::nas_mm().debug(
"Encoded Authentication_Parameter_AUTN len (%d)", encoded_size); "Encoded Authentication_Parameter_AUTN len (%d)", encoded_size);
return encoded_size; return encoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int Authentication_Parameter_AUTN::Decode( int Authentication_Parameter_AUTN::Decode(uint8_t* buf, int len, bool is_iei) {
uint8_t* buf, int len, bool is_option) { uint8_t decoded_size = 0;
Logger::nas_mm().debug( uint8_t octet = 0;
"Decoding Authentication_Parameter_AUTN IEI (0x%x)", *buf); Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
int decoded_size = 0;
if (is_option) { // IEI and Length
decoded_size++; int decoded_header_size = Type4NasIe::Decode(buf + decoded_size, len, is_iei);
} if (decoded_header_size == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size++; decoded_size += decoded_header_size;
for (int i = 0; i < 16; i++) {
_value[i] = *(buf + decoded_size); if (GetLengthIndicator() != kAuthenticationParameterAutnValueLength)
decoded_size++; return KEncodeDecodeError;
for (int i = 0; i < kAuthenticationParameterAutnValueLength; i++) {
DECODE_U8(buf + decoded_size, _value[i], decoded_size);
} }
for (int j = 0; j < 16; j++) { for (int j = 0; j < kAuthenticationParameterAutnValueLength; j++) {
Logger::nas_mm().debug( Logger::nas_mm().debug(
"Decoded Authentication_Parameter_AUTN value (0x%2x)", _value[j]); "Decoded Authentication_Parameter_AUTN value (0x%2x)", _value[j]);
} }
......
...@@ -18,35 +18,35 @@ ...@@ -18,35 +18,35 @@
* For more information about the OpenAirInterface (OAI) Software Alliance: * For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org * contact@openairinterface.org
*/ */
#ifndef _AUTHENTICATION_PARAMETER_AUTN_H_
#define _AUTHENTICATION_PARAMETER_AUTN_H_
/*! \file #include "Type4NasIe.hpp"
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef __Authentication_Parameter_AUTN_H_
#define __Authentication_Parameter_AUTN_H_
#include <stdint.h> #include <stdint.h>
constexpr uint8_t kAuthenticationParameterAutnLength = 18;
constexpr uint8_t kAuthenticationParameterAutnValueLength =
kAuthenticationParameterAutnLength - 2;
constexpr auto kAuthenticationParameterAutnIeName =
"Authentication Parameter AUTN";
namespace nas { namespace nas {
class Authentication_Parameter_AUTN { class Authentication_Parameter_AUTN : public Type4NasIe {
public: public:
Authentication_Parameter_AUTN(); Authentication_Parameter_AUTN();
Authentication_Parameter_AUTN(uint8_t iei); Authentication_Parameter_AUTN(uint8_t iei);
Authentication_Parameter_AUTN(const uint8_t iei, uint8_t* value); Authentication_Parameter_AUTN(
const uint8_t iei,
uint8_t value[kAuthenticationParameterAutnValueLength]);
~Authentication_Parameter_AUTN(); ~Authentication_Parameter_AUTN();
// void setValue(uint8_t iei, uint8_t value);
int Encode(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_option); int Decode(uint8_t* buf, int len, bool is_option);
uint8_t* getValue();
private: private:
uint8_t _iei; uint8_t _value[kAuthenticationParameterAutnValueLength];
uint8_t _value[16];
}; };
} // namespace nas } // namespace nas
......
...@@ -39,9 +39,9 @@ Authentication_Parameter_RAND::Authentication_Parameter_RAND(uint8_t iei) ...@@ -39,9 +39,9 @@ Authentication_Parameter_RAND::Authentication_Parameter_RAND(uint8_t iei)
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
Authentication_Parameter_RAND::Authentication_Parameter_RAND( Authentication_Parameter_RAND::Authentication_Parameter_RAND(
uint8_t iei, uint8_t* value) uint8_t iei, uint8_t value[kAuthenticationParameterRandValueLength])
: Type3NasIe(iei) { : Type3NasIe(iei) {
for (int i = 0; i < 16; i++) { for (int i = 0; i < kAuthenticationParameterRandValueLength; i++) {
this->_value[i] = value[i]; this->_value[i] = value[i];
} }
SetIeName(kAuthenticationParameterRandIeName); SetIeName(kAuthenticationParameterRandIeName);
...@@ -71,7 +71,8 @@ int Authentication_Parameter_RAND::Encode(uint8_t* buf, int len) { ...@@ -71,7 +71,8 @@ int Authentication_Parameter_RAND::Encode(uint8_t* buf, int len) {
// IEI // IEI
encoded_size += Type3NasIe::Encode(buf + encoded_size, len); encoded_size += Type3NasIe::Encode(buf + encoded_size, len);
for (int i = 0; i < kAuthenticationParameterRandLength - 1; i++) {
for (int i = 0; i < kAuthenticationParameterRandValueLength; i++) {
ENCODE_U8(buf + encoded_size, _value[i], encoded_size); ENCODE_U8(buf + encoded_size, _value[i], encoded_size);
} }
...@@ -96,11 +97,11 @@ int Authentication_Parameter_RAND::Decode(uint8_t* buf, int len, bool is_iei) { ...@@ -96,11 +97,11 @@ int Authentication_Parameter_RAND::Decode(uint8_t* buf, int len, bool is_iei) {
// IEI and Length // IEI and Length
decoded_size += Type3NasIe::Decode(buf + decoded_size, len, is_iei); decoded_size += Type3NasIe::Decode(buf + decoded_size, len, is_iei);
for (int i = 0; i < kAuthenticationParameterRandLength - 1; i++) { for (int i = 0; i < kAuthenticationParameterRandValueLength; i++) {
DECODE_U8(buf + decoded_size, _value[i], decoded_size); DECODE_U8(buf + decoded_size, _value[i], decoded_size);
} }
for (int j = 0; j < kAuthenticationParameterRandLength - 1; j++) { for (int j = 0; j < kAuthenticationParameterRandValueLength; j++) {
Logger::nas_mm().debug( Logger::nas_mm().debug(
"Decoded Authentication_Parameter_RAND value (0x%2x)", _value[j]); "Decoded Authentication_Parameter_RAND value (0x%2x)", _value[j]);
} }
......
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <stdint.h> #include <stdint.h>
constexpr uint8_t kAuthenticationParameterRandLength = 17; constexpr uint8_t kAuthenticationParameterRandLength = 17;
constexpr uint8_t kAuthenticationParameterRandValueLength =
kAuthenticationParameterRandLength - 1;
constexpr auto kAuthenticationParameterRandIeName = constexpr auto kAuthenticationParameterRandIeName =
"Authentication Parameter RAND"; "Authentication Parameter RAND";
...@@ -36,7 +38,8 @@ class Authentication_Parameter_RAND : public Type3NasIe { ...@@ -36,7 +38,8 @@ class Authentication_Parameter_RAND : public Type3NasIe {
public: public:
Authentication_Parameter_RAND(); Authentication_Parameter_RAND();
Authentication_Parameter_RAND(uint8_t iei); Authentication_Parameter_RAND(uint8_t iei);
Authentication_Parameter_RAND(uint8_t iei, uint8_t* value); Authentication_Parameter_RAND(
uint8_t iei, uint8_t value[kAuthenticationParameterRandValueLength]);
~Authentication_Parameter_RAND(); ~Authentication_Parameter_RAND();
int Encode(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
...@@ -45,7 +48,7 @@ class Authentication_Parameter_RAND : public Type3NasIe { ...@@ -45,7 +48,7 @@ class Authentication_Parameter_RAND : public Type3NasIe {
// uint8_t* getValue(); // uint8_t* getValue();
private: private:
uint8_t _value[kAuthenticationParameterRandLength - 1]; uint8_t _value[kAuthenticationParameterRandValueLength];
}; };
} // namespace nas } // namespace nas
......
...@@ -55,14 +55,16 @@ void AuthenticationRequest::setABBA(uint8_t length, uint8_t* value) { ...@@ -55,14 +55,16 @@ void AuthenticationRequest::setABBA(uint8_t length, uint8_t* value) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::setAuthentication_Parameter_RAND(uint8_t* value) { void AuthenticationRequest::setAuthentication_Parameter_RAND(
uint8_t value[kAuthenticationParameterRandValueLength]) {
ie_authentication_parameter_rand = ie_authentication_parameter_rand =
std::make_optional<Authentication_Parameter_RAND>( std::make_optional<Authentication_Parameter_RAND>(
kIeiAuthenticationParameterRand, value); kIeiAuthenticationParameterRand, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::setAuthentication_Parameter_AUTN(uint8_t* value) { void AuthenticationRequest::setAuthentication_Parameter_AUTN(
uint8_t value[kAuthenticationParameterAutnValueLength]) {
ie_authentication_parameter_autn = ie_authentication_parameter_autn =
std::make_optional<Authentication_Parameter_AUTN>( std::make_optional<Authentication_Parameter_AUTN>(
kIeiAuthenticationParameterAutn, value); kIeiAuthenticationParameterAutn, value);
......
...@@ -39,8 +39,10 @@ class AuthenticationRequest : public NasMmPlainHeader { ...@@ -39,8 +39,10 @@ class AuthenticationRequest : public NasMmPlainHeader {
void setngKSI(uint8_t tsc, uint8_t key_set_id); void setngKSI(uint8_t tsc, uint8_t key_set_id);
void setEAP_Message(bstring eap); void setEAP_Message(bstring eap);
void setABBA(uint8_t length, uint8_t* value); void setABBA(uint8_t length, uint8_t* value);
void setAuthentication_Parameter_RAND(uint8_t* value); void setAuthentication_Parameter_RAND(
void setAuthentication_Parameter_AUTN(uint8_t* value); uint8_t value[kAuthenticationParameterRandValueLength]);
void setAuthentication_Parameter_AUTN(
uint8_t value[kAuthenticationParameterAutnValueLength]);
public: public:
NasKeySetIdentifier ie_ngKSI; // Mandatory NasKeySetIdentifier ie_ngKSI; // Mandatory
......
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