From 4e60475200e988e7d21e6d8658967c5540b06a9a Mon Sep 17 00:00:00 2001 From: Bedran Karakoc Date: Fri, 22 Oct 2021 17:27:25 +0200 Subject: [PATCH] Apply security to Deregistration Request (UE Originating) --- srsue/src/stack/upper/nas_5g.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/srsue/src/stack/upper/nas_5g.cc b/srsue/src/stack/upper/nas_5g.cc index de5b72bd1..9622893bf 100644 --- a/srsue/src/stack/upper/nas_5g.cc +++ b/srsue/src/stack/upper/nas_5g.cc @@ -622,6 +622,8 @@ int nas_5g::send_deregistration_request_ue_originating(bool switch_off) nas_5gs_msg nas_msg; deregistration_request_ue_originating_t& deregistration_request = nas_msg.set_deregistration_request_ue_originating(); + nas_msg.hdr.security_header_type = nas_5gs_hdr::security_header_type_opts::integrity_protected_and_ciphered; + nas_msg.hdr.sequence_number = ctxt_base.tx_count; // Note 5.5.2.2.2 : AMF does not send a Deregistration Accept NAS message if De-registration type IE indicates "switch // off" @@ -655,10 +657,17 @@ int nas_5g::send_deregistration_request_ue_originating(bool switch_off) } logger.info("Sending Deregistration Request (UE Originating)"); - rrc_nr->write_sdu(std::move(pdu)); + cipher_encrypt(pdu.get()); + integrity_generate(&ctxt_base.k_nas_int[16], + ctxt_base.tx_count, + SECURITY_DIRECTION_UPLINK, + &pdu->msg[SEQ_5G_OFFSET], + pdu->N_bytes - SEQ_5G_OFFSET, + &pdu->msg[MAC_5G_OFFSET]); + rrc_nr->write_sdu(std::move(pdu)); + ctxt_base.tx_count++; reset_pdu_sessions(); - // TODO: Delete / Reset context (ctxt & ctxt_5g) return SRSASN_SUCCESS;