Skip to content

Commit

Permalink
chore: Adds staticcheck lint check (#37)
Browse files Browse the repository at this point in the history
* chore: Adds staticcheck lint check

* Moves random number generation to its own func
  • Loading branch information
gruyaume committed Jan 5, 2024
1 parent 874846b commit 18c2823
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ linters:
- gofmt
- govet
- errcheck
# - staticcheck
- staticcheck
- unused
# - gosimple
# - structcheck
Expand Down
4 changes: 2 additions & 2 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ package factory

import (
"fmt"
"io/ioutil"
"os"

"gopkg.in/yaml.v2"

Expand All @@ -22,7 +22,7 @@ var AusfConfig Config

// TODO: Support configuration update from REST api
func InitConfigFactory(f string) error {
if content, err := ioutil.ReadFile(f); err != nil {
if content, err := os.ReadFile(f); err != nil {
return err
} else {
AusfConfig = Config{}
Expand Down
25 changes: 18 additions & 7 deletions producer/ue_authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ package producer

import (
"context"
"math/big"

"crypto/rand"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
"math/rand"
"net/http"
"strings"
"time"

"github.com/bronze1man/radius"
"github.com/google/gopacket"
Expand All @@ -27,6 +28,16 @@ import (
"github.com/omec-project/openapi/models"
)

// Generates a random int between 0 and 255
func GenerateRandomNumber() (uint8, error) {
max := big.NewInt(256)
randomNumber, err := rand.Int(rand.Reader, max)
if err != nil {
return 0, err
}
return uint8(randomNumber.Int64()), nil
}

func HandleEapAuthComfirmRequest(request *http_wrapper.Request) *http_wrapper.Response {
logger.Auth5gAkaComfirmLog.Infof("EapAuthComfirmRequest")

Expand Down Expand Up @@ -221,12 +232,12 @@ func UeAuthPostRequestProcedure(updateAuthenticationInfo models.AuthenticationIn
ausfUeContext.Kseaf = hex.EncodeToString(Kseaf)

var eapPkt radius.EapPacket
var randIdentifier int
rand.Seed(time.Now().Unix())

randIdentifier, err := GenerateRandomNumber()
if err != nil {
logger.Auth5gAkaComfirmLog.Warnf("Generate random number failed: %+v", err)
}
eapPkt.Identifier = randIdentifier
eapPkt.Code = radius.EapCode(1)
randIdentifier = rand.Intn(256)
eapPkt.Identifier = uint8(randIdentifier)
eapPkt.Type = radius.EapType(50) // according to RFC5448 6.1
var atRand, atAutn, atKdf, atKdfInput, atMAC string
if atRandTmp, err := EapEncodeAttribute("AT_RAND", RAND); err != nil {
Expand Down
22 changes: 22 additions & 0 deletions producer/ue_authentication_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Canonical Ltd.

package producer_test

import (
"fmt"
"testing"

"github.com/omec-project/ausf/producer"
)

func TestGenerateRandomNumber(t *testing.T) {
value, err := producer.GenerateRandomNumber()

if err != nil {
t.Fatalf("GenerateRandomNumber() failed: %s", err)
}

fmt.Printf("Random number: %d\n", value)

}
6 changes: 6 additions & 0 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,16 @@ func (ausf *AUSF) UpdateNF() {
problemDetails.Status == 404 || problemDetails.Status == 400 {
//register with NRF full profile
nfProfile, err = ausf.BuildAndSendRegisterNFInstance()
if err != nil {
initLog.Errorf("AUSF register to NRF Error[%s]", err.Error())
}
}
} else if err != nil {
initLog.Errorf("AUSF update to NRF Error[%s]", err.Error())
nfProfile, err = ausf.BuildAndSendRegisterNFInstance()
if err != nil {
initLog.Errorf("AUSF register to NRF Error[%s]", err.Error())
}
}

if nfProfile.HeartBeatTimer != 0 {
Expand Down

0 comments on commit 18c2823

Please sign in to comment.