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

Code cleanup for Authentication Request/Reject/Failure

parent 7a295360
...@@ -2156,7 +2156,7 @@ bool amf_n1::start_authentication_procedure( ...@@ -2156,7 +2156,7 @@ bool amf_n1::start_authentication_procedure(
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;
auth_request->setAuthentication_Parameter_RAND(nc->_5g_av[vindex].rand); auth_request->SetAuthenticationParameterRand(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 < kAuthenticationParameterRandValueLength; i++) for (int i = 0; i < kAuthenticationParameterRandValueLength; i++)
...@@ -2164,7 +2164,7 @@ bool amf_n1::start_authentication_procedure( ...@@ -2164,7 +2164,7 @@ bool amf_n1::start_authentication_procedure(
printf("\n"); printf("\n");
uint8_t* autn = nc->_5g_av[vindex].autn; uint8_t* autn = nc->_5g_av[vindex].autn;
if (autn) auth_request->setAuthentication_Parameter_AUTN(autn); if (autn) auth_request->SetAuthenticationParameterAutn(autn);
uint8_t buffer[1024] = {0}; uint8_t buffer[1024] = {0};
int encoded_size = auth_request->Encode(buffer, 1024); int encoded_size = auth_request->Encode(buffer, 1024);
if (!encoded_size) { if (!encoded_size) {
...@@ -2319,7 +2319,7 @@ void amf_n1::authentication_failure_handle( ...@@ -2319,7 +2319,7 @@ void amf_n1::authentication_failure_handle(
auto auth_failure = std::make_unique<AuthenticationFailure>(); auto auth_failure = std::make_unique<AuthenticationFailure>();
auth_failure->Decode((uint8_t*) bdata(plain_msg), blength(plain_msg)); auth_failure->Decode((uint8_t*) bdata(plain_msg), blength(plain_msg));
uint8_t mm_cause = auth_failure->Get5GMmCause(); uint8_t mm_cause = auth_failure->Get5gmmCause();
if (mm_cause == -1) { if (mm_cause == -1) {
Logger::amf_n1().error("Missing mandatory IE 5G_MM_CAUSE"); Logger::amf_n1().error("Missing mandatory IE 5G_MM_CAUSE");
send_registration_reject_msg( send_registration_reject_msg(
......
...@@ -150,7 +150,7 @@ static const std::vector<std::string> nas_ciphering_algorithm_list_e2str = { ...@@ -150,7 +150,7 @@ static const std::vector<std::string> nas_ciphering_algorithm_list_e2str = {
/************************** cause value for 5g mobility management(Annex A) /************************** cause value for 5g mobility management(Annex A)
* ********************************/ * ********************************/
#define _5GMM_CAUSE_ILLEGAL_UE 3 #define _5GMM_CAUSE_ILLEGAL_UE 3
#define _5GMM_CAUSE_SYNCH_FAILURE 0b00010101 #define _5GMM_CAUSE_SYNCH_FAILURE 0b00010101 // 21
#define _5GMM_CAUSE_IMPLICITLY_DE_REGISTERED 10 #define _5GMM_CAUSE_IMPLICITLY_DE_REGISTERED 10
#define _5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED 9 #define _5GMM_CAUSE_UE_IDENTITY_CANNOT_BE_DERIVED 9
#define _5GMM_CAUSE_NGKSI_ALREADY_IN_USE 0b01000111 // 71 #define _5GMM_CAUSE_NGKSI_ALREADY_IN_USE 0b01000111 // 71
......
...@@ -46,7 +46,7 @@ void AuthenticationFailure::Set5gmmCause(uint8_t value) { ...@@ -46,7 +46,7 @@ void AuthenticationFailure::Set5gmmCause(uint8_t value) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t AuthenticationFailure::Get5GMmCause() { uint8_t AuthenticationFailure::Get5gmmCause() const {
return ie_5gmm_cause.GetValue(); return ie_5gmm_cause.GetValue();
} }
...@@ -101,11 +101,11 @@ int AuthenticationFailure::Encode(uint8_t* buf, int len) { ...@@ -101,11 +101,11 @@ int AuthenticationFailure::Encode(uint8_t* buf, int len) {
encoded_size += encoded_ie_size; encoded_size += encoded_ie_size;
int size = ie_5gmm_cause.Encode(buf + encoded_size, len - encoded_size); int size = ie_5gmm_cause.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) { if (size != KEncodeDecodeError) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error("Encoding ie_5gmm_cause error"); Logger::nas_mm().error(
"Encoding %s error", _5gmmCause::GetIeName().c_str());
return KEncodeDecodeError; return KEncodeDecodeError;
} }
...@@ -120,7 +120,8 @@ int AuthenticationFailure::Encode(uint8_t* buf, int len) { ...@@ -120,7 +120,8 @@ int AuthenticationFailure::Encode(uint8_t* buf, int len) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error( Logger::nas_mm().error(
"Encoding ie_authentication_failure_parameter error"); "Encoding %s error",
AuthenticationFailureParameter::GetIeName().c_str());
return KEncodeDecodeError; return KEncodeDecodeError;
} }
} }
...@@ -148,8 +149,11 @@ int AuthenticationFailure::Decode(uint8_t* buf, int len) { ...@@ -148,8 +149,11 @@ int AuthenticationFailure::Decode(uint8_t* buf, int len) {
// 5GMM Cause // 5GMM Cause
if ((decoded_result = ie_5gmm_cause.Decode( if ((decoded_result = ie_5gmm_cause.Decode(
buf + decoded_size, len - decoded_size, false)) == buf + decoded_size, len - decoded_size, false)) ==
KEncodeDecodeError) KEncodeDecodeError) {
Logger::nas_mm().error(
"Decoding %s error", _5gmmCause::GetIeName().c_str());
return KEncodeDecodeError; return KEncodeDecodeError;
}
decoded_size += decoded_result; decoded_size += decoded_result;
Logger::nas_mm().debug("Decoded_size (%d)", decoded_size); Logger::nas_mm().debug("Decoded_size (%d)", decoded_size);
...@@ -161,7 +165,8 @@ int AuthenticationFailure::Decode(uint8_t* buf, int len) { ...@@ -161,7 +165,8 @@ int AuthenticationFailure::Decode(uint8_t* buf, int len) {
Logger::nas_mm().debug("IEI 0x%x", octet); Logger::nas_mm().debug("IEI 0x%x", octet);
switch (octet) { switch (octet) {
case kIeiAuthenticationFailureParameter: { case kIeiAuthenticationFailureParameter: {
Logger::nas_mm().debug("Decoding IEI (0x30)"); Logger::nas_mm().debug(
"Decoding IEI 0x%x", kIeiAuthenticationFailureParameter);
AuthenticationFailureParameter ie_authentication_failure_parameter_tmp = AuthenticationFailureParameter ie_authentication_failure_parameter_tmp =
{}; {};
if ((decoded_result = ie_authentication_failure_parameter_tmp.Decode( if ((decoded_result = ie_authentication_failure_parameter_tmp.Decode(
......
...@@ -37,7 +37,7 @@ class AuthenticationFailure : public NasMmPlainHeader { ...@@ -37,7 +37,7 @@ class AuthenticationFailure : public NasMmPlainHeader {
void SetHeader(uint8_t security_header_type); void SetHeader(uint8_t security_header_type);
void Set5gmmCause(uint8_t value); void Set5gmmCause(uint8_t value);
uint8_t Get5GMmCause(); uint8_t Get5gmmCause() const;
// void SetAuthenticationFailureParameter(const uint8_t // void SetAuthenticationFailureParameter(const uint8_t
// (&value)[kAuthenticationFailureParameterContentLength]); bool // (&value)[kAuthenticationFailureParameterContentLength]); bool
......
...@@ -68,7 +68,8 @@ int AuthenticationReject::Encode(uint8_t* buf, int len) { ...@@ -68,7 +68,8 @@ int AuthenticationReject::Encode(uint8_t* buf, int len) {
if (size != KEncodeDecodeError) { if (size != KEncodeDecodeError) {
encoded_size += size; encoded_size += size;
} else { } else {
Logger::nas_mm().error("Encoding ie_eap_message error"); Logger::nas_mm().error(
"Encoding %s error", EapMessage::GetIeName().c_str());
return KEncodeDecodeError; return KEncodeDecodeError;
} }
} }
......
...@@ -44,9 +44,9 @@ void AuthenticationRequest::SetHeader(uint8_t security_header_type) { ...@@ -44,9 +44,9 @@ void AuthenticationRequest::SetHeader(uint8_t security_header_type) {
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::SetNgKsi(uint8_t tsc, uint8_t key_set_id) { void AuthenticationRequest::SetNgKsi(uint8_t tsc, uint8_t key_set_id) {
ie_ngKSI.Set(false); // 4 lower bits ie_ng_ksi.Set(false); // 4 lower bits
ie_ngKSI.SetNasKeyIdentifier(key_set_id); ie_ng_ksi.SetNasKeyIdentifier(key_set_id);
ie_ngKSI.SetTypeOfSecurityContext(tsc); ie_ng_ksi.SetTypeOfSecurityContext(tsc);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -55,7 +55,7 @@ void AuthenticationRequest::SetAbba(uint8_t length, uint8_t* value) { ...@@ -55,7 +55,7 @@ void AuthenticationRequest::SetAbba(uint8_t length, uint8_t* value) {
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::setAuthentication_Parameter_RAND( void AuthenticationRequest::SetAuthenticationParameterRand(
uint8_t value[kAuthenticationParameterRandValueLength]) { uint8_t value[kAuthenticationParameterRandValueLength]) {
ie_authentication_parameter_rand = ie_authentication_parameter_rand =
std::make_optional<Authentication_Parameter_RAND>( std::make_optional<Authentication_Parameter_RAND>(
...@@ -63,7 +63,7 @@ void AuthenticationRequest::setAuthentication_Parameter_RAND( ...@@ -63,7 +63,7 @@ void AuthenticationRequest::setAuthentication_Parameter_RAND(
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::setAuthentication_Parameter_AUTN( void AuthenticationRequest::SetAuthenticationParameterAutn(
uint8_t value[kAuthenticationParameterAutnValueLength]) { uint8_t value[kAuthenticationParameterAutnValueLength]) {
ie_authentication_parameter_autn = ie_authentication_parameter_autn =
std::make_optional<Authentication_Parameter_AUTN>( std::make_optional<Authentication_Parameter_AUTN>(
...@@ -71,7 +71,7 @@ void AuthenticationRequest::setAuthentication_Parameter_AUTN( ...@@ -71,7 +71,7 @@ void AuthenticationRequest::setAuthentication_Parameter_AUTN(
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void AuthenticationRequest::SetEapMessage(bstring eap) { void AuthenticationRequest::SetEapMessage(const bstring& eap) {
ie_eap_message = std::make_optional<EapMessage>(kIeiEapMessage, eap); ie_eap_message = std::make_optional<EapMessage>(kIeiEapMessage, eap);
} }
...@@ -89,7 +89,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) { ...@@ -89,7 +89,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
} }
encoded_size += encoded_ie_size; encoded_size += encoded_ie_size;
int size = ie_ngKSI.Encode(buf + encoded_size, len - encoded_size); int size = ie_ng_ksi.Encode(buf + encoded_size, len - encoded_size);
if (size != KEncodeDecodeError) { if (size != KEncodeDecodeError) {
encoded_size += size; encoded_size += size;
} else { } else {
...@@ -98,7 +98,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) { ...@@ -98,7 +98,7 @@ int AuthenticationRequest::Encode(uint8_t* buf, int len) {
return KEncodeDecodeError; return KEncodeDecodeError;
} }
// 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_ng_ksi
// ABBA // ABBA
size = ie_abba.Encode(buf + encoded_size, len - encoded_size); size = ie_abba.Encode(buf + encoded_size, len - encoded_size);
...@@ -181,7 +181,7 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) { ...@@ -181,7 +181,7 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) {
decoded_size += decoded_result; decoded_size += decoded_result;
// NgKSI // NgKSI
decoded_result = ie_ngKSI.Decode( decoded_result = ie_ng_ksi.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
if (decoded_result == KEncodeDecodeError) { if (decoded_result == KEncodeDecodeError) {
...@@ -190,7 +190,7 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) { ...@@ -190,7 +190,7 @@ int AuthenticationRequest::Decode(uint8_t* buf, int len) {
return KEncodeDecodeError; return KEncodeDecodeError;
} }
decoded_size += decoded_result; decoded_size += decoded_result;
decoded_size++; // 1/2 octet from ie_ngKSI, 1/2 from Spare half octet decoded_size++; // 1/2 octet from ie_ng_ksi, 1/2 from Spare half octet
// ABBA // ABBA
decoded_result = decoded_result =
......
...@@ -37,15 +37,24 @@ class AuthenticationRequest : public NasMmPlainHeader { ...@@ -37,15 +37,24 @@ class AuthenticationRequest : public NasMmPlainHeader {
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); // TODO: Get
void SetEapMessage(const bstring& eap);
// TODO: Get
void SetAbba(uint8_t length, uint8_t* value); void SetAbba(uint8_t length, uint8_t* value);
void setAuthentication_Parameter_RAND( // TODO: Get
void SetAuthenticationParameterRand(
uint8_t value[kAuthenticationParameterRandValueLength]); uint8_t value[kAuthenticationParameterRandValueLength]);
void setAuthentication_Parameter_AUTN( // TODO: Get
void SetAuthenticationParameterAutn(
uint8_t value[kAuthenticationParameterAutnValueLength]); uint8_t value[kAuthenticationParameterAutnValueLength]);
// TODO: Get
public: public:
NasKeySetIdentifier ie_ngKSI; // Mandatory NasKeySetIdentifier ie_ng_ksi; // Mandatory
// Spare half octet (will be processed together with NgKSI) // Spare half octet (will be processed together with NgKSI)
ABBA ie_abba; // Mandatory ABBA ie_abba; // 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