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

Update Security Mode Command

parent 4f9b867a
...@@ -2405,11 +2405,8 @@ bool amf_n1::start_security_mode_control_procedure( ...@@ -2405,11 +2405,8 @@ bool amf_n1::start_security_mode_control_procedure(
smc->setUE_Security_Capability(nc->ueSecurityCapEnc, nc->ueSecurityCapInt); smc->setUE_Security_Capability(nc->ueSecurityCapEnc, nc->ueSecurityCapInt);
} }
if (smc->ie_ue_security_capability != NULL) { // TODO: remove
smc->ie_ue_security_capability->SetLengthIndicator(nc->ueSecurityCaplen); // smc->ie_ue_security_capability->SetLengthIndicator(nc->ueSecurityCaplen);
} else {
Logger::amf_n1().error("UE Security Capability is missing");
}
smc->setIMEISV_Request(0xe1); // TODO: remove hardcoded value smc->setIMEISV_Request(0xe1); // TODO: remove hardcoded value
smc->setAdditional_5G_Security_Information(true, false); smc->setAdditional_5G_Security_Information(true, false);
......
...@@ -48,22 +48,23 @@ EPS_NAS_Security_Algorithms::EPS_NAS_Security_Algorithms( ...@@ -48,22 +48,23 @@ EPS_NAS_Security_Algorithms::EPS_NAS_Security_Algorithms(
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void EPS_NAS_Security_Algorithms::setCIPHERING(uint8_t value) { void EPS_NAS_Security_Algorithms::SetTypeOfCipheringAlgorithm(uint8_t value) {
CIPHERING = value; CIPHERING = value;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void EPS_NAS_Security_Algorithms::setINTEGRITY_PROTECTION(uint8_t value) { void EPS_NAS_Security_Algorithms::SetTypeOfIntegrityProtectionAlgorithm(
uint8_t value) {
INTEGRITY_PROTECTION = value; INTEGRITY_PROTECTION = value;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t EPS_NAS_Security_Algorithms::getCIPHERING() { uint8_t EPS_NAS_Security_Algorithms::GetTypeOfCipheringAlgorithm() {
return CIPHERING; return CIPHERING;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t EPS_NAS_Security_Algorithms::getINTEGRITY_PROTECTION() { uint8_t EPS_NAS_Security_Algorithms::GetTypeOfIntegrityProtectionAlgorithm() {
return INTEGRITY_PROTECTION; return INTEGRITY_PROTECTION;
} }
......
...@@ -39,10 +39,10 @@ class EPS_NAS_Security_Algorithms { ...@@ -39,10 +39,10 @@ class EPS_NAS_Security_Algorithms {
~EPS_NAS_Security_Algorithms(); ~EPS_NAS_Security_Algorithms();
EPS_NAS_Security_Algorithms( EPS_NAS_Security_Algorithms(
uint8_t iei, uint8_t ciphering, uint8_t integrity_protection); uint8_t iei, uint8_t ciphering, uint8_t integrity_protection);
void setCIPHERING(uint8_t value); void SetTypeOfCipheringAlgorithm(uint8_t value);
void setINTEGRITY_PROTECTION(uint8_t value); void SetTypeOfIntegrityProtectionAlgorithm(uint8_t value);
uint8_t getCIPHERING(); uint8_t GetTypeOfCipheringAlgorithm();
uint8_t getINTEGRITY_PROTECTION(); uint8_t GetTypeOfIntegrityProtectionAlgorithm();
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);
......
...@@ -35,64 +35,116 @@ using namespace nas; ...@@ -35,64 +35,116 @@ using namespace nas;
using namespace std; using namespace std;
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms() {} NAS_Security_Algorithms::NAS_Security_Algorithms()
: Type3NasIe(),
type_of_ciphering_algorithm_(),
type_of_integrity_protection_algorithm_() {
SetIeName(kNasSecurityAlgorithmsIeName);
}
//------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms(uint8_t iei)
: Type3NasIe(iei),
type_of_ciphering_algorithm_(),
type_of_integrity_protection_algorithm_() {
SetIeName(kNasSecurityAlgorithmsIeName);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
NAS_Security_Algorithms::~NAS_Security_Algorithms() {} NAS_Security_Algorithms::~NAS_Security_Algorithms() {}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
NAS_Security_Algorithms::NAS_Security_Algorithms( NAS_Security_Algorithms::NAS_Security_Algorithms(
uint8_t ciphering, uint8_t integrity_protection) { uint8_t ciphering, uint8_t integrity_protection)
CIPHERING = ciphering; : Type3NasIe() {
INTEGRITY_PROTECTION = integrity_protection; type_of_ciphering_algorithm_ = ciphering & 0x0f;
type_of_integrity_protection_algorithm_ = integrity_protection & 0x0f;
SetIeName(kNasSecurityAlgorithmsIeName);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void NAS_Security_Algorithms::setCIPHERING(uint8_t value) { void NAS_Security_Algorithms::SetTypeOfCipheringAlgorithm(uint8_t value) {
CIPHERING = value; type_of_ciphering_algorithm_ = value & 0x0f;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void NAS_Security_Algorithms::setINTEGRITY_PROTECTION(uint8_t value) { void NAS_Security_Algorithms::SetTypeOfIntegrityProtectionAlgorithm(
INTEGRITY_PROTECTION = value; uint8_t value) {
type_of_integrity_protection_algorithm_ = value & 0x0f;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t NAS_Security_Algorithms::getCIPHERING() { uint8_t NAS_Security_Algorithms::GetTypeOfCipheringAlgorithm() const {
return CIPHERING; return type_of_ciphering_algorithm_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
uint8_t NAS_Security_Algorithms::getINTEGRITY_PROTECTION() { uint8_t NAS_Security_Algorithms::GetTypeOfIntegrityProtectionAlgorithm() const {
return INTEGRITY_PROTECTION; return type_of_integrity_protection_algorithm_;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::Set(
uint8_t ciphering, uint8_t integrity_protection) {
type_of_ciphering_algorithm_ = ciphering & 0x0f;
type_of_integrity_protection_algorithm_ = integrity_protection & 0x0f;
}
//------------------------------------------------------------------------------
void NAS_Security_Algorithms::Get(
uint8_t& ciphering, uint8_t& integrity_protection) const {
ciphering = type_of_ciphering_algorithm_;
integrity_protection = type_of_integrity_protection_algorithm_;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int NAS_Security_Algorithms::Encode(uint8_t* buf, int len) { int NAS_Security_Algorithms::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("encoding NAS_Security_Algorithms "); Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
if (len < 1) {
Logger::nas_mm().error("len is less than one"); if (len < kNasSecurityAlgorithmsLength) {
return -1; Logger::nas_mm().error(
} else { "Buffer length is less than the minimum length of this IE (%d octet)",
*buf = ((CIPHERING & 0x0f) << 4) | (INTEGRITY_PROTECTION & 0x0f); kNasSecurityAlgorithmsLength);
Logger::nas_mm().debug("encoded NAS_Security_Algorithms IE 0x%x", *buf); return KEncodeDecodeError;
} }
return 1; int encoded_size = 0;
// IEI
encoded_size += Type3NasIe::Encode(buf + encoded_size, len);
uint8_t octet = 0;
octet = ((type_of_ciphering_algorithm_ & 0x0f) << 4) |
(type_of_integrity_protection_algorithm_ & 0x0f);
ENCODE_U8(buf + encoded_size, octet, encoded_size);
Logger::nas_mm().debug(
"Encoded %s, len (%d)", GetIeName().c_str(), encoded_size);
return encoded_size;
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int NAS_Security_Algorithms::Decode(uint8_t* buf, int len, bool is_option) { int NAS_Security_Algorithms::Decode(uint8_t* buf, int len, bool is_iei) {
Logger::nas_mm().debug("decoding NAS_Security_Algorithms IE"); Logger::nas_mm().debug("Decoding %s", GetIeName().c_str());
if (len < 1) {
Logger::nas_mm().error("len is less than one"); if (len < kNasSecurityAlgorithmsLength) {
return 0; Logger::nas_mm().error(
} else { "Buffer length is less than the minimum length of this IE (%d octet)",
CIPHERING = (*buf & 0xf0) >> 4; kNasSecurityAlgorithmsLength);
INTEGRITY_PROTECTION = *buf & 0x0f; return KEncodeDecodeError;
Logger::nas_mm().debug(
"decoded NAS_Security_Algorithms len 1 "
"octet,CIPHERING=0x%x,INTEGRITY_PROTECTION=0x%x",
CIPHERING, INTEGRITY_PROTECTION);
return 1;
} }
int decoded_size = 0;
// IEI and Length
decoded_size += Type3NasIe::Decode(buf + decoded_size, len, is_iei);
uint8_t octet = 0;
DECODE_U8(buf + decoded_size, octet, decoded_size);
type_of_ciphering_algorithm_ = (octet & 0xf0) >> 4;
type_of_integrity_protection_algorithm_ = octet & 0x0f;
Logger::nas_mm().debug(
"Decoded %s, len (%d)", GetIeName().c_str(), decoded_size);
return decoded_size;
} }
...@@ -19,35 +19,41 @@ ...@@ -19,35 +19,41 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file #ifndef _NAS_SECURITY_ALGORITHS_H
\brief #define _NAS_SECURITY_ALGORITHS_H
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef __NAS_Security_Algorithms_H
#define __NAS_Security_Algorithms_H
#include "Type3NasIe.hpp"
#include <stdint.h> #include <stdint.h>
constexpr uint8_t kNasSecurityAlgorithmsLength = 2;
constexpr auto kNasSecurityAlgorithmsIeName = "NAS Security Algorithms";
namespace nas { namespace nas {
class NAS_Security_Algorithms { class NAS_Security_Algorithms : public Type3NasIe {
public: public:
NAS_Security_Algorithms(); NAS_Security_Algorithms();
~NAS_Security_Algorithms(); NAS_Security_Algorithms(uint8_t iei);
NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity_protection); NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity_protection);
void setCIPHERING(uint8_t value); NAS_Security_Algorithms(
void setINTEGRITY_PROTECTION(uint8_t value); uint8_t iei, uint8_t ciphering, uint8_t integrity_protection);
uint8_t getCIPHERING(); ~NAS_Security_Algorithms();
uint8_t getINTEGRITY_PROTECTION();
void SetTypeOfCipheringAlgorithm(uint8_t value);
uint8_t GetTypeOfCipheringAlgorithm() const;
void SetTypeOfIntegrityProtectionAlgorithm(uint8_t value);
uint8_t GetTypeOfIntegrityProtectionAlgorithm() const;
void Set(uint8_t ciphering, uint8_t integrity_protection);
void Get(uint8_t& ciphering, uint8_t& integrity_protection) const;
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_iei);
private: private:
uint8_t CIPHERING; uint8_t type_of_ciphering_algorithm_;
uint8_t INTEGRITY_PROTECTION; uint8_t type_of_integrity_protection_algorithm_;
}; };
} // namespace nas } // namespace nas
......
...@@ -145,6 +145,22 @@ bool UESecurityCapability::GetEia(uint8_t& value) const { ...@@ -145,6 +145,22 @@ bool UESecurityCapability::GetEia(uint8_t& value) const {
return false; return false;
} }
//------------------------------------------------------------------------------
void UESecurityCapability::Set(uint8_t _5g_ea, uint8_t _5g_ia) {
_5g_ea_ = _5g_ea;
_5g_ia_ = _5g_ia;
}
//------------------------------------------------------------------------------
void UESecurityCapability::Set(
uint8_t _5g_ea, uint8_t _5g_ia, uint8_t eea, uint8_t eia) {
_5g_ea_ = _5g_ea;
_5g_ia_ = _5g_ia;
eea_ = std::optional<uint8_t>(eea);
eia_ = std::optional<uint8_t>(eia);
SetLengthIndicator(4);
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int UESecurityCapability::Encode(uint8_t* buf, int len) { int UESecurityCapability::Encode(uint8_t* buf, int len) {
Logger::nas_mm().debug("Encoding %s", GetIeName().c_str()); Logger::nas_mm().debug("Encoding %s", GetIeName().c_str());
......
...@@ -56,6 +56,9 @@ class UESecurityCapability : public Type4NasIe { ...@@ -56,6 +56,9 @@ class UESecurityCapability : public Type4NasIe {
void SetEia(uint8_t value); void SetEia(uint8_t value);
bool GetEia(uint8_t& value) const; bool GetEia(uint8_t& value) const;
void Set(uint8_t _5g_ea, uint8_t _5g_ia);
void Set(uint8_t _5g_ea, uint8_t _5g_ia, uint8_t eea, uint8_t eia);
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);
......
This diff is collapsed.
...@@ -19,50 +19,58 @@ ...@@ -19,50 +19,58 @@
* contact@openairinterface.org * contact@openairinterface.org
*/ */
/*! \file #ifndef _SECURITY_MODE_COMMAND_H_
\brief #define _SECURITY_MODE_COMMAND_H_
\author Keliang DU, BUPT
\date 2020
\email: contact@openairinterface.org
*/
#ifndef _SecurityModeCommand_H_
#define _SecurityModeCommand_H_
#include "NasIeHeader.hpp" #include "NasIeHeader.hpp"
namespace nas { namespace nas {
class SecurityModeCommand { class SecurityModeCommand : public NasMmPlainHeader {
public: public:
SecurityModeCommand(); SecurityModeCommand();
~SecurityModeCommand(); ~SecurityModeCommand();
void setHeader(uint8_t security_header_type);
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(NasMmPlainHeader* header, uint8_t* buf, int len);
void setHeader(uint8_t security_header_type);
void setNAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity); void setNAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity);
void setngKSI(uint8_t tsc, uint8_t key_set_id); void setngKSI(uint8_t tsc, uint8_t key_set_id);
void setUE_Security_Capability(uint8_t g_EASel, uint8_t g_IASel); void setUE_Security_Capability(uint8_t g_EASel, uint8_t g_IASel);
void setUE_Security_Capability( void setUE_Security_Capability(
uint8_t g_EASel, uint8_t g_IASel, uint8_t eea, uint8_t eia); uint8_t g_EASel, uint8_t g_IASel, uint8_t eea, uint8_t eia);
void setIMEISV_Request(uint8_t value); void setIMEISV_Request(uint8_t value);
void setEPS_NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity); void setEPS_NAS_Security_Algorithms(uint8_t ciphering, uint8_t integrity);
void setAdditional_5G_Security_Information(bool rinmr, bool hdp); void setAdditional_5G_Security_Information(bool rinmr, bool hdp);
void SetEapMessage(bstring eap); void SetEapMessage(bstring eap);
void setABBA(uint8_t length, uint8_t* value); void setABBA(uint8_t length, uint8_t* value);
void setS1_UE_Security_Capability(uint8_t g_EEASel, uint8_t g_EIASel); void setS1_UE_Security_Capability(uint8_t g_EEASel, uint8_t g_EIASel);
public: public:
NasMmPlainHeader* plain_header; NAS_Security_Algorithms ie_selected_nas_security_algorithms; // Mandatory
NAS_Security_Algorithms* ie_selected_nas_security_algorithms; NasKeySetIdentifier ie_ngKSI; // Mandatory
NasKeySetIdentifier* ie_ngKSI; UESecurityCapability ie_ue_security_capability; // Mandatory
UESecurityCapability* ie_ue_security_capability;
IMEISV_Request* ie_imeisv_request; std::optional<IMEISV_Request> ie_imeisv_request; // Optional
EPS_NAS_Security_Algorithms* ie_eps_nas_security_algorithms; std::optional<EPS_NAS_Security_Algorithms>
Additional_5G_Security_Information* ie_additional_5G_security_information; ie_eps_nas_security_algorithms; // Optional
EapMessage* ie_eap_message; std::optional<Additional_5G_Security_Information>
ABBA* ie_abba; ie_additional_5G_security_information; // Optional
S1_UE_Security_Capability* ie_s1_ue_security_capability; std::optional<EapMessage> ie_eap_message; // Optional
std::optional<ABBA> ie_abba; // Optional
std::optional<S1_UE_Security_Capability>
ie_s1_ue_security_capability; // Optional
}; };
} // 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