Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use free5gc's upstream libraries instead of maintaining a fork of them inside PacketRusher #54

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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
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
Loading