Skip to content

Commit

Permalink
fix(amf): fix authentication will never be rejected when use 5g-guti (#…
Browse files Browse the repository at this point in the history
…48)

* fix authentication will never be rejected when use 5g-guti

* update IdentityTypeUsedForRegistration only when re-auth

* send identity request only once during authentication procedure
  • Loading branch information
chliu-nems committed Oct 27, 2021
1 parent d0d5d1f commit e857bcd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions context/amf_ue.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ type AmfUe struct {
RoutingIndicator string
AuthenticationCtx *models.UeAuthenticationCtx
AuthFailureCauseSynchFailureTimes int
IdentityRequestSendTimes int
ABBA []uint8
Kseaf string
Kamf string
Expand Down Expand Up @@ -538,6 +539,7 @@ func (ue *AmfUe) ClearRegistrationRequestData(accessType models.AccessType) {
ue.RegistrationType5GS = 0
ue.IdentityTypeUsedForRegistration = 0
ue.AuthFailureCauseSynchFailureTimes = 0
ue.IdentityRequestSendTimes = 0
ue.ServingAmfChanged = false
ue.RegistrationAcceptForNon3GPPAccess = nil
if ranUe := ue.RanUe[accessType]; ranUe != nil {
Expand Down
10 changes: 7 additions & 3 deletions gmm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,7 @@ func AuthenticationProcedure(ue *context.AmfUe, accessType models.AccessType) (b
}
} else {
// Request UE's SUCI by sending identity request
ue.IdentityRequestSendTimes++
gmm_message.SendIdentityRequest(ue.RanUe[accessType], accessType, nasMessage.MobileIdentity5GSTypeSuci)
return false, nil
}
Expand Down Expand Up @@ -1914,7 +1915,8 @@ func HandleAuthenticationResponse(ue *context.AmfUe, accessType models.AccessTyp
if hResStar != av5gAka.HxresStar {
ue.GmmLog.Errorf("HRES* Validation Failure (received: %s, expected: %s)", hResStar, av5gAka.HxresStar)

if ue.IdentityTypeUsedForRegistration == nasMessage.MobileIdentity5GSType5gGuti {
if ue.IdentityTypeUsedForRegistration == nasMessage.MobileIdentity5GSType5gGuti && ue.IdentityRequestSendTimes == 0 {
ue.IdentityRequestSendTimes++
gmm_message.SendIdentityRequest(ue.RanUe[accessType], accessType, nasMessage.MobileIdentity5GSTypeSuci)
return nil
} else {
Expand Down Expand Up @@ -1947,7 +1949,8 @@ func HandleAuthenticationResponse(ue *context.AmfUe, accessType models.AccessTyp
ArgEAPMessage: "",
})
case models.AuthResult_FAILURE:
if ue.IdentityTypeUsedForRegistration == nasMessage.MobileIdentity5GSType5gGuti {
if ue.IdentityTypeUsedForRegistration == nasMessage.MobileIdentity5GSType5gGuti && ue.IdentityRequestSendTimes == 0 {
ue.IdentityRequestSendTimes++
gmm_message.SendIdentityRequest(ue.RanUe[accessType], accessType, nasMessage.MobileIdentity5GSTypeSuci)
return nil
} else {
Expand Down Expand Up @@ -1982,7 +1985,8 @@ func HandleAuthenticationResponse(ue *context.AmfUe, accessType models.AccessTyp
ArgEAPMessage: response.EapPayload,
})
case models.AuthResult_FAILURE:
if ue.IdentityTypeUsedForRegistration == nasMessage.MobileIdentity5GSType5gGuti {
if ue.IdentityTypeUsedForRegistration == nasMessage.MobileIdentity5GSType5gGuti && ue.IdentityRequestSendTimes == 0 {
ue.IdentityRequestSendTimes++
gmm_message.SendAuthenticationResult(ue.RanUe[accessType], false, response.EapPayload)
gmm_message.SendIdentityRequest(ue.RanUe[accessType], accessType, nasMessage.MobileIdentity5GSTypeSuci)
return nil
Expand Down
6 changes: 6 additions & 0 deletions gmm/sm.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/free5gc/amf/logger"
"github.com/free5gc/fsm"
"github.com/free5gc/nas"
"github.com/free5gc/nas/nasConvert"
"github.com/free5gc/nas/nasMessage"
"github.com/free5gc/openapi/models"
)
Expand Down Expand Up @@ -167,6 +168,10 @@ func Authentication(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
if err := HandleIdentityResponse(amfUe, gmmMessage.IdentityResponse); err != nil {
logger.GmmLog.Errorln(err)
}
// update identity type used for reauthentication
mobileIdentityContents := gmmMessage.IdentityResponse.MobileIdentity.GetMobileIdentityContents()
amfUe.IdentityTypeUsedForRegistration = nasConvert.GetTypeOfIdentity(mobileIdentityContents[0])

err := GmmFSM.SendEvent(state, AuthRestartEvent, fsm.ArgsType{ArgAmfUe: amfUe, ArgAccessType: accessType})
if err != nil {
logger.GmmLog.Errorln(err)
Expand Down Expand Up @@ -205,6 +210,7 @@ func Authentication(state *fsm.State, event fsm.EventType, args fsm.ArgsType) {
amfUe.GmmLog.Debugln(event)
amfUe.AuthenticationCtx = nil
amfUe.AuthFailureCauseSynchFailureTimes = 0
amfUe.IdentityRequestSendTimes = 0
default:
logger.GmmLog.Errorf("Unknown event [%+v]", event)
}
Expand Down

0 comments on commit e857bcd

Please sign in to comment.