From 84cdc71406622ffb8c5e47e4946f4967e90bb4c4 Mon Sep 17 00:00:00 2001 From: donald1218 Date: Thu, 12 Sep 2024 09:30:40 +0000 Subject: [PATCH 1/4] fix: use authctxId to auth not ue.suci --- internal/sbi/consumer/ausf_service.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/sbi/consumer/ausf_service.go b/internal/sbi/consumer/ausf_service.go index 6376225..efd7555 100644 --- a/internal/sbi/consumer/ausf_service.go +++ b/internal/sbi/consumer/ausf_service.go @@ -4,6 +4,7 @@ import ( "encoding/base64" "fmt" "net/url" + "regexp" "strconv" "sync" @@ -119,9 +120,12 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta if err != nil { return nil, nil, err } + re := regexp.MustCompile("/ue-authentications/.*/") + match := re.FindStringSubmatch(ue.AuthenticationCtx.Links["5g-aka"].Href) + authctxId := match[0][20 : len(match[0])-1] confirmResult, httpResponse, err := client.DefaultApi.UeAuthenticationsAuthCtxId5gAkaConfirmationPut( - ctx, ue.Suci, confirmData) + ctx, authctxId, confirmData) defer func() { if httpResponse != nil { if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { @@ -171,7 +175,11 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n return nil, nil, err } - eapSession, httpResponse, err := client.DefaultApi.EapAuthMethod(ctx, ue.Suci, eapSessionReq) + re := regexp.MustCompile("/ue-authentications/.*/") + match := re.FindStringSubmatch(ue.AuthenticationCtx.Links["eap-session"].Href) + authctxId := match[0][20 : len(match[0])-1] + + eapSession, httpResponse, err := client.DefaultApi.EapAuthMethod(ctx, authctxId, eapSessionReq) defer func() { if httpResponse != nil { if rspCloseErr := httpResponse.Body.Close(); rspCloseErr != nil { From b3490e794e4bd8621b8afe91331d57616aec0d07 Mon Sep 17 00:00:00 2001 From: donald1218 Date: Fri, 13 Sep 2024 03:37:04 +0000 Subject: [PATCH 2/4] fix: check array length before retrieve value --- internal/sbi/consumer/ausf_service.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/internal/sbi/consumer/ausf_service.go b/internal/sbi/consumer/ausf_service.go index efd7555..61bc89c 100644 --- a/internal/sbi/consumer/ausf_service.go +++ b/internal/sbi/consumer/ausf_service.go @@ -4,8 +4,8 @@ import ( "encoding/base64" "fmt" "net/url" - "regexp" "strconv" + "strings" "sync" "github.com/antihax/optional" @@ -100,7 +100,8 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta *models.ConfirmationDataResponse, *models.ProblemDetails, error, ) { var ausfUri string - if confirmUri, err := url.Parse(ue.AuthenticationCtx.Links["5g-aka"].Href); err != nil { + confirmUri, err := url.Parse(ue.AuthenticationCtx.Links["5g-aka"].Href) + if err != nil { return nil, nil, err } else { ausfUri = fmt.Sprintf("%s://%s", confirmUri.Scheme, confirmUri.Host) @@ -120,9 +121,13 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta if err != nil { return nil, nil, err } - re := regexp.MustCompile("/ue-authentications/.*/") - match := re.FindStringSubmatch(ue.AuthenticationCtx.Links["5g-aka"].Href) - authctxId := match[0][20 : len(match[0])-1] + splituri := strings.Split(confirmUri.RequestURI(), "/") + authctxId := "" + if len(splituri) > 4 { + authctxId = splituri[4] + } else { + return nil, nil, fmt.Errorf("authctxId is nil") + } confirmResult, httpResponse, err := client.DefaultApi.UeAuthenticationsAuthCtxId5gAkaConfirmationPut( ctx, authctxId, confirmData) @@ -175,9 +180,13 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n return nil, nil, err } - re := regexp.MustCompile("/ue-authentications/.*/") - match := re.FindStringSubmatch(ue.AuthenticationCtx.Links["eap-session"].Href) - authctxId := match[0][20 : len(match[0])-1] + splituri := strings.Split(confirmUri.RequestURI(), "/") + authctxId := "" + if len(splituri) > 4 { + authctxId = splituri[4] + } else { + return nil, nil, fmt.Errorf("authctxId is nil") + } eapSession, httpResponse, err := client.DefaultApi.EapAuthMethod(ctx, authctxId, eapSessionReq) defer func() { From 4a8c6b369e82f8cabd3726f84b3408ee8ddffa5b Mon Sep 17 00:00:00 2001 From: donald1218 Date: Fri, 13 Sep 2024 04:47:47 +0000 Subject: [PATCH 3/4] fix: add comment --- internal/sbi/consumer/ausf_service.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/sbi/consumer/ausf_service.go b/internal/sbi/consumer/ausf_service.go index 61bc89c..1d213ba 100644 --- a/internal/sbi/consumer/ausf_service.go +++ b/internal/sbi/consumer/ausf_service.go @@ -121,6 +121,8 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta if err != nil { return nil, nil, err } + // splituri = ["","nausf-auth","ue-authentications","{authctxId}","5g-aka-confirmation"] + // authctxId = {authctxId} splituri := strings.Split(confirmUri.RequestURI(), "/") authctxId := "" if len(splituri) > 4 { @@ -180,6 +182,8 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n return nil, nil, err } + // splituri = ["","nausf-auth","ue-authentications","{authctxId}","eap-session"] + // authctxId = {authctxId} splituri := strings.Split(confirmUri.RequestURI(), "/") authctxId := "" if len(splituri) > 4 { From b41fa67964470f42238d93c49e80a187ebf6c63a Mon Sep 17 00:00:00 2001 From: donald1218 Date: Fri, 13 Sep 2024 05:01:35 +0000 Subject: [PATCH 4/4] fix: remove quotes and add uri in comment --- internal/sbi/consumer/ausf_service.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/internal/sbi/consumer/ausf_service.go b/internal/sbi/consumer/ausf_service.go index 1d213ba..402fb6d 100644 --- a/internal/sbi/consumer/ausf_service.go +++ b/internal/sbi/consumer/ausf_service.go @@ -121,7 +121,8 @@ func (s *nausfService) SendAuth5gAkaConfirmRequest(ue *amf_context.AmfUe, resSta if err != nil { return nil, nil, err } - // splituri = ["","nausf-auth","ue-authentications","{authctxId}","5g-aka-confirmation"] + // confirmUri.RequestURI() = "/nausf-auth/v1/ue-authentications/{authctxId}/5g-aka-confirmation" + // splituri = ["","nausf-auth","ue-authentications",{authctxId},"5g-aka-confirmation"] // authctxId = {authctxId} splituri := strings.Split(confirmUri.RequestURI(), "/") authctxId := "" @@ -182,7 +183,8 @@ func (s *nausfService) SendEapAuthConfirmRequest(ue *amf_context.AmfUe, eapMsg n return nil, nil, err } - // splituri = ["","nausf-auth","ue-authentications","{authctxId}","eap-session"] + // confirmUri.RequestURI() = "/nausf-auth/v1/ue-authentications/{authctxId}/eap-session" + // splituri = ["","nausf-auth","ue-authentications",{authctxId},"eap-session"] // authctxId = {authctxId} splituri := strings.Split(confirmUri.RequestURI(), "/") authctxId := ""