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

Remove use of UeauCommon and start using ueauth from the util repo #185

Merged
merged 5 commits into from
Feb 2, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions context/amf_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"sync"
"time"

"github.com/omec-project/UeauCommon"
"github.com/omec-project/amf/logger"
"github.com/omec-project/amf/metrics"
"github.com/omec-project/amf/protos/sdcoreAmfServer"
Expand All @@ -32,6 +31,7 @@ import (
"github.com/omec-project/ngap/ngapType"
"github.com/omec-project/openapi/models"
"github.com/omec-project/util/fsm"
"github.com/omec-project/util/ueauth"
thakurajayL marked this conversation as resolved.
Show resolved Hide resolved
"github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -615,42 +615,54 @@ func (ue *AmfUe) DerivateKamf() {
}

P0 := []byte(groups[1])
L0 := UeauCommon.KDFLen(P0)
L0 := ueauth.KDFLen(P0)
P1 := ue.ABBA
L1 := UeauCommon.KDFLen(P1)
L1 := ueauth.KDFLen(P1)

KseafDecode, err := hex.DecodeString(ue.Kseaf)
if err != nil {
logger.ContextLog.Error(err)
return
}
KamfBytes := UeauCommon.GetKDFValue(KseafDecode, UeauCommon.FC_FOR_KAMF_DERIVATION, P0, L0, P1, L1)
KamfBytes, err := ueauth.GetKDFValue(KseafDecode, ueauth.FC_FOR_KAMF_DERIVATION, P0, L0, P1, L1)
if err != nil {
logger.ContextLog.Error(err)
return
}
ue.Kamf = hex.EncodeToString(KamfBytes)
}

// Algorithm key Derivation function defined in TS 33.501 Annex A.9
func (ue *AmfUe) DerivateAlgKey() {
// Security Key
P0 := []byte{security.NNASEncAlg}
L0 := UeauCommon.KDFLen(P0)
L0 := ueauth.KDFLen(P0)
P1 := []byte{ue.CipheringAlg}
L1 := UeauCommon.KDFLen(P1)
L1 := ueauth.KDFLen(P1)

KamfBytes, err := hex.DecodeString(ue.Kamf)
if err != nil {
logger.ContextLog.Error(err)
return
}
kenc := UeauCommon.GetKDFValue(KamfBytes, UeauCommon.FC_FOR_ALGORITHM_KEY_DERIVATION, P0, L0, P1, L1)
kenc, err := ueauth.GetKDFValue(KamfBytes, ueauth.FC_FOR_ALGORITHM_KEY_DERIVATION, P0, L0, P1, L1)
if err != nil {
logger.ContextLog.Error(err)
return
}
copy(ue.KnasEnc[:], kenc[16:32])

// Integrity Key
P0 = []byte{security.NNASIntAlg}
L0 = UeauCommon.KDFLen(P0)
L0 = ueauth.KDFLen(P0)
P1 = []byte{ue.IntegrityAlg}
L1 = UeauCommon.KDFLen(P1)
L1 = ueauth.KDFLen(P1)

kint := UeauCommon.GetKDFValue(KamfBytes, UeauCommon.FC_FOR_ALGORITHM_KEY_DERIVATION, P0, L0, P1, L1)
kint, err := ueauth.GetKDFValue(KamfBytes, ueauth.FC_FOR_ALGORITHM_KEY_DERIVATION, P0, L0, P1, L1)
if err != nil {
logger.ContextLog.Error(err)
return
}
copy(ue.KnasInt[:], kint[16:32])
}

Expand All @@ -659,19 +671,23 @@ func (ue *AmfUe) DerivateAnKey(anType models.AccessType) {
accessType := security.AccessType3GPP // Defalut 3gpp
P0 := make([]byte, 4)
binary.BigEndian.PutUint32(P0, ue.ULCount.Get())
L0 := UeauCommon.KDFLen(P0)
L0 := ueauth.KDFLen(P0)
if anType == models.AccessType_NON_3_GPP_ACCESS {
accessType = security.AccessTypeNon3GPP
}
P1 := []byte{accessType}
L1 := UeauCommon.KDFLen(P1)
L1 := ueauth.KDFLen(P1)

KamfBytes, err := hex.DecodeString(ue.Kamf)
if err != nil {
logger.ContextLog.Error(err)
return
}
key := UeauCommon.GetKDFValue(KamfBytes, UeauCommon.FC_FOR_KGNB_KN3IWF_DERIVATION, P0, L0, P1, L1)
key, err := ueauth.GetKDFValue(KamfBytes, ueauth.FC_FOR_KGNB_KN3IWF_DERIVATION, P0, L0, P1, L1)
if err != nil {
logger.ContextLog.Error(err)
return
}
switch accessType {
case security.AccessType3GPP:
ue.Kgnb = key
Expand All @@ -683,14 +699,18 @@ func (ue *AmfUe) DerivateAnKey(anType models.AccessType) {
// NH Derivation function defined in TS 33.501 Annex A.10
func (ue *AmfUe) DerivateNH(syncInput []byte) {
P0 := syncInput
L0 := UeauCommon.KDFLen(P0)
L0 := ueauth.KDFLen(P0)

KamfBytes, err := hex.DecodeString(ue.Kamf)
if err != nil {
logger.ContextLog.Error(err)
return
}
ue.NH = UeauCommon.GetKDFValue(KamfBytes, UeauCommon.FC_FOR_NH_DERIVATION, P0, L0)
ue.NH, err = ueauth.GetKDFValue(KamfBytes, ueauth.FC_FOR_NH_DERIVATION, P0, L0)
if err != nil {
logger.ContextLog.Error(err)
return
}
}

func (ue *AmfUe) UpdateSecurityContext(anType models.AccessType) {
Expand Down
Loading