Commit aed18962 authored by Tien Thinh NGUYEN's avatar Tien Thinh NGUYEN

Update Authentication Request with NKSI

parent 2d7a889a
...@@ -131,11 +131,13 @@ int NasKeySetIdentifier::Decode( ...@@ -131,11 +131,13 @@ int NasKeySetIdentifier::Decode(
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void NasKeySetIdentifier::setTypeOfSecurityContext(const bool& type) { void NasKeySetIdentifier::setTypeOfSecurityContext(const bool& type) {
tsc_ = type; tsc_ = type;
SetValue(); // Update value
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void NasKeySetIdentifier::setNasKeyIdentifier(const uint8_t& id) { void NasKeySetIdentifier::setNasKeyIdentifier(const uint8_t& id) {
key_id_ = 0x07 & id; key_id_ = 0x07 & id;
SetValue(); // Update value
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
......
...@@ -19,13 +19,6 @@ ...@@ -19,13 +19,6 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file
\brief
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#include "AuthenticationRequest.hpp" #include "AuthenticationRequest.hpp"
#include "3gpp_24.501.hpp" #include "3gpp_24.501.hpp"
...@@ -34,9 +27,8 @@ ...@@ -34,9 +27,8 @@
using namespace nas; using namespace nas;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
AuthenticationRequest::AuthenticationRequest() { AuthenticationRequest::AuthenticationRequest()
plain_header = NULL; : NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_REQUEST) {
ie_ngKSI = NULL;
ie_abba = NULL; ie_abba = NULL;
ie_authentication_parameter_rand = NULL; ie_authentication_parameter_rand = NULL;
ie_authentication_parameter_autn = NULL; ie_authentication_parameter_autn = NULL;
...@@ -48,14 +40,14 @@ AuthenticationRequest::~AuthenticationRequest() {} ...@@ -48,14 +40,14 @@ AuthenticationRequest::~AuthenticationRequest() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::setHeader(uint8_t security_header_type) { void AuthenticationRequest::setHeader(uint8_t security_header_type) {
plain_header = new NasMmPlainHeader(); NasMmPlainHeader::SetSecurityHeaderType(security_header_type);
plain_header->setHeader(
EPD_5GS_MM_MSG, security_header_type, AUTHENTICATION_REQUEST);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) { void AuthenticationRequest::setngKSI(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI = new NasKeySetIdentifier(tsc, key_set_id); ie_ngKSI.Set(false); // 4 lower bits
ie_ngKSI.setNasKeyIdentifier(key_set_id);
ie_ngKSI.setTypeOfSecurityContext(tsc);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -84,16 +76,17 @@ void AuthenticationRequest::setEAP_Message(bstring eap) { ...@@ -84,16 +76,17 @@ void AuthenticationRequest::setEAP_Message(bstring eap) {
int AuthenticationRequest::Encode(uint8_t* buf, int len) { int AuthenticationRequest::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AuthenticationRequest message"); Logger::nas_mm().debug("Encoding AuthenticationRequest message");
int encoded_size = 0; int encoded_size = 0;
if (!plain_header) { int encoded_ie_size = 0;
Logger::nas_mm().error("Mandatory IE missing Header");
return 0; // Header
if ((encoded_ie_size = NasMmPlainHeader::Encode(buf, len)) ==
KEncodeDecodeError) {
Logger::nas_mm().error("Encoding NAS Header error");
return KEncodeDecodeError;
} }
if (!(plain_header->Encode(buf, len))) return 0; encoded_size += encoded_ie_size;
encoded_size += 3;
if (!ie_ngKSI) { int size = ie_ngKSI.Encode(buf + encoded_size, len - encoded_size);
Logger::nas_mm().warn("IE ie_ngKSI is not available");
} else {
int size = ie_ngKSI->Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) { if (size != KEncodeDecodeError) {
encoded_size += size; encoded_size += size;
} else { } else {
...@@ -102,7 +95,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) { ...@@ -102,7 +95,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
} }
// Spare half octet // Spare half octet
encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI
}
if (!ie_abba) { if (!ie_abba) {
Logger::nas_mm().warn("IE ie_abba is not available"); Logger::nas_mm().warn("IE ie_abba is not available");
} else { } else {
...@@ -161,13 +154,12 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) { ...@@ -161,13 +154,12 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int AuthenticationRequest::Decode( int AuthenticationRequest::Decode(uint8_t* buf, int len) {
NasMmPlainHeader* header, uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding RegistrationReject message"); Logger::nas_mm().debug("Decoding RegistrationReject message");
int decoded_size = 3; int decoded_size = 0;
plain_header = header; decoded_size = NasMmPlainHeader::Decode(buf, len);
ie_ngKSI = new NasKeySetIdentifier();
decoded_size += ie_ngKSI->Decode( decoded_size += ie_ngKSI.Decode(
buf + decoded_size, len - decoded_size, false, buf + decoded_size, len - decoded_size, false,
false); // length 1/2, low position false); // length 1/2, low position
decoded_size++; // 1/2 octet from ie_ngKSI, 1/2 from Spare half octet decoded_size++; // 1/2 octet from ie_ngKSI, 1/2 from Spare half octet
......
...@@ -19,27 +19,23 @@ ...@@ -19,27 +19,23 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file #ifndef _AUTHENTICATION_REQUEST_H_
\brief #define _AUTHENTICATION_REQUEST_H_
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AuthenticationRequest_H_
#define _AuthenticationRequest_H_
#include "NasIeHeader.hpp" #include "NasIeHeader.hpp"
namespace nas { namespace nas {
class AuthenticationRequest { class AuthenticationRequest : public NasMmPlainHeader {
public: public:
AuthenticationRequest(); AuthenticationRequest();
~AuthenticationRequest(); ~AuthenticationRequest();
int Encode(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
int Decode(NasMmPlainHeader* header, uint8_t* buf, int len); int Decode(uint8_t* buf, int len);
void setHeader(uint8_t security_header_type); void setHeader(uint8_t security_header_type);
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);
...@@ -47,8 +43,7 @@ class AuthenticationRequest { ...@@ -47,8 +43,7 @@ class AuthenticationRequest {
void setAuthentication_Parameter_AUTN(uint8_t* value); void setAuthentication_Parameter_AUTN(uint8_t* value);
public: public:
NasMmPlainHeader* plain_header; NasKeySetIdentifier ie_ngKSI;
NasKeySetIdentifier* ie_ngKSI;
ABBA* ie_abba; ABBA* ie_abba;
Authentication_Parameter_RAND* ie_authentication_parameter_rand; Authentication_Parameter_RAND* ie_authentication_parameter_rand;
Authentication_Parameter_AUTN* ie_authentication_parameter_autn; Authentication_Parameter_AUTN* ie_authentication_parameter_autn;
......
...@@ -72,6 +72,21 @@ void NasMmPlainHeader::setHeader( ...@@ -72,6 +72,21 @@ void NasMmPlainHeader::setHeader(
msg_type_.Set(msg_type); msg_type_.Set(msg_type);
} }
//------------------------------------------------------------------------------
void NasMmPlainHeader::SetMessageName(const std::string& name) {
msg_name_ = name;
}
//------------------------------------------------------------------------------
std::string NasMmPlainHeader::GetMessageName() const {
return msg_name_;
}
//------------------------------------------------------------------------------
void NasMmPlainHeader::GetMessageName(std::string& name) const {
name = msg_name_;
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int NasMmPlainHeader::Encode(uint8_t* buf, int len) { int NasMmPlainHeader::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding NasMmPlainHeader"); Logger::nas_mm().debug("Encoding NasMmPlainHeader");
......
...@@ -35,9 +35,13 @@ class NasMmPlainHeader { ...@@ -35,9 +35,13 @@ class NasMmPlainHeader {
NasMmPlainHeader(){}; NasMmPlainHeader(){};
NasMmPlainHeader(const uint8_t& epd, const uint8_t& msg_type); NasMmPlainHeader(const uint8_t& epd, const uint8_t& msg_type);
virtual ~NasMmPlainHeader(); virtual ~NasMmPlainHeader();
void setHeader( void setHeader(
const uint8_t& epd, const uint8_t& security_header_type, const uint8_t& epd, const uint8_t& security_header_type,
const uint8_t& msg_type); const uint8_t& msg_type);
void SetMessageName(const std::string& name);
std::string GetMessageName() const;
void GetMessageName(std::string& name) const;
int Encode(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
int Decode(const uint8_t* const buf, int len); int Decode(const uint8_t* const buf, int len);
...@@ -53,9 +57,11 @@ class NasMmPlainHeader { ...@@ -53,9 +57,11 @@ class NasMmPlainHeader {
private: private:
ExtendedProtocolDiscriminator epd_; // Mandatory ExtendedProtocolDiscriminator epd_; // Mandatory
// TODO: Spare half octet (1/2 octet)
SecurityHeaderType secu_header_type_; // Mandatory (1/2 octet) SecurityHeaderType secu_header_type_; // Mandatory (1/2 octet)
// TODO: Spare half octet (1/2 octet)
NasMessageType msg_type_; // Mandatory NasMessageType msg_type_; // Mandatory
std::string msg_name_; // non 3GPP IE
}; };
} // namespace nas } // namespace nas
......
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