Commit fc77df61 authored by Jerome Peraldi's avatar Jerome Peraldi

Merge branch 'sequans/eap_aka' into 'sqn/3GPP_TTCN_System_Simulator'

bug #127303 - [L3 SIMU] NAS NR : EAP-AKA' support@TTCN level

See merge request sequans/system/ttcn/openairinterface5g!1
parents affb4dc8 daafc076
......@@ -1368,6 +1368,7 @@ set(NR_PDCP_SRC
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_sdu.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_timer_thread.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_security_nea2.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_security_nea1.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_integrity_nia2.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/nr_pdcp_integrity_nia1.c
${OPENAIR2_DIR}/LAYER2/nr_pdcp/asn1_utils.c
......@@ -1794,6 +1795,7 @@ set(libnas_ies_OBJS
${NAS_SRC}COMMON/IES/AuthenticationParameterAutn.c
${NAS_SRC}COMMON/IES/AuthenticationParameterRand.c
${NAS_SRC}COMMON/IES/AuthenticationResponseParameter.c
${NAS_SRC}COMMON/IES/EapMessage.c
${NAS_SRC}COMMON/IES/CipheringKeySequenceNumber.c
${NAS_SRC}COMMON/IES/Cli.c
${NAS_SRC}COMMON/IES/CsfbResponse.c
......
......@@ -1346,9 +1346,11 @@ INPUT = \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_sdu.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_sdu.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_security_nea2.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_security_nea1.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_ue_manager.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_entity.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_security_nea2.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_security_nea1.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_ue_manager.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_integrity_nia1.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair2/LAYER2/nr_pdcp/nr_pdcp_asn1_utils.h \
......@@ -1758,6 +1760,7 @@ INPUT = \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/TimeZoneAndTime.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/Cli.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationResponseParameter.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EapMessage.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SORTransparentContainer.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/FGSRegistrationType.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/NasRequestType.h \
......@@ -1857,6 +1860,7 @@ INPUT = \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/ProtocolConfigurationOptions.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsQualityOfService.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/AuthenticationResponseParameter.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EapMessage.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/PdnType.h \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/EpsMobileIdentity.c \
@CMAKE_CURRENT_SOURCE_DIR@/../openair3/NAS/COMMON/IES/SupportedCodecList.c \
......
......@@ -3761,6 +3761,7 @@ int16_t fill_dmrs_mask(const NR_PDSCH_Config_t *pdsch_Config,
// For TypeB, ld is the duration of the scheduled PDSCH resources
ld = (mappingtype == typeA) ? (NrOfSymbols + startSymbol) : NrOfSymbols;
if (ld == 0) ld = 7; //TODO: ACHTUNG!!! Temporary W/A, need to fix the assert somewhere else.
AssertFatal(ld > 2 && ld < 15,"Illegal NrOfSymbols according to Table 5.1.2.1-1 Spec 38.214 %d\n",ld);
AssertFatal((NrOfSymbols + startSymbol) < 15,"Illegal S+L according to Table 5.1.2.1-1 Spec 38.214 S:%d L:%d\n",startSymbol, NrOfSymbols);
......
......@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include "nr_pdcp_security_nea1.h"
#include "nr_pdcp_security_nea2.h"
#include "nr_pdcp_integrity_nia2.h"
#include "nr_pdcp_integrity_nia1.h"
......@@ -342,14 +343,15 @@ static void nr_pdcp_entity_set_security(nr_pdcp_entity_t *entity,
entity->has_integrity = 0;
if (entity->free_integrity != NULL) {
entity->free_integrity(entity->integrity_context);
entity->free_integrity = NULL;
}
entity->free_integrity = NULL;
}
if (integrity_algorithm != 0 && integrity_algorithm != -1) {
entity->has_integrity = 1;
if (entity->free_integrity != NULL) {
entity->free_integrity(entity->integrity_context);
entity->free_integrity = NULL;
}
if (integrity_algorithm == 2) {
entity->integrity_context = nr_pdcp_integrity_nia2_init(entity->integrity_key);
......@@ -369,24 +371,31 @@ static void nr_pdcp_entity_set_security(nr_pdcp_entity_t *entity,
entity->has_ciphering = NR_PDCP_ENTITY_CIPHERING_OFF;
if (entity->free_security != NULL) {
entity->free_security(entity->security_context);
entity->free_security = NULL;
}
entity->free_security = NULL;
}
if (ciphering_algorithm != 0 && ciphering_algorithm != -1) {
if (ciphering_algorithm != 2) {
LOG_E(PDCP, "FATAL: only nea2 supported for the moment\n");
exit(1);
}
entity->has_ciphering = entity->has_ciphering == NR_PDCP_ENTITY_CIPHERING_ON?NR_PDCP_ENTITY_CIPHERING_ON:NR_PDCP_ENTITY_CIPHERING_SMC;
LOG_I(PDCP, "%s: entity->has_ciphering %d\n", __FUNCTION__, entity->has_ciphering);
if (entity->free_security != NULL) {
entity->free_security(entity->security_context);
entity->free_security = NULL;
}
if (ciphering_algorithm == 2) {
entity->security_context = nr_pdcp_security_nea2_init(entity->ciphering_key);
entity->cipher = nr_pdcp_security_nea2_cipher;
entity->free_security = nr_pdcp_security_nea2_free_security;
} else if (ciphering_algorithm == 1) {
entity->security_context = nr_pdcp_security_nea1_init(entity->ciphering_key);
entity->cipher = nr_pdcp_security_nea1_cipher;
entity->free_security = nr_pdcp_security_nea1_free_security;
} else {
LOG_E(PDCP, "FATAL: only nea1 and nea2 supported for the moment\n");
exit(1);
}
entity->security_context = nr_pdcp_security_nea2_init(entity->ciphering_key);
entity->cipher = nr_pdcp_security_nea2_cipher;
entity->free_security = nr_pdcp_security_nea2_free_security;
}
FNOUT;
}
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include "common/utils/assertions.h"
#include "nr_pdcp_security_nea1.h"
#include <arpa/inet.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#include "UTIL/OSA/osa_defs.h"
int stream_encrypt_eea1(stream_cipher_t *stream_cipher, uint8_t **out);
void *nr_pdcp_security_nea1_init(unsigned char *ciphering_key)
{
// This is a hack, IMO init, cipher and free functions should be reduced to cipher.
// Test show a ~10% more processing time
return ciphering_key;
}
void nr_pdcp_security_nea1_cipher(void *security_context, unsigned char *buffer, int length, int bearer, int count, int direction)
{
DevAssert(security_context != NULL);
DevAssert(buffer != NULL);
DevAssert(length > 0);
DevAssert(bearer > -1 && bearer < 32);
DevAssert(direction > -1 && direction < 2);
DevAssert(count > -1);
uint8_t *ciphering_key = (uint8_t *)security_context;
uint8_t *out = NULL;
stream_cipher_t stream_cipher;
stream_cipher.key_length = 16;
stream_cipher.count = count;
stream_cipher.bearer = bearer - 1;
stream_cipher.direction = direction;
stream_cipher.key = ciphering_key;
stream_cipher.message = buffer;
/* length in bits */
stream_cipher.blength = length << 3;
// out will be set to stream_cipher.message, no need to free it
stream_encrypt_eea1(&stream_cipher, &out);
memmove(buffer, out, length);
}
void nr_pdcp_security_nea1_free_security(void *security_context)
{
(void)security_context;
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#ifndef _NR_PDCP_SECURITY_NEA1_H_
#define _NR_PDCP_SECURITY_NEA1_H_
void *nr_pdcp_security_nea1_init(unsigned char *ciphering_key);
void nr_pdcp_security_nea1_cipher(void *security_context,
unsigned char *buffer, int length,
int bearer, int count, int direction);
void nr_pdcp_security_nea1_free_security(void *security_context);
#endif /* _NR_PDCP_SECURITY_NEA1_H_ */
......@@ -44,12 +44,25 @@ int encode_fgs_authentication_response(fgs_authentication_response_msg *authenti
int encode_result = 0;
if ((encode_result =
encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter,
AUTHENTICATION_RESPONSE_PARAMETER_IEI, buffer + encoded, len - encoded)) < 0) //Return in case of error
return encode_result;
else
encoded += encode_result;
if ((authentication_response->presencemask & FGS_AUTHENTICATION_RESPONSE_AUTH_RESPONSE_PARAM_PRESENT)
== FGS_AUTHENTICATION_RESPONSE_AUTH_RESPONSE_PARAM_PRESENT) {
if ((encode_result =
encode_authentication_response_parameter(&authentication_response->authenticationresponseparameter,
FGS_AUTHENTICATION_RESPONSE_AUTH_RESPONSE_PARAM_IEI, buffer + encoded, len - encoded)) < 0) //Return in case of error
return encode_result;
else
encoded += encode_result;
}
if ((authentication_response->presencemask & FGS_AUTHENTICATION_RESPONSE_EAP_MESSAGE_PRESENT)
== FGS_AUTHENTICATION_RESPONSE_EAP_MESSAGE_PRESENT) {
if ((encode_result =
encode_eap_message(&authentication_response->eapmessage,
FGS_AUTHENTICATION_RESPONSE_EAP_MESSAGE_IEI, buffer + encoded, len - encoded)) < 0) //Return in case of error
return encode_result;
else
encoded += encode_result;
}
return encoded;
}
......
......@@ -37,11 +37,18 @@
#include "SpareHalfOctet.h"
#include "MessageType.h"
#include "AuthenticationResponseParameter.h"
#include "EapMessage.h"
#ifndef FGS_AUTHENTICATION_RESPONSE_H_
#define FGS_AUTHENTICATION_RESPONSE_H_
#define AUTHENTICATION_RESPONSE_PARAMETER_IEI 0x2d
# define FGS_AUTHENTICATION_RESPONSE_AUTH_RESPONSE_PARAM_PRESENT (1<<0)
# define FGS_AUTHENTICATION_RESPONSE_EAP_MESSAGE_PRESENT (1<<1)
typedef enum fgs_authentication_response_iei_tag {
FGS_AUTHENTICATION_RESPONSE_AUTH_RESPONSE_PARAM_IEI = 0x2D, /* 0x2D = 45 */
FGS_AUTHENTICATION_RESPONSE_EAP_MESSAGE_IEI = 0x78, /* 0x78 = 120 */
} fgs_authentication_response_iei;
/*
* Message name: Identity response
......@@ -56,7 +63,10 @@ typedef struct fgs_authentication_response_msg_tag {
SecurityHeaderType securityheadertype:4;
SpareHalfOctet sparehalfoctet:4;
MessageType messagetype;
/* Optional fields */
uint32_t presencemask;
AuthenticationResponseParameter authenticationresponseparameter;
EapMessage eapmessage;
} fgs_authentication_response_msg;
int encode_fgs_authentication_response(fgs_authentication_response_msg *authentication_response, uint8_t *buffer, uint32_t len);
......
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "TLVEncoder.h"
#include "TLVDecoder.h"
#include "EapMessage.h"
int decode_eap_message(EapMessage *eapmessage, uint8_t iei, uint8_t *buffer, uint32_t len)
{
int decoded = 0;
uint16_t ielen = 0;
int decode_result;
if (iei > 0) {
CHECK_IEI_DECODER(iei, *buffer);
decoded++;
}
ielen = (uint16_t)(*(buffer + decoded) << 8);
ielen |= (uint16_t)(*(buffer + decoded + 1));
decoded += 2;
CHECK_LENGTH_DECODER(len - decoded, ielen);
if ((decode_result = decode_octet_string(&eapmessage->eapMsg, ielen, buffer + decoded, len - decoded)) < 0)
return decode_result;
else
decoded += decode_result;
#if defined (NAS_DEBUG)
dump_eap_message_xml(eapmessage, iei);
#endif
return decoded;
}
int encode_eap_message(EapMessage *eapmessage, uint8_t iei, uint8_t *buffer, uint32_t len)
{
uint16_t ielen = 0;
uint8_t *lenPtr;
uint32_t encoded = 0;
int encode_result;
/* Checking IEI and pointer */
CHECK_PDU_POINTER_AND_LENGTH_ENCODER(buffer, EAP_MESSAGE_MINIMUM_LENGTH, len);
#if defined (NAS_DEBUG)
dump_eap_message_xml(eapmessage, iei);
#endif
if (iei > 0) {
*buffer = iei;
encoded++;
}
lenPtr = (buffer + encoded);
encoded += 2;
if ((encode_result = encode_octet_string(&eapmessage->eapMsg, buffer + encoded, len - encoded)) < 0)
return encode_result;
else
encoded += encode_result;
ielen = encoded - 2 - ((iei > 0) ? 1 : 0);
*lenPtr = (uint8_t)((ielen >> 8) & 0xFF);
*(lenPtr + 1) = (uint8_t)(ielen & 0xFF);
return encoded;
}
void dump_eap_message_xml(EapMessage *eapmessage, uint8_t iei)
{
printf("<EAP Message>\n");
dump_octet_string_xml(&eapmessage->eapMsg);
printf("</EAP Message>\n");
}
/*
* Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The OpenAirInterface Software Alliance licenses this file to You under
* the OAI Public License, Version 1.1 (the "License"); you may not use this file
* except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.openairinterface.org/?page_id=698
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*-------------------------------------------------------------------------------
* For more information about the OpenAirInterface (OAI) Software Alliance:
* contact@openairinterface.org
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "OctetString.h"
#ifndef EAP_MESSAGE_H_
#define EAP_MESSAGE_H_
#define EAP_MESSAGE_MINIMUM_LENGTH 7
#define EAP_MESSAGE_MAXIMUM_LENGTH 1503
typedef struct EapMessage_tag {
OctetString eapMsg;
} EapMessage;
int encode_eap_message(EapMessage *eapmessage, uint8_t iei, uint8_t *buffer, uint32_t len);
int decode_eap_message(EapMessage *eapmessage, uint8_t iei, uint8_t *buffer, uint32_t len);
void dump_eap_message_xml(EapMessage *eapmessage, uint8_t iei);
#endif /* EAP_MESSAGE_H_ */
This diff is collapsed.
......@@ -103,6 +103,9 @@
/* Security Key for SA UE */
typedef struct {
uint8_t mk[256]; // EAP-AKA' master-key.
// PRF' produces as many bits of output as is needed,
// lets define 256 bytes MK.
uint8_t kausf[32];
uint8_t kseaf[32];
uint8_t kamf[32];
......
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