pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43212?usp=email )


Change subject: 5gc: Fix NG NAS ul_count not incremented
......................................................................

5gc: Fix NG NAS ul_count not incremented

Since open5gs.git b9823196b5de3394b7a144569f186d7d62fad6f9, open5gs
properly validates received seq_nr (ul_count) of integrity protected
NG-NAS message to make sure it increases with each new UL message, in
order to protect against accepting replayed messages.

This made the 5gc testsuite fail since our NGAP/NG-NAS emulation was not
properly increasing ul_count when sending new messages, but always using
ul_count=0.

Change-Id: I7ea4460c902a5f612243e155a484acc89acd447f
---
M library/NG_CryptoFunctions.ttcn
1 file changed, 10 insertions(+), 6 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-ttcn3-hacks 
refs/changes/12/43212/1

diff --git a/library/NG_CryptoFunctions.ttcn b/library/NG_CryptoFunctions.ttcn
index b16029e..d53945f 100644
--- a/library/NG_CryptoFunctions.ttcn
+++ b/library/NG_CryptoFunctions.ttcn
@@ -307,13 +307,16 @@
        var BIT4 sec_hdr_t;
        var OCT4 mac;
        var NG_NAS_UL_Message_Type nas_out;
-
-       if (nus.use_enc == false and nus.use_int == false) {
-               return nas_in;
-       }
+       var OCT1 seq_nr;

        if (nus.new_ctx) {
                nus.tx_count := 0;
+       } else {
+               nus.tx_count := nus.tx_count + 1;
+       }
+
+       if (nus.use_enc == false and nus.use_int == false) {
+               return nas_in;
        }

        var octetstring nas_enc := enc_NG_NAS_UL_Message_Type(nas_in)
@@ -327,14 +330,15 @@
                Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail, "Not 
supported");
        }

+       seq_nr := int2oct(nus.tx_count, 1);
        sec_hdr_t := f_NG_NAS_determine_sec_hdr_t(nus.use_enc, nus.use_int, 
nus.new_ctx);
        mac := f_NG_NAS_mac_calc(nus.alg_int, nus.k_nas_int, nus.tx_count,
                                 bit2int(tsc_NG_RegResult_3GPP),
-                                f_tx_is_downlink(nus), '00'O & nas_enc);
+                                f_tx_is_downlink(nus), seq_nr & nas_enc);
        nas_out := valueof(cs_NG_SECURITY_PROTECTED_NAS_MESSAGE(tsc_EPD_GMM,
                                                                sec_hdr_t,
                                                                mac,
-                                                               
int2oct(nus.tx_count, 1),
+                                                               seq_nr,
                                                                nas_enc));

        return nas_out;

--
To view, visit https://gerrit.osmocom.org/c/osmo-ttcn3-hacks/+/43212?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: osmo-ttcn3-hacks
Gerrit-Branch: master
Gerrit-Change-Id: I7ea4460c902a5f612243e155a484acc89acd447f
Gerrit-Change-Number: 43212
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to