Skip to content

Commit

Permalink
Merge pull request #47 from enowars/clean-up
Browse files Browse the repository at this point in the history
Some clean up, remove unused features
  • Loading branch information
theodorsm committed Jul 18, 2023
2 parents 74fcaf2 + 332142f commit 7b32e88
Show file tree
Hide file tree
Showing 16 changed files with 60 additions and 235 deletions.
1 change: 0 additions & 1 deletion checker/requirements.txt

This file was deleted.

12 changes: 6 additions & 6 deletions checker/src/internal/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,8 @@ func (h *Handler) checkNullEncCore(ctx context.Context, message *enochecker.Task
return err
}

regMsg := nas.NASRegRequestMsg{SecHeader: 0,
MobileId: nas.MobileIdType{Mcc: 0, Mnc: 0, ProtecScheme: 0, HomeNetPki: 0, Msin: 0},
regMsg := nas.NASRegRequestMsg{
MobileId: nas.MobileIdType{Mcc: 0, Mnc: 0, HomeNetPki: 0, Msin: 0},
SecCap: nas.SecCapType{EaCap: nas.EA0, IaCap: nas.IA1},
}

Expand Down Expand Up @@ -511,7 +511,7 @@ func (h *Handler) checkNullEncCore(ctx context.Context, message *enochecker.Task
}

res := crypto.IA2(authReq.Rand, key)
authRes := nas.NASAuthResponseMsg{SecHeader: 0, Res: res}
authRes := nas.NASAuthResponseMsg{Res: res}
authResMsg, mac, err := nas.BuildMessagePlain(&authRes)
if err != nil {
return err
Expand Down Expand Up @@ -677,7 +677,7 @@ func (h *Handler) checkNullEncUE(ctx context.Context, message *enochecker.TaskMe

auth := crypto.IA2(authRand, key)

authReq := nas.NASAuthRequestMsg{SecHeader: 0, Rand: randToken, AuthRand: authRand, Auth: auth}
authReq := nas.NASAuthRequestMsg{Rand: randToken, AuthRand: authRand, Auth: auth}

authReqbuf, mac, err := nas.BuildMessagePlain(&authReq)
if err != nil {
Expand All @@ -698,10 +698,10 @@ func (h *Handler) checkNullEncUE(ctx context.Context, message *enochecker.TaskMe
ia = 1
}

secModeCmd := nas.NASSecurityModeCommandMsg{SecHeader: 1, EaAlg: 0,
secModeCmd := nas.NASSecurityModeCommandMsg{EaAlg: 0,
IaAlg: 1, ReplaySecCap: sec,
}
secModeMsg, mac, err := nas.BuildMessagePlain(&secModeCmd)
secModeMsg, mac, err := nas.BuildMessage(0, 1, &secModeCmd, key)
if err != nil {
return err
}
Expand Down
18 changes: 6 additions & 12 deletions checker/src/internal/nas/msgTypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,34 +99,29 @@ type MobileIdType struct {
Mcc uint8
Mnc uint8
// Routing indicator
ProtecScheme uint8
HomeNetPki uint8
Msin uint
HomeNetPki uint8
Msin uint
}

type NASRegRequestMsg struct {
// Extended protocol discriminator
SecHeader uint8
// 5GS registration type
// ngKsi
MobileId MobileIdType
SecCap SecCapType
}

type NASAuthRequestMsg struct {
SecHeader uint8
Rand []byte
AuthRand []byte
Auth []byte
Rand []byte
AuthRand []byte
Auth []byte
}

type NASAuthResponseMsg struct {
SecHeader uint8
Res []byte
Res []byte
}

type NASSecurityModeCommandMsg struct {
SecHeader uint8
EaAlg uint8
IaAlg uint8
ReplaySecCap SecCapType
Expand All @@ -135,7 +130,6 @@ type NASSecurityModeCommandMsg struct {
type PDUSessionEstRequestMsg struct {
PduSesId uint8
PduSesType uint8
// add integrity protetion maximum data rate
}

type PDUSessionEstAcceptMsg struct {
Expand Down
81 changes: 0 additions & 81 deletions checker/tester.py

This file was deleted.

2 changes: 0 additions & 2 deletions service/.service-secrets.env

This file was deleted.

Binary file modified service/gnb
Binary file not shown.
12 changes: 7 additions & 5 deletions service/src/cmd/ue/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func handleConnection(logger *zap.Logger, c net.Conn) {

u := *ue.NewUE(logger)

err := sendRegistrationRequest(u, c)
err := sendRegistrationRequest(&u, c)
if err != nil {
log.Error(err)
return
Expand Down Expand Up @@ -115,11 +115,13 @@ func handleConnection(logger *zap.Logger, c net.Conn) {

}

func sendRegistrationRequest(u ue.UE, c net.Conn) error {
regMsg := nas.NASRegRequestMsg{SecHeader: 0,
MobileId: nas.MobileIdType{Mcc: 0, Mnc: 0, ProtecScheme: 0, HomeNetPki: 0, Msin: 0},
SecCap: nas.SecCapType{EaCap: nas.EA1, IaCap: nas.IA1 ^ nas.IA2 ^ nas.IA3 ^ nas.IA4},
func sendRegistrationRequest(u *ue.UE, c net.Conn) error {
sec := nas.SecCapType{EaCap: nas.EA1, IaCap: nas.IA1 ^ nas.IA2 ^ nas.IA3 ^ nas.IA4}
regMsg := nas.NASRegRequestMsg{
MobileId: nas.MobileIdType{Mcc: 0, Mnc: 0, HomeNetPki: 0, Msin: 0},
SecCap: sec,
}
u.SecCap = sec

msg, err := parser.EncodeMsg(&regMsg)
if err != nil {
Expand Down
33 changes: 0 additions & 33 deletions service/src/internal/core/builder.go

This file was deleted.

4 changes: 2 additions & 2 deletions service/src/internal/core/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func (amf *Amf) handleInitUEMessage(c net.Conn, buf []byte, amfg *AmfGNB) error

ue.RandToken = randToken

authReq := nas.NASAuthRequestMsg{SecHeader: 0, Rand: ue.RandToken, AuthRand: authRand, Auth: auth}
authReq := nas.NASAuthRequestMsg{Rand: ue.RandToken, AuthRand: authRand, Auth: auth}

authReqbuf, mac, err := nas.BuildMessagePlain(&authReq)
if err != nil {
Expand Down Expand Up @@ -390,7 +390,7 @@ func (amf *Amf) handleNASAuthResponse(c net.Conn, buf []byte, amfg *AmfGNB, ue *

ue.EaAlg = EA
ue.IaAlg = IA
secModeCmd := nas.NASSecurityModeCommandMsg{SecHeader: 1, EaAlg: ue.EaAlg,
secModeCmd := nas.NASSecurityModeCommandMsg{EaAlg: ue.EaAlg,
IaAlg: ue.IaAlg, ReplaySecCap: ue.SecCap,
}
secModeMsg, mac, err := nas.BuildMessagePlain(&secModeCmd)
Expand Down
48 changes: 0 additions & 48 deletions service/src/internal/core/handler_test.go

This file was deleted.

1 change: 0 additions & 1 deletion service/src/internal/ue/builder.go

This file was deleted.

15 changes: 2 additions & 13 deletions service/src/internal/ue/handler.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package ue

import (
"bufio"
"bytes"
"errors"
"net"
"os"
"phreaking/internal/crypto"
"phreaking/internal/io"
"phreaking/pkg/nas"
Expand Down Expand Up @@ -59,19 +57,10 @@ func (u *UE) HandleNASSecurityModeCommand(c net.Conn, msgbuf []byte) error {
u.EaAlg = msg.EaAlg
u.IaAlg = msg.IaAlg

location := ""
readFile, err := os.Open("/service/data/location.data")
location, err := u.GetLocation()
if err != nil {
return err
}

fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
location = fileScanner.Text()
}
readFile.Close()

loc := nas.LocationUpdateMsg{Location: location}
locMsg, mac, err := nas.BuildMessage(u.EaAlg, u.IaAlg, &loc)
if err != nil {
Expand Down Expand Up @@ -106,7 +95,7 @@ func (u *UE) HandleNASAuthRequest(c net.Conn, msgbuf []byte) error {
}

res := crypto.IA2(msg.Rand)
authRes := nas.NASAuthResponseMsg{SecHeader: 0, Res: res}
authRes := nas.NASAuthResponseMsg{Res: res}
authResMsg, mac, err := nas.BuildMessagePlain(&authRes)
if err != nil {
return err
Expand Down
23 changes: 22 additions & 1 deletion service/src/internal/ue/ue.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
package ue

import (
"bufio"
"os"
"phreaking/pkg/nas"

"go.uber.org/zap"
)

type UE struct {
Logger *zap.Logger
state StateType
//MobileId ngap.MobileIdType
//SecCap ngap.SecCapType
SecCap nas.SecCapType
EaAlg uint8
IaAlg uint8
ActivePduId uint8
Expand All @@ -31,6 +35,23 @@ func (u *UE) InState(s StateType) bool {
return (u.state == s)
}

func (u *UE) GetLocation() (string, error) {
u.Logger.Sugar().Debugf("Getting location from UE OS API")
location := ""
readFile, err := os.Open("/service/data/location.data")
if err != nil {
return location, err
}

fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
for fileScanner.Scan() {
location = fileScanner.Text()
}
readFile.Close()
return location, nil
}

type StateType string

// state for UE
Expand Down
Loading

0 comments on commit 7b32e88

Please sign in to comment.