Commit 08d942d8 authored by Yann Garcia's avatar Yann Garcia
Browse files

Review f_send_authentication_request_await_authentication_response function

parent 5a48ca99
Loading
Loading
Loading
Loading
+17 −16
Changes for etc/AtsNGAP/AtsNGAP_GNB_p_net.cfg_: 17 added lines, 16 removed lines.
Original line number Diff line number Diff line
[MODULE_PARAMETERS]
# This section shall contain the values of all parameters that are defined in your TTCN-3 modules.

LibCommon_Time.PX_TDONE                 := 30.0;
LibCommon_Time.PX_TAC                   := 30.0;
LibCommon_Time.PX_TNOAC                 := 10.0;
LibCommon_Time.PX_TWAIT                 := 30.0;
LibCommon_Sync.PX_TSYNC_TIME_LIMIT      := 40.0;
LibCommon_Sync.PX_TSHUT_DOWN_TIME_LIMIT := 40.0;
LibCommon_Time.PX_TDONE                 := 300.0
LibCommon_Time.PX_TAC                   := 300.0
LibCommon_Time.PX_TNOAC                 := 100.0
LibCommon_Time.PX_TWAIT                 := 300.0
LibCommon_Sync.PX_TSYNC_TIME_LIMIT      := 350.0
LibCommon_Sync.PX_TSHUT_DOWN_TIME_LIMIT := 350.0

LibNGAP_Pixits.PX_NGAP_TWAIT            := 300.0
LibNGAP_Pixits.PX_TIMER_T3560           := 500

NGAP_Pics.PICS_NGAP_AMF_IUT    := false
NGAP_Pics.PICS_NGAP_GNB_IUT    := true

LibNGAP_Pics.PICS_OFFLINE_MODE    := false # true for offline mode with pcap files, false for online mode with SCTP server
LibNGAP_Pics.PICS_USE_UERANSIMU   := false # true to start UERANSIM gNB and UE simulators, false to not start them
LibNGAP_Pics.PICS_USE_AT_COMMANDS := false # true to use AT commands to start UERANSIM gNB and UE simulators, false to not use them

LibNGAP_Pics.PICS_NO_RAN_NODE_NAME                                := true # true to not use RAN node name, false to use it
LibNGAP_Pics.PICS_REGISTRATION_REQUEST_WITH_NO_UE_CONTEXT_REQUEST := true # true to send RegistrationRequest with no UE Context Request IE, false to send it with UE Context Request IE

LibNGAP_Pixits.PX_NAS_MCC          := '999'H
LibNGAP_Pixits.PX_NAS_MNC          := '39'H
LibNGAP_Pixits.PX_NAS_MNC          := '40'H
LibNGAP_Pixits.PX_RAN_NODE_NAME    := "gnb0012345"
LibNGAP_Pixits.PX_GNB_ID           := '0000011000010010111001'B
LibNGAP_Pixits.PX_RAN_NODE_NAME    := "UERANSIM-gnb-999-70-1"
@@ -29,7 +34,7 @@ LibNGAP_Pixits.PX_AMF_NAME := "open5gs-amf0"
LibNGAP_Pixits.PX_AMF_REGION_ID    := '00000010'B
LibNGAP_Pixits.PX_AMF_SET_ID       := '0000000001'B
LibNGAP_Pixits.PX_AMF_POINTER      := '000000'B
LibNGAP_Pixits.PX_RAN_UE_NGAP_ID   := 1
LibNGAP_Pixits.PX_RAN_UE_NGAP_ID   := 16856248
LibNGAP_Pixits.PX_AMF_UE_NGAP_ID   := 1

LibNGAP_Pixits.PX_TIME_ZONE        := '80'O # 0x40 for GMT+1, 0x80 for GMT+2
@@ -41,7 +46,7 @@ LibNGAP_Pixits.PX_NR_INTEGRITY_PROTECTION_ALGORITHMS := '1110000000000000'B
LibNGAP_Pixits.PX_EUTRA_ENCRYPTION_ALGORITHMS           := '1110000000000000'B
LibNGAP_Pixits.PX_EUTRA_INTEGRITY_PROTECTION_ALGORITHMS := '1110000000000000'B

