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

Update Authentication Result

parent 2cd7a486
...@@ -49,7 +49,12 @@ EapMessage::EapMessage(const uint8_t iei, bstring eap) : Type6NasIe(iei) { ...@@ -49,7 +49,12 @@ EapMessage::EapMessage(const uint8_t iei, bstring eap) : Type6NasIe(iei) {
EapMessage::~EapMessage() {} EapMessage::~EapMessage() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void EapMessage::getValue(bstring& eap) { void EapMessage::SetValue(const bstring& eap) {
eap_ = bstrcpy(eap);
}
//------------------------------------------------------------------------------
void EapMessage::GetValue(bstring& eap) const {
eap = bstrcpy(eap_); eap = bstrcpy(eap_);
} }
......
...@@ -48,8 +48,8 @@ class EapMessage : Type6NasIe { ...@@ -48,8 +48,8 @@ class EapMessage : Type6NasIe {
int Encode(uint8_t* buf, int len); int Encode(uint8_t* buf, int len);
int Decode(uint8_t* buf, int len, bool is_iei); int Decode(uint8_t* buf, int len, bool is_iei);
// void setValue(uint8_t iei, uint8_t value); void SetValue(const bstring& eap);
void getValue(bstring& eap); void GetValue(bstring& eap) const;
private: private:
bstring eap_; bstring eap_;
......
...@@ -75,6 +75,7 @@ void AuthenticationFailure::SetAuthenticationFailureParameter( ...@@ -75,6 +75,7 @@ void AuthenticationFailure::SetAuthenticationFailureParameter(
std::make_optional<AuthenticationFailureParameter>(value); std::make_optional<AuthenticationFailureParameter>(value);
} }
//------------------------------------------------------------------------------
bool AuthenticationFailure::GetAuthenticationFailureParameter( bool AuthenticationFailure::GetAuthenticationFailureParameter(
bstring& value) const { bstring& value) const {
if (ie_authentication_failure_parameter.has_value()) { if (ie_authentication_failure_parameter.has_value()) {
......
...@@ -66,7 +66,7 @@ void AuthenticationResponse::SetEapMessage(const bstring& eap) { ...@@ -66,7 +66,7 @@ void AuthenticationResponse::SetEapMessage(const bstring& eap) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
bool AuthenticationResponse::GetEapMessage(bstring& eap) { bool AuthenticationResponse::GetEapMessage(bstring& eap) {
if (ie_eap_message.has_value()) { if (ie_eap_message.has_value()) {
ie_eap_message.value().getValue(eap); ie_eap_message.value().GetValue(eap);
return true; return true;
} else { } else {
return false; return false;
......
...@@ -34,11 +34,9 @@ ...@@ -34,11 +34,9 @@
using namespace nas; using namespace nas;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
AuthenticationResult::AuthenticationResult() { AuthenticationResult::AuthenticationResult()
plain_header = NULL; : NasMmPlainHeader(EPD_5GS_MM_MSG, AUTHENTICATION_RESULT) {
ie_ngKSI = NULL; ie_abba = std::nullopt;
ie_abba = NULL;
ie_eap_message = NULL;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -46,103 +44,125 @@ AuthenticationResult::~AuthenticationResult() {} ...@@ -46,103 +44,125 @@ AuthenticationResult::~AuthenticationResult() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationResult::SetHeader(uint8_t security_header_type) { void AuthenticationResult::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_RESULT);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationResult::SetNgKsi(uint8_t tsc, uint8_t key_set_id) { void AuthenticationResult::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.SetTypeOfSecurityContext(tsc);
ie_ngKSI.SetNasKeyIdentifier(key_set_id);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationResult::SetAbba(uint8_t length, uint8_t* value) { void AuthenticationResult::SetAbba(uint8_t length, uint8_t* value) {
ie_abba = new ABBA(0x38, length, value); ie_abba = std::make_optional<ABBA>(0x38, length, value);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationResult::SetEapMessage(bstring eap) { void AuthenticationResult::SetEapMessage(bstring eap) {
ie_eap_message = new EapMessage(0x00, eap); ie_eap_message.SetValue(eap);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int AuthenticationResult::Encode(uint8_t* buf, int len) { int AuthenticationResult::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding AuthenticationResult message"); Logger::nas_mm().debug("Encoding AuthenticationResult message");
int encoded_size = 0;
if (!plain_header) { int encoded_size = 0;
Logger::nas_mm().error("Mandatory IE missing Header"); int encoded_ie_size = 0;
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) { // ngKSI
Logger::nas_mm().warn("IE ie_ngKSI is not available"); int size = ie_ngKSI.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else { } else {
if (int size = ie_ngKSI->Encode(buf + encoded_size, len - encoded_size) == Logger::nas_mm().error("Encoding ie_ngKSI error");
KEncodeDecodeError) { return KEncodeDecodeError;
Logger::nas_mm().error("Encoding ie_ngKSI error");
return 0;
}
// Spare half octet
encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI
} }
if (!ie_eap_message) { // Spare half octet
Logger::nas_mm().warn("IE ie_eap_message is not available"); encoded_size++; // 1/2 octet + 1/2 octet from ie_ngKSI
// EAP message
size = ie_eap_message.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size;
} else { } else {
if (int size = Logger::nas_mm().error("Encoding ie_eap_message error");
ie_eap_message->Encode(buf + encoded_size, len - encoded_size)) { return KEncodeDecodeError;
encoded_size += size;
} else {
Logger::nas_mm().error("Encoding ie_eap_message error");
return 0;
}
} }
if (!ie_abba) {
if (!ie_abba.has_value()) {
Logger::nas_mm().warn("IE ie_abba is not available"); Logger::nas_mm().warn("IE ie_abba is not available");
} else { } else {
if (int size = ie_abba->Encode(buf + encoded_size, len - encoded_size)) { size = ie_abba.value().Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error("encoding ie_abba error"); Logger::nas_mm().error("encoding ie_abba error");
return 0; return KEncodeDecodeError;
} }
} }
Logger::nas_mm().debug( Logger::nas_mm().debug(
"Encoded AuthenticationResult message len (%d)", encoded_size); "Encoded AuthenticationResult message len (%d)", encoded_size);
return 1; return encoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int AuthenticationResult::Decode( int AuthenticationResult::Decode(uint8_t* buf, int len) {
NasMmPlainHeader* header, uint8_t* buf, int len) {
Logger::nas_mm().debug("Decoding AuthenticationResult message"); Logger::nas_mm().debug("Decoding AuthenticationResult message");
int decoded_size = 3; int decoded_size = 0;
plain_header = header; int decoded_result = 0;
ie_ngKSI = new NasKeySetIdentifier(); // Header
decoded_size += ie_ngKSI->Decode( decoded_result = NasMmPlainHeader::Decode(buf, len);
buf + decoded_size, len - decoded_size, false, if (decoded_result == KEncodeDecodeError) {
false); // length 1/2, low position Logger::nas_mm().error("Decoding NAS Header error");
decoded_size++; // 1/2 octet from ie_ngKSI, 1/2 from Spare half octet return KEncodeDecodeError;
ie_eap_message = new EapMessage(); }
decoded_size += decoded_size += decoded_result;
ie_eap_message->Decode(buf + decoded_size, len - decoded_size, false);
// NAS key set identifier
decoded_result =
ie_ngKSI.Decode(buf + decoded_size, len - decoded_size, false, false);
if (decoded_result == KEncodeDecodeError) return KEncodeDecodeError;
decoded_size++; // 1/2 octet for ngKSI, 1/2 for Spare half octet
// EAP message
decoded_result =
ie_eap_message.Decode(buf + decoded_size, len - decoded_size, false);
if (decoded_result == KEncodeDecodeError == KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size); Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
uint8_t octet = *(buf + decoded_size); uint8_t octet = *(buf + decoded_size);
Logger::nas_mm().debug("First option IEI (0x%x)", octet); Logger::nas_mm().debug("First option IEI (0x%x)", octet);
while ((octet != 0x0)) { while ((octet != 0x0)) {
switch (octet) { switch (octet) {
case 0x38: { case kIeiAbba: {
Logger::nas_mm().debug("Decoding IEI (0x38)"); Logger::nas_mm().debug("decoding IEI (0x38)");
ie_abba = new ABBA(); ABBA ie_abba_tmp = {};
decoded_size += if ((decoded_result = ie_abba_tmp.Decode(
ie_abba->Decode(buf + decoded_size, len - decoded_size, true); buf + decoded_size, len - decoded_size, true)) ==
octet = *(buf + decoded_size); KEncodeDecodeError)
return decoded_result;
decoded_size += decoded_result;
ie_abba = std::optional<ABBA>(ie_abba_tmp);
octet = *(buf + decoded_size);
Logger::nas_mm().debug("Next IEI (0x%x)", octet); Logger::nas_mm().debug("Next IEI (0x%x)", octet);
} break; } break;
} }
} }
Logger::nas_mm().debug( Logger::nas_mm().debug(
"Decoded AuthenticationResult message len (%d)", decoded_size); "Decoded AuthenticationResult message len (%d)", decoded_size);
return 1; return decoded_size;
} }
...@@ -19,36 +19,30 @@ ...@@ -19,36 +19,30 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file #ifndef _AUTHENTICATION_RESULT_H_
\brief #define _AUTHENTICATION_RESULT_H_
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _AuthenticationResult_H_
#define _AuthenticationResult_H_
#include "NasIeHeader.hpp" #include "NasIeHeader.hpp"
namespace nas { namespace nas {
class AuthenticationResult { class AuthenticationResult : public NasMmPlainHeader {
public: public:
AuthenticationResult(); AuthenticationResult();
~AuthenticationResult(); ~AuthenticationResult();
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 SetEapMessage(bstring eap); void SetEapMessage(bstring eap);
void SetAbba(uint8_t length, uint8_t* value); void SetAbba(uint8_t length, uint8_t* value);
public: public:
NasMmPlainHeader* plain_header; NasKeySetIdentifier ie_ngKSI; // Mandatory (1/2 lower octet)
NasKeySetIdentifier* ie_ngKSI; EapMessage ie_eap_message; // Mandatory
EapMessage* ie_eap_message; std::optional<ABBA> ie_abba; // Optional
ABBA* ie_abba;
}; };
} // 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