• Add the reminder in the modified code place.

AUSF improvement 2

  • Before
    image
  • After
    image

Reason

image
image

1st req & resp

Method

  • Use the function call in AMF, instead of call AUSF's API.
    image
    • In ue_authentication.go(AMF)
    • Call by func SendUEAuthenticationAuthenticateRequest
    • Need to check whether creating another new file for function calling is needed or not.
      • No, all modification is done in ue_authentication.go
  • Reserve parts :
    • RAND, AUTN pass in AUSF
      image
      • In ue_authentication.go(AUSF)
      • Call by func UeAuthPostRequestProcedure
    • RAND, AUTN gen in UDM
      image
      • In generate_auth_data.go(UDM)
      • func GenerateAuthDataProcedure
      • func strictHex
      • func aucSQN
    • MongoDB API in UDR
      • In data_repository.go(UDR)
      • func QueryAuthSubsDataProcedure
      • func getDataFromDB
      • func ModifyAuthenticationProcedure
      • func patchDataToDBAndNotify
  • Reduction
    • API -> function calling (Some functions, URI creating, parameters passing, http interaction)
    • AUSF selection
    • AUSF context create.
    • EAP-AKA'
    • Service network authorization
    • Simplfy resyncronization, SUCI checking
    • SUCI to SUPI

Modification

Prerequisite

  • Move the file from the VM in server room to computer in lab because of storage problem.
  • OS changed from ubuntu 20.04 to 18.04, and kernel version is still on 5.4.0, so it is OK for gtp module.
  • Move the reserved parts to AMF, and put them above func SendUEAuthenticationAuthenticateRequest.

Implementation

The parts need to check after modification :
(They are in the folded area below, here just for final confirmation and not for check list)

  • func SendUEAuthenticationAuthenticateRequest
  • func UeAuthPostRequestProcedure
  • func GenerateAuthDataProcedure
func SendUEAuthenticationAuthenticateRequest

image

  1. Why I dont call func UeAuthPostRequestProcedure of AUSF directly from func AuthenticationProcedure of AMF.
    • In modification before, it has a transformation of the format authInfo.
      image
    • The parameters passed from AuthenticationProcedure are image
    • The received side is image
    • And it use them to make the parameters will be passed to AUSF.
      image
    • So I reserved them first and to see if I need to move them to AuthenticationProcedure or remove them.
  2. Change the receive parameters to ignore the API part and match the return. image
    image
    • The locationURI in UeAuthPostRequestProcedure also needs to modify.
    • The return parameters remain three to match AuthenticationProcedure's calling, or modify to another err reporting format.
    • Not sure if the format of ueAuthenticationCtx is matched or not.
      image
      image
      image
  3. Remove part
    image
func UeAuthPostRequestProcedure

image

  1. Comment out the service network authorization.
    image
  2. Reduce EAP-AKA'
    image
  3. Reduce the return parameters to two(rep & err).
    image
    image
    • Need to check the pointer format when test.
  4. Comment out the locationURI processing.
    image
    • Because it is used in one of the return parameter(responseBody), so reserve it first, and see if I can remove it latter.(Code explanation)
      image
  5. Resynchronization
    image
    • Originally it will not be used at UE's first attach in func AuthenticationProcedure, it passes a nil to func SendUEAuthenticationAuthenticateRequest.
      image
      image
    • In func HandleAuthenticationFailure, it will call again and give it resynchronizationInfo.
      image
    • Comment out here and need to prepare how to deal with resyncronization.
      image
  6. Call UDM -> Call function
    • Original API server parameters passing to UDM is like this.
      image
    • Ignore the original API calling, and modify the parameters to call function.
      image
      • The UDM function side.
        image
    • The return parameters in UDM function are matched with original API.
      image
      • Format in UDM function
        image
        image
        image
      • So remove the API parameter rsp, and Im not sure if the format of err is matched with problemDetails, because it's originally passed to API function.
        image
  7. Reduce the ausf context process part, and reserve ueid access, print it to add a pause and see the result.
    • I dont know which one can print on terminal so I use two of them.
      image
    • The other part below.
      image
  8. Kseaf & Kausf
    • I reserved the Kseaf derive part first, although, because Kseaf will be used in 2nd req & rep to generate Kamf, I dont know if that will be reduced or not.
      image
    • Kausf will be gen in UDM function, and it is included in AV , so it will beb reserved.
  • Modules need to be added
  • logger function
    • Original in AMF
      image
    • The logger file may not has the function of AUSF print function, need to add or change to AMF print function.