Lib_NG_NAS_Pixits.PX_CHECK_SECURITY                  := false
Lib_NG_NAS_Pixits.PX_CHECK_SECURITY                  := true
Lib_NG_NAS_Pixits.PX_SUPI_FORMAT                     := '0000'B # IMSI format
Lib_NG_NAS_Pixits.PX_TYPE_OF_ID                      := '001'B # SUCI type
Lib_NG_NAS_Pixits.PX_SUPI_DIGITS                     := '00f110214300014444330302'O
@@ -53,7 +58,7 @@ Lib_NG_NAS_Pixits.PX_OPERATOR_KEY := '00000000000000000000000
# OPc
Lib_NG_NAS_Pixits.PX_OPERATOR_SECRET_KEY             := 'B4FCB931721D7BF412E4FB7AAF42E676'O
Lib_NG_NAS_Pixits.PX_FORCE_USING_OPERATOR_SECRET_KEY := true
Lib_NG_NAS_Pixits.PX_SUBSCRIPTION_KEY                := '11010010100110100101110000010100011110010011111101001000000101010101101100001101000111101000111110111001100011011110000111001001'B # 465B5CE8B199B49FAA5F0A2EE238A6BC
Lib_NG_NAS_Pixits.PX_SUBSCRIPTION_KEY                := '11010010100110100101110000010100011110010011111101001000000101010101101100001101000111101000111110111001100011011110000111001001'B # D29A5C14793F48155B0D1E8FB98DE1C9
Lib_NG_NAS_Pixits.PX_BEARER_ID                       := '00001'B
Lib_NG_NAS_Pixits.PX_SQN                             := '000000000000000000000000000000000000001000000000'B
#Lib_NG_NAS_Pixits.PX_AMF                             := oct2bit('8000'O)
@@ -63,12 +68,6 @@ Parameters.px_IMSI_Def := '39393934303030303030343
Parameters.px_IMEISV_Def                             := '73806121856151f1'H
NAS_5GC_Parameters.px_NAS_5GC_XRES_Length            := 8 # In ETSI TS 135 206 V16.0.0 (2020-08) Table Table 5. f2 output, RES length is 8 octets (64 bits)

# Upper tester parameters for UERANSIM integration
LibNGAP_Pixits.PX_GNB_BINARY_FILE := "/home/yann/dev/UERANSIM/build/nr-gnb";
LibNGAP_Pixits.PX_GNB_CONFIG_FILE := "/home/yann/dev/UERANSIM/config/open5gs-gnb.yaml";
LibNGAP_Pixits.PX_UE_BINARY_FILE := "/home/yann/dev/UERANSIM/build/nr-ue";
LibNGAP_Pixits.PX_UE_CONFIG_FILE := "/home/yann/dev/UERANSIM/config/open5gs-ue.yaml";

[LOGGING]
# In this section you can specify the name of the log file and the classes of events
# you want to log into the file or display on console (standard error).
@@ -94,6 +93,8 @@ system.NGAP_gNB_1.params := "NGAP/SCTP(local_server=10.174.19.14,server_mode=1,l
#system.NGAP_AMF.params := "NGAP/SCTP_FILE/IP_OFFLINE/PCAP_FILE(file=../captures/ttcn_5g_ngap.pcapng)" # Linux cooked capture v2, no Ethernet layer
#system.NGAP_AMF.params := "NGAP/SCTP_FILE/IP_OFFLINE/ETH(mac_src=8c554ac1eee0,mac_dst=8c554ac1eee1)/PCAP_FILE(file=../captures/TC_NGAP_AMF_PDU_01.pcap)" # regular pcap with Ethernet layer

system.utPort.params := "UT/TCP(server=localhost,port=12000,debug=1)"

