Skip to content

Commit

Permalink
Use free5gc's upstream libraries instead of maintaining a fork of the…
Browse files Browse the repository at this point in the history
…m inside PacketRusher (#54)

Signed-off-by: Valentin <[email protected]>
  • Loading branch information
linouxis9 authored Dec 27, 2023
1 parent f104a31 commit 1c66eba
Show file tree
Hide file tree
Showing 647 changed files with 315 additions and 16,406 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ go 1.21
require (
github.com/davecgh/go-spew v1.1.1
github.com/free5gc/go-gtp5gnl v1.4.5
github.com/free5gc/nas v1.1.1
github.com/free5gc/aper v1.0.5-0.20230614030933-c73735898582
github.com/free5gc/nas v1.1.2-0.20230828074825-175b09665828
github.com/free5gc/ngap v1.0.7-0.20230614061954-9c128114ab1f
github.com/free5gc/openapi v1.0.6
github.com/free5gc/util v1.0.4
github.com/google/gopacket v1.1.19
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/free5gc/aper v1.0.5-0.20230614030933-c73735898582 h1:IV9PXKo6MH62e7nngSqr+cwjuoffkouPMmyX3jHC9Ds=
github.com/free5gc/aper v1.0.5-0.20230614030933-c73735898582/go.mod h1:ybHxhYnRqQ9wD4yB9r/3MZdbCYCjtqUyfLpSnJpwWd4=
github.com/free5gc/go-gtp5gnl v1.4.5 h1:w4mHuEue4hwpnQdYc19C5sXmxvYLZ0s2vJyDNdmt2wk=
github.com/free5gc/go-gtp5gnl v1.4.5/go.mod h1:TT5aXB90NuSPMehuIK9lV2yJFnq6Qjw37ZqNB1QAKh0=
github.com/free5gc/nas v1.1.1 h1:xUsqOOrb3kH38TQCzwZY7WN6WJkIerjERNjORDtnCbo=
github.com/free5gc/nas v1.1.1/go.mod h1:fjWwpyp7/wOyL72HTkjvIe9YTCfGyZosjITsI5sXyuU=
github.com/free5gc/nas v1.1.2-0.20230828074825-175b09665828 h1:/gIlzF8hacxWa6hsx+HQlw9F8yEorTvZvS1VR5Iwpjc=
github.com/free5gc/nas v1.1.2-0.20230828074825-175b09665828/go.mod h1:fjWwpyp7/wOyL72HTkjvIe9YTCfGyZosjITsI5sXyuU=
github.com/free5gc/ngap v1.0.7-0.20230614061954-9c128114ab1f h1:wgXjoknZ7JJoZ72J15g/f2/0DgdCpfcTg189lnhUPuY=
github.com/free5gc/ngap v1.0.7-0.20230614061954-9c128114ab1f/go.mod h1:lKA1sLTYM3CGEBhZVxkGGJIkai5+Bvy2yHIMhb7Vx/k=
github.com/free5gc/openapi v1.0.6 h1:ytRjU/YZRI8UhKKyfajXSyGB6s1YDFkJ1weeAGJ8LXw=
github.com/free5gc/openapi v1.0.6/go.mod h1:iw/N0E+FlX44EEx24IBi2EdZW8v+bkj3ETWPGnlK9DI=
github.com/free5gc/util v1.0.4 h1:GxliLpjI3NHMrKck3PDfx4OLJUuBjU182sVj+zbZK50=
Expand Down
2 changes: 1 addition & 1 deletion internal/control_test_engine/gnb/context/ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ package context

import (
"errors"
"my5G-RANTester/lib/ngap/ngapType"
"sync"

"github.com/free5gc/ngap/ngapType"
"github.com/ishidawataru/sctp"
)

Expand Down
8 changes: 5 additions & 3 deletions internal/control_test_engine/gnb/ngap/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
package ngap

import (
log "github.com/sirupsen/logrus"
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/internal/control_test_engine/gnb/ngap/handler"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/ngap/ngapType"
log "github.com/sirupsen/logrus"
)

func Dispatch(amf *context.GNBAmf, gnb *context.GNBContext, message []byte) {
Expand Down
7 changes: 4 additions & 3 deletions internal/control_test_engine/gnb/ngap/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import (
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/internal/control_test_engine/gnb/nas/message/sender"
"my5G-RANTester/internal/control_test_engine/gnb/ngap/trigger"
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap/ngapConvert"
"my5G-RANTester/lib/ngap/ngapType"
_ "net"

"github.com/free5gc/aper"

"github.com/free5gc/ngap/ngapConvert"
"github.com/free5gc/ngap/ngapType"
log "github.com/sirupsen/logrus"
_ "github.com/vishvananda/netlink"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package interface_management

import (
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"
"github.com/free5gc/ngap"

"github.com/free5gc/ngap/ngapType"
)

func AmfConfigurationUpdateAcknowledge() ([]byte, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ package interface_management

import (
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/aper"

"github.com/free5gc/ngap/ngapType"
)

func BuildNGSetupRequest(gnb *context.GNBContext) (pdu ngapType.NGAPPDU) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ package interface_management

import (
"fmt"

"github.com/free5gc/ngap"
"github.com/free5gc/ngap/ngapType"

"github.com/ishidawataru/sctp"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"
)

func NgSetupResponse(connN2 *sctp.SCTPConn) (*ngapType.NGAPPDU, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ package nas_transport

import (
"fmt"
"time"

"github.com/free5gc/ngap"
"github.com/free5gc/ngap/ngapType"

"github.com/ishidawataru/sctp"
log "github.com/sirupsen/logrus"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"
"time"
)

func DownlinkNasTransport(connN2 *sctp.SCTPConn, supi string) (*ngapType.NGAPPDU, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
"encoding/hex"
"fmt"
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/aper"

"github.com/free5gc/ngap/ngapType"
)

var TestPlmn ngapType.PLMNIdentity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ package nas_transport
import (
"fmt"
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/aper"

"github.com/free5gc/ngap/ngapType"
)

func getUplinkNASTransport(amfUeNgapID, ranUeNgapID int64, nasPdu []byte, plmn []byte, tac []byte) ([]byte, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
package pdu_session_management

import (
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap/ngapType"
"github.com/free5gc/aper"

"github.com/free5gc/ngap/ngapType"
)

func getGtpTeidFromNgUpUpTnlInformation(payload []byte) ([]byte, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package pdu_session_management

import (
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/ngap/ngapType"
)

func PDUSessionReleaseResponse(pduSessionIds []ngapType.PDUSessionID, ue *context.GNBUe) ([]byte, error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ package pdu_session_management
import (
"encoding/binary"
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapConvert"
"my5G-RANTester/lib/ngap/ngapType"
"net"

"github.com/free5gc/ngap"

"github.com/free5gc/aper"

customNgapType "my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap/ngapConvert"
"github.com/free5gc/ngap/ngapType"
)

func PDUSessionResourceSetupResponse(pduSession *context.GnbPDUSession, ue *context.GNBUe, ipv4 string) ([]byte, error) {
Expand Down Expand Up @@ -113,7 +118,7 @@ func GetPDUSessionResourceSetupResponseTransfer(ipv4 string, teid uint32, qosId
return encodeData
}

func buildPDUSessionResourceSetupResponseTransfer(ipv4 string, teid uint32, qosId int64) (data ngapType.PDUSessionResourceSetupResponseTransfer) {
func buildPDUSessionResourceSetupResponseTransfer(ipv4 string, teid uint32, qosId int64) (data customNgapType.PDUSessionResourceSetupResponseTransfer) {

// QoS Flow per TNL Information
qosFlowPerTNLInformation := &data.QosFlowPerTNLInformation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package ue_context_management

import (
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/ngap/ngapType"
)

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ package ue_context_management

import (
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/ngap/ngapType"
)

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import (
"bytes"
"encoding/binary"
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/lib/aper"
"my5G-RANTester/lib/ngap"
"my5G-RANTester/lib/ngap/ngapConvert"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap"

"github.com/free5gc/aper"

"github.com/free5gc/ngap/ngapConvert"
"github.com/free5gc/ngap/ngapType"
)

type PathSwitchRequestBuilder struct {
Expand Down
3 changes: 2 additions & 1 deletion internal/control_test_engine/gnb/ngap/message/sender/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ package sender

import (
"fmt"
"github.com/ishidawataru/sctp"
"my5G-RANTester/lib/ngap/ngapSctp"

"github.com/ishidawataru/sctp"
)

func SendToAmF(message []byte, conn *sctp.SCTPConn) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/control_test_engine/gnb/ngap/trigger/trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"my5G-RANTester/internal/control_test_engine/gnb/ngap/message/ngap_control/ue_context_management"
"my5G-RANTester/internal/control_test_engine/gnb/ngap/message/ngap_control/ue_mobility_management"
"my5G-RANTester/internal/control_test_engine/gnb/ngap/message/sender"
"my5G-RANTester/lib/ngap/ngapType"

"github.com/free5gc/ngap/ngapType"
log "github.com/sirupsen/logrus"
)

Expand Down
42 changes: 27 additions & 15 deletions internal/control_test_engine/ue/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"fmt"
"my5G-RANTester/internal/control_test_engine/gnb/context"
"my5G-RANTester/internal/control_test_engine/ue/scenario"
"my5G-RANTester/lib/UeauCommon"
"my5G-RANTester/lib/milenage"
"net"
"reflect"
"regexp"
Expand All @@ -22,6 +20,9 @@ import (
"github.com/free5gc/nas/nasType"
"github.com/free5gc/nas/security"

"github.com/free5gc/util/milenage"
"github.com/free5gc/util/ueauth"

"my5G-RANTester/internal/common/auth"

"github.com/free5gc/openapi/models"
Expand Down Expand Up @@ -569,13 +570,13 @@ func (ue *UEContext) DeriveRESstarAndSetKey(authSubs models.AuthenticationSubscr
}

// Generate RES, CK, IK, AK, AKstar
milenage.F2345_Test(OPC, K, RAND, RES, CK, IK, AK, AKstar)
milenage.F2345(OPC, K, RAND, RES, CK, IK, AK, AKstar)

// Get SQN, MAC_A, AMF from AUTN
sqnHn, _, mac_aHn := ue.deriveAUTN(AUTN, AK)

// Generate MAC_A, MAC_S
milenage.F1_Test(OPC, K, RAND, sqnHn, AMF, mac_a, mac_s)
milenage.F1(OPC, K, RAND, sqnHn, AMF, mac_a, mac_s)

// MAC verification.
if !reflect.DeepEqual(mac_a, mac_aHn) {
Expand All @@ -586,13 +587,13 @@ func (ue *UEContext) DeriveRESstarAndSetKey(authSubs models.AuthenticationSubscr
if bytes.Compare(sqnUe, sqnHn) > 0 {

// get AK*
milenage.F2345_Test(OPC, K, RAND, RES, CK, IK, AK, AKstar)
milenage.F2345(OPC, K, RAND, RES, CK, IK, AK, AKstar)

// From the standard, AMF(0x0000) should be used in the synch failure.
amfSynch, _ := hex.DecodeString("0000")

// get mac_s using sqn ue.
milenage.F1_Test(OPC, K, RAND, sqnUe, amfSynch, mac_a, mac_s)
milenage.F1(OPC, K, RAND, sqnUe, amfSynch, mac_a, mac_s)

sqnUeXorAK := make([]byte, 6)
for i := 0; i < len(sqnUe); i++ {
Expand All @@ -609,39 +610,50 @@ func (ue *UEContext) DeriveRESstarAndSetKey(authSubs models.AuthenticationSubscr

// derive RES*
key := append(CK, IK...)
FC := UeauCommon.FC_FOR_RES_STAR_XRES_STAR_DERIVATION
FC := ueauth.FC_FOR_RES_STAR_XRES_STAR_DERIVATION
P0 := []byte(snNmae)
P1 := RAND
P2 := RES

ue.DerivateKamf(key, snNmae, sqnHn, AK)
ue.DerivateAlgKey()
kdfVal_for_resStar := UeauCommon.GetKDFValue(key, FC, P0, UeauCommon.KDFLen(P0), P1, UeauCommon.KDFLen(P1), P2, UeauCommon.KDFLen(P2))
kdfVal_for_resStar, err := ueauth.GetKDFValue(key, FC, P0, ueauth.KDFLen(P0), P1, ueauth.KDFLen(P1), P2, ueauth.KDFLen(P2))
if err != nil {
log.Fatal("[UE] Error while deriving KDF ", err)
}
return kdfVal_for_resStar[len(kdfVal_for_resStar)/2:], "successful"
}

func (ue *UEContext) DerivateKamf(key []byte, snName string, SQN, AK []byte) {

FC := UeauCommon.FC_FOR_KAUSF_DERIVATION
FC := ueauth.FC_FOR_KAUSF_DERIVATION
P0 := []byte(snName)
SQNxorAK := make([]byte, 6)
for i := 0; i < len(SQN); i++ {
SQNxorAK[i] = SQN[i] ^ AK[i]
}
P1 := SQNxorAK
Kausf := UeauCommon.GetKDFValue(key, FC, P0, UeauCommon.KDFLen(P0), P1, UeauCommon.KDFLen(P1))
Kausf, err := ueauth.GetKDFValue(key, FC, P0, ueauth.KDFLen(P0), P1, ueauth.KDFLen(P1))
if err != nil {
log.Fatal("[UE] Error while deriving Kausf ", err)
}
P0 = []byte(snName)
Kseaf := UeauCommon.GetKDFValue(Kausf, UeauCommon.FC_FOR_KSEAF_DERIVATION, P0, UeauCommon.KDFLen(P0))

Kseaf, err := ueauth.GetKDFValue(Kausf, ueauth.FC_FOR_KSEAF_DERIVATION, P0, ueauth.KDFLen(P0))
if err != nil {
log.Fatal("[UE] Error while deriving Kseaf ", err)
}
supiRegexp, _ := regexp.Compile("(?:imsi|supi)-([0-9]{5,15})")
groups := supiRegexp.FindStringSubmatch(ue.UeSecurity.Supi)

P0 = []byte(groups[1])
L0 := UeauCommon.KDFLen(P0)
L0 := ueauth.KDFLen(P0)
P1 = []byte{0x00, 0x00}
L1 := UeauCommon.KDFLen(P1)
L1 := ueauth.KDFLen(P1)

ue.UeSecurity.Kamf = UeauCommon.GetKDFValue(Kseaf, UeauCommon.FC_FOR_KAMF_DERIVATION, P0, L0, P1, L1)
ue.UeSecurity.Kamf, err = ueauth.GetKDFValue(Kseaf, ueauth.FC_FOR_KAMF_DERIVATION, P0, L0, P1, L1)
if err != nil {
log.Fatal("[UE] Error while deriving Kamf ", err)
}
}

func (ue *UEContext) DerivateAlgKey() {
Expand Down
Loading

0 comments on commit 1c66eba

Please sign in to comment.