func GenerateAuthDataProcedure
  1. Reduce EAP-AKA'
    image
  2. Call ToSupi -> Call function
    • Need to check whether to pass supi directly.
    1. Original source in UDM
      image
      image
      image
      • ToSupi function is in suci.go, and it calls other key transform functions above it, so if I move all of them, I need to modify a lot, then I take a see of Terry's method.
    2. Terry's solution
      • Example test link
      • Im not sure if it can transform or not, so I print the SUCI in AMF and SUPI in UDM.
        image
        image
        image
      • This solu assumes that the UE use IMSI SUPI type, and mcc/mnc parts are fixed, so if the mcc/mnc are changed, it turns out error.
    3. So here I'm concerning to move suci.go.
      • Move to here and change the packge name.
        image
        • The logger imported print function should be modified.
      • Here I found a problem is that it has a passing parameter called suciProfiles, which is used in home nework key & SUCI to SUPI transfrom, like the below description.
        image
        • And the several functions above ToSupi are all for the profileA & profileB.
    4. So here I decide to combine the mcc/mnc extract method in ToSupi and Terry's method.
      • Create the const
        image
      • Original other guys' method
        • Terry
          image
        • ToSupi
          image
      • My final method
        image
      • Remove the supi.go which I wanted to move to here, and this part.
        image
  3. Call UDR -> Call function
    • The API part from UDM side to UDR side, maybe I have to put the selected part into the UDM's calling side(it's moved now).
      image
    • In the main part, UDR side passes two parameters to get UE data from mongoDB, and in the getDataFromDB, it imports something.
      • image
      • image
      • About how it imports, go here for more info.
      • When I was checking Terry's approach of here(connect and get data from mongoDB), I have more problem about the difference with my past import methods, go here for more info about what I has discovered.
    • Pint the ueId which will be use in the API process of UDM-UDR, so it is SUPI.
      image
      image
    • Remove UDR client creating, and move the parameters creating from UDR.
      image
    • Pint the return value of API and the function I want to move.
      image
      image
      • Im not sure if authSubs can directly receive the return of this format(map[string]interface{}), without the trasformation of API(response->authSubs), the usage of authSubs below are all in the content of the return from func QueryAuthSubsDataProcedure in UDR.
        image
        image
        image
        image
        image
        image
      • Sort up the output of return map of func QueryAuthSubsDataProcedure, so they are matched and can indeed call the parameters.
        image
    • Reduce the receive parameters to two, an comment out the API process.
      image
    • Delete the redundent of API part, because it has directly calls the func QueryAuthSubsDataProcedure.
      image
      • But keep the printing line in
        image
  4. strictHex
    image
    image
    image
    image
    • Add one more function from UDM, here is what it does.
      image
  5. make -> Link
    image
  6. Resynchronization
    Here I just checked the modification before :
    • So in func AuthenticationProcedure, the resync info passed to func SendUEAuthenticationAuthenticateRequest will be set to nil.
      image
      But it will be set in func HandleAuthenticationFailure if there is a sync failure happened.
      image
      image
    • In func SendUEAuthenticationAuthenticateRequest, it just passes the parameter if it receives it, and doesn't do more process.
      image
    • In past modification, I commented out the resync process in func UeAuthPostRequestProcedure because it includes ausf context edit, but I want to keep the resync info passing, so I do this modificaiton.
      image
      • Then if the resync info exists, the info will not be lost, and will be received by func GenerateAuthDataProcedure.
      • But here I'm not sure commenting out this Rand parameter filling will affect or not (There will not have Rand parameter ?).
        image
    • In func GenerateAuthDataProcedure.
      • It decodes Auts/Rand from ResynchronizationInfo, and use aucSQN to generate SQN & mac.
      • aucSQN image
        • It is a function in original UDM, so copy it to AMF.
          image
      • Then it uses some imported function to do computation in if/else -> Link
        • In else part, comment out the suci checking, only keep the logger printing and return.
          image
  7. increment sqn(call UDR -> call function)
    • Do some computation for SQN. -> Link
      image
    • Save the computaion results into DB
      image
      • Here is the API operation in UDR, need to combine it into AMF.
        image
        image
    • Modification 1 : Move the API calling/parameter passing to here.
      image
      • Modify the error process.
        image
    • Modification 2 : Attach the parts (1&2) forgot in the UDR function calling last time (get data from DB), the http calling has been imported when doing AUSF funciton moving.
      image
      And the util calling need to be modified because it is originally from UDR.
      image
    • Modification 3 : util function
      • Originally, UDR import this folder "github.com/free5gc/udr/internal/util" and call the function in this file.
        image
      • But only these two functions(get, modify) I import from UDR call that file, so I decide to move the called functions directly.
        image
        image
        image
      • The http and model need to add have been imported in my files, so just move and modify.
        image
        image
      • About the variable declaration -> Link
    • Modification 4 : func patchDataToDBAndNotify
      • Add one import ("encoding/json").
      • Comment out the notify function calling, because it is not nessesiry to send a notification from UDR in future, just modify the DB. But Im not sure whether this notification will affect other module or not.
        image
        image
        image
      • About the recover() function -> Link

Compilation

Problem 1

  • Need to go get some imported module
    image
  • About tha fatal lines info -> Link
  • Type these commands :
cd NFs/amf go get github.com/free5gc/util/mongoapi@v1.0.5-0.20230306071612-a52909216bd2 go get github.com/free5gc/amf/internal/sbi/consumer
  • I don't know if it is right to go get in the root folder.
    image

image
image

  • Need to go get in the folder which has go.mod
    image
  • I don't know why make command say that I need to go get amf/comsumer, maybe because I did the modification in comsumer folder.
    image
  • And if I ignore the errors above and make directly, I will get the same errors.
    image
  • So I just ignore it and keep debugging.

Problem 2

image

  1. image
    -> image
  2. The logger problem : logger printing functions used in UDR/UDM/AUSF are not in AMF.
    • When you check the logger.go it imports in AMF and UDR, you will find they has very similar structure.
      image
      image
    • So I think we can just add the logger variable that AMF does not have, but UDR has.
      • image
      • image
  3. This variable is definded in orignal file, by a const function, so add it.
    image
    Vimage
  4. Add variables
    • image
    • image
  5. Plus M to prevent the repeat error.
    • image

Problem 3

image

  1. This error is that I didnt deal with the parameters in the function calling which I have commented out.
    image
    • For checking whther this action will affect the DB modifiction or not, I print out these two variables in original free5gc, so the modification is the SQN number, and we can make sure that the modification is made between these two RestfulAPIGetOne.
      image
    • And if you check the content of the notify functions, you can find that they only use these got values for sending http message, not for computing or something, so we can peacefully ignore them.
      image
      image
    • So this check item is finished.
      image
    • And the method is adding two print line so the variables will be used.
      image
      image
  2. Need to difine it using :=, or the compiler can not verify it in return line.
    image
    -> image
  3. image
    • In error place, it use the received err to give to Detail.
      image
    • In the called function, the pd is returned as err.
      image
    • As you can see, the pd is also created from problemDetails.
      image
    • So there is no one item called err.Error() for us to use, I think it is because it is originally call API, not function, there will has some funciton we can call.
    • Here I change it to one of the item in the models.ProblemDetails that can be called, and to represent the Detail(DATA NOT FOUND).
      image
    • Change the function name.
      image
      -> image
  4. image
    • The compiler can not find the PermanentKey item, I guess it is because the passing format problem or naming problem.
      image
      image
    • I print the passing value in three places
      • image
      • image
      • image
    • The results are like below, we can see that the value turn to memory address after API process.
      image
    • So based on the error message, we need to transform the map[string]interface format.
      • About the explanation, disadvantage and reason of this format -> Link .
        • The other reason that I don't use this fromat directly as below, is that there are too many palce need to modify, so it's more efficient by creating a structure.
      • First do the definition.
        image
        • Compared to the content of map format.
          image
      • Then do the transformation of the data received from MongoDB in this function.
        image
      • The original calling of authSubs should be done successfully, notice that the return format defining should be changed correctlly, or the compiler will report the same error.
        image
        V image
      • Compared to Terry's MongoDB client -> Link .
  5. image
    image
    • This is also defined as const in original funciton, so add it.
      image

image

  1. The AuthSubs declaration is in the same file with calling function, so don't need to add model. to import.
    image
    V image
  2. Just delete the redundent returned variable, I forgot why I put one more variable here.
    image
    V image

Problem 4

image

  1. image
    • I think the problem here is the previous declaration assign err as *model.ProblemDetails, because the called function is from UDR, the return format is not the same as here(hex.DecodeString originally from UDM).
      image
    • So I change the parameter name which will be used only for hex function,
      image
  2. image
    • The problem is the checking action here can not match the structure(Milenage.Op) with nil.
      image
    • Here we can reserver the OpValue only, because the error report here is just to know whther the OpValue exists or not.
      image
  3. The remaining errors are all the same with 1.
    image
    • So I just change their names.
      image
      image
    • Here is another function calling(milenage), so I change to another nameing.
      image
    • The 411 line is still hex function.
      image
    • Need to change to :=, or there will have this problem
      image
      image
      image
      image
    • Or like this.
      image
      image

Problem 5

image

  • The same so keep changing.
    image
    image
    image
    image

Problem 6

image

  1. image
    • It is continued from problem 2-5, and is same as problem 3-3.
    • In func ModifyAuthenticationProcedure, the returned structure include Cause and Detail, but Detail is assigned as "", so we can only use Cause to print out what happened("MODIFY_NOT_ALLOWED").
      image
      image
  2. At line 602.
    image
    V image
  3. At line 609.
    image
    V image
    • I dont know why it doesnt need := here, the error pops up when I add :=.
      image
  4. image
    • From the model it imports, the type is not string.
      image
    • One solution is that transfer the string format to model.AuthMethod.
      image
      • But we need to define this model like the github import.
        image
    • Another solution is that change the declaration in AuthSub.
      image
    • Originally I dont want to use model.AuthMethod, but use "5G_AKA" to compare directly.
      image
      • But there are some flaws.
        image
      • Also below has some other palce using this model format, to compare with the reutrn value from this UDM function.
        image
        image
    • So I decide to change the format in AuthSubs, then I don't need to do some change if the model is used in the part after.
      image

Problem 7

image

  1. After the resync part is OK, compiler say that we didnt use the parameters k, op, opc.
    image
    image
    image
    • So comment out them at here.
      image
      V image
      • But it will be another problem, because the k declared in if/else will only be seen recognized in if/else.
        image
        image
    • So we still need to define them at begining, and need to change := to =, then the errHex and errMil need to be defined too.
      • Like here, after uncomment out the parameters defining and change := to =.
        image
      • Comfirm te return formats of these function.
        image
        image
      • We can see the err returned by them are type error.
        image
      • So the declaration is like this.
        image
        image
        image
        image
  • Until here, we finish the successful compiling of func GenerateAuthDataProcedure of UDM, so next is to keep debug in below part(AUSF, AMF).

Problem 8

image

  1. Add variables.
    image
    image
  2. image
    V image
  3. image
    • The same as previous problem.
    • There are some return inlcuding Detail, some doesnt include, so I print out both cause and detail.
      image
  4. image
    • It assign status code but parameter rep has been commented out.
      image
      • The rep is declared as http.Response
        image
      • So I go to see the format of status code in this package(net/http).
        image
      • About the int32 function : Link
    • Then I want to know the status code value when error happens, so I change the K in webconsole, and add printing lines in original free5gc.
      image
      V image
      image
      • Here you can see the Forbidden status code is 403.
        image
    • And if you check all error return, you can find that their status are all http.StatusForbidden, so change the parameter to 403(int) directly.
      • Confirm that the format of problemDetails.Status is int32, so that the value 403 can be assigned directly.
        image
        image
  5. image
    • In the function definition, the returned variable number need to change.
      image
      V image
  6. image
    image
    • Add variables.
      image
      image

Problem 9

image

  1. image
    V image
  2. image
    • Because I commented out here before.
      image
      • But now I think it can be reserved before, because updateAuthenticationInfo.ServingNetworkName is received from func SendUEAuthenticationAuthenticateRequest and it write the SN name here.
        image
      • Because it has value, I think we can just store it but not do any authorization.
    • So uncomment out it, and assign it to responseBody and authInfoReq.
      image
  3. image
    • No need to add &.
      image
      V image
  4. image
    • It is also resulted from the format of err, because of the changing from API to function calling.
      image
    • Because there is no API passing between func SendUEAuthenticationAuthenticateRequest and func UeAuthPostRequestProcedure, the received err has already been &models.ProblemDetails, we don't need to extract the problem from err, use err directly(err is address so don't add & before it).
      image

image

  • Derive Kseaf but not used.
    image
  • I think it will not be used so just comment out this part.
    image

Test

Problem 1

image

  • The explanation of ChatGPT.
    image
var client *mongo.Client var err error client, err = mongo.Connect(context.TODO(), options.Client().ApplyURI("mongodb://localhost:27017")) if err != nil { log.Fatal(err) } // 檢查連接 err = client.Ping(context.TODO(), nil) if err != nil { log.Fatal(err) }
  • It seems that I didn't set a client for MongoDB connection, go to see the line that error tells to me.
    image
    V
    image
    V
    image
    • As you can see, the client is also created in the same file which is called by UDR function, and in this func SetMongoDB it will build the connection with DB.
    • Terry build the connection by himself, you can see the process -> Link
    • And then I'm wondering where the original Free5GC do thhis action -> Link
  • So I copy the connection building process from UDR to AMF in init.go.
    • The passing parameters in called function can be find in factory.
      image
      image
    • And the parameters creating sequence is like below.
      • image
        V
        image
        V
        image
        V
        image
        V
        image
        V
        image
      • I don't know how it fill the mongo name and url from config.yaml to here, but it is confirmed that this two parameters are set in yaml file.
        image
        image
    • So we can direcly input these value to set the connection.
      image
      image
      image

Problem 2

image

  • For logs' sources.
    image
    image
  • I have comfirmed that the setting in free5gc-ue.yaml and webconsole are no problem.
  • Then I think maybe the searching keywords have problem, so I printing out supi.
    image
    image
    • As you can see, the collname is matched with the display on mongodb-compass, one hyphen(-, or you can say dash) is missing in ueId.
      image
    • So modify here.
      image
      V image

Problem 3

image

  • For logs' sources, it is right after the getDataFromDB, so data is got, but the transfer is not successful.
    image
  • The explanation from ChatGPT.
    image
    image
    image
    image
  • So I think we can change the format of which will recieve number into float64 directly.
    image
    image
    • And this is also why Terry has some float64 in his structure.
      image
    • I also check that these EncryptionAlgorithm and EncryptionKey will not be used in parts after, so this change will not cause error.

Result

Result 1

  • CN side
    image
    • It has a successful req. generating, but stucks in handling resp. and then keeps receiving the initial messages from UE.
      image
  • gnb side
    image
  • UE side
    image
    • The timer will expired when waiting the ACK, after UE receives the req. and send the resp., so UE stucks on here and then keeps retrying registration.
      image

Trace the result 1.

image
V image
V image
V
image
image
image
V image
V image

Problem 1

  • Normally, if the modification on auth req. is successful, CN should properly process the rep., and have a successful 5G-AKA, so I go to find the source of the server no response error, to see which part cause this.
    • First I print out the passing variable and received variables, I want to check the content or resStar and the err which causes the error report.
      image
      • The result.
        image
    • Then keep tracing where is the final stop point, so I go into func HandleAuth5gAkaComfirmRequest, which is call by client.DefaultApi.UeAuthenticationsAuthCtxId5gAkaConfirmationPut.
      • After the API routing and the function of comparing res* and xres*, print out something to check whether the received values from the called func Auth5gAkaComfirmRequestProcedure are matched with previous part.
        image
      • The strange thing is that it didnt print out anything, still the same after compiling.
    • So I go back to the API routing place who forward the message to func HandleAuth5gAkaComfirmRequest.
      • Print out some text before and after forwarding, to see where is the stop point.
        image
      • The result is still the same, nothing printed out, which means the error happens before the message reaching the router.go & api_defaut.go of AUSF.
  • I go back to see the printed err, it says missing protocol scheme, and no return & http response.
    image
    • I go to see the format confirmData is declared.
      image
      V
      image
      V
      image
      V but I can only find the function about configuration.
      image
    • Then I notice that the scheme is used in here, and confirmUri is declared from parsing ue.AuthenticationCtx.Links["5g-aka"].Href, which is matched with the printed err.
      image
    • So I go to see the content of ue.
      image
      V
      image
      V
      image
      V then find that the format of ue.AuthenticationCtx is imported here.
      image
    • Find on github.
      image
      V we can see the Links definition
      image
      V see back to code, you can see it use Links.Herf
      image
      V if you check here, you can see the source of Herf
      image
      image
  • Finally, if you search Links or Herf in the file, you can confirm that real reason is that I modify the putLink generating process, so there are some missed item.
    image
    image
    • Then it is wrapped in responseBody, returned to handler.go as ueAuthenticationCtx, and wrapped into ue, so that is why there is an error when parsing ue.AuthenticationCtx, causing that ausfUri is not complete.
      image
      V
      image
    • You can also confirm by see that the first %s doesnt print out.
      image
      image
  • I need to reconstruct the URI if I want to have a successful call to AUSF, but it is useless for the 2nd modification, because the client including ausfUri will be commented out after changing to function calling.
  • But I want to test whether my change on 1st is OK for UE access, so I will just assign the locationURI manually even if it will be commented out.
    image
    • self is declared here.
      image
      V find in original ausf file
      image
      V
      image
      V
      image
      V
      image
    • And factory.AusfAuthResUriPrefix is here.
      image
    • It seems that printing out them in original free5gc is faster
      • image
        image
      • image
        image
  • So they are all string format, can direcly add them together.
    image

Result 2

  • CN side
    image
  • gnb side & UE side
    • The same.

Problem 2

  • I comment out here and assign the value manually.
    image
    image
  • It will turn out these error in process.
    image
    image
  • After compiling OK, it turns out other errors related to AUSF context.
    image
    image
  • It will be too much if I keep modify the AUSF context, so I decide to do 2nd modification directly, and ignore AUSF related part.

Github upload version before problem 1

image

Github upload version after problem 2

image

2nd req & resp

Method

  • Same as 1st, use the function call in AMF.
    image
    • In ue_authentication.go(AMF)
    • Call by func SendAuth5gAkaConfirmRequest
  • Reserve parts :
    • RES* & XRES* comparison in AUSF
      • In ue_authentication.go
        • func HandleAuth5gAkaComfirmRequestProcedure
      • In function.go
        • func logConfirmFailureAndInformUDM
        • func sendAuthResultToUDM
    • Change format and call UDR in UDM
      • In generate_auth_data.go
        • func ConfirmAuthDataProcedure
      • In converter.go
        • func ToBsonM
    • MongoDB API in UDR
      • In data_repository.go
      • func CreateAuthenticationStatusProcedure
  • Reduction
    • API -> function calling (Some functions, URI setting, parameters passing, http interaction)
    • Get data from AUSF context.
    • EAP-AKA'
    • Simplfy SUCI checking

Modification

Prerequisite

  • Move the reserved parts to AMF, and put them above func SendAuth5gAkaConfirmRequest.

Implementation

The parts need to check after modification :
(They are in the folded area below, here just for final confirmation and not for check list)

  • func SendAuth5gAkaConfirmRequest
  • func HandleAuth5gAkaComfirmRequestProcedure
  • func logConfirmFailureAndInformUDM
  • func sendAuthResultToUDM
  • func ConfirmAuthDataProcedure
  • func CreateAuthenticationStatusProcedure
func SendAuth5gAkaConfirmRequest

image

  1. Comment out the ausf part.
    image
    • I dont know whether it is necessory to use comfirmData's optional.Interface format or I can pass resStar directly.
    • But it seems like an API working on Nausf, so I think I can ignore it by just pass resStar string to function.
      image
  2. I want to know the received value in the called function func HandleAuth5gAkaComfirmRequest, so I print out these variables.
    image
    • The result is restar and suci.
      image
    • So that I know I can modify like this.
      image
      • Also change the name of called function.
        image
func HandleAuth5gAkaComfirmRequestProcedure

image

  1. About the API function between this and previous function, I just move the logger and comment out it.
    image
    image
  2. Format
    • This variable will receive resStar, so change format to string.
      image
    • This format is from model, and includes supi and Kseaf
      image
      image
      • supi will be return back to handler.go and save to ue, so we can reserve this format.
        image
      • There is another format in model for resStar, but here I just pass resStar directly.
        image
    • Delete this redudent parameter, because I passed resStar to here directly.
      image
    • I find that handler encode resStar before passing it, so I print out some value in original free5gc to confirm if I need to decode it.
      image
      • In handler, resStar, resStar[:] are the same, so the point is tha value after encoding.
        image
        Use text book for conveniently wathing.
        image
      • In AMF, the value stay same after the wrap of confirmData.
        image
        image
      • In AUSF, there has already a printing function existedd to compare the res* and xres*, but the printing format is Hexadecimal(%x), so I just print out the %+v format to ensure that they are compared in encoded status.
        image
        image
        • About the explanation of %x -> Link
      • So if two sides are all encoded and then compared, I dont need to do decoding.
  3. ausf context
    • Comment out the process of checking SUCI and get the SUPI from ausf context, because all ausf context related parts are commented out, and we need to get the SUPI from ConfirmationDataResponseID(SUCI).
      image
      • Use this transfer again, and change variable name.
        image
        image
      • Then manually set the SNname by print out the string in original free5gc
        image
        image
        image
    • Because Xres* store in AUSF context originally, and previous modification comments out it and didnt store it in other parameter, so we need to add one to store Xres*.
      image
      image
      image
      • Xres* is encoded in func GenerateAuthDataProcedure.
        image
      • And is stored in ausf context in func UeAuthPostRequestProcedure.
        image
        image
      • Add a global variable to store it.
        image
        image
      • Change the variable.
        image
    • HRES* & HXRES* comparison is here, above the calling of func SendAuth5gAkaConfirmRequest.
      image
      image
      • And HxresStar is got from ue.AuthenticationCtx.Var5gAuthData, which receives the hxres* from AUSF function direcly.
        image
        image
      • So it will not be affected by ausf context.
    • Kseaf process is commented out before, so here just give it zero string for storing in ue context.
      image
    • Comment out these two.
      image
    • UdmUeauUrl doesnt exist without ausf context, so comment them out too.
      image
      image
  • logger function
    • image
    • image
    • image
    • image
func logConfirmFailureAndInformUDM
  • Before
    image
  • After
    image
  • logger function
    • image
    • image
    • image
func sendAuthResultToUDM
  • Before
    image
  • After
    image
    • self.GetSelfID() get the Nfid which is string.
      image
      • Here change to get the AMF Nfid, but AMF doesnt have func GetSelfID(), so directly retrieve it, I dont know it is right or not using pointer to do it.
        image
func ConfirmAuthDataProcedure
  • Move the logger and comment out UDM API process.
    image
  • Before
    image
  • After
    • Move the DB parameters setting and function calling and then comment out the UDR API process
      image
      • The original authEvent wrapping uses optional.Interface format , which I think is for API process, so I comment out them, and to see how to pass authEvent to DB.
        image
        image
      • Here is the modification of moved parameters setting and function calling in UDR API process.
        image
        • The function changing the authEvent to Bson is from UDR, so we need to move it to here, make sure if there is any new import mod or not.
          image
          V
          image
      • Delete the util.
        image
        -> image
    • Because func CreateAuthenticationStatusProcedure doesnt have return, so we can comment the http API error report, and also API calling.
      image
      • But this function need to return one err, so just keep it nil.
  • logger function
    • image
func CreateAuthenticationStatusProcedure
  • No need to change.
    image
    • About the ueId adding, because originally authEvent doesnt have this item, and the chatGPT explanation.
      image
      image

Comilation

Problem 1

image

  • image
    image
    • This problem is that originally the variables in string format are declared together, about the explanation -> Link.
      image
      image
  • So just give them the format.
    image
    image

Problem 2

image

  1. I think that is becaues logger.DataRepoLog.Errorf needs string to print, but the format of err is error, original print function use logger.DataRepoLog.Error.
    image
    V
    image
  2. image
    image
    image
    • Change the return format declaration.
      image
      V
      image
    • It causes other problem.
      image
      • Just print problemDetails itself.
        image
        image
        V
        image
        image
  3. image
    image
    • Remove the redudent &.
      image
      V
      image

Test

No problem

Result

  • CN side
    image
    image
    • 5G-AKA is successful but security mode has some problem.
  • gnb side
    image
  • UE side
    image
  • The original log is like this.
    image
  • The SMC explanation -> Link
  • Wireshark (Test with UERANSIM in other VM)
    • From UE's reject message, it has a cause.
      image
      • And security mode rejected, unspecified (24) is a keyword to search.
      • It is a LTE note about SMC in here
    • From 5GC's DownlinkNAS SMC, we can see the contens of the packet is the same as normal 5GC (Except for message authentication code).
      • Modified.
        image
      • Normal.
        image
  • In logs.
    • It is hard to find where is the problem source by tracing the 5GC error message (wrong security header type : 0x0, message type 95) in code or googleing the UE error message (Rejecting Security Mode Command with cause [SEC_MODE_REJECTED_UNSPECIFIED]).
      • Will only find the header of UE's uplinkNAS is wrong, and print the error by call the printing function, and the parameters is from free5gc/nas.
        image
        image
        image
      • Or find some problem discussion.
  • In the process above, I was doubting that maybe the cause is from the modification in ue_authentication.go, the missing in some parameter resulit in the rejection of UE.
  • And I ask Terry that whether the commenting out of Kseaf generating affects it or not, the answar is YES.
    • But I didnt know which part in security mode will use Kseaf, because I need to know where to put Kseaf value instead of AUSF context if I recover the generating process.
    • And Terry say that I can put into AMF context, becausee the security mode is working in AMF, and will access the parameter in AMF context.

Github upload version

image

Security mode

Method

  • Uncomment out the Derive Kseaf from Kausf in AUSF function (func UeAuthPostRequestProcedure) and try to put the value in UE context of AMF : type AmfUe struct.
    image
  • image

Modification & Compilation & Test

Problem 1 (Preparation)

  • The point is that the mutual context of UE is passing in handler.go and func SendUEAuthenticationAuthenticateRequest in ue_authentication.go, so we can not direcly put the value in func UeAuthPostRequestProcedure because ue.context is not passed to this function (Or we add a new variable, but we need to modify more place).
    1. Like this error is that I want to call AmfUe in context folder.
      image
    2. Even I change to the right name of import, and compile successfully, the test has error.
      image
      image
    3. Or I want to use GetSelf in context, but it is wrong, Kseaf is in context for UE, not in the AMFcontext
      image
      image
      • The error for this
        image

Problem 2 (Preparation)

image

  • We need to use hex.EncodeToString().

Problem 3 (1st req & resp : func UeAuthPostRequestProcedure)

image

  • Because this function doesnt have the ue context variable, so I decide to put Kseaf into return variable.
    image
  • Then receive and put Kseaf into ue context in this function.
    image
  • In handler.go, it will receive ue and the ue variable is the same one (amfUe) passed from func Authentication in sm.go.
    image
    V
    image
    V
    image
    • In func Authentication, it uses the same variable amfUe to call this function.
      image
    • So if I load Kseaf into ue, it will be saved into amfUe by pointer passing.
  • My method is put Kseaf into responseBody, so we need to change its format.
    • Check the format on model repo.
      image
      image
    • Then put it above this function, change the responseBody declaration, and add Kseaf declaration in structure.
      image
    • And assign Kseaf to it after generating.
      image
  • And the error in above screenshot is about the format of variables in structure.
    • For first one you can find the difined source on repo
      image
      V
      image
      V
      image
      V
      image
    • For second one.
      image
      V
      image
      V
      image
      V
      image

Problem 3-1

  • image
    V
    image
  • image
    V
    image
  • The problem is caused by the format in structure, which is not matched with the use below.
  • Here I can change two places, in struc or in the use below, I choose to modify in struc directly, it is successful so I didnt try to change the second place.
    • image
    • The original variables are set as remarks commented out behind the sentence.

Problem 3-2

  1. image
  2. image
  • This form is correct one.
    image

Problem 4 (Functions calling & func SendUEAuthenticationAuthenticateRequest)

image

  1. image
    • It is caused by the return variable declaration.
      image
  2. image
    • It is in func SendUEAuthenticationAuthenticateRequest, to put the received Kseaf into ue context which is passed from func AuthenticaionProcedure to here.
    • Dont need to add models.
      image
    • After Kseaf is assigned, we need to put the other value into the original passing format, so declar a new variable using model's format and assign the value one by one.
  3. image

Problem 5 (2nd req & resp : func HandleAuthenticationResponse & func SendAuth5gAkaConfirmRequest & func HandleAuth5gAkaComfirmRequestProcedure)

  • The compilation is successful but the test is still tha same problem.
    image
  • So I find another place where call Kseaf in UE context for using, and add logger in three places to see whether the Kseaf exists or not.
    • In func SendUEAuthenticationAuthenticateRequest.
      image
    • In func AuthenticationProcedure
      image
    • The results of these two all have the value of Kseaf.
      • image
      • image
    • In func HandleAuthenticationResponse
      image
    • But the third place doesnt have.
      • image
  • Then when you go to :
    image
    V
    func SendAuth5gAkaConfirmRequest
    image
    V
    func HandleAuth5gAkaComfirmRequestProcedure
    image
  • You can see if the authentication confirm is successful, it will get Kseaf from susf context, but I have commented out it and give it null value, because I thought Kseaf would not ne used.
    • So I comment out here to prevent the null value cover the original value.
      image

Result

  • CN side
    image
    • The SMC is successful, and UE get the IP
      image
    • PFCP is also builded.
      image
  • gnb side
    image
  • UE side
    image
  • Remember to comment out the logger which is used for test.

Github upload version

image

Removal process

Prerequisite

  • Because the result is successful, meaning that we don't need AUSF for 5G-AKA, now we can remove it to test again.
  • After that, you can see there is no AUSF initialization when running.
    image
    image
    image
    image

Modification & Compilation & Test

Problem 1

image
image
image

  • Comment out AUSF selecting part.
    image

Result

  • After the error is solved, it is successful, then it is the same as above.

Github upload version

image

Test with muiltiple UE

Method

  • Use the commands on the wiki of UERANSIM github -> Link
  • Pre-register the UE in webconsole.
    image

Problems encountered

  • Use 5 UEs to test.

Problem 1

  • CN side
    image
  • gnb side
    image
  • UE side
    image
  • There is no UE data in 5GC, so add them on webconsole, the SUCI will be from imsi-3~7.

Problem 2

image

image

  • Only one UE will successfully build the PDU session.
  • And you can see some Synch failure for 4 UEs
    image
    image
    image
    image
  • Other four will have a confirmation failed
    image
    image
    • Find that the XresStar comparison is not successful, not the same with res*.
  • But if I use original free5gc, it will be successful for muiltiple UE.
    • CN side
      image
      image
      image
      image
    • gnb side
      image
    • UE side
      image
      image
      image
      image
  • So I think the problem is that I use global variable for setting Xres*, then every UE's Xres* will be the same.
    • Here you can check the result that tests with 2 UEs.
      image
    • And if you scroll up, you can see the final XresStar stored in the global variable is from imsi-0003, so the imsi-0004 will not pass the 5G-AKA confirmation.
      image

Modification & Compilation

Pre

  • Some differences between the original storing method and global method.
    image
    image
  • eed to ensure Xres* is stored independently for each UE. Using global variables in a concurrent environment can lead to race conditions and data corruption.So I need to use context or mapping to process it.
    • First import "sync", and change the delclaration.
      image
      image
    • Then before comparison, get the value using supi from map, and do the error report.
      image

Problem 1

image

  • hex.DecodeString() has two return, but encode only one, so dont mess up them.

Problem 2

image

image
V
image

Problem 3

image

image

  • Instead of hex.encodestring()
    image

Problem 4

image

  • The Xres* is in if/else, so outside there can not be used.
  • Put the if/else of map in the most ouside place.
    image

Test

Problem 1

image

  • Because there is no supi transformation in func UeAuthPostRequestProcedure
    image
  • So here change supi to ConfirmationDataResponseID which is suci, use supci to find in map.
    image
    V
    image

Result

2 UEs

  • CN side (Can accept 2 UEs.)
    image
  • gnb side
    image
  • UE side
    image
    image

5 UEs

  • UE side
    image
  • Ping internet test
    • You can see there are 5 tunnels builded in UE's VM.
      image
      image
    • Ping from these tunnels.
      image
      image
  • Ping from uesimtun0 not successful but ping directly successful.
    image
  • In the VM of free5gc, need to set these network rules.
sudo sysctl -w net.ipv4.ip_forward=1 sudo iptables -t nat -A POSTROUTING -o ens18 -j MASQUERADE sudo iptables -A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --set-mss 1400 sudo systemctl stop ufw sudo iptables -I FORWARD 1 -j ACCEPT

Github upload version

image

Select a repo