[DEFINE]
# In this section you can create macro definitions,
# that can be used in other configuration file sections except [INCLUDE] and [ORDERED_INCLUDE].
+2 −0
Changes for ttcn/LibNGAP/lib/LibNGAP_Pics.ttcn: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -10,4 +10,6 @@ module LibNGAP_Pics {

    modulepar boolean PICS_NO_RAN_NODE_NAME := false; // If true, the test system does not use RAN node name in NGAP messages

    modulepar boolean PICS_REGISTRATION_REQUEST_WITH_NO_UE_CONTEXT_REQUEST := false; // If true, RegistrationRequest is sent with no UE Context Request IE

} // End of module LibNGAP_Pics
+36 −0
Changes for ttcn/LibNGAP/lib/LibNGAP_Templates.ttcn: 36 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -5535,6 +5535,42 @@ module LibNGAP_Templates {
                                             }
                        } // End of template mw_n2_initialUeMessage
                        template (present) InitiatingMessage mw_n2_initialUeMessage_no_UEContextRequest(
                                                                                                        template (present) RAN_UE_NGAP_ID p_RANUeNgapID := ?,
                                                                                                        template (present) NAS_PDU p_nasPdu := ?,
                                                                                                        template (present) UserLocationInformation p_UeLocInf := ?,
                                                                                                        template (present) RRCEstablishmentCause p_rrcEstCause := ?
                                                                                                        ) := {
                            procedureCode := id_InitialUEMessage,
                            criticality   := ignore,
                            value_        := {
                                              InitialUEMessage := {
                                                                   protocolIEs := {permutation(
                                                                                   {
                                                                                    id := id_RAN_UE_NGAP_ID,
                                                                                    criticality := reject,
                                                                                    value_ := { RAN_UE_NGAP_ID := p_RANUeNgapID }
                                                                                   },
                                                                                   {
                                                                                    id := id_NAS_PDU,
                                                                                    criticality := reject,
                                                                                    value_ := { NAS_PDU := p_nasPdu }
                                                                                   },
                                                                                   {
                                                                                    id := id_UserLocationInformation,
                                                                                    criticality := reject,
                                                                                    value_ := { UserLocationInformation := p_UeLocInf }
                                                                                   },
                                                                                   {
                                                                                    id := id_RRCEstablishmentCause,
                                                                                    criticality := ignore,
                                                                                    value_ := { RRCEstablishmentCause := p_rrcEstCause }
                                                                                   },*)
                                                                                  }
                                                                  }
                                             }
                        } // End of template mw_n2_initialUeMessage_no_UEContextRequest
                    } // End of group Receive
                } // End of group INITIAL_UE_MESSAGE
+79 −72
Changes for ttcn/LibNGAP/lib_system/LibNGAP_Functions.ttcn: 79 added lines, 72 removed lines.
Original line number Diff line number Diff line
@@ -303,84 +303,17 @@ module LibNGAP_Functions {
        log(">>> f_await_registration_request");

        // REGISTRATION_REQUEST
        tc_ac.start;
        alt { // In case the UE rejected the authentication vector with a Synch failure and returned an AUTS for resync (per TS 24.501 §5.4.1.3.7)
            [] N2_gNBaMF_P.check(
                                 receive(
                                         mw_ngap_initMsg(
                                                         mw_n2_UplinkNASTransport(
                                                                                  -,
                                                                                  -,
                                                                                  decmatch(
                                                                                           mw_NG_AUTHENTICATION_FAILURE(
                                                                                                                        mw_GMM_GSM_Cause(
                                                                                                                                         -,
                                                                                                                                         int2bit(21, 8) // SYNC failure
                                         ))))))) {
                // the UE rejected the authentication vector with a Synch failure
        if (PICS_REGISTRATION_REQUEST_WITH_NO_UE_CONTEXT_REQUEST) {
            f_recv_NGAP_PDU(
                            mw_ngap_initMsg(
                                                mw_n2_UplinkNASTransport(
                                                                         -,
                                                                         -,
                                                                         decmatch(
                                                                                  mw_NG_AUTHENTICATION_FAILURE(
                                                                                                               mw_GMM_GSM_Cause(
                                                                                                                                -,
                                                                                                                                int2bit(21, 8) // SYNC failure
                                ))))));
                f_NASPDU_Get(vc_recvNGAP_PDU);
                // Re-calculate the security context with the AUTS value received from the UE
                // (TS 33.102 clause 6.3.3 "Re-synchronisation procedure"):
                //   AUTS = (SQN_MS xor AK*) (48 bits) || MAC-S (64 bits)
                //   AK*  = f5star(K, RAND)   -- RAND is the one from the rejected Authentication Request
                //   SQN_MS = (SQN_MS xor AK*) xor AK*
                //   MAC-S  = f1star(K, RAND, SQN_MS, AMF*) with a dummy AMF* of all zeros
                if (ispresent(vc_recvNgNasUl_Msg.authentication_Failure.authFailureParam)) {
                    var B112_Type v_auts        := vc_recvNgNasUl_Msg.authentication_Failure.authFailureParam.auts;
                    var B48_Type  v_sqn_ms_akstar := substr(v_auts, 0, 48);
                    var B64_Type  v_mac_s        := substr(v_auts, 48, 64);
                    log("f_await_registration_request: v_auts=", bit2oct(v_auts));

                    var B48_Type v_ak_star;
                    if (f_f5star(PX_SUBSCRIPTION_KEY, vc_ng_nas_security_params_type.AuthParams.RandValue, v_ak_star) != 0) {
                        log("*** " & __SCOPE__ & ": FAIL: 'f_f5star' failed to compute AK*");
                        setverdict(fail, "*** " & __SCOPE__ & ": FAIL: 'f_f5star' failed to compute AK*");
                    }
                    var B48_Type v_sqn_ms := v_sqn_ms_akstar xor4b v_ak_star;
                    log("f_await_registration_request: v_sqn_ms=", bit2oct(v_sqn_ms));

                    // Verify MAC-S; the resynchronisation MAC always uses a dummy AMF* of all zeros
                    // so it does not have to be sent in the clear (TS 33.102 clause 6.3.3)
                    var B64_Type v_mac_s_expected;
                    if (f_f1star(PX_SUBSCRIPTION_KEY, vc_ng_nas_security_params_type.AuthParams.RandValue, v_sqn_ms, int2bit(0, 16), v_mac_s_expected) != 0) {
                        log("*** " & __SCOPE__ & ": FAIL: 'f_f1star' failed to compute MAC-S");
                        setverdict(fail, "*** " & __SCOPE__ & ": FAIL: 'f_f1star' failed to compute MAC-S");
                    }
                    if (PX_CHECK_SECURITY and (v_mac_s != v_mac_s_expected)) {
                        log("*** " & __SCOPE__ & ": FAIL: MAC-S mismatch: received=", bit2oct(v_mac_s), ", expected=", bit2oct(v_mac_s_expected));
                        setverdict(fail, "*** " & __SCOPE__ & ": FAIL: MAC-S mismatch in resynchronisation");
                    }

                    // Advance the network's SQN past the UE's own counter so the Authentication Request
                    // that follows (f_send_authentication_request_await_authentication_response) is accepted
                    vc_NG_NAS_SQN := int2bit(bit2int(v_sqn_ms) + 1, 48);
                    log("f_await_registration_request: resynchronised vc_NG_NAS_SQN=", bit2oct(vc_NG_NAS_SQN));
                                            mw_n2_initialUeMessage_no_UEContextRequest
                            ));
        } else {
                    log("*** " & __SCOPE__ & ": FAIL: Authentication failure with no AUTS");
                    setverdict(fail, "*** " & __SCOPE__ & ": FAIL: Authentication failure with no AUTS");
                }
            }
            [] tc_ac.timeout {
                // No message received, let's consider the message was accepted and proceed with the test case execution
                log("*** " & __SCOPE__ & ": FAIL: No NAS message received");
                setverdict(fail, "*** " & __SCOPE__ & ": FAIL: No NAS message received");
            }
        }
            f_recv_NGAP_PDU(
                            mw_ngap_initMsg(
                                            mw_n2_initialUeMessage
                            ));
        }
        f_NASPDU_Get(vc_recvNGAP_PDU);
        if (match(vc_recvNgNasUl_Msg, mw_NG_REGISTRATION_REQUEST)) {
            log("Received NG_REGISTRATION_REQUEST NAS message");
@@ -746,7 +679,81 @@ module LibNGAP_Functions {
                                                                   bit2oct(encvalue(valueof(v_dl_message))) // AuthorizationRequest
                        )));

        // Await response for AUTHENTICATION_REQUEST
        // Await AUTHENTICATION_RESPONSE or Synch failure
        tc_ac.start;
        alt { // In case the UE rejected the authentication vector with a Synch failure and returned an AUTS for resync (per TS 24.501 §5.4.1.3.7)
            [] N2_gNBaMF_P.check(
                                receive(
                                        mw_ngap_initMsg(
                                                        mw_n2_UplinkNASTransport(
                                                                                 -,
                                                                                 -,
                                                                                 decmatch(
                                                                                          mw_NG_AUTHENTICATION_FAILURE(
                                                                                                                       mw_GMM_GSM_Cause(
                                                                                                                                        -,
                                                                                                                                        int2bit(21, 8) // SYNC failure
                                        ))))))) {
                // the UE rejected the authentication vector with a Synch failure
                f_recv_NGAP_PDU(
                                mw_ngap_initMsg(
                                                mw_n2_UplinkNASTransport(
                                                                         -,
                                                                         -,
                                                                         decmatch(
                                                                                  mw_NG_AUTHENTICATION_FAILURE(
                                                                                                               mw_GMM_GSM_Cause(
                                                                                                                                -,
                                                                                                                                int2bit(21, 8) // SYNC failure
                                ))))));
                f_NASPDU_Get(vc_recvNGAP_PDU);
                // Re-calculate the security context with the AUTS value received from the UE
                // (TS 33.102 clause 6.3.3 "Re-synchronisation procedure"):
                //   AUTS = (SQN_MS xor AK*) (48 bits) || MAC-S (64 bits)
                //   AK*  = f5star(K, RAND)   -- RAND is the one from the rejected Authentication Request
                //   SQN_MS = (SQN_MS xor AK*) xor AK*
                //   MAC-S  = f1star(K, RAND, SQN_MS, AMF*) with a dummy AMF* of all zeros
                if (ispresent(vc_recvNgNasUl_Msg.authentication_Failure.authFailureParam)) {
                    var B112_Type v_auts        := vc_recvNgNasUl_Msg.authentication_Failure.authFailureParam.auts;
                    var B48_Type  v_sqn_ms_akstar := substr(v_auts, 0, 48);
                    var B64_Type  v_mac_s        := substr(v_auts, 48, 64);
                    log("f_await_registration_request: v_auts=", bit2oct(v_auts));

                    var B48_Type v_ak_star;
                    if (f_f5star(PX_SUBSCRIPTION_KEY, vc_ng_nas_security_params_type.AuthParams.RandValue, v_ak_star) != 0) {
                        log("*** " & __SCOPE__ & ": FAIL: 'f_f5star' failed to compute AK*");
                        setverdict(fail, "*** " & __SCOPE__ & ": FAIL: 'f_f5star' failed to compute AK*");
                    }
                    var B48_Type v_sqn_ms := v_sqn_ms_akstar xor4b v_ak_star;
                    log("f_await_registration_request: v_sqn_ms=", bit2oct(v_sqn_ms));

                    // Verify MAC-S; the resynchronisation MAC always uses a dummy AMF* of all zeros
                    // so it does not have to be sent in the clear (TS 33.102 clause 6.3.3)
                    var B64_Type v_mac_s_expected;
                    if (f_f1star(PX_SUBSCRIPTION_KEY, vc_ng_nas_security_params_type.AuthParams.RandValue, v_sqn_ms, int2bit(0, 16), v_mac_s_expected) != 0) {
                        log("*** " & __SCOPE__ & ": FAIL: 'f_f1star' failed to compute MAC-S");
                        setverdict(fail, "*** " & __SCOPE__ & ": FAIL: 'f_f1star' failed to compute MAC-S");
                    }
                    if (PX_CHECK_SECURITY and (v_mac_s != v_mac_s_expected)) {
                        log("*** " & __SCOPE__ & ": FAIL: MAC-S mismatch: received=", bit2oct(v_mac_s), ", expected=", bit2oct(v_mac_s_expected));
                        setverdict(fail, "*** " & __SCOPE__ & ": FAIL: MAC-S mismatch in resynchronisation");
                    }

                    // Advance the network's SQN past the UE's own counter so the Authentication Request
                    // that follows (f_send_authentication_request_await_authentication_response) is accepted
                    vc_NG_NAS_SQN := int2bit(bit2int(v_sqn_ms) + 1, 48);
                    log("f_await_registration_request: resynchronised vc_NG_NAS_SQN=", bit2oct(vc_NG_NAS_SQN));
                } else {
                    log("*** " & __SCOPE__ & ": FAIL: Authentication failure with no AUTS");
                    setverdict(fail, "*** " & __SCOPE__ & ": FAIL: Authentication failure with no AUTS");
                }
            }
            [] tc_ac.timeout {
                // No message received, let's consider the message was accepted and proceed with the test case execution
                log("*** " & __SCOPE__ & ": FAIL: No NAS message received");
                setverdict(fail, "*** " & __SCOPE__ & ": FAIL: No NAS message received");
            }
        }
        f_recv_NGAP_PDU(
                        mw_ngap_initMsg(
                                        mw_n2_UplinkNASTransport(
+2 −2

File changed.

Contains only whitespace changes.

+2 −2

File changed.

Contains only whitespace changes.