From f86c37b03324d1f8ede5cf5385ff4aa1d527666e Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 10:10:36 +0900 Subject: [PATCH 1/9] Use new openapi5g's models in NRF client codes --- go.mod | 38 ++-- go.sum | 31 ++++ internal/context/ausf_context_init.go | 33 ++-- internal/context/context.go | 39 ++-- internal/sbi/consumer/consumer.go | 8 +- internal/sbi/consumer/nrf_service.go | 192 ++++++++++---------- internal/sbi/consumer/udm_service.go | 2 +- internal/sbi/processor/ue_authentication.go | 2 +- 8 files changed, 197 insertions(+), 148 deletions(-) diff --git a/go.mod b/go.mod index 37e0437..2a75f14 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/free5gc/ausf -go 1.21 +go 1.22.0 require ( github.com/antihax/optional v1.0.0 @@ -8,9 +8,9 @@ require ( github.com/bronze1man/radius v0.0.0-20190516032554-afd8baec892d github.com/free5gc/openapi v1.0.8 github.com/free5gc/util v1.0.6 - github.com/gin-gonic/gin v1.9.1 + github.com/gin-gonic/gin v1.10.0 github.com/google/gopacket v1.1.19 - github.com/google/uuid v1.3.0 + github.com/google/uuid v1.6.0 github.com/pkg/errors v0.9.1 github.com/sirupsen/logrus v1.8.1 github.com/urfave/cli v1.22.5 @@ -18,39 +18,41 @@ require ( ) require ( - github.com/bytedance/sonic v1.9.1 // indirect + github.com/ShouheiNishi/openapi5g v0.0.0-20241106074548-e84ac6a60950 // indirect + github.com/bytedance/sonic v1.11.6 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.14.0 // indirect + github.com/go-playground/validator/v10 v10.20.0 // indirect github.com/goccy/go-json v0.10.2 // indirect - github.com/golang-jwt/jwt v3.2.1+incompatible // indirect + github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang/protobuf v1.5.0 // indirect github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.4 // indirect - github.com/leodido/go-urn v1.2.4 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/leodido/go-urn v1.4.0 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.0.8 // indirect + github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/russross/blackfriday/v2 v2.0.1 // indirect + github.com/samber/lo v1.47.0 // indirect github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect github.com/tim-ywliu/nested-logrus-formatter v1.3.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect - github.com/ugorji/go/codec v1.2.11 // indirect - golang.org/x/arch v0.3.0 // indirect - golang.org/x/crypto v0.21.0 // indirect - golang.org/x/net v0.23.0 // indirect + github.com/ugorji/go/codec v1.2.12 // indirect + golang.org/x/arch v0.8.0 // indirect + golang.org/x/crypto v0.28.0 // indirect + golang.org/x/net v0.30.0 // indirect golang.org/x/oauth2 v0.0.0-20210810183815-faf39c7919d5 // indirect - golang.org/x/sys v0.18.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/sys v0.26.0 // indirect + golang.org/x/text v0.19.0 // indirect google.golang.org/appengine v1.6.6 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect gopkg.in/h2non/gock.v1 v1.1.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 173ecee..729cd83 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,8 @@ cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9 dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/ShouheiNishi/openapi5g v0.0.0-20241106074548-e84ac6a60950 h1:lD8BK+Coo6Jo2ohqACL8Pq21Y0fsDsG6kI3NQP0VVLQ= +github.com/ShouheiNishi/openapi5g v0.0.0-20241106074548-e84ac6a60950/go.mod h1:SxloHkTjPLm6g3y/aYblNJr2vTo8kb8PBBAj4DbokLs= github.com/antihax/optional v1.0.0 h1:xK2lYat7ZLaVVcIuj82J8kIro4V6kDe0AUDFboUCwcg= github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY= github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ= @@ -42,6 +44,8 @@ github.com/bronze1man/radius v0.0.0-20190516032554-afd8baec892d/go.mod h1:iZQ+zY github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= github.com/bytedance/sonic v1.9.1 h1:6iJ6NqdoxCDr6mbY8h18oSO+cShGSMRGCEo7F2h0x8s= github.com/bytedance/sonic v1.9.1/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= +github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/chenzhuoyu/base64x v0.0.0-20211019084208-fb5309c8db06/go.mod h1:DH46F32mSOjUmXrMHnKwZdA8wcEefY7UVqBKYGjpdQY= github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 h1:qSGYFH7+jGhDF8vLC+iwCD4WpbV1EBDSzWkJODFLams= @@ -50,6 +54,8 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI= github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= +github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= +github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQPiEFhY= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= @@ -66,10 +72,12 @@ github.com/free5gc/util v1.0.6 h1:dBt9drcXtYKE/cY5XuQcuffgsYclPIpIArhSeS6M+DQ= github.com/free5gc/util v1.0.6/go.mod h1:eSGN7POUM8LNTvg/E591XR6447a6/w1jFWGKNZPHcXw= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8= @@ -81,10 +89,12 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c= github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= +github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -137,6 +147,7 @@ github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hf github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw= @@ -152,6 +163,8 @@ github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+o github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= +github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= @@ -159,8 +172,10 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= +github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -172,6 +187,7 @@ github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= +github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= @@ -180,6 +196,8 @@ github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1: github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q= github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/samber/lo v1.47.0 h1:z7RynLwP5nbyRscyvcD043DWYoOcYRv3mV8lBeqOCLc= +github.com/samber/lo v1.47.0/go.mod h1:RmDH9Ct32Qy3gduHQuKJ3gW1fMHAnE/fAzQuf6He5cU= github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo= github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= @@ -187,6 +205,7 @@ github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -197,12 +216,15 @@ github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tim-ywliu/nested-logrus-formatter v1.3.2 h1:jugNJ2/CNCI79SxOJCOhwUHeN3O7/7/bj+ZRGOFlCSw= github.com/tim-ywliu/nested-logrus-formatter v1.3.2/go.mod h1:oGPmcxZB65j9Wo7mCnQKSrKEJtVDqyjD666SGmyStXI= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU= github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= +github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU= github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= @@ -216,6 +238,7 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= +golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -223,6 +246,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -281,6 +305,7 @@ golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs= golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.30.0/go.mod h1:2wGyMJ5iFasEhkwi13ChkO/t1ECNC4X4eBKkVFyYFlU= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -323,9 +348,11 @@ golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -333,6 +360,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -458,6 +487,7 @@ google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlba google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= @@ -477,6 +507,7 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg= honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= +nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8= rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0= diff --git a/internal/context/ausf_context_init.go b/internal/context/ausf_context_init.go index 575a04f..b47d3d9 100644 --- a/internal/context/ausf_context_init.go +++ b/internal/context/ausf_context_init.go @@ -5,11 +5,12 @@ import ( "os" "strconv" + "github.com/ShouheiNishi/openapi5g/models" "github.com/google/uuid" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/ausf/pkg/factory" - "github.com/free5gc/openapi/models" + oldModels "github.com/free5gc/openapi/models" ) func InitAusfContext(context *AUSFContext) { @@ -19,7 +20,7 @@ func InitAusfContext(context *AUSFContext) { configuration := config.Configuration sbi := configuration.Sbi - context.NfId = uuid.New().String() + context.NfId = uuid.New() context.GroupID = configuration.GroupId context.NrfUri = configuration.NrfUri context.NrfCertPem = configuration.NrfCertPem @@ -35,9 +36,9 @@ func InitAusfContext(context *AUSFContext) { } if sbi.Scheme == "https" { - context.UriScheme = models.UriScheme_HTTPS + context.UriScheme = models.Https } else { - context.UriScheme = models.UriScheme_HTTP + context.UriScheme = models.Http } context.BindingIPv4 = os.Getenv(sbi.BindingIPv4) @@ -56,37 +57,37 @@ func InitAusfContext(context *AUSFContext) { context.PlmnList = append(context.PlmnList, configuration.PlmnSupportList...) // context.NfService - context.NfService = make(map[models.ServiceName]models.NfService) + context.NfService = make(map[oldModels.ServiceName]models.NrfNFService) AddNfServices(&context.NfService, config, context) fmt.Println("ausf context = ", context) context.EapAkaSupiImsiPrefix = configuration.EapAkaSupiImsiPrefix } -func AddNfServices(serviceMap *map[models.ServiceName]models.NfService, config *factory.Config, context *AUSFContext) { - var nfService models.NfService +func AddNfServices(serviceMap *map[oldModels.ServiceName]models.NrfNFService, config *factory.Config, context *AUSFContext) { + var nfService models.NrfNFService var ipEndPoints []models.IpEndPoint - var nfServiceVersions []models.NfServiceVersion + var nfServiceVersions []models.NFServiceVersion services := *serviceMap // nausf-auth - nfService.ServiceInstanceId = context.NfId - nfService.ServiceName = models.ServiceName_NAUSF_AUTH + nfService.ServiceInstanceId = context.NfId.String() + nfService.ServiceName = models.ServiceNameNausfAuth var ipEndPoint models.IpEndPoint ipEndPoint.Ipv4Address = context.RegisterIPv4 - ipEndPoint.Port = int32(context.SBIPort) + ipEndPoint.Port = &context.SBIPort ipEndPoints = append(ipEndPoints, ipEndPoint) - var nfServiceVersion models.NfServiceVersion + var nfServiceVersion models.NFServiceVersion nfServiceVersion.ApiFullVersion = config.Info.Version nfServiceVersion.ApiVersionInUri = "v1" nfServiceVersions = append(nfServiceVersions, nfServiceVersion) nfService.Scheme = context.UriScheme - nfService.NfServiceStatus = models.NfServiceStatus_REGISTERED + nfService.NfServiceStatus = models.NFServiceStatusREGISTERED - nfService.IpEndPoints = &ipEndPoints - nfService.Versions = &nfServiceVersions - services[models.ServiceName_NAUSF_AUTH] = nfService + nfService.IpEndPoints = ipEndPoints + nfService.Versions = nfServiceVersions + services[oldModels.ServiceName_NAUSF_AUTH] = nfService } diff --git a/internal/context/context.go b/internal/context/context.go index 017ac74..7d5257c 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -2,18 +2,22 @@ package context import ( "context" + "net/http" "regexp" "sync" + "github.com/ShouheiNishi/openapi5g/models" "github.com/free5gc/ausf/internal/logger" - "github.com/free5gc/openapi/models" + oldModels "github.com/free5gc/openapi/models" "github.com/free5gc/openapi/oauth" + "github.com/free5gc/util/oauth2" + "github.com/google/uuid" ) type AUSFContext struct { suciSupiMap sync.Map UePool sync.Map - NfId string + NfId uuid.UUID GroupID string SBIPort int RegisterIPv4 string @@ -22,8 +26,8 @@ type AUSFContext struct { UriScheme models.UriScheme NrfUri string NrfCertPem string - NfService map[models.ServiceName]models.NfService - PlmnList []models.PlmnId + NfService map[oldModels.ServiceName]models.NrfNFService + PlmnList []oldModels.PlmnId UdmUeauUrl string snRegex *regexp.Regexp EapAkaSupiImsiPrefix bool @@ -35,7 +39,7 @@ type AusfUeContext struct { Kausf string Kseaf string ServingNetworkName string - AuthStatus models.AuthResult + AuthStatus oldModels.AuthResult UdmUeauUrl string // for 5G AKA @@ -105,7 +109,7 @@ func Init() { } type NFContext interface { - AuthorizationCheck(token string, serviceName models.ServiceName) error + AuthorizationCheck(token string, serviceName oldModels.ServiceName) error } var _ NFContext = &AUSFContext{} @@ -162,21 +166,32 @@ func GetSelf() *AUSFContext { return &ausfContext } -func (a *AUSFContext) GetSelfID() string { +func (a *AUSFContext) GetSelfID() uuid.UUID { return a.NfId } -func (c *AUSFContext) GetTokenCtx(serviceName models.ServiceName, targetNF models.NfType) ( - context.Context, *models.ProblemDetails, error, +func (c *AUSFContext) GetTokenCtx(serviceName oldModels.ServiceName, targetNF oldModels.NfType) ( + context.Context, *oldModels.ProblemDetails, error, ) { if !c.OAuth2Required { return context.TODO(), nil, nil } - return oauth.GetTokenCtx(models.NfType_AUSF, targetNF, - c.NfId, c.NrfUri, string(serviceName)) + return oauth.GetTokenCtx(oldModels.NfType_AUSF, targetNF, + c.NfId.String(), c.NrfUri, string(serviceName)) } -func (c *AUSFContext) AuthorizationCheck(token string, serviceName models.ServiceName) error { +func (c *AUSFContext) GetTokenRequestEditor(ctx context.Context, + serviceName models.ServiceName, targetNF models.NFType, +) (func(ctx context.Context, req *http.Request) error, error) { + if !c.OAuth2Required { + return func(ctx context.Context, req *http.Request) error { + return nil + }, nil + } + return oauth2.GetOauth2RequestEditor(ctx, models.NFTypeAUSF, targetNF, c.NfId, c.NrfUri, string(serviceName)) +} + +func (c *AUSFContext) AuthorizationCheck(token string, serviceName oldModels.ServiceName) error { if !c.OAuth2Required { logger.UtilLog.Debugf("AUSFContext::AuthorizationCheck: OAuth2 not required\n") return nil diff --git a/internal/sbi/consumer/consumer.go b/internal/sbi/consumer/consumer.go index a0cd457..3978120 100644 --- a/internal/sbi/consumer/consumer.go +++ b/internal/sbi/consumer/consumer.go @@ -1,9 +1,9 @@ package consumer import ( + nrf_discovery "github.com/ShouheiNishi/openapi5g/nrf/discovery" + nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management" "github.com/free5gc/ausf/pkg/app" - "github.com/free5gc/openapi/Nnrf_NFDiscovery" - "github.com/free5gc/openapi/Nnrf_NFManagement" "github.com/free5gc/openapi/Nudm_UEAuthentication" ) @@ -25,8 +25,8 @@ func NewConsumer(ausf ConsumerAusf) (*Consumer, error) { c.nnrfService = &nnrfService{ consumer: c, - nfMngmntClients: make(map[string]*Nnrf_NFManagement.APIClient), - nfDiscClients: make(map[string]*Nnrf_NFDiscovery.APIClient), + nfMngmntClients: make(map[string]*nrf_management.ClientWithResponses), + nfDiscClients: make(map[string]*nrf_discovery.ClientWithResponses), } c.nudmService = &nudmService{ diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 0a5a01b..0d542de 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -9,15 +9,18 @@ import ( "sync" "time" - "github.com/antihax/optional" "github.com/pkg/errors" + "github.com/ShouheiNishi/openapi5g/models" + nrf_discovery "github.com/ShouheiNishi/openapi5g/nrf/discovery" + nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management" + utils_error "github.com/ShouheiNishi/openapi5g/utils/error" + "github.com/ShouheiNishi/openapi5g/utils/problem" ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/Nnrf_NFDiscovery" - "github.com/free5gc/openapi/Nnrf_NFManagement" - "github.com/free5gc/openapi/models" + "github.com/free5gc/util/httpclient" + "github.com/google/uuid" ) type nnrfService struct { @@ -26,158 +29,151 @@ type nnrfService struct { nfMngmntMu sync.RWMutex nfDiscMu sync.RWMutex - nfMngmntClients map[string]*Nnrf_NFManagement.APIClient - nfDiscClients map[string]*Nnrf_NFDiscovery.APIClient + nfMngmntClients map[string]*nrf_management.ClientWithResponses + nfDiscClients map[string]*nrf_discovery.ClientWithResponses } -func (s *nnrfService) getNFManagementClient(uri string) *Nnrf_NFManagement.APIClient { +func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientWithResponses, error) { if uri == "" { - return nil + return nil, fmt.Errorf("empty URI") } s.nfMngmntMu.RLock() client, ok := s.nfMngmntClients[uri] if ok { s.nfMngmntMu.RUnlock() - return client + return client, nil + } + + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNnrfNfm, models.NFTypeNRF) + if err != nil { + return nil, err } - configuration := Nnrf_NFManagement.NewConfiguration() - configuration.SetBasePath(uri) - client = Nnrf_NFManagement.NewAPIClient(configuration) + uriFull := uri + "/nnrf-nfm/v1" + client, err = nrf_management.NewClientWithResponses(uriFull, func(c *nrf_management.Client) error { + c.Client = httpclient.GetHttpClient(uriFull) + return nil + }, nrf_management.WithRequestEditorFn(editor)) + if err != nil { + return nil, err + } s.nfMngmntMu.RUnlock() s.nfMngmntMu.Lock() defer s.nfMngmntMu.Unlock() s.nfMngmntClients[uri] = client - return client + return client, nil } -func (s *nnrfService) getNFDiscClient(uri string) *Nnrf_NFDiscovery.APIClient { +func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResponses, error) { if uri == "" { - return nil + return nil, fmt.Errorf("empty URI") } s.nfDiscMu.RLock() client, ok := s.nfDiscClients[uri] if ok { s.nfDiscMu.RUnlock() - return client + return client, nil } - configuration := Nnrf_NFDiscovery.NewConfiguration() - configuration.SetBasePath(uri) - client = Nnrf_NFDiscovery.NewAPIClient(configuration) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNnrfDisc, models.NFTypeNRF) + if err != nil { + return nil, err + } + + uriFull := uri + "/nnrf-disc/v1" + client, err = nrf_discovery.NewClientWithResponses(uriFull, func(c *nrf_discovery.Client) error { + c.Client = httpclient.GetHttpClient(uriFull) + return nil + }, nrf_discovery.WithRequestEditorFn(editor)) + if err != nil { + return nil, err + } s.nfDiscMu.RUnlock() s.nfDiscMu.Lock() defer s.nfDiscMu.Unlock() s.nfDiscClients[uri] = client - return client + return client, nil } func (s *nnrfService) SendSearchNFInstances( - nrfUri string, targetNfType, requestNfType models.NfType, param *Nnrf_NFDiscovery.SearchNFInstancesParamOpts) ( + nrfUri string, targetNfType, requestNfType models.NFType, param nrf_discovery.SearchNFInstancesParams) ( *models.SearchResult, error, ) { // Set client and set url - client := s.getNFDiscClient(nrfUri) + client, err := s.getNFDiscClient(nrfUri) if client == nil { return nil, openapi.ReportError("nrf not found") } + param.TargetNfType = targetNfType + param.RequesterNfType = requestNfType + rsp, err := client.SearchNFInstancesWithResponse(context.TODO(), ¶m) - ctx, _, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_DISC, models.NfType_NRF) - if err != nil { - return nil, err - } - - result, res, err := client.NFInstancesStoreApi.SearchNFInstances(ctx, targetNfType, requestNfType, param) - - if res != nil && res.StatusCode == http.StatusTemporaryRedirect { - return nil, fmt.Errorf("temporary Redirect For Non NRF Consumer") + if err != nil || rsp.JSON200 == nil { + return nil, utils_error.ExtractAndWrapOpenAPIError("nrf_discovery.SearchNFInstancesWithResponse", rsp, err) } - if res == nil || res.Body == nil { - return &result, err - } - defer func() { - if res != nil { - if bodyCloseErr := res.Body.Close(); bodyCloseErr != nil { - err = fmt.Errorf("SearchNFInstances' response body cannot close: %+w", bodyCloseErr) - } - } - }() - return &result, err + return rsp.JSON200, nil } -func (s *nnrfService) SendDeregisterNFInstance() (problemDetails *models.ProblemDetails, err error) { +func (s *nnrfService) SendDeregisterNFInstance() (*models.ProblemDetails, error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") - ctx, pd, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NNRF_NFM, models.NfType_NRF) + ausfContext := s.consumer.Context() + client, err := s.getNFManagementClient(ausfContext.NrfUri) if err != nil { - return pd, err + return nil, err } - ausfContext := s.consumer.Context() - client := s.getNFManagementClient(ausfContext.NrfUri) - - var res *http.Response - - res, err = client.NFInstanceIDDocumentApi.DeregisterNFInstance(ctx, ausfContext.NfId) - if err == nil { - return problemDetails, err - } else if res != nil { - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("DeregisterNFInstance response cannot close: %+v", resCloseErr) - } - }() - if res.Status != err.Error() { - return problemDetails, err - } - problem := err.(openapi.GenericOpenAPIError).Model().(models.ProblemDetails) - problemDetails = &problem - } else { - err = openapi.ReportError("server no response") + res, err := client.DeregisterNFInstanceWithResponse(context.Background(), ausfContext.NfId) + if err != nil { + return nil, fmt.Errorf("nrf_management.DeregisterNFInstanceWithResponse: %w", err) + } + if res.StatusCode() != http.StatusNoContent { + _, pd, err := problem.ExtractStatusCodeAndProblemDetails(res) + return pd, err } - return problemDetails, err + return nil, nil } func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( - resouceNrfUri string, retrieveNfInstanceID string, err error, + resouceNrfUri string, retrieveNfInstanceID uuid.UUID, err error, ) { ausfContext := s.consumer.Context() - client := s.getNFManagementClient(ausfContext.NrfUri) + client, err := s.getNFManagementClient(ausfContext.NrfUri) + if err != nil { + return "", uuid.Nil, err + } + nfProfile, err := s.buildNfProfile(ausfContext) if err != nil { - return "", "", errors.Wrap(err, "RegisterNFInstance buildNfProfile()") + return "", uuid.Nil, errors.Wrap(err, "RegisterNFInstance buildNfProfile()") } - var nf models.NfProfile - var res *http.Response for { - nf, res, err = client.NFInstanceIDDocumentApi.RegisterNFInstance(ctx, ausfContext.NfId, nfProfile) + res, err := client.RegisterNFInstanceWithResponse(context.TODO(), ausfContext.NfId, nil, nfProfile) if err != nil || res == nil { logger.ConsumerLog.Errorf("AUSF register to NRF Error[%v]", err) time.Sleep(2 * time.Second) continue } - defer func() { - if resCloseErr := res.Body.Close(); resCloseErr != nil { - logger.ConsumerLog.Errorf("RegisterNFInstance response body cannot close: %+v", resCloseErr) - } - }() - status := res.StatusCode + status := res.StatusCode() if status == http.StatusOK { // NFUpdate break - } else if status == http.StatusCreated { + } else if nf := res.JSON201; nf != nil { // NFRegister - resourceUri := res.Header.Get("Location") + resourceUri := res.HTTPResponse.Header.Get("Location") resouceNrfUri = resourceUri[:strings.Index(resourceUri, "/nnrf-nfm/")] - retrieveNfInstanceID = resourceUri[strings.LastIndex(resourceUri, "/")+1:] + retrieveNfInstanceID, err = uuid.Parse(resourceUri[strings.LastIndex(resourceUri, "/")+1:]) + if err != nil { + return "", uuid.Nil, err + } oauth2 := false if nf.CustomInfo != nil { - v, ok := nf.CustomInfo["oauth2"].(bool) + v, ok := (*nf.CustomInfo)["oauth2"].(bool) if ok { oauth2 = v logger.MainLog.Infoln("OAuth2 setting receive from NRF:", oauth2) @@ -196,17 +192,17 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( return resouceNrfUri, retrieveNfInstanceID, err } -func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) (profile models.NfProfile, err error) { +func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) (profile models.NFManagementNFProfile, err error) { profile.NfInstanceId = ausfContext.NfId - profile.NfType = models.NfType_AUSF - profile.NfStatus = models.NfStatus_REGISTERED + profile.NfType = models.NFTypeAUSF + profile.NfStatus = models.NFStatusREGISTERED profile.Ipv4Addresses = append(profile.Ipv4Addresses, ausfContext.RegisterIPv4) - services := []models.NfService{} + services := []models.NrfNFService{} for _, nfService := range ausfContext.NfService { services = append(services, nfService) } if len(services) > 0 { - profile.NfServices = &services + profile.NfServices = services } profile.AusfInfo = &models.AusfInfo{ // Todo @@ -225,23 +221,27 @@ func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) (pro func (s *nnrfService) GetUdmUrl(nrfUri string) string { udmUrl := "https://localhost:29503" // default - nfDiscoverParam := &Nnrf_NFDiscovery.SearchNFInstancesParamOpts{ - ServiceNames: optional.NewInterface([]models.ServiceName{models.ServiceName_NUDM_UEAU}), + nfDiscoverParam := nrf_discovery.SearchNFInstancesParams{ + ServiceNames: &[]models.ServiceName{models.ServiceNameNudmUeau}, } res, err := s.SendSearchNFInstances( nrfUri, - models.NfType_UDM, - models.NfType_AUSF, + models.NFTypeUDM, + models.NFTypeAUSF, nfDiscoverParam, ) if err != nil { logger.ConsumerLog.Errorln("[Search UDM UEAU] ", err.Error(), "use defalt udmUrl", udmUrl) } else if len(res.NfInstances) > 0 { udmInstance := res.NfInstances[0] - if len(udmInstance.Ipv4Addresses) > 0 && udmInstance.NfServices != nil { - ueauService := (*udmInstance.NfServices)[0] - ueauEndPoint := (*ueauService.IpEndPoints)[0] - udmUrl = string(ueauService.Scheme) + "://" + ueauEndPoint.Ipv4Address + ":" + strconv.Itoa(int(ueauEndPoint.Port)) + if len(udmInstance.Ipv4Addresses) > 0 && len(udmInstance.NfServices) != 0 { + ueauService := udmInstance.NfServices[0] + if len(ueauService.IpEndPoints) != 0 { + ueauEndPoint := ueauService.IpEndPoints[0] + if ueauEndPoint.Port != nil { + udmUrl = string(ueauService.Scheme) + "://" + ueauEndPoint.Ipv4Address + ":" + strconv.Itoa(*ueauEndPoint.Port) + } + } } } else { logger.ConsumerLog.Errorln("[Search UDM UEAU] len(NfInstances) = 0") diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index 69e2603..f391c2a 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -56,7 +56,7 @@ func (s *nudmService) SendAuthResultToUDM( AuthType: authType, Success: success, ServingNetworkName: servingNetworkName, - NfInstanceId: self.GetSelfID(), + NfInstanceId: self.GetSelfID().String(), } client := s.getUdmUeauClient(udmUrl) diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index 57dc802..5d9492b 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -235,7 +235,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat responseBody.ServingNetworkName = snName authInfoReq.ServingNetworkName = snName self := ausf_context.GetSelf() - authInfoReq.AusfInstanceId = self.GetSelfID() + authInfoReq.AusfInstanceId = self.GetSelfID().String() var lastEapID uint8 if updateAuthenticationInfo.ResynchronizationInfo != nil { From f86ebcc1bfa4ee71e28a382698fe1e66069ae733 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 10:33:00 +0900 Subject: [PATCH 2/9] Fix lock and other error --- internal/sbi/consumer/nrf_service.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 0d542de..2144b84 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -18,7 +18,6 @@ import ( "github.com/ShouheiNishi/openapi5g/utils/problem" ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" - "github.com/free5gc/openapi" "github.com/free5gc/util/httpclient" "github.com/google/uuid" ) @@ -46,6 +45,7 @@ func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientW editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNnrfNfm, models.NFTypeNRF) if err != nil { + s.nfMngmntMu.RUnlock() return nil, err } @@ -55,6 +55,7 @@ func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientW return nil }, nrf_management.WithRequestEditorFn(editor)) if err != nil { + s.nfMngmntMu.RUnlock() return nil, err } @@ -78,6 +79,7 @@ func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResp editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNnrfDisc, models.NFTypeNRF) if err != nil { + s.nfDiscMu.RUnlock() return nil, err } @@ -87,6 +89,7 @@ func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResp return nil }, nrf_discovery.WithRequestEditorFn(editor)) if err != nil { + s.nfDiscMu.RUnlock() return nil, err } @@ -103,8 +106,8 @@ func (s *nnrfService) SendSearchNFInstances( ) { // Set client and set url client, err := s.getNFDiscClient(nrfUri) - if client == nil { - return nil, openapi.ReportError("nrf not found") + if err != nil { + return nil, err } param.TargetNfType = targetNfType param.RequesterNfType = requestNfType From 98e8554d9ec0084aeb471f1d7b186d8714dc3a7c Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 12:47:20 +0900 Subject: [PATCH 3/9] UDM client --- internal/sbi/consumer/consumer.go | 4 +- internal/sbi/consumer/udm_service.go | 117 ++++++++++++-------- internal/sbi/processor/ue_authentication.go | 24 ++-- 3 files changed, 87 insertions(+), 58 deletions(-) diff --git a/internal/sbi/consumer/consumer.go b/internal/sbi/consumer/consumer.go index 3978120..040f0f5 100644 --- a/internal/sbi/consumer/consumer.go +++ b/internal/sbi/consumer/consumer.go @@ -3,8 +3,8 @@ package consumer import ( nrf_discovery "github.com/ShouheiNishi/openapi5g/nrf/discovery" nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management" + udm_ueau "github.com/ShouheiNishi/openapi5g/udm/ueau" "github.com/free5gc/ausf/pkg/app" - "github.com/free5gc/openapi/Nudm_UEAuthentication" ) type ConsumerAusf interface { @@ -31,7 +31,7 @@ func NewConsumer(ausf ConsumerAusf) (*Consumer, error) { c.nudmService = &nudmService{ consumer: c, - ueauClients: make(map[string]*Nudm_UEAuthentication.APIClient), + ueauClients: make(map[string]*udm_ueau.ClientWithResponses), } return c, nil diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index f391c2a..ba19bc0 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -1,13 +1,20 @@ package consumer import ( + "context" + "encoding/json" + "fmt" + "net/http" "sync" "time" + "github.com/ShouheiNishi/openapi5g/models" + udm_ueau "github.com/ShouheiNishi/openapi5g/udm/ueau" + utils_error "github.com/ShouheiNishi/openapi5g/utils/error" ausf_context "github.com/free5gc/ausf/internal/context" - "github.com/free5gc/ausf/internal/logger" - Nudm_UEAU "github.com/free5gc/openapi/Nudm_UEAuthentication" - "github.com/free5gc/openapi/models" + oldModels "github.com/free5gc/openapi/models" + "github.com/free5gc/util/httpclient" + "github.com/samber/lo" ) type nudmService struct { @@ -15,29 +22,41 @@ type nudmService struct { ueauMu sync.RWMutex - ueauClients map[string]*Nudm_UEAU.APIClient + ueauClients map[string]*udm_ueau.ClientWithResponses } -func (s *nudmService) getUdmUeauClient(uri string) *Nudm_UEAU.APIClient { +func (s *nudmService) getUdmUeauClient(uri string) (*udm_ueau.ClientWithResponses, error) { if uri == "" { - return nil + return nil, fmt.Errorf("empty URI") } s.ueauMu.RLock() client, ok := s.ueauClients[uri] if ok { s.ueauMu.RUnlock() - return client + return client, nil + } + + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNudmUeau, models.NFTypeUDM) + if err != nil { + s.ueauMu.RUnlock() + return nil, err } - configuration := Nudm_UEAU.NewConfiguration() - configuration.SetBasePath(uri) - client = Nudm_UEAU.NewAPIClient(configuration) + uriFull := uri + "/nudm-ueau/v1" + client, err = udm_ueau.NewClientWithResponses(uriFull, func(c *udm_ueau.Client) error { + c.Client = httpclient.GetHttpClient(uriFull) + return nil + }, udm_ueau.WithRequestEditorFn(editor)) + if err != nil { + s.ueauMu.RUnlock() + return nil, err + } s.ueauMu.RUnlock() s.ueauMu.Lock() defer s.ueauMu.Unlock() s.ueauClients[uri] = client - return client + return client, nil } func (s *nudmService) SendAuthResultToUDM( @@ -47,61 +66,71 @@ func (s *nudmService) SendAuthResultToUDM( servingNetworkName, udmUrl string, ) error { timeNow := time.Now() - timePtr := &timeNow self := s.consumer.Context() authEvent := models.AuthEvent{ - TimeStamp: timePtr, + TimeStamp: timeNow, AuthType: authType, Success: success, ServingNetworkName: servingNetworkName, - NfInstanceId: self.GetSelfID().String(), + NfInstanceId: self.GetSelfID(), } - client := s.getUdmUeauClient(udmUrl) - - ctx, _, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_UEAU, models.NfType_UDM) + client, err := s.getUdmUeauClient(udmUrl) if err != nil { return err } - _, rsp, confirmAuthErr := client.ConfirmAuthApi.ConfirmAuth(ctx, id, authEvent) - defer func() { - if rspCloseErr := rsp.Body.Close(); rspCloseErr != nil { - logger.ConsumerLog.Errorf("ConfirmAuth Response cannot close: %v", rspCloseErr) - } - }() - return confirmAuthErr + rsp, err := client.ConfirmAuthWithResponse(context.Background(), id, authEvent) + if err != nil || rsp.StatusCode() != http.StatusCreated { + return utils_error.ExtractAndWrapOpenAPIError("udm_ueau.ConfirmAuthWithResponse", rsp, err) + } + return nil } func (s *nudmService) GenerateAuthDataApi( udmUrl string, supiOrSuci string, + oldAuthInfoReq oldModels.AuthenticationInfoRequest, +) (*oldModels.AuthenticationInfoResult, error, *models.ProblemDetails) { + var newAuthInfoReq models.AuthenticationInfoRequest + if buf, err := json.Marshal(oldAuthInfoReq); err != nil { + return nil, err, nil + } else if err := json.Unmarshal(buf, &newAuthInfoReq); err != nil { + return nil, err, nil + } else { + newResult, errOrig, pd := s.realGenerateAuthDataApi(udmUrl, models.SupiOrSuci(supiOrSuci), newAuthInfoReq) + if newResult == nil { + return nil, errOrig, pd + } + if buf, err := json.Marshal(newResult); err != nil { + return nil, err, nil + } else { + var oldResult oldModels.AuthenticationInfoResult + if err := json.Unmarshal(buf, &oldResult); err != nil { + return nil, err, nil + } else { + return &oldResult, errOrig, nil + } + } + } +} + +func (s *nudmService) realGenerateAuthDataApi( + udmUrl string, + supiOrSuci models.SupiOrSuci, authInfoReq models.AuthenticationInfoRequest, ) (*models.AuthenticationInfoResult, error, *models.ProblemDetails) { - client := s.getUdmUeauClient(udmUrl) - - ctx, pd, err := ausf_context.GetSelf().GetTokenCtx(models.ServiceName_NUDM_UEAU, models.NfType_UDM) + client, err := s.getUdmUeauClient(udmUrl) if err != nil { - return nil, err, pd + return nil, err, nil } - authInfoResult, rsp, err := client.GenerateAuthDataApi.GenerateAuthData(ctx, supiOrSuci, authInfoReq) - if err != nil { - var problemDetails models.ProblemDetails - if authInfoResult.AuthenticationVector == nil { - problemDetails.Cause = "AV_GENERATION_PROBLEM" - } else { - problemDetails.Cause = "UPSTREAM_SERVER_ERROR" - } - problemDetails.Status = int32(rsp.StatusCode) - return nil, err, &problemDetails + rsp, err := client.GenerateAuthDataWithResponse(context.TODO(), supiOrSuci, authInfoReq) + if err != nil || rsp.JSON200 == nil { + err = utils_error.ExtractAndWrapOpenAPIError("udm_ueau.GenerateAuthDataWithResponse", rsp, err) + return nil, err, lo.ToPtr(utils_error.ErrorToProblemDetails(err)) } - defer func() { - if rspCloseErr := rsp.Body.Close(); rspCloseErr != nil { - logger.UeAuthLog.Errorf("GenerateAuthDataApi response body cannot close: %+v", rspCloseErr) - } - }() - return &authInfoResult, nil, nil + return rsp.JSON200, nil, nil } diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index 5d9492b..0243565 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -15,16 +15,16 @@ import ( "strings" "time" + newModels "github.com/ShouheiNishi/openapi5g/models" "github.com/bronze1man/radius" - "github.com/gin-gonic/gin" - "github.com/google/gopacket" - "github.com/google/gopacket/layers" - ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/ausf/pkg/factory" "github.com/free5gc/openapi/models" "github.com/free5gc/util/ueauth" + "github.com/gin-gonic/gin" + "github.com/google/gopacket" + "github.com/google/gopacket/layers" ) func (p *Processor) HandleEapAuthComfirmRequest(c *gin.Context, eapSession models.EapSession, eapSessionId string) { @@ -124,7 +124,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( udmUrl := ausfCurrentContext.UdmUeauUrl if sendErr := p.Consumer().SendAuthResultToUDM( eapSessionID, - models.AuthType_EAP_AKA_PRIME, + newModels.AuthTypeEAPAKAPRIME, true, servingNetworkName, udmUrl); sendErr != nil { @@ -171,7 +171,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( if !eapOK { logger.AuthELog.Warnf("EAP-AKA' failure: %s", eapErrStr) - if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthType_EAP_AKA_PRIME, false, servingNetworkName, + if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, newModels.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ @@ -192,7 +192,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( eapSession.Links = make(map[string]models.LinksValueSchema) eapSession.Links["eap-session"] = linksValue } else if ausfCurrentContext.AuthStatus == models.AuthResult_FAILURE { - if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthType_EAP_AKA_PRIME, false, servingNetworkName, + if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, newModels.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) var problemDetails models.ProblemDetails @@ -497,11 +497,11 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi } else { ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE confirmDataRsp.AuthResult = models.AuthResult_FAILURE - p.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, models.AuthType__5_G_AKA, servingNetworkName, + p.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, newModels.AuthTypeN5GAKA, servingNetworkName, "5G AKA confirmation failed", ausfCurrentContext.UdmUeauUrl) } - if sendErr := p.Consumer().SendAuthResultToUDM(currentSupi, models.AuthType__5_G_AKA, success, servingNetworkName, + if sendErr := p.Consumer().SendAuthResultToUDM(currentSupi, newModels.AuthTypeN5GAKA, success, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ @@ -819,14 +819,14 @@ func ConstructEapNoTypePkt(code radius.EapCode, pktID uint8) string { } func (p *Processor) logConfirmFailureAndInformUDM( - id string, authType models.AuthType, servingNetworkName, errStr, udmUrl string, + id string, authType newModels.AuthType, servingNetworkName, errStr, udmUrl string, ) { - if authType == models.AuthType__5_G_AKA { + if authType == newModels.AuthTypeN5GAKA { logger.Auth5gAkaLog.Infoln(servingNetworkName, errStr) if sendErr := p.Consumer().SendAuthResultToUDM(id, authType, false, "", udmUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) } - } else if authType == models.AuthType_EAP_AKA_PRIME { + } else if authType == newModels.AuthTypeEAPAKAPRIME { logger.AuthELog.Infoln(errStr) if sendErr := p.Consumer().SendAuthResultToUDM(id, authType, false, "", udmUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) From a84edf6e0e43de67097b6339bb895a803e7e5c42 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 13:33:43 +0900 Subject: [PATCH 4/9] UE authentication service --- internal/context/context.go | 2 +- internal/sbi/api_ueauthentication.go | 33 +-- internal/sbi/consumer/udm_service.go | 30 --- internal/sbi/processor/ue_authentication.go | 235 +++++++++++++------- 4 files changed, 173 insertions(+), 127 deletions(-) diff --git a/internal/context/context.go b/internal/context/context.go index 7d5257c..ae263f4 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -39,7 +39,7 @@ type AusfUeContext struct { Kausf string Kseaf string ServingNetworkName string - AuthStatus oldModels.AuthResult + AuthStatus models.AuthResult UdmUeauUrl string // for 5G AKA diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go index 073a6b1..52f662d 100644 --- a/internal/sbi/api_ueauthentication.go +++ b/internal/sbi/api_ueauthentication.go @@ -14,11 +14,12 @@ package sbi import ( "net/http" + "github.com/ShouheiNishi/openapi5g/models" "github.com/gin-gonic/gin" + "github.com/samber/lo" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/openapi" - "github.com/free5gc/openapi/models" ) // Index is the index handler. @@ -58,10 +59,10 @@ func (s *Server) EapAuthMethodPost(c *gin.Context) { requestBody, err := c.GetRawData() if err != nil { problemDetail := models.ProblemDetails{ - Title: "System failure", + Title: lo.ToPtr("System failure"), Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", + Detail: lo.ToPtr(err.Error()), + Cause: lo.ToPtr("SYSTEM_FAILURE"), } logger.Auth5gAkaLog.Errorf("Get Request Body error: %+v", err) c.JSON(http.StatusInternalServerError, problemDetail) @@ -72,9 +73,9 @@ func (s *Server) EapAuthMethodPost(c *gin.Context) { if err != nil { problemDetail := "[Request Body] " + err.Error() rsp := models.ProblemDetails{ - Title: "Malformed request syntax", + Title: lo.ToPtr("Malformed request syntax"), Status: http.StatusBadRequest, - Detail: problemDetail, + Detail: &problemDetail, } logger.Auth5gAkaLog.Errorln(problemDetail) c.JSON(http.StatusBadRequest, rsp) @@ -92,10 +93,10 @@ func (s *Server) UeAuthenticationsPost(c *gin.Context) { requestBody, err := c.GetRawData() if err != nil { problemDetail := models.ProblemDetails{ - Title: "System failure", + Title: lo.ToPtr("System failure"), Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", + Detail: lo.ToPtr(err.Error()), + Cause: lo.ToPtr("SYSTEM_FAILURE"), } logger.UeAuthLog.Errorf("Get Request Body error: %+v", err) c.JSON(http.StatusInternalServerError, problemDetail) @@ -106,9 +107,9 @@ func (s *Server) UeAuthenticationsPost(c *gin.Context) { if err != nil { problemDetail := "[Request Body] " + err.Error() rsp := models.ProblemDetails{ - Title: "Malformed request syntax", + Title: lo.ToPtr("Malformed request syntax"), Status: http.StatusBadRequest, - Detail: problemDetail, + Detail: &problemDetail, } logger.UeAuthLog.Errorln(problemDetail) c.JSON(http.StatusBadRequest, rsp) @@ -125,10 +126,10 @@ func (s *Server) UeAuthenticationsAuthCtxID5gAkaConfirmationPut(c *gin.Context) requestBody, err := c.GetRawData() if err != nil { problemDetail := models.ProblemDetails{ - Title: "System failure", + Title: lo.ToPtr("System failure"), Status: http.StatusInternalServerError, - Detail: err.Error(), - Cause: "SYSTEM_FAILURE", + Detail: lo.ToPtr(err.Error()), + Cause: lo.ToPtr("SYSTEM_FAILURE"), } logger.Auth5gAkaLog.Errorf("Get Request Body error: %+v", err) c.JSON(http.StatusInternalServerError, problemDetail) @@ -139,9 +140,9 @@ func (s *Server) UeAuthenticationsAuthCtxID5gAkaConfirmationPut(c *gin.Context) if err != nil { problemDetail := "[Request Body] " + err.Error() rsp := models.ProblemDetails{ - Title: "Malformed request syntax", + Title: lo.ToPtr("Malformed request syntax"), Status: http.StatusBadRequest, - Detail: problemDetail, + Detail: &problemDetail, } logger.Auth5gAkaLog.Errorln(problemDetail) c.JSON(http.StatusBadRequest, rsp) diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index ba19bc0..2cf6515 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -2,7 +2,6 @@ package consumer import ( "context" - "encoding/json" "fmt" "net/http" "sync" @@ -12,7 +11,6 @@ import ( udm_ueau "github.com/ShouheiNishi/openapi5g/udm/ueau" utils_error "github.com/ShouheiNishi/openapi5g/utils/error" ausf_context "github.com/free5gc/ausf/internal/context" - oldModels "github.com/free5gc/openapi/models" "github.com/free5gc/util/httpclient" "github.com/samber/lo" ) @@ -90,34 +88,6 @@ func (s *nudmService) SendAuthResultToUDM( } func (s *nudmService) GenerateAuthDataApi( - udmUrl string, - supiOrSuci string, - oldAuthInfoReq oldModels.AuthenticationInfoRequest, -) (*oldModels.AuthenticationInfoResult, error, *models.ProblemDetails) { - var newAuthInfoReq models.AuthenticationInfoRequest - if buf, err := json.Marshal(oldAuthInfoReq); err != nil { - return nil, err, nil - } else if err := json.Unmarshal(buf, &newAuthInfoReq); err != nil { - return nil, err, nil - } else { - newResult, errOrig, pd := s.realGenerateAuthDataApi(udmUrl, models.SupiOrSuci(supiOrSuci), newAuthInfoReq) - if newResult == nil { - return nil, errOrig, pd - } - if buf, err := json.Marshal(newResult); err != nil { - return nil, err, nil - } else { - var oldResult oldModels.AuthenticationInfoResult - if err := json.Unmarshal(buf, &oldResult); err != nil { - return nil, err, nil - } else { - return &oldResult, errOrig, nil - } - } - } -} - -func (s *nudmService) realGenerateAuthDataApi( udmUrl string, supiOrSuci models.SupiOrSuci, authInfoReq models.AuthenticationInfoRequest, diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index 0243565..e0f6a34 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -15,16 +15,18 @@ import ( "strings" "time" - newModels "github.com/ShouheiNishi/openapi5g/models" + "github.com/ShouheiNishi/openapi5g/models" + utils_error "github.com/ShouheiNishi/openapi5g/utils/error" "github.com/bronze1man/radius" + "github.com/gin-gonic/gin" + "github.com/google/gopacket" + "github.com/google/gopacket/layers" + "github.com/samber/lo" + ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/ausf/pkg/factory" - "github.com/free5gc/openapi/models" "github.com/free5gc/util/ueauth" - "github.com/gin-gonic/gin" - "github.com/google/gopacket" - "github.com/google/gopacket/layers" ) func (p *Processor) HandleEapAuthComfirmRequest(c *gin.Context, eapSession models.EapSession, eapSessionId string) { @@ -44,7 +46,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( logger.AuthELog.Infoln("supiSuciPair does not exist, confirmation failed") problemDetails := models.ProblemDetails{ Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", + Cause: lo.ToPtr("USER_NOT_FOUND"), } c.JSON(int(problemDetails.Status), problemDetails) return @@ -55,7 +57,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( logger.AuthELog.Infoln("SUPI does not exist, confirmation failed") problemDetails := models.ProblemDetails{ Status: http.StatusNotFound, - Cause: "USER_NOT_FOUND", + Cause: lo.ToPtr("USER_NOT_FOUND"), } c.JSON(int(problemDetails.Status), problemDetails) return @@ -64,17 +66,19 @@ func (p *Processor) EapAuthComfirmRequestProcedure( ausfCurrentContext := ausf_context.GetAusfUeContext(currentSupi) servingNetworkName := ausfCurrentContext.ServingNetworkName - if ausfCurrentContext.AuthStatus == models.AuthResult_FAILURE { + if ausfCurrentContext.AuthStatus == models.AUTHENTICATIONFAILURE { logger.AuthELog.Warnf("Authentication failed with status: %s", ausfCurrentContext.AuthStatus) eapFailPkt := ConstructEapNoTypePkt(radius.EapCodeFailure, 0) - eapSession.EapPayload = eapFailPkt - eapSession.AuthResult = models.AuthResult_FAILURE + eapSession.EapPayload = &eapFailPkt + eapSession.AuthResult = models.AUTHENTICATIONFAILURE c.JSON(http.StatusUnauthorized, eapSession) return } var eapPayload []byte - if eapPayloadTmp, err := base64.StdEncoding.DecodeString(updateEapSession.EapPayload); err != nil { + if updateEapSession.EapPayload == nil { + logger.AuthELog.Warnf("EAP Payload is not exist") + } else if eapPayloadTmp, err := base64.StdEncoding.DecodeString(*updateEapSession.EapPayload); err != nil { logger.AuthELog.Warnf("EAP Payload decode failed: %+v", err) } else { eapPayload = eapPayloadTmp @@ -118,30 +122,31 @@ func (p *Processor) EapAuthComfirmRequestProcedure( logger.AuthELog.Infoln("Correct RES value, EAP-AKA' auth succeed") eapSession.KSeaf = ausfCurrentContext.Kseaf eapSession.Supi = currentSupi - eapSession.AuthResult = models.AuthResult_SUCCESS + eapSession.AuthResult = models.AUTHENTICATIONSUCCESS eapSuccPkt := ConstructEapNoTypePkt(radius.EapCodeSuccess, eapContent.Id) - eapSession.EapPayload = eapSuccPkt + eapSession.EapPayload = &eapSuccPkt udmUrl := ausfCurrentContext.UdmUeauUrl if sendErr := p.Consumer().SendAuthResultToUDM( eapSessionID, - newModels.AuthTypeEAPAKAPRIME, + models.AuthTypeEAPAKAPRIME, true, servingNetworkName, udmUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ - Cause: "UPSTREAM_SERVER_ERROR", + Status: http.StatusInternalServerError, + Cause: lo.ToPtr("UPSTREAM_SERVER_ERROR"), } c.JSON(http.StatusInternalServerError, problemDetails) return } - ausfCurrentContext.AuthStatus = models.AuthResult_SUCCESS + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONSUCCESS } else { eapOK = false eapErrStr = "Wrong RES value, EAP-AKA' auth failed" } case ausf_context.AKA_AUTHENTICATION_REJECT_SUBTYPE: - ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE case ausf_context.AKA_SYNCHRONIZATION_FAILURE_SUBTYPE: logger.AuthELog.Warnf("EAP-AKA' synchronziation failure") if ausfCurrentContext.Resynced { @@ -160,49 +165,54 @@ func (p *Processor) EapAuthComfirmRequestProcedure( return } case ausf_context.AKA_NOTIFICATION_SUBTYPE: - ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE case ausf_context.AKA_CLIENT_ERROR_SUBTYPE: logger.AuthELog.Warnf("EAP-AKA' failure: receive client-error") - ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE default: - ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE } } if !eapOK { logger.AuthELog.Warnf("EAP-AKA' failure: %s", eapErrStr) - if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, newModels.AuthTypeEAPAKAPRIME, false, servingNetworkName, + if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ Status: http.StatusInternalServerError, - Cause: "UPSTREAM_SERVER_ERROR", + Cause: lo.ToPtr("UPSTREAM_SERVER_ERROR"), } c.JSON(http.StatusInternalServerError, problemDetails) return } - ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE - eapSession.AuthResult = models.AuthResult_ONGOING + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE + eapSession.AuthResult = models.AUTHENTICATIONONGOING failEapAkaNoti := ConstructFailEapAkaNotification(eapContent.Id) - eapSession.EapPayload = failEapAkaNoti + eapSession.EapPayload = &failEapAkaNoti self := ausf_context.GetSelf() linkUrl := self.Url + factory.AusfAuthResUriPrefix + "/ue-authentications/" + eapSessionID + "/eap-session" - linksValue := models.LinksValueSchema{Href: linkUrl} - eapSession.Links = make(map[string]models.LinksValueSchema) - eapSession.Links["eap-session"] = linksValue - } else if ausfCurrentContext.AuthStatus == models.AuthResult_FAILURE { - if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, newModels.AuthTypeEAPAKAPRIME, false, servingNetworkName, + var linksValue models.LinksValueSchema + if err := linksValue.FromLink(models.Link{Href: &linkUrl}); err != nil { + problemDetails := utils_error.ErrorToProblemDetails(err) + c.JSON(problemDetails.Status, problemDetails) + return + } + eapSession.Links = &map[string]models.LinksValueSchema{} + (*eapSession.Links)["eap-session"] = linksValue + } else if ausfCurrentContext.AuthStatus == models.AUTHENTICATIONFAILURE { + if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) var problemDetails models.ProblemDetails problemDetails.Status = http.StatusInternalServerError - problemDetails.Cause = "UPSTREAM_SERVER_ERROR" + problemDetails.Cause = lo.ToPtr("UPSTREAM_SERVER_ERROR") } eapFailPkt := ConstructEapNoTypePkt(radius.EapCodeFailure, eapPayload[1]) - eapSession.EapPayload = eapFailPkt - eapSession.AuthResult = models.AuthResult_FAILURE + eapSession.EapPayload = &eapFailPkt + eapSession.AuthResult = models.AUTHENTICATIONFAILURE } c.JSON(http.StatusOK, eapSession) @@ -214,7 +224,7 @@ func (p *Processor) HandleUeAuthPostRequest(c *gin.Context, authenticationInfo m } func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticationInfo models.AuthenticationInfo) { - var responseBody models.UeAuthenticationCtx + var responseBody models.UEAuthenticationCtx var authInfoReq models.AuthenticationInfoRequest supiOrSuci := updateAuthenticationInfo.SupiOrSuci @@ -223,7 +233,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat servingNetworkAuthorized := ausf_context.IsServingNetworkAuthorized(snName) if !servingNetworkAuthorized { problemDetails := models.ProblemDetails{ - Cause: "SERVING_NETWORK_NOT_AUTHORIZED", + Cause: lo.ToPtr("SERVING_NETWORK_NOT_AUTHORIZED"), Status: http.StatusForbidden, } logger.UeAuthLog.Infoln("403 forbidden: serving network NOT AUTHORIZED") @@ -235,7 +245,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat responseBody.ServingNetworkName = snName authInfoReq.ServingNetworkName = snName self := ausf_context.GetSelf() - authInfoReq.AusfInstanceId = self.GetSelfID().String() + authInfoReq.AusfInstanceId = self.GetSelfID() var lastEapID uint8 if updateAuthenticationInfo.ResynchronizationInfo != nil { @@ -265,7 +275,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat ueid := authInfoResult.Supi ausfUeContext := ausf_context.NewAusfUeContext(ueid) ausfUeContext.ServingNetworkName = snName - ausfUeContext.AuthStatus = models.AuthResult_ONGOING + ausfUeContext.AuthStatus = models.AUTHENTICATIONONGOING ausfUeContext.UdmUeauUrl = udmUrl ausf_context.AddAusfUeContextToPool(ausfUeContext) @@ -274,19 +284,33 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat locationURI := self.Url + factory.AusfAuthResUriPrefix + "/ue-authentications/" + supiOrSuci putLink := locationURI - if authInfoResult.AuthType == models.AuthType__5_G_AKA { + if authInfoResult.AuthType == models.AuthTypeN5GAKA { logger.UeAuthLog.Infoln("Use 5G AKA auth method") putLink += "/5g-aka-confirmation" + var av5GHeAka models.Av5GHeAka + if av5GHeAka_tmp, err := authInfoResult.AuthenticationVector.AsAv5GHeAka(); err != nil { + problemDetails := &models.ProblemDetails{ + Cause: lo.ToPtr("UDM_CLIENT_FAIL"), + Detail: lo.ToPtr(err.Error()), + Status: http.StatusInternalServerError, + } + logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") + c.JSON(http.StatusInternalServerError, problemDetails) + return + } else { + av5GHeAka = av5GHeAka_tmp + } + // Derive HXRES* from XRES* - concat := authInfoResult.AuthenticationVector.Rand + authInfoResult.AuthenticationVector.XresStar + concat := av5GHeAka.Rand + av5GHeAka.XresStar var hxresStarBytes []byte if bytes, err := hex.DecodeString(concat); err != nil { logger.Auth5gAkaLog.Errorf("decode concat error: %+v", err) problemDetails := models.ProblemDetails{ - Title: "Concat Decode Problem", - Cause: "CONCAT_DECODE_PROBLEM", - Detail: err.Error(), + Title: lo.ToPtr("Concat Decode Problem"), + Cause: lo.ToPtr("CONCAT_DECODE_PROBLEM"), + Detail: lo.ToPtr(err.Error()), Status: http.StatusInternalServerError, } c.JSON(http.StatusInternalServerError, problemDetails) @@ -296,17 +320,17 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat } hxresStarAll := sha256.Sum256(hxresStarBytes) hxresStar := hex.EncodeToString(hxresStarAll[16:]) // last 128 bits - logger.Auth5gAkaLog.Infof("XresStar = %x\n", authInfoResult.AuthenticationVector.XresStar) + logger.Auth5gAkaLog.Infof("XresStar = %x\n", av5GHeAka.XresStar) // Derive Kseaf from Kausf - Kausf := authInfoResult.AuthenticationVector.Kausf + Kausf := av5GHeAka.Kausf var KausfDecode []byte if ausfDecode, err := hex.DecodeString(Kausf); err != nil { logger.Auth5gAkaLog.Errorf("decode Kausf failed: %+v", err) problemDetails := models.ProblemDetails{ - Title: "Kausf Decode Problem", - Cause: "KAUSF_DECODE_PROBLEM", - Detail: err.Error(), + Title: lo.ToPtr("Kausf Decode Problem"), + Cause: lo.ToPtr("KAUSF_DECODE_PROBLEM"), + Detail: lo.ToPtr(err.Error()), Status: http.StatusInternalServerError, } c.JSON(http.StatusInternalServerError, problemDetails) @@ -319,32 +343,63 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat if err != nil { logger.Auth5gAkaLog.Errorf("GetKDFValue failed: %+v", err) problemDetails := models.ProblemDetails{ - Title: "Kseaf Derivation Problem", - Cause: "KSEAF_DERIVATION_PROBLEM", - Detail: err.Error(), + Title: lo.ToPtr("Kseaf Derivation Problem"), + Cause: lo.ToPtr("KSEAF_DERIVATION_PROBLEM"), + Detail: lo.ToPtr(err.Error()), Status: http.StatusInternalServerError, } c.JSON(http.StatusInternalServerError, problemDetails) return } - ausfUeContext.XresStar = authInfoResult.AuthenticationVector.XresStar + ausfUeContext.XresStar = av5GHeAka.XresStar ausfUeContext.Kausf = Kausf ausfUeContext.Kseaf = hex.EncodeToString(Kseaf) - ausfUeContext.Rand = authInfoResult.AuthenticationVector.Rand + ausfUeContext.Rand = av5GHeAka.Rand var av5gAka models.Av5gAka - av5gAka.Rand = authInfoResult.AuthenticationVector.Rand - av5gAka.Autn = authInfoResult.AuthenticationVector.Autn + av5gAka.Rand = av5GHeAka.Rand + av5gAka.Autn = av5GHeAka.Autn av5gAka.HxresStar = hxresStar - responseBody.Var5gAuthData = av5gAka + if err := responseBody.N5gAuthData.FromAv5gAka(av5gAka); err != nil { + problemDetails := &models.ProblemDetails{ + Cause: lo.ToPtr("UDM_CLIENT_FAIL"), + Detail: lo.ToPtr(err.Error()), + Status: http.StatusInternalServerError, + } + logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") + c.JSON(http.StatusInternalServerError, problemDetails) + return + } - linksValue := models.LinksValueSchema{Href: putLink} + var linksValue models.LinksValueSchema + if err := linksValue.FromLink(models.Link{Href: &putLink}); err != nil { + problemDetails := &models.ProblemDetails{ + Cause: lo.ToPtr("UDM_CLIENT_FAIL"), + Detail: lo.ToPtr(err.Error()), + Status: http.StatusInternalServerError, + } + logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") + c.JSON(http.StatusInternalServerError, problemDetails) + return + } responseBody.Links = make(map[string]models.LinksValueSchema) responseBody.Links["5g-aka"] = linksValue - } else if authInfoResult.AuthType == models.AuthType_EAP_AKA_PRIME { + } else if authInfoResult.AuthType == models.AuthTypeEAPAKAPRIME { logger.UeAuthLog.Infoln("Use EAP-AKA' auth method") putLink += "/eap-session" + avEapAkaPrime, err := authInfoResult.AuthenticationVector.AsAvEapAkaPrime() + if err != nil { + problemDetails := &models.ProblemDetails{ + Cause: lo.ToPtr("UDM_CLIENT_FAIL"), + Detail: lo.ToPtr(err.Error()), + Status: http.StatusInternalServerError, + } + logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") + c.JSON(http.StatusInternalServerError, problemDetails) + return + } + var identity string // TODO support more SUPI type if ueid[:4] == "imsi" { @@ -356,14 +411,14 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat identity = ueid } } - ikPrime := authInfoResult.AuthenticationVector.IkPrime - ckPrime := authInfoResult.AuthenticationVector.CkPrime - RAND := authInfoResult.AuthenticationVector.Rand - AUTN := authInfoResult.AuthenticationVector.Autn - XRES := authInfoResult.AuthenticationVector.Xres + ikPrime := avEapAkaPrime.IkPrime + ckPrime := avEapAkaPrime.CkPrime + RAND := avEapAkaPrime.Rand + AUTN := avEapAkaPrime.Autn + XRES := avEapAkaPrime.Xres ausfUeContext.XRES = XRES - ausfUeContext.Rand = authInfoResult.AuthenticationVector.Rand + ausfUeContext.Rand = avEapAkaPrime.Rand _, K_aut, _, _, EMSK := eapAkaPrimePrf(ikPrime, ckPrime, identity) logger.AuthELog.Tracef("K_aut: %x", K_aut) @@ -431,14 +486,33 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat eapPkt.Data = []byte(dataArrayAfterMAC) encodedPktAfterMAC := eapPkt.Encode() - responseBody.Var5gAuthData = base64.StdEncoding.EncodeToString(encodedPktAfterMAC) + if err := responseBody.N5gAuthData.FromEapPayload(base64.StdEncoding.EncodeToString(encodedPktAfterMAC)); err != nil { + problemDetails := &models.ProblemDetails{ + Cause: lo.ToPtr("UDM_CLIENT_FAIL"), + Detail: lo.ToPtr(err.Error()), + Status: http.StatusInternalServerError, + } + logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") + c.JSON(http.StatusInternalServerError, problemDetails) + return + } - linksValue := models.LinksValueSchema{Href: putLink} + var linksValue models.LinksValueSchema + if err := linksValue.FromLink(models.Link{Href: &putLink}); err != nil { + problemDetails := &models.ProblemDetails{ + Cause: lo.ToPtr("UDM_CLIENT_FAIL"), + Detail: lo.ToPtr(err.Error()), + Status: http.StatusInternalServerError, + } + logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") + c.JSON(http.StatusInternalServerError, problemDetails) + return + } responseBody.Links = make(map[string]models.LinksValueSchema) responseBody.Links["eap-session"] = linksValue } - responseBody.AuthType = authInfoResult.AuthType + responseBody.AuthType = models.AusfAuthType(authInfoResult.AuthType) c.Header("Location", locationURI) c.JSON(http.StatusCreated, responseBody) @@ -458,13 +532,13 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi ) { var confirmDataRsp models.ConfirmationDataResponse success := false - confirmDataRsp.AuthResult = models.AuthResult_FAILURE + confirmDataRsp.AuthResult = models.AUTHENTICATIONFAILURE if !ausf_context.CheckIfSuciSupiPairExists(ConfirmationDataResponseID) { logger.Auth5gAkaLog.Infof("supiSuciPair does not exist, confirmation failed (queried by %s)\n", ConfirmationDataResponseID) problemDetails := models.ProblemDetails{ - Cause: "USER_NOT_FOUND", + Cause: lo.ToPtr("USER_NOT_FOUND"), Status: http.StatusBadRequest, } c.JSON(http.StatusBadRequest, problemDetails) @@ -475,7 +549,7 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi if !ausf_context.CheckIfAusfUeContextExists(currentSupi) { logger.Auth5gAkaLog.Infof("SUPI does not exist, confirmation failed (queried by %s)\n", currentSupi) problemDetails := models.ProblemDetails{ - Cause: "USER_NOT_FOUND", + Cause: lo.ToPtr("USER_NOT_FOUND"), Status: http.StatusBadRequest, } c.JSON(http.StatusBadRequest, problemDetails) @@ -487,26 +561,27 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi // Compare the received RES* with the stored XRES* logger.Auth5gAkaLog.Infof("res*: %x\nXres*: %x\n", updateConfirmationData.ResStar, ausfCurrentContext.XresStar) - if strings.EqualFold(updateConfirmationData.ResStar, ausfCurrentContext.XresStar) { - ausfCurrentContext.AuthStatus = models.AuthResult_SUCCESS - confirmDataRsp.AuthResult = models.AuthResult_SUCCESS + if updateConfirmationData.ResStar != nil && + strings.EqualFold(*updateConfirmationData.ResStar, ausfCurrentContext.XresStar) { + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONSUCCESS + confirmDataRsp.AuthResult = models.AUTHENTICATIONSUCCESS success = true logger.Auth5gAkaLog.Infoln("5G AKA confirmation succeeded") confirmDataRsp.Supi = currentSupi confirmDataRsp.Kseaf = ausfCurrentContext.Kseaf } else { - ausfCurrentContext.AuthStatus = models.AuthResult_FAILURE - confirmDataRsp.AuthResult = models.AuthResult_FAILURE - p.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, newModels.AuthTypeN5GAKA, servingNetworkName, + ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE + confirmDataRsp.AuthResult = models.AUTHENTICATIONFAILURE + p.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, "5G AKA confirmation failed", ausfCurrentContext.UdmUeauUrl) } - if sendErr := p.Consumer().SendAuthResultToUDM(currentSupi, newModels.AuthTypeN5GAKA, success, servingNetworkName, + if sendErr := p.Consumer().SendAuthResultToUDM(currentSupi, models.AuthTypeN5GAKA, success, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ Status: http.StatusInternalServerError, - Cause: "UPSTREAM_SERVER_ERROR", + Cause: lo.ToPtr("UPSTREAM_SERVER_ERROR"), } c.JSON(http.StatusInternalServerError, problemDetails) return @@ -819,14 +894,14 @@ func ConstructEapNoTypePkt(code radius.EapCode, pktID uint8) string { } func (p *Processor) logConfirmFailureAndInformUDM( - id string, authType newModels.AuthType, servingNetworkName, errStr, udmUrl string, + id string, authType models.AuthType, servingNetworkName, errStr, udmUrl string, ) { - if authType == newModels.AuthTypeN5GAKA { + if authType == models.AuthTypeN5GAKA { logger.Auth5gAkaLog.Infoln(servingNetworkName, errStr) if sendErr := p.Consumer().SendAuthResultToUDM(id, authType, false, "", udmUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) } - } else if authType == newModels.AuthTypeEAPAKAPRIME { + } else if authType == models.AuthTypeEAPAKAPRIME { logger.AuthELog.Infoln(errStr) if sendErr := p.Consumer().SendAuthResultToUDM(id, authType, false, "", udmUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) From 2ba7bc5dbfadf36fd14e9de4235e1beb8f520fd7 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 13:44:51 +0900 Subject: [PATCH 5/9] Remove old models use --- internal/context/ausf_context_init.go | 7 +++---- internal/context/context.go | 22 ++++++---------------- internal/sbi/server.go | 14 +++++++------- internal/util/router_auth_check.go | 2 +- internal/util/router_auth_check_test.go | 3 +-- pkg/factory/config.go | 2 +- 6 files changed, 19 insertions(+), 31 deletions(-) diff --git a/internal/context/ausf_context_init.go b/internal/context/ausf_context_init.go index b47d3d9..b2ff5f9 100644 --- a/internal/context/ausf_context_init.go +++ b/internal/context/ausf_context_init.go @@ -10,7 +10,6 @@ import ( "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/ausf/pkg/factory" - oldModels "github.com/free5gc/openapi/models" ) func InitAusfContext(context *AUSFContext) { @@ -57,14 +56,14 @@ func InitAusfContext(context *AUSFContext) { context.PlmnList = append(context.PlmnList, configuration.PlmnSupportList...) // context.NfService - context.NfService = make(map[oldModels.ServiceName]models.NrfNFService) + context.NfService = make(map[models.ServiceName]models.NrfNFService) AddNfServices(&context.NfService, config, context) fmt.Println("ausf context = ", context) context.EapAkaSupiImsiPrefix = configuration.EapAkaSupiImsiPrefix } -func AddNfServices(serviceMap *map[oldModels.ServiceName]models.NrfNFService, config *factory.Config, context *AUSFContext) { +func AddNfServices(serviceMap *map[models.ServiceName]models.NrfNFService, config *factory.Config, context *AUSFContext) { var nfService models.NrfNFService var ipEndPoints []models.IpEndPoint var nfServiceVersions []models.NFServiceVersion @@ -89,5 +88,5 @@ func AddNfServices(serviceMap *map[oldModels.ServiceName]models.NrfNFService, co nfService.IpEndPoints = ipEndPoints nfService.Versions = nfServiceVersions - services[oldModels.ServiceName_NAUSF_AUTH] = nfService + services[models.ServiceNameNausfAuth] = nfService } diff --git a/internal/context/context.go b/internal/context/context.go index ae263f4..04b6ef3 100644 --- a/internal/context/context.go +++ b/internal/context/context.go @@ -7,11 +7,11 @@ import ( "sync" "github.com/ShouheiNishi/openapi5g/models" + "github.com/google/uuid" + "github.com/free5gc/ausf/internal/logger" - oldModels "github.com/free5gc/openapi/models" "github.com/free5gc/openapi/oauth" "github.com/free5gc/util/oauth2" - "github.com/google/uuid" ) type AUSFContext struct { @@ -26,8 +26,8 @@ type AUSFContext struct { UriScheme models.UriScheme NrfUri string NrfCertPem string - NfService map[oldModels.ServiceName]models.NrfNFService - PlmnList []oldModels.PlmnId + NfService map[models.ServiceName]models.NrfNFService + PlmnList []models.PlmnId UdmUeauUrl string snRegex *regexp.Regexp EapAkaSupiImsiPrefix bool @@ -109,7 +109,7 @@ func Init() { } type NFContext interface { - AuthorizationCheck(token string, serviceName oldModels.ServiceName) error + AuthorizationCheck(token string, serviceName models.ServiceName) error } var _ NFContext = &AUSFContext{} @@ -170,16 +170,6 @@ func (a *AUSFContext) GetSelfID() uuid.UUID { return a.NfId } -func (c *AUSFContext) GetTokenCtx(serviceName oldModels.ServiceName, targetNF oldModels.NfType) ( - context.Context, *oldModels.ProblemDetails, error, -) { - if !c.OAuth2Required { - return context.TODO(), nil, nil - } - return oauth.GetTokenCtx(oldModels.NfType_AUSF, targetNF, - c.NfId.String(), c.NrfUri, string(serviceName)) -} - func (c *AUSFContext) GetTokenRequestEditor(ctx context.Context, serviceName models.ServiceName, targetNF models.NFType, ) (func(ctx context.Context, req *http.Request) error, error) { @@ -191,7 +181,7 @@ func (c *AUSFContext) GetTokenRequestEditor(ctx context.Context, return oauth2.GetOauth2RequestEditor(ctx, models.NFTypeAUSF, targetNF, c.NfId, c.NrfUri, string(serviceName)) } -func (c *AUSFContext) AuthorizationCheck(token string, serviceName oldModels.ServiceName) error { +func (c *AUSFContext) AuthorizationCheck(token string, serviceName models.ServiceName) error { if !c.OAuth2Required { logger.UtilLog.Debugf("AUSFContext::AuthorizationCheck: OAuth2 not required\n") return nil diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 90b3c09..646fc58 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -9,6 +9,7 @@ import ( "sync" "time" + "github.com/ShouheiNishi/openapi5g/models" "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" @@ -19,7 +20,6 @@ import ( "github.com/free5gc/ausf/internal/util" "github.com/free5gc/ausf/pkg/app" "github.com/free5gc/ausf/pkg/factory" - "github.com/free5gc/openapi/models" "github.com/free5gc/util/httpwrapper" logger_util "github.com/free5gc/util/logger" ) @@ -63,26 +63,26 @@ func newRouter(s *Server) *gin.Engine { for _, serverName := range factory.AusfConfig.Configuration.ServiceNameList { switch models.ServiceName(serverName) { - case models.ServiceName_NAUSF_AUTH: + case models.ServiceNameNausfAuth: ausfUeAuthenticationGroup := router.Group(factory.AusfAuthResUriPrefix) ausfUeAuthenticationRoutes := s.getUeAuthenticationRoutes() - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NAUSF_AUTH) + routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceNameNausfAuth) ausfUeAuthenticationGroup.Use(func(c *gin.Context) { routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) }) applyRoutes(ausfUeAuthenticationGroup, ausfUeAuthenticationRoutes) - case models.ServiceName_NAUSF_SORPROTECTION: + case models.ServiceNameNausfSorprotection: ausfSorprotectionGroup := router.Group(factory.AusfSorprotectionResUriPrefix) ausfSorprotectionRoutes := s.getSorprotectionRoutes() - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NAUSF_SORPROTECTION) + routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceNameNausfSorprotection) ausfSorprotectionGroup.Use(func(c *gin.Context) { routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) }) applyRoutes(ausfSorprotectionGroup, ausfSorprotectionRoutes) - case models.ServiceName_NAUSF_UPUPROTECTION: + case models.ServiceNameNausfUpuprotection: ausfUpuprotectionGroup := router.Group(factory.AusfUpuprotectionResUriPrefix) ausfUpuprotectionRoutes := s.getUpuprotectionRoutes() - routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceName_NAUSF_UPUPROTECTION) + routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceNameNausfUpuprotection) ausfUpuprotectionGroup.Use(func(c *gin.Context) { routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) }) diff --git a/internal/util/router_auth_check.go b/internal/util/router_auth_check.go index 754fc83..71452c9 100644 --- a/internal/util/router_auth_check.go +++ b/internal/util/router_auth_check.go @@ -3,11 +3,11 @@ package util import ( "net/http" + "github.com/ShouheiNishi/openapi5g/models" "github.com/gin-gonic/gin" ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" - "github.com/free5gc/openapi/models" ) type RouterAuthorizationCheck struct { diff --git a/internal/util/router_auth_check_test.go b/internal/util/router_auth_check_test.go index df1612c..9135158 100644 --- a/internal/util/router_auth_check_test.go +++ b/internal/util/router_auth_check_test.go @@ -5,10 +5,9 @@ import ( "net/http/httptest" "testing" + "github.com/ShouheiNishi/openapi5g/models" "github.com/gin-gonic/gin" "github.com/pkg/errors" - - "github.com/free5gc/openapi/models" ) const ( diff --git a/pkg/factory/config.go b/pkg/factory/config.go index e61b852..690bbd1 100644 --- a/pkg/factory/config.go +++ b/pkg/factory/config.go @@ -11,10 +11,10 @@ import ( "strconv" "sync" + "github.com/ShouheiNishi/openapi5g/models" "github.com/asaskevich/govalidator" "github.com/free5gc/ausf/internal/logger" - "github.com/free5gc/openapi/models" ) const ( From 805f0e8a4bffddbe071aacf33ef11f1fab993455 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 15:43:51 +0900 Subject: [PATCH 6/9] oapi-codegen strict server --- internal/sbi/api_sorprotection.go | 26 --- internal/sbi/api_ueauthentication.go | 154 ------------- internal/sbi/api_upuprotection.go | 26 --- internal/sbi/processor/sor_protection.go | 28 +++ internal/sbi/processor/ue_authentication.go | 226 +++++++++++++------- internal/sbi/processor/upu_protection.go | 28 +++ internal/sbi/server.go | 56 +++-- 7 files changed, 247 insertions(+), 297 deletions(-) delete mode 100644 internal/sbi/api_sorprotection.go delete mode 100644 internal/sbi/api_ueauthentication.go delete mode 100644 internal/sbi/api_upuprotection.go create mode 100644 internal/sbi/processor/sor_protection.go create mode 100644 internal/sbi/processor/upu_protection.go diff --git a/internal/sbi/api_sorprotection.go b/internal/sbi/api_sorprotection.go deleted file mode 100644 index ff5ebf3..0000000 --- a/internal/sbi/api_sorprotection.go +++ /dev/null @@ -1,26 +0,0 @@ -package sbi - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -func (s *Server) getSorprotectionRoutes() []Route { - return []Route{ - { - Method: http.MethodGet, - Pattern: "/", - APIFunc: Index, - }, - { - Method: http.MethodPost, - Pattern: "/:supi/ue-sor", - APIFunc: s.SupiUeSorPost, - }, - } -} - -func (s *Server) SupiUeSorPost(c *gin.Context) { - c.JSON(http.StatusNotImplemented, gin.H{}) -} diff --git a/internal/sbi/api_ueauthentication.go b/internal/sbi/api_ueauthentication.go deleted file mode 100644 index 52f662d..0000000 --- a/internal/sbi/api_ueauthentication.go +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Nausf_UeAuthentication - * - * UeAuthentication Service - * © 2021, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). - * All rights reserved. - * - * API version: 3.0.3 - * Generated by: OpenAPI Generator (https://openapi-generator.tech) - */ - -package sbi - -import ( - "net/http" - - "github.com/ShouheiNishi/openapi5g/models" - "github.com/gin-gonic/gin" - "github.com/samber/lo" - - "github.com/free5gc/ausf/internal/logger" - "github.com/free5gc/openapi" -) - -// Index is the index handler. -func Index(c *gin.Context) { - c.String(http.StatusOK, "Hello World!") -} - -func (s *Server) getUeAuthenticationRoutes() []Route { - return []Route{ - { - Method: http.MethodGet, - Pattern: "/", - APIFunc: Index, - }, - { - Method: http.MethodPost, - Pattern: "/ue-authentications/:authCtxId/eap-session", - APIFunc: s.EapAuthMethodPost, - }, - { - Method: http.MethodPost, - Pattern: "/ue-authentications", - APIFunc: s.UeAuthenticationsPost, - }, - { - Method: http.MethodPut, - Pattern: "/ue-authentications/:authCtxId/5g-aka-confirmation", - APIFunc: s.UeAuthenticationsAuthCtxID5gAkaConfirmationPut, - }, - } -} - -// EapAuthMethodPost - -func (s *Server) EapAuthMethodPost(c *gin.Context) { - var eapSessionReq models.EapSession - - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: lo.ToPtr("System failure"), - Status: http.StatusInternalServerError, - Detail: lo.ToPtr(err.Error()), - Cause: lo.ToPtr("SYSTEM_FAILURE"), - } - logger.Auth5gAkaLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - err = openapi.Deserialize(&eapSessionReq, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: lo.ToPtr("Malformed request syntax"), - Status: http.StatusBadRequest, - Detail: &problemDetail, - } - logger.Auth5gAkaLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - eapSessionId := c.Param("authCtxId") - - s.Processor().HandleEapAuthComfirmRequest(c, eapSessionReq, eapSessionId) -} - -// UeAuthenticationsPost -func (s *Server) UeAuthenticationsPost(c *gin.Context) { - var authInfo models.AuthenticationInfo - - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: lo.ToPtr("System failure"), - Status: http.StatusInternalServerError, - Detail: lo.ToPtr(err.Error()), - Cause: lo.ToPtr("SYSTEM_FAILURE"), - } - logger.UeAuthLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - err = openapi.Deserialize(&authInfo, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: lo.ToPtr("Malformed request syntax"), - Status: http.StatusBadRequest, - Detail: &problemDetail, - } - logger.UeAuthLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - - s.Processor().HandleUeAuthPostRequest(c, authInfo) -} - -// UeAuthenticationsAuthCtxID5gAkaConfirmationPut -func (s *Server) UeAuthenticationsAuthCtxID5gAkaConfirmationPut(c *gin.Context) { - var confirmationData models.ConfirmationData - - requestBody, err := c.GetRawData() - if err != nil { - problemDetail := models.ProblemDetails{ - Title: lo.ToPtr("System failure"), - Status: http.StatusInternalServerError, - Detail: lo.ToPtr(err.Error()), - Cause: lo.ToPtr("SYSTEM_FAILURE"), - } - logger.Auth5gAkaLog.Errorf("Get Request Body error: %+v", err) - c.JSON(http.StatusInternalServerError, problemDetail) - return - } - - err = openapi.Deserialize(&confirmationData, requestBody, "application/json") - if err != nil { - problemDetail := "[Request Body] " + err.Error() - rsp := models.ProblemDetails{ - Title: lo.ToPtr("Malformed request syntax"), - Status: http.StatusBadRequest, - Detail: &problemDetail, - } - logger.Auth5gAkaLog.Errorln(problemDetail) - c.JSON(http.StatusBadRequest, rsp) - return - } - confirmationDataResponseId := c.Param("authCtxId") - - s.Processor().HandleAuth5gAkaComfirmRequest(c, confirmationData, confirmationDataResponseId) -} diff --git a/internal/sbi/api_upuprotection.go b/internal/sbi/api_upuprotection.go deleted file mode 100644 index 856ebf1..0000000 --- a/internal/sbi/api_upuprotection.go +++ /dev/null @@ -1,26 +0,0 @@ -package sbi - -import ( - "net/http" - - "github.com/gin-gonic/gin" -) - -func (s *Server) getUpuprotectionRoutes() []Route { - return []Route{ - { - Method: http.MethodGet, - Pattern: "/", - APIFunc: Index, - }, - { - Method: http.MethodPost, - Pattern: "/:supi/ue-upu", - APIFunc: s.SupiUeUpuPost, - }, - } -} - -func (s *Server) SupiUeUpuPost(c *gin.Context) { - c.JSON(http.StatusNotImplemented, gin.H{}) -} diff --git a/internal/sbi/processor/sor_protection.go b/internal/sbi/processor/sor_protection.go new file mode 100644 index 0000000..f78b582 --- /dev/null +++ b/internal/sbi/processor/sor_protection.go @@ -0,0 +1,28 @@ +package processor + +import ( + "context" + "errors" + + ausf_sor_protection "github.com/ShouheiNishi/openapi5g/ausf/sor" + "github.com/ShouheiNishi/openapi5g/utils/error/middleware" + strictgin "github.com/oapi-codegen/runtime/strictmiddleware/gin" +) + +func NewServerAusfSorProtection(processor *Processor) ausf_sor_protection.ServerInterface { + return ausf_sor_protection.NewStrictHandler( + &ausfSorProtectionStrictServer{ + processor: processor, + }, + []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, + ) +} + +type ausfSorProtectionStrictServer struct { + processor *Processor +} + +// (POST /{supi}/ue-sor) +func (s *ausfSorProtectionStrictServer) PostSupiUeSor(ctx context.Context, request ausf_sor_protection.PostSupiUeSorRequestObject) (ausf_sor_protection.PostSupiUeSorResponseObject, error) { + return nil, errors.New("not implemented") +} diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index e0f6a34..efce596 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -2,11 +2,13 @@ package processor import ( "bytes" + "context" "crypto/hmac" "crypto/sha256" "encoding/base64" "encoding/binary" "encoding/hex" + "errors" "fmt" "hash" "math/rand" @@ -15,12 +17,14 @@ import ( "strings" "time" + ausf_authentication "github.com/ShouheiNishi/openapi5g/ausf/authentication" "github.com/ShouheiNishi/openapi5g/models" utils_error "github.com/ShouheiNishi/openapi5g/utils/error" + "github.com/ShouheiNishi/openapi5g/utils/error/middleware" "github.com/bronze1man/radius" - "github.com/gin-gonic/gin" "github.com/google/gopacket" "github.com/google/gopacket/layers" + strictgin "github.com/oapi-codegen/runtime/strictmiddleware/gin" "github.com/samber/lo" ausf_context "github.com/free5gc/ausf/internal/context" @@ -29,17 +33,48 @@ import ( "github.com/free5gc/util/ueauth" ) -func (p *Processor) HandleEapAuthComfirmRequest(c *gin.Context, eapSession models.EapSession, eapSessionId string) { - logger.Auth5gAkaLog.Infof("EapAuthComfirmRequest") +func NewServerAusfAuthentication(processor *Processor) ausf_authentication.ServerInterface { + return ausf_authentication.NewStrictHandler( + &ausfAuthenticationStrictServer{ + processor: processor, + }, + []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, + ) +} - p.EapAuthComfirmRequestProcedure(c, eapSession, eapSessionId) +type ausfAuthenticationStrictServer struct { + processor *Processor } -func (p *Processor) EapAuthComfirmRequestProcedure( - c *gin.Context, - updateEapSession models.EapSession, - eapSessionID string, -) { +// (POST /rg-authentications) +func (s *ausfAuthenticationStrictServer) PostRgAuthentications(ctx context.Context, request ausf_authentication.PostRgAuthenticationsRequestObject) (ausf_authentication.PostRgAuthenticationsResponseObject, error) { + return nil, errors.New("not implemented") +} + +// (POST /ue-authentications/deregister) +func (s *ausfAuthenticationStrictServer) PostUeAuthenticationsDeregister(ctx context.Context, request ausf_authentication.PostUeAuthenticationsDeregisterRequestObject) (ausf_authentication.PostUeAuthenticationsDeregisterResponseObject, error) { + return nil, errors.New("not implemented") +} + +// Deletes the authentication result in the UDM +// (DELETE /ue-authentications/{authCtxId}/5g-aka-confirmation) +func (s *ausfAuthenticationStrictServer) Delete5gAkaAuthenticationResult(ctx context.Context, request ausf_authentication.Delete5gAkaAuthenticationResultRequestObject) (ausf_authentication.Delete5gAkaAuthenticationResultResponseObject, error) { + return nil, errors.New("not implemented") +} + +// Deletes the authentication result in the UDM +// (DELETE /ue-authentications/{authCtxId}/eap-session) +func (s *ausfAuthenticationStrictServer) DeleteEapAuthenticationResult(ctx context.Context, request ausf_authentication.DeleteEapAuthenticationResultRequestObject) (ausf_authentication.DeleteEapAuthenticationResultResponseObject, error) { + return nil, errors.New("not implemented") +} + +// (POST /ue-authentications/{authCtxId}/eap-session) +func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, request ausf_authentication.EapAuthMethodRequestObject) (ausf_authentication.EapAuthMethodResponseObject, error) { + logger.Auth5gAkaLog.Infof("EapAuthComfirmRequest") + + updateEapSession := request.Body + eapSessionID := request.AuthCtxId + var eapSession models.EapSession if !ausf_context.CheckIfSuciSupiPairExists(eapSessionID) { @@ -48,8 +83,10 @@ func (p *Processor) EapAuthComfirmRequestProcedure( Status: http.StatusNotFound, Cause: lo.ToPtr("USER_NOT_FOUND"), } - c.JSON(int(problemDetails.Status), problemDetails) - return + return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } currentSupi := ausf_context.GetSupiFromSuciSupiMap(eapSessionID) @@ -59,8 +96,10 @@ func (p *Processor) EapAuthComfirmRequestProcedure( Status: http.StatusNotFound, Cause: lo.ToPtr("USER_NOT_FOUND"), } - c.JSON(int(problemDetails.Status), problemDetails) - return + return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } ausfCurrentContext := ausf_context.GetAusfUeContext(currentSupi) @@ -71,8 +110,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( eapFailPkt := ConstructEapNoTypePkt(radius.EapCodeFailure, 0) eapSession.EapPayload = &eapFailPkt eapSession.AuthResult = models.AUTHENTICATIONFAILURE - c.JSON(http.StatusUnauthorized, eapSession) - return + return ausf_authentication.EapAuthMethod200JSONResponse(eapSession), nil } var eapPayload []byte @@ -126,7 +164,7 @@ func (p *Processor) EapAuthComfirmRequestProcedure( eapSuccPkt := ConstructEapNoTypePkt(radius.EapCodeSuccess, eapContent.Id) eapSession.EapPayload = &eapSuccPkt udmUrl := ausfCurrentContext.UdmUeauUrl - if sendErr := p.Consumer().SendAuthResultToUDM( + if sendErr := s.processor.Consumer().SendAuthResultToUDM( eapSessionID, models.AuthTypeEAPAKAPRIME, true, @@ -137,8 +175,10 @@ func (p *Processor) EapAuthComfirmRequestProcedure( Status: http.StatusInternalServerError, Cause: lo.ToPtr("UPSTREAM_SERVER_ERROR"), } - c.JSON(http.StatusInternalServerError, problemDetails) - return + return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } ausfCurrentContext.AuthStatus = models.AUTHENTICATIONSUCCESS } else { @@ -161,8 +201,21 @@ func (p *Processor) EapAuthComfirmRequestProcedure( authInfo.SupiOrSuci = eapSessionID authInfo.ServingNetworkName = servingNetworkName authInfo.ResynchronizationInfo = resynchronizationInfo - p.UeAuthPostRequestProcedure(c, authInfo) - return + response, _, problemDetails := s.processor.UeAuthPostRequestProcedure(c, authInfo) + if problemDetails != nil { + return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: *problemDetails, + }, nil + } + ausfCurrentContext.Resynced = true + eapPayload, err := response.N5gAuthData.AsEapPayload() + if err != nil { + return nil, err + } + eapSession.EapPayload = &eapPayload + eapSession.Links = &response.Links + eapSession.AuthResult = models.AUTHENTICATIONONGOING } case ausf_context.AKA_NOTIFICATION_SUBTYPE: ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE @@ -176,15 +229,17 @@ func (p *Processor) EapAuthComfirmRequestProcedure( if !eapOK { logger.AuthELog.Warnf("EAP-AKA' failure: %s", eapErrStr) - if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, + if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ Status: http.StatusInternalServerError, Cause: lo.ToPtr("UPSTREAM_SERVER_ERROR"), } - c.JSON(http.StatusInternalServerError, problemDetails) - return + return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE @@ -196,13 +251,15 @@ func (p *Processor) EapAuthComfirmRequestProcedure( var linksValue models.LinksValueSchema if err := linksValue.FromLink(models.Link{Href: &linkUrl}); err != nil { problemDetails := utils_error.ErrorToProblemDetails(err) - c.JSON(problemDetails.Status, problemDetails) - return + return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } eapSession.Links = &map[string]models.LinksValueSchema{} (*eapSession.Links)["eap-session"] = linksValue } else if ausfCurrentContext.AuthStatus == models.AUTHENTICATIONFAILURE { - if sendErr := p.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, + if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) var problemDetails models.ProblemDetails @@ -215,15 +272,46 @@ func (p *Processor) EapAuthComfirmRequestProcedure( eapSession.AuthResult = models.AUTHENTICATIONFAILURE } - c.JSON(http.StatusOK, eapSession) + return ausf_authentication.EapAuthMethod200JSONResponse(eapSession), nil } -func (p *Processor) HandleUeAuthPostRequest(c *gin.Context, authenticationInfo models.AuthenticationInfo) { +// (POST /ue-authentications) +func (s *ausfAuthenticationStrictServer) PostUeAuthentications(ctx context.Context, request ausf_authentication.PostUeAuthenticationsRequestObject) (ausf_authentication.PostUeAuthenticationsResponseObject, error) { logger.UeAuthLog.Infof("HandleUeAuthPostRequest") - p.UeAuthPostRequestProcedure(c, authenticationInfo) + + if request.Body == nil { + return ausf_authentication.PostUeAuthentications400ApplicationProblemPlusJSONResponse{ + Cause: lo.ToPtr("BODY_NOT_EXIST"), + Status: http.StatusBadRequest, + }, nil + } + + updateAuthenticationInfo := *request.Body + + response, locationURI, problemDetails := s.processor.UeAuthPostRequestProcedure(ctx, updateAuthenticationInfo) + + if response != nil { + return ausf_authentication.PostUeAuthentications201Application3gppHalPlusJSONResponse{ + Body: *response, + Headers: ausf_authentication.PostUeAuthentications201ResponseHeaders{ + Location: locationURI, + }, + }, nil + } else if problemDetails != nil { + return ausf_authentication.PostUeAuthenticationsdefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: *problemDetails, + }, nil + } + problemDetails = &models.ProblemDetails{ + Status: http.StatusForbidden, + Cause: lo.ToPtr("UNSPECIFIED"), + } + return ausf_authentication.PostUeAuthentications403ApplicationProblemPlusJSONResponse(*problemDetails), nil } -func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticationInfo models.AuthenticationInfo) { +func (p *Processor) UeAuthPostRequestProcedure(c context.Context, updateAuthenticationInfo models.AuthenticationInfo, +) (*models.UEAuthenticationCtx, string, *models.ProblemDetails) { var responseBody models.UEAuthenticationCtx var authInfoReq models.AuthenticationInfoRequest @@ -237,8 +325,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusForbidden, } logger.UeAuthLog.Infoln("403 forbidden: serving network NOT AUTHORIZED") - c.JSON(http.StatusForbidden, problemDetails) - return + return nil, "", &problemDetails } logger.UeAuthLog.Infoln("Serving network authorized") @@ -266,9 +353,11 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat result, err, pd := p.Consumer().GenerateAuthDataApi(udmUrl, supiOrSuci, authInfoReq) if err != nil { + if pd == nil { + pd = lo.ToPtr(utils_error.ErrorToProblemDetails(err)) + } logger.UeAuthLog.Infof("GenerateAuthDataApi error: %+v", err) - c.JSON(http.StatusInternalServerError, pd) - return + return nil, "", pd } authInfoResult := *result @@ -296,8 +385,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusInternalServerError, } logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", problemDetails } else { av5GHeAka = av5GHeAka_tmp } @@ -313,8 +401,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Detail: lo.ToPtr(err.Error()), Status: http.StatusInternalServerError, } - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", &problemDetails } else { hxresStarBytes = bytes } @@ -333,8 +420,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Detail: lo.ToPtr(err.Error()), Status: http.StatusInternalServerError, } - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", &problemDetails } else { KausfDecode = ausfDecode } @@ -348,8 +434,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Detail: lo.ToPtr(err.Error()), Status: http.StatusInternalServerError, } - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", &problemDetails } ausfUeContext.XresStar = av5GHeAka.XresStar ausfUeContext.Kausf = Kausf @@ -367,8 +452,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusInternalServerError, } logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", problemDetails } var linksValue models.LinksValueSchema @@ -379,8 +463,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusInternalServerError, } logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", problemDetails } responseBody.Links = make(map[string]models.LinksValueSchema) responseBody.Links["5g-aka"] = linksValue @@ -396,8 +479,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusInternalServerError, } logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", problemDetails } var identity string @@ -493,8 +575,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusInternalServerError, } logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", problemDetails } var linksValue models.LinksValueSchema @@ -505,8 +586,7 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat Status: http.StatusInternalServerError, } logger.UeAuthLog.Infoln("500 internal server error: UDM client fail") - c.JSON(http.StatusInternalServerError, problemDetails) - return + return nil, "", problemDetails } responseBody.Links = make(map[string]models.LinksValueSchema) responseBody.Links["eap-session"] = linksValue @@ -514,22 +594,16 @@ func (p *Processor) UeAuthPostRequestProcedure(c *gin.Context, updateAuthenticat responseBody.AuthType = models.AusfAuthType(authInfoResult.AuthType) - c.Header("Location", locationURI) - c.JSON(http.StatusCreated, responseBody) + return &responseBody, locationURI, nil } -func (p *Processor) HandleAuth5gAkaComfirmRequest( - c *gin.Context, - confirmationData models.ConfirmationData, - confirmationDataResponseId string, -) { +// (PUT /ue-authentications/{authCtxId}/5g-aka-confirmation) +func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfirmation(ctx context.Context, request ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationRequestObject) (ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationResponseObject, error) { logger.Auth5gAkaLog.Infof("Auth5gAkaComfirmRequest") - p.Auth5gAkaComfirmRequestProcedure(c, confirmationData, confirmationDataResponseId) -} -func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfirmationData models.ConfirmationData, - ConfirmationDataResponseID string, -) { + updateConfirmationData := request.Body + ConfirmationDataResponseID := request.AuthCtxId + var confirmDataRsp models.ConfirmationDataResponse success := false confirmDataRsp.AuthResult = models.AUTHENTICATIONFAILURE @@ -541,8 +615,10 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi Cause: lo.ToPtr("USER_NOT_FOUND"), Status: http.StatusBadRequest, } - c.JSON(http.StatusBadRequest, problemDetails) - return + return ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationdefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } currentSupi := ausf_context.GetSupiFromSuciSupiMap(ConfirmationDataResponseID) @@ -552,8 +628,10 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi Cause: lo.ToPtr("USER_NOT_FOUND"), Status: http.StatusBadRequest, } - c.JSON(http.StatusBadRequest, problemDetails) - return + return ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationdefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } ausfCurrentContext := ausf_context.GetAusfUeContext(currentSupi) @@ -572,22 +650,24 @@ func (p *Processor) Auth5gAkaComfirmRequestProcedure(c *gin.Context, updateConfi } else { ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE confirmDataRsp.AuthResult = models.AUTHENTICATIONFAILURE - p.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, + s.processor.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, "5G AKA confirmation failed", ausfCurrentContext.UdmUeauUrl) } - if sendErr := p.Consumer().SendAuthResultToUDM(currentSupi, models.AuthTypeN5GAKA, success, servingNetworkName, + if sendErr := s.processor.Consumer().SendAuthResultToUDM(currentSupi, models.AuthTypeN5GAKA, success, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ Status: http.StatusInternalServerError, Cause: lo.ToPtr("UPSTREAM_SERVER_ERROR"), } - c.JSON(http.StatusInternalServerError, problemDetails) - return + return ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationdefaultApplicationProblemPlusJSONResponse{ + StatusCode: problemDetails.Status, + Body: problemDetails, + }, nil } - c.JSON(http.StatusOK, confirmDataRsp) + return ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmation200JSONResponse(confirmDataRsp), nil } func KDF5gAka(param ...string) hash.Hash { diff --git a/internal/sbi/processor/upu_protection.go b/internal/sbi/processor/upu_protection.go new file mode 100644 index 0000000..bf6c6b9 --- /dev/null +++ b/internal/sbi/processor/upu_protection.go @@ -0,0 +1,28 @@ +package processor + +import ( + "context" + "errors" + + ausf_upu_protection "github.com/ShouheiNishi/openapi5g/ausf/upu" + "github.com/ShouheiNishi/openapi5g/utils/error/middleware" + strictgin "github.com/oapi-codegen/runtime/strictmiddleware/gin" +) + +func NewServerAusfUpuProtection(processor *Processor) ausf_upu_protection.ServerInterface { + return ausf_upu_protection.NewStrictHandler( + &ausfUpuProtectionStrictServer{ + processor: processor, + }, + []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, + ) +} + +type ausfUpuProtectionStrictServer struct { + processor *Processor +} + +// (POST /{supi}/ue-upu) +func (s *ausfUpuProtectionStrictServer) PostSupiUeUpu(ctx context.Context, request ausf_upu_protection.PostSupiUeUpuRequestObject) (ausf_upu_protection.PostSupiUeUpuResponseObject, error) { + return nil, errors.New("not implemented") +} diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 646fc58..012743a 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -13,6 +13,11 @@ import ( "github.com/gin-gonic/gin" "github.com/sirupsen/logrus" + ausf_authentication "github.com/ShouheiNishi/openapi5g/ausf/authentication" + ausf_sor_protection "github.com/ShouheiNishi/openapi5g/ausf/sor" + ausf_upu_protection "github.com/ShouheiNishi/openapi5g/ausf/upu" + "github.com/ShouheiNishi/openapi5g/utils/error/middleware" + ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/ausf/internal/sbi/consumer" @@ -61,32 +66,47 @@ func NewServer(ausf ServerAusf, tlsKeyLogPath string) (*Server, error) { func newRouter(s *Server) *gin.Engine { router := logger_util.NewGinWithLogrus(logger.GinLog) + router.Use(middleware.GinMiddleWare) + router.NoRoute(middleware.GinNotFoundHandler) + for _, serverName := range factory.AusfConfig.Configuration.ServiceNameList { switch models.ServiceName(serverName) { case models.ServiceNameNausfAuth: - ausfUeAuthenticationGroup := router.Group(factory.AusfAuthResUriPrefix) - ausfUeAuthenticationRoutes := s.getUeAuthenticationRoutes() routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceNameNausfAuth) - ausfUeAuthenticationGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) - }) - applyRoutes(ausfUeAuthenticationGroup, ausfUeAuthenticationRoutes) + ausf_authentication.RegisterHandlersWithOptions(router, processor.NewServerAusfAuthentication(s.Processor()), + ausf_authentication.GinServerOptions{ + BaseURL: factory.AusfAuthResUriPrefix, + Middlewares: []ausf_authentication.MiddlewareFunc{ + func(c *gin.Context) { + routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) + }, + }, + ErrorHandler: middleware.GinServerErrorHandler, + }) case models.ServiceNameNausfSorprotection: - ausfSorprotectionGroup := router.Group(factory.AusfSorprotectionResUriPrefix) - ausfSorprotectionRoutes := s.getSorprotectionRoutes() routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceNameNausfSorprotection) - ausfSorprotectionGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) - }) - applyRoutes(ausfSorprotectionGroup, ausfSorprotectionRoutes) + ausf_sor_protection.RegisterHandlersWithOptions(router, processor.NewServerAusfSorProtection(s.Processor()), + ausf_sor_protection.GinServerOptions{ + BaseURL: factory.AusfSorprotectionResUriPrefix, + Middlewares: []ausf_sor_protection.MiddlewareFunc{ + func(c *gin.Context) { + routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) + }, + }, + ErrorHandler: middleware.GinServerErrorHandler, + }) case models.ServiceNameNausfUpuprotection: - ausfUpuprotectionGroup := router.Group(factory.AusfUpuprotectionResUriPrefix) - ausfUpuprotectionRoutes := s.getUpuprotectionRoutes() routerAuthorizationCheck := util.NewRouterAuthorizationCheck(models.ServiceNameNausfUpuprotection) - ausfUpuprotectionGroup.Use(func(c *gin.Context) { - routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) - }) - applyRoutes(ausfUpuprotectionGroup, ausfUpuprotectionRoutes) + ausf_upu_protection.RegisterHandlersWithOptions(router, processor.NewServerAusfUpuProtection(s.Processor()), + ausf_upu_protection.GinServerOptions{ + BaseURL: factory.AusfUpuprotectionResUriPrefix, + Middlewares: []ausf_upu_protection.MiddlewareFunc{ + func(c *gin.Context) { + routerAuthorizationCheck.Check(c, ausf_context.GetSelf()) + }, + }, + ErrorHandler: middleware.GinServerErrorHandler, + }) } } From 0b5d8a4a36dbfe0a9d248216c20f663830c0d697 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 16:18:48 +0900 Subject: [PATCH 7/9] fix golangci-lint error --- internal/context/ausf_context_init.go | 4 +- internal/sbi/consumer/consumer.go | 1 + internal/sbi/consumer/nrf_service.go | 19 +++++--- internal/sbi/consumer/udm_service.go | 6 ++- internal/sbi/processor/sor_protection.go | 4 +- internal/sbi/processor/ue_authentication.go | 49 +++++++++++++++------ internal/sbi/processor/upu_protection.go | 4 +- internal/sbi/routes.go | 26 ----------- internal/sbi/server.go | 7 ++- 9 files changed, 64 insertions(+), 56 deletions(-) delete mode 100644 internal/sbi/routes.go diff --git a/internal/context/ausf_context_init.go b/internal/context/ausf_context_init.go index b2ff5f9..e1cedd7 100644 --- a/internal/context/ausf_context_init.go +++ b/internal/context/ausf_context_init.go @@ -63,7 +63,9 @@ func InitAusfContext(context *AUSFContext) { context.EapAkaSupiImsiPrefix = configuration.EapAkaSupiImsiPrefix } -func AddNfServices(serviceMap *map[models.ServiceName]models.NrfNFService, config *factory.Config, context *AUSFContext) { +func AddNfServices(serviceMap *map[models.ServiceName]models.NrfNFService, config *factory.Config, + context *AUSFContext, +) { var nfService models.NrfNFService var ipEndPoints []models.IpEndPoint var nfServiceVersions []models.NFServiceVersion diff --git a/internal/sbi/consumer/consumer.go b/internal/sbi/consumer/consumer.go index 040f0f5..58c15b2 100644 --- a/internal/sbi/consumer/consumer.go +++ b/internal/sbi/consumer/consumer.go @@ -4,6 +4,7 @@ import ( nrf_discovery "github.com/ShouheiNishi/openapi5g/nrf/discovery" nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management" udm_ueau "github.com/ShouheiNishi/openapi5g/udm/ueau" + "github.com/free5gc/ausf/pkg/app" ) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index 2144b84..b39f78e 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -9,17 +9,17 @@ import ( "sync" "time" - "github.com/pkg/errors" - "github.com/ShouheiNishi/openapi5g/models" nrf_discovery "github.com/ShouheiNishi/openapi5g/nrf/discovery" nrf_management "github.com/ShouheiNishi/openapi5g/nrf/management" utils_error "github.com/ShouheiNishi/openapi5g/utils/error" "github.com/ShouheiNishi/openapi5g/utils/problem" + "github.com/google/uuid" + "github.com/pkg/errors" + ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" "github.com/free5gc/util/httpclient" - "github.com/google/uuid" ) type nnrfService struct { @@ -43,7 +43,8 @@ func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientW return client, nil } - editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNnrfNfm, models.NFTypeNRF) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), + models.ServiceNameNnrfNfm, models.NFTypeNRF) if err != nil { s.nfMngmntMu.RUnlock() return nil, err @@ -77,7 +78,8 @@ func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResp return client, nil } - editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNnrfDisc, models.NFTypeNRF) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), + models.ServiceNameNnrfDisc, models.NFTypeNRF) if err != nil { s.nfDiscMu.RUnlock() return nil, err @@ -155,7 +157,8 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( } for { - res, err := client.RegisterNFInstanceWithResponse(context.TODO(), ausfContext.NfId, nil, nfProfile) + var res *nrf_management.RegisterNFInstanceResponse + res, err = client.RegisterNFInstanceWithResponse(context.TODO(), ausfContext.NfId, nil, nfProfile) if err != nil || res == nil { logger.ConsumerLog.Errorf("AUSF register to NRF Error[%v]", err) time.Sleep(2 * time.Second) @@ -195,7 +198,9 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( return resouceNrfUri, retrieveNfInstanceID, err } -func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) (profile models.NFManagementNFProfile, err error) { +func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) ( + profile models.NFManagementNFProfile, err error, +) { profile.NfInstanceId = ausfContext.NfId profile.NfType = models.NFTypeAUSF profile.NfStatus = models.NFStatusREGISTERED diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index 2cf6515..94d0980 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -10,9 +10,10 @@ import ( "github.com/ShouheiNishi/openapi5g/models" udm_ueau "github.com/ShouheiNishi/openapi5g/udm/ueau" utils_error "github.com/ShouheiNishi/openapi5g/utils/error" + "github.com/samber/lo" + ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/util/httpclient" - "github.com/samber/lo" ) type nudmService struct { @@ -34,7 +35,8 @@ func (s *nudmService) getUdmUeauClient(uri string) (*udm_ueau.ClientWithResponse return client, nil } - editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), models.ServiceNameNudmUeau, models.NFTypeUDM) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), + models.ServiceNameNudmUeau, models.NFTypeUDM) if err != nil { s.ueauMu.RUnlock() return nil, err diff --git a/internal/sbi/processor/sor_protection.go b/internal/sbi/processor/sor_protection.go index f78b582..38a204e 100644 --- a/internal/sbi/processor/sor_protection.go +++ b/internal/sbi/processor/sor_protection.go @@ -23,6 +23,8 @@ type ausfSorProtectionStrictServer struct { } // (POST /{supi}/ue-sor) -func (s *ausfSorProtectionStrictServer) PostSupiUeSor(ctx context.Context, request ausf_sor_protection.PostSupiUeSorRequestObject) (ausf_sor_protection.PostSupiUeSorResponseObject, error) { +func (s *ausfSorProtectionStrictServer) PostSupiUeSor(ctx context.Context, + request ausf_sor_protection.PostSupiUeSorRequestObject, +) (ausf_sor_protection.PostSupiUeSorResponseObject, error) { return nil, errors.New("not implemented") } diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index efce596..021fbfb 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -47,29 +47,43 @@ type ausfAuthenticationStrictServer struct { } // (POST /rg-authentications) -func (s *ausfAuthenticationStrictServer) PostRgAuthentications(ctx context.Context, request ausf_authentication.PostRgAuthenticationsRequestObject) (ausf_authentication.PostRgAuthenticationsResponseObject, error) { +func (s *ausfAuthenticationStrictServer) PostRgAuthentications(ctx context.Context, + request ausf_authentication.PostRgAuthenticationsRequestObject) ( + ausf_authentication.PostRgAuthenticationsResponseObject, error, +) { return nil, errors.New("not implemented") } // (POST /ue-authentications/deregister) -func (s *ausfAuthenticationStrictServer) PostUeAuthenticationsDeregister(ctx context.Context, request ausf_authentication.PostUeAuthenticationsDeregisterRequestObject) (ausf_authentication.PostUeAuthenticationsDeregisterResponseObject, error) { +func (s *ausfAuthenticationStrictServer) PostUeAuthenticationsDeregister( + ctx context.Context, request ausf_authentication.PostUeAuthenticationsDeregisterRequestObject) ( + ausf_authentication.PostUeAuthenticationsDeregisterResponseObject, error, +) { return nil, errors.New("not implemented") } // Deletes the authentication result in the UDM // (DELETE /ue-authentications/{authCtxId}/5g-aka-confirmation) -func (s *ausfAuthenticationStrictServer) Delete5gAkaAuthenticationResult(ctx context.Context, request ausf_authentication.Delete5gAkaAuthenticationResultRequestObject) (ausf_authentication.Delete5gAkaAuthenticationResultResponseObject, error) { +func (s *ausfAuthenticationStrictServer) Delete5gAkaAuthenticationResult( + ctx context.Context, request ausf_authentication.Delete5gAkaAuthenticationResultRequestObject) ( + ausf_authentication.Delete5gAkaAuthenticationResultResponseObject, error, +) { return nil, errors.New("not implemented") } // Deletes the authentication result in the UDM // (DELETE /ue-authentications/{authCtxId}/eap-session) -func (s *ausfAuthenticationStrictServer) DeleteEapAuthenticationResult(ctx context.Context, request ausf_authentication.DeleteEapAuthenticationResultRequestObject) (ausf_authentication.DeleteEapAuthenticationResultResponseObject, error) { +func (s *ausfAuthenticationStrictServer) DeleteEapAuthenticationResult( + ctx context.Context, request ausf_authentication.DeleteEapAuthenticationResultRequestObject) ( + ausf_authentication.DeleteEapAuthenticationResultResponseObject, error, +) { return nil, errors.New("not implemented") } // (POST /ue-authentications/{authCtxId}/eap-session) -func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, request ausf_authentication.EapAuthMethodRequestObject) (ausf_authentication.EapAuthMethodResponseObject, error) { +func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, + request ausf_authentication.EapAuthMethodRequestObject, +) (ausf_authentication.EapAuthMethodResponseObject, error) { logger.Auth5gAkaLog.Infof("EapAuthComfirmRequest") updateEapSession := request.Body @@ -229,8 +243,8 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, reques if !eapOK { logger.AuthELog.Warnf("EAP-AKA' failure: %s", eapErrStr) - if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, - ausfCurrentContext.UdmUeauUrl); sendErr != nil { + if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, + servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ Status: http.StatusInternalServerError, @@ -259,8 +273,8 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, reques eapSession.Links = &map[string]models.LinksValueSchema{} (*eapSession.Links)["eap-session"] = linksValue } else if ausfCurrentContext.AuthStatus == models.AUTHENTICATIONFAILURE { - if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, - ausfCurrentContext.UdmUeauUrl); sendErr != nil { + if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, + servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) var problemDetails models.ProblemDetails problemDetails.Status = http.StatusInternalServerError @@ -276,7 +290,10 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, reques } // (POST /ue-authentications) -func (s *ausfAuthenticationStrictServer) PostUeAuthentications(ctx context.Context, request ausf_authentication.PostUeAuthenticationsRequestObject) (ausf_authentication.PostUeAuthenticationsResponseObject, error) { +func (s *ausfAuthenticationStrictServer) PostUeAuthentications(ctx context.Context, + request ausf_authentication.PostUeAuthenticationsRequestObject) ( + ausf_authentication.PostUeAuthenticationsResponseObject, error, +) { logger.UeAuthLog.Infof("HandleUeAuthPostRequest") if request.Body == nil { @@ -568,7 +585,8 @@ func (p *Processor) UeAuthPostRequestProcedure(c context.Context, updateAuthenti eapPkt.Data = []byte(dataArrayAfterMAC) encodedPktAfterMAC := eapPkt.Encode() - if err := responseBody.N5gAuthData.FromEapPayload(base64.StdEncoding.EncodeToString(encodedPktAfterMAC)); err != nil { + if err := responseBody.N5gAuthData.FromEapPayload( + base64.StdEncoding.EncodeToString(encodedPktAfterMAC)); err != nil { problemDetails := &models.ProblemDetails{ Cause: lo.ToPtr("UDM_CLIENT_FAIL"), Detail: lo.ToPtr(err.Error()), @@ -598,7 +616,10 @@ func (p *Processor) UeAuthPostRequestProcedure(c context.Context, updateAuthenti } // (PUT /ue-authentications/{authCtxId}/5g-aka-confirmation) -func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfirmation(ctx context.Context, request ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationRequestObject) (ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationResponseObject, error) { +func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfirmation(ctx context.Context, + request ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationRequestObject) ( + ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationResponseObject, error, +) { logger.Auth5gAkaLog.Infof("Auth5gAkaComfirmRequest") updateConfirmationData := request.Body @@ -654,8 +675,8 @@ func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfi "5G AKA confirmation failed", ausfCurrentContext.UdmUeauUrl) } - if sendErr := s.processor.Consumer().SendAuthResultToUDM(currentSupi, models.AuthTypeN5GAKA, success, servingNetworkName, - ausfCurrentContext.UdmUeauUrl); sendErr != nil { + if sendErr := s.processor.Consumer().SendAuthResultToUDM(currentSupi, models.AuthTypeN5GAKA, success, + servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ Status: http.StatusInternalServerError, diff --git a/internal/sbi/processor/upu_protection.go b/internal/sbi/processor/upu_protection.go index bf6c6b9..fb56a8c 100644 --- a/internal/sbi/processor/upu_protection.go +++ b/internal/sbi/processor/upu_protection.go @@ -23,6 +23,8 @@ type ausfUpuProtectionStrictServer struct { } // (POST /{supi}/ue-upu) -func (s *ausfUpuProtectionStrictServer) PostSupiUeUpu(ctx context.Context, request ausf_upu_protection.PostSupiUeUpuRequestObject) (ausf_upu_protection.PostSupiUeUpuResponseObject, error) { +func (s *ausfUpuProtectionStrictServer) PostSupiUeUpu(ctx context.Context, + request ausf_upu_protection.PostSupiUeUpuRequestObject, +) (ausf_upu_protection.PostSupiUeUpuResponseObject, error) { return nil, errors.New("not implemented") } diff --git a/internal/sbi/routes.go b/internal/sbi/routes.go deleted file mode 100644 index 124bbf8..0000000 --- a/internal/sbi/routes.go +++ /dev/null @@ -1,26 +0,0 @@ -package sbi - -import "github.com/gin-gonic/gin" - -type Route struct { - Method string - Pattern string - APIFunc gin.HandlerFunc -} - -func applyRoutes(group *gin.RouterGroup, routes []Route) { - for _, route := range routes { - switch route.Method { - case "GET": - group.GET(route.Pattern, route.APIFunc) - case "POST": - group.POST(route.Pattern, route.APIFunc) - case "PUT": - group.PUT(route.Pattern, route.APIFunc) - case "PATCH": - group.PATCH(route.Pattern, route.APIFunc) - case "DELETE": - group.DELETE(route.Pattern, route.APIFunc) - } - } -} diff --git a/internal/sbi/server.go b/internal/sbi/server.go index 012743a..bca58f1 100644 --- a/internal/sbi/server.go +++ b/internal/sbi/server.go @@ -9,14 +9,13 @@ import ( "sync" "time" - "github.com/ShouheiNishi/openapi5g/models" - "github.com/gin-gonic/gin" - "github.com/sirupsen/logrus" - ausf_authentication "github.com/ShouheiNishi/openapi5g/ausf/authentication" ausf_sor_protection "github.com/ShouheiNishi/openapi5g/ausf/sor" ausf_upu_protection "github.com/ShouheiNishi/openapi5g/ausf/upu" + "github.com/ShouheiNishi/openapi5g/models" "github.com/ShouheiNishi/openapi5g/utils/error/middleware" + "github.com/gin-gonic/gin" + "github.com/sirupsen/logrus" ausf_context "github.com/free5gc/ausf/internal/context" "github.com/free5gc/ausf/internal/logger" From dcc5f534bcee6bee744cc63f76096d5c6b30947c Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 16:34:36 +0900 Subject: [PATCH 8/9] good context handling --- internal/sbi/consumer/nrf_service.go | 31 +++++++++++---------- internal/sbi/consumer/udm_service.go | 15 +++++----- internal/sbi/processor/ue_authentication.go | 25 +++++++++-------- pkg/service/init.go | 6 +++- 4 files changed, 42 insertions(+), 35 deletions(-) diff --git a/internal/sbi/consumer/nrf_service.go b/internal/sbi/consumer/nrf_service.go index b39f78e..4a30c5c 100644 --- a/internal/sbi/consumer/nrf_service.go +++ b/internal/sbi/consumer/nrf_service.go @@ -32,7 +32,9 @@ type nnrfService struct { nfDiscClients map[string]*nrf_discovery.ClientWithResponses } -func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientWithResponses, error) { +func (s *nnrfService) getNFManagementClient(ctx context.Context, uri string) ( + *nrf_management.ClientWithResponses, error, +) { if uri == "" { return nil, fmt.Errorf("empty URI") } @@ -43,8 +45,7 @@ func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientW return client, nil } - editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), - models.ServiceNameNnrfNfm, models.NFTypeNRF) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(ctx, models.ServiceNameNnrfNfm, models.NFTypeNRF) if err != nil { s.nfMngmntMu.RUnlock() return nil, err @@ -67,7 +68,7 @@ func (s *nnrfService) getNFManagementClient(uri string) (*nrf_management.ClientW return client, nil } -func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResponses, error) { +func (s *nnrfService) getNFDiscClient(ctx context.Context, uri string) (*nrf_discovery.ClientWithResponses, error) { if uri == "" { return nil, fmt.Errorf("empty URI") } @@ -78,8 +79,7 @@ func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResp return client, nil } - editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), - models.ServiceNameNnrfDisc, models.NFTypeNRF) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(ctx, models.ServiceNameNnrfDisc, models.NFTypeNRF) if err != nil { s.nfDiscMu.RUnlock() return nil, err @@ -102,18 +102,18 @@ func (s *nnrfService) getNFDiscClient(uri string) (*nrf_discovery.ClientWithResp return client, nil } -func (s *nnrfService) SendSearchNFInstances( +func (s *nnrfService) SendSearchNFInstances(ctx context.Context, nrfUri string, targetNfType, requestNfType models.NFType, param nrf_discovery.SearchNFInstancesParams) ( *models.SearchResult, error, ) { // Set client and set url - client, err := s.getNFDiscClient(nrfUri) + client, err := s.getNFDiscClient(ctx, nrfUri) if err != nil { return nil, err } param.TargetNfType = targetNfType param.RequesterNfType = requestNfType - rsp, err := client.SearchNFInstancesWithResponse(context.TODO(), ¶m) + rsp, err := client.SearchNFInstancesWithResponse(ctx, ¶m) if err != nil || rsp.JSON200 == nil { return nil, utils_error.ExtractAndWrapOpenAPIError("nrf_discovery.SearchNFInstancesWithResponse", rsp, err) @@ -121,16 +121,16 @@ func (s *nnrfService) SendSearchNFInstances( return rsp.JSON200, nil } -func (s *nnrfService) SendDeregisterNFInstance() (*models.ProblemDetails, error) { +func (s *nnrfService) SendDeregisterNFInstance(ctx context.Context) (*models.ProblemDetails, error) { logger.ConsumerLog.Infof("Send Deregister NFInstance") ausfContext := s.consumer.Context() - client, err := s.getNFManagementClient(ausfContext.NrfUri) + client, err := s.getNFManagementClient(ctx, ausfContext.NrfUri) if err != nil { return nil, err } - res, err := client.DeregisterNFInstanceWithResponse(context.Background(), ausfContext.NfId) + res, err := client.DeregisterNFInstanceWithResponse(ctx, ausfContext.NfId) if err != nil { return nil, fmt.Errorf("nrf_management.DeregisterNFInstanceWithResponse: %w", err) } @@ -146,7 +146,7 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( ) { ausfContext := s.consumer.Context() - client, err := s.getNFManagementClient(ausfContext.NrfUri) + client, err := s.getNFManagementClient(ctx, ausfContext.NrfUri) if err != nil { return "", uuid.Nil, err } @@ -158,7 +158,7 @@ func (s *nnrfService) RegisterNFInstance(ctx context.Context) ( for { var res *nrf_management.RegisterNFInstanceResponse - res, err = client.RegisterNFInstanceWithResponse(context.TODO(), ausfContext.NfId, nil, nfProfile) + res, err = client.RegisterNFInstanceWithResponse(ctx, ausfContext.NfId, nil, nfProfile) if err != nil || res == nil { logger.ConsumerLog.Errorf("AUSF register to NRF Error[%v]", err) time.Sleep(2 * time.Second) @@ -227,12 +227,13 @@ func (s *nnrfService) buildNfProfile(ausfContext *ausf_context.AUSFContext) ( return } -func (s *nnrfService) GetUdmUrl(nrfUri string) string { +func (s *nnrfService) GetUdmUrl(ctx context.Context, nrfUri string) string { udmUrl := "https://localhost:29503" // default nfDiscoverParam := nrf_discovery.SearchNFInstancesParams{ ServiceNames: &[]models.ServiceName{models.ServiceNameNudmUeau}, } res, err := s.SendSearchNFInstances( + ctx, nrfUri, models.NFTypeUDM, models.NFTypeAUSF, diff --git a/internal/sbi/consumer/udm_service.go b/internal/sbi/consumer/udm_service.go index 94d0980..2d52ef9 100644 --- a/internal/sbi/consumer/udm_service.go +++ b/internal/sbi/consumer/udm_service.go @@ -24,7 +24,7 @@ type nudmService struct { ueauClients map[string]*udm_ueau.ClientWithResponses } -func (s *nudmService) getUdmUeauClient(uri string) (*udm_ueau.ClientWithResponses, error) { +func (s *nudmService) getUdmUeauClient(ctx context.Context, uri string) (*udm_ueau.ClientWithResponses, error) { if uri == "" { return nil, fmt.Errorf("empty URI") } @@ -35,8 +35,7 @@ func (s *nudmService) getUdmUeauClient(uri string) (*udm_ueau.ClientWithResponse return client, nil } - editor, err := ausf_context.GetSelf().GetTokenRequestEditor(context.TODO(), - models.ServiceNameNudmUeau, models.NFTypeUDM) + editor, err := ausf_context.GetSelf().GetTokenRequestEditor(ctx, models.ServiceNameNudmUeau, models.NFTypeUDM) if err != nil { s.ueauMu.RUnlock() return nil, err @@ -60,6 +59,7 @@ func (s *nudmService) getUdmUeauClient(uri string) (*udm_ueau.ClientWithResponse } func (s *nudmService) SendAuthResultToUDM( + ctx context.Context, id string, authType models.AuthType, success bool, @@ -77,12 +77,12 @@ func (s *nudmService) SendAuthResultToUDM( NfInstanceId: self.GetSelfID(), } - client, err := s.getUdmUeauClient(udmUrl) + client, err := s.getUdmUeauClient(ctx, udmUrl) if err != nil { return err } - rsp, err := client.ConfirmAuthWithResponse(context.Background(), id, authEvent) + rsp, err := client.ConfirmAuthWithResponse(ctx, id, authEvent) if err != nil || rsp.StatusCode() != http.StatusCreated { return utils_error.ExtractAndWrapOpenAPIError("udm_ueau.ConfirmAuthWithResponse", rsp, err) } @@ -90,16 +90,17 @@ func (s *nudmService) SendAuthResultToUDM( } func (s *nudmService) GenerateAuthDataApi( + ctx context.Context, udmUrl string, supiOrSuci models.SupiOrSuci, authInfoReq models.AuthenticationInfoRequest, ) (*models.AuthenticationInfoResult, error, *models.ProblemDetails) { - client, err := s.getUdmUeauClient(udmUrl) + client, err := s.getUdmUeauClient(ctx, udmUrl) if err != nil { return nil, err, nil } - rsp, err := client.GenerateAuthDataWithResponse(context.TODO(), supiOrSuci, authInfoReq) + rsp, err := client.GenerateAuthDataWithResponse(ctx, supiOrSuci, authInfoReq) if err != nil || rsp.JSON200 == nil { err = utils_error.ExtractAndWrapOpenAPIError("udm_ueau.GenerateAuthDataWithResponse", rsp, err) return nil, err, lo.ToPtr(utils_error.ErrorToProblemDetails(err)) diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index 021fbfb..e85bf53 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -81,7 +81,7 @@ func (s *ausfAuthenticationStrictServer) DeleteEapAuthenticationResult( } // (POST /ue-authentications/{authCtxId}/eap-session) -func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, +func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, request ausf_authentication.EapAuthMethodRequestObject, ) (ausf_authentication.EapAuthMethodResponseObject, error) { logger.Auth5gAkaLog.Infof("EapAuthComfirmRequest") @@ -179,6 +179,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, eapSession.EapPayload = &eapSuccPkt udmUrl := ausfCurrentContext.UdmUeauUrl if sendErr := s.processor.Consumer().SendAuthResultToUDM( + ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, true, @@ -215,7 +216,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, authInfo.SupiOrSuci = eapSessionID authInfo.ServingNetworkName = servingNetworkName authInfo.ResynchronizationInfo = resynchronizationInfo - response, _, problemDetails := s.processor.UeAuthPostRequestProcedure(c, authInfo) + response, _, problemDetails := s.processor.UeAuthPostRequestProcedure(ctx, authInfo) if problemDetails != nil { return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ StatusCode: problemDetails.Status, @@ -243,7 +244,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, if !eapOK { logger.AuthELog.Warnf("EAP-AKA' failure: %s", eapErrStr) - if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, + if sendErr := s.processor.Consumer().SendAuthResultToUDM(ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ @@ -273,7 +274,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(c context.Context, eapSession.Links = &map[string]models.LinksValueSchema{} (*eapSession.Links)["eap-session"] = linksValue } else if ausfCurrentContext.AuthStatus == models.AUTHENTICATIONFAILURE { - if sendErr := s.processor.Consumer().SendAuthResultToUDM(eapSessionID, models.AuthTypeEAPAKAPRIME, false, + if sendErr := s.processor.Consumer().SendAuthResultToUDM(ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) var problemDetails models.ProblemDetails @@ -327,7 +328,7 @@ func (s *ausfAuthenticationStrictServer) PostUeAuthentications(ctx context.Conte return ausf_authentication.PostUeAuthentications403ApplicationProblemPlusJSONResponse(*problemDetails), nil } -func (p *Processor) UeAuthPostRequestProcedure(c context.Context, updateAuthenticationInfo models.AuthenticationInfo, +func (p *Processor) UeAuthPostRequestProcedure(ctx context.Context, updateAuthenticationInfo models.AuthenticationInfo, ) (*models.UEAuthenticationCtx, string, *models.ProblemDetails) { var responseBody models.UEAuthenticationCtx var authInfoReq models.AuthenticationInfoRequest @@ -366,9 +367,9 @@ func (p *Processor) UeAuthPostRequestProcedure(c context.Context, updateAuthenti lastEapID = ausfCurrentContext.EapID } - udmUrl := p.Consumer().GetUdmUrl(self.NrfUri) + udmUrl := p.Consumer().GetUdmUrl(ctx, self.NrfUri) - result, err, pd := p.Consumer().GenerateAuthDataApi(udmUrl, supiOrSuci, authInfoReq) + result, err, pd := p.Consumer().GenerateAuthDataApi(ctx, udmUrl, supiOrSuci, authInfoReq) if err != nil { if pd == nil { pd = lo.ToPtr(utils_error.ErrorToProblemDetails(err)) @@ -671,11 +672,11 @@ func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfi } else { ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE confirmDataRsp.AuthResult = models.AUTHENTICATIONFAILURE - s.processor.logConfirmFailureAndInformUDM(ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, + s.processor.logConfirmFailureAndInformUDM(ctx, ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, "5G AKA confirmation failed", ausfCurrentContext.UdmUeauUrl) } - if sendErr := s.processor.Consumer().SendAuthResultToUDM(currentSupi, models.AuthTypeN5GAKA, success, + if sendErr := s.processor.Consumer().SendAuthResultToUDM(ctx, currentSupi, models.AuthTypeN5GAKA, success, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ @@ -995,16 +996,16 @@ func ConstructEapNoTypePkt(code radius.EapCode, pktID uint8) string { } func (p *Processor) logConfirmFailureAndInformUDM( - id string, authType models.AuthType, servingNetworkName, errStr, udmUrl string, + ctx context.Context, id string, authType models.AuthType, servingNetworkName, errStr, udmUrl string, ) { if authType == models.AuthTypeN5GAKA { logger.Auth5gAkaLog.Infoln(servingNetworkName, errStr) - if sendErr := p.Consumer().SendAuthResultToUDM(id, authType, false, "", udmUrl); sendErr != nil { + if sendErr := p.Consumer().SendAuthResultToUDM(ctx, id, authType, false, "", udmUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) } } else if authType == models.AuthTypeEAPAKAPRIME { logger.AuthELog.Infoln(errStr) - if sendErr := p.Consumer().SendAuthResultToUDM(id, authType, false, "", udmUrl); sendErr != nil { + if sendErr := p.Consumer().SendAuthResultToUDM(ctx, id, authType, false, "", udmUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) } } diff --git a/pkg/service/init.go b/pkg/service/init.go index bb01b5d..06f3dbb 100644 --- a/pkg/service/init.go +++ b/pkg/service/init.go @@ -6,6 +6,7 @@ import ( "os" "runtime/debug" "sync" + "time" "github.com/sirupsen/logrus" @@ -162,8 +163,11 @@ func (a *AusfApp) Terminate() { func (a *AusfApp) terminateProcedure() { logger.MainLog.Infof("Terminating AUSF...") + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + // deregister with NRF - problemDetails, err := a.Consumer().SendDeregisterNFInstance() + problemDetails, err := a.Consumer().SendDeregisterNFInstance(ctx) if problemDetails != nil { logger.MainLog.Errorf("Deregister NF instance Failed Problem[%+v]", problemDetails) } else if err != nil { From 9549eec69c717872acb5e0f0459aef4c476e5830 Mon Sep 17 00:00:00 2001 From: Shouhei Nishi Date: Fri, 15 Nov 2024 16:47:48 +0900 Subject: [PATCH 9/9] Processor is used as strict server interface directly --- internal/sbi/processor/sor_protection.go | 12 ++----- internal/sbi/processor/ue_authentication.go | 37 +++++++++------------ internal/sbi/processor/upu_protection.go | 12 ++----- 3 files changed, 19 insertions(+), 42 deletions(-) diff --git a/internal/sbi/processor/sor_protection.go b/internal/sbi/processor/sor_protection.go index 38a204e..34f171b 100644 --- a/internal/sbi/processor/sor_protection.go +++ b/internal/sbi/processor/sor_protection.go @@ -11,20 +11,12 @@ import ( func NewServerAusfSorProtection(processor *Processor) ausf_sor_protection.ServerInterface { return ausf_sor_protection.NewStrictHandler( - &ausfSorProtectionStrictServer{ - processor: processor, - }, - []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, + processor, []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, ) } -type ausfSorProtectionStrictServer struct { - processor *Processor -} - // (POST /{supi}/ue-sor) -func (s *ausfSorProtectionStrictServer) PostSupiUeSor(ctx context.Context, - request ausf_sor_protection.PostSupiUeSorRequestObject, +func (p *Processor) PostSupiUeSor(ctx context.Context, request ausf_sor_protection.PostSupiUeSorRequestObject, ) (ausf_sor_protection.PostSupiUeSorResponseObject, error) { return nil, errors.New("not implemented") } diff --git a/internal/sbi/processor/ue_authentication.go b/internal/sbi/processor/ue_authentication.go index e85bf53..d0d5263 100644 --- a/internal/sbi/processor/ue_authentication.go +++ b/internal/sbi/processor/ue_authentication.go @@ -35,19 +35,12 @@ import ( func NewServerAusfAuthentication(processor *Processor) ausf_authentication.ServerInterface { return ausf_authentication.NewStrictHandler( - &ausfAuthenticationStrictServer{ - processor: processor, - }, - []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, + processor, []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, ) } -type ausfAuthenticationStrictServer struct { - processor *Processor -} - // (POST /rg-authentications) -func (s *ausfAuthenticationStrictServer) PostRgAuthentications(ctx context.Context, +func (p *Processor) PostRgAuthentications(ctx context.Context, request ausf_authentication.PostRgAuthenticationsRequestObject) ( ausf_authentication.PostRgAuthenticationsResponseObject, error, ) { @@ -55,7 +48,7 @@ func (s *ausfAuthenticationStrictServer) PostRgAuthentications(ctx context.Conte } // (POST /ue-authentications/deregister) -func (s *ausfAuthenticationStrictServer) PostUeAuthenticationsDeregister( +func (p *Processor) PostUeAuthenticationsDeregister( ctx context.Context, request ausf_authentication.PostUeAuthenticationsDeregisterRequestObject) ( ausf_authentication.PostUeAuthenticationsDeregisterResponseObject, error, ) { @@ -64,7 +57,7 @@ func (s *ausfAuthenticationStrictServer) PostUeAuthenticationsDeregister( // Deletes the authentication result in the UDM // (DELETE /ue-authentications/{authCtxId}/5g-aka-confirmation) -func (s *ausfAuthenticationStrictServer) Delete5gAkaAuthenticationResult( +func (p *Processor) Delete5gAkaAuthenticationResult( ctx context.Context, request ausf_authentication.Delete5gAkaAuthenticationResultRequestObject) ( ausf_authentication.Delete5gAkaAuthenticationResultResponseObject, error, ) { @@ -73,7 +66,7 @@ func (s *ausfAuthenticationStrictServer) Delete5gAkaAuthenticationResult( // Deletes the authentication result in the UDM // (DELETE /ue-authentications/{authCtxId}/eap-session) -func (s *ausfAuthenticationStrictServer) DeleteEapAuthenticationResult( +func (p *Processor) DeleteEapAuthenticationResult( ctx context.Context, request ausf_authentication.DeleteEapAuthenticationResultRequestObject) ( ausf_authentication.DeleteEapAuthenticationResultResponseObject, error, ) { @@ -81,7 +74,7 @@ func (s *ausfAuthenticationStrictServer) DeleteEapAuthenticationResult( } // (POST /ue-authentications/{authCtxId}/eap-session) -func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, +func (p *Processor) EapAuthMethod(ctx context.Context, request ausf_authentication.EapAuthMethodRequestObject, ) (ausf_authentication.EapAuthMethodResponseObject, error) { logger.Auth5gAkaLog.Infof("EapAuthComfirmRequest") @@ -178,7 +171,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, eapSuccPkt := ConstructEapNoTypePkt(radius.EapCodeSuccess, eapContent.Id) eapSession.EapPayload = &eapSuccPkt udmUrl := ausfCurrentContext.UdmUeauUrl - if sendErr := s.processor.Consumer().SendAuthResultToUDM( + if sendErr := p.Consumer().SendAuthResultToUDM( ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, @@ -216,7 +209,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, authInfo.SupiOrSuci = eapSessionID authInfo.ServingNetworkName = servingNetworkName authInfo.ResynchronizationInfo = resynchronizationInfo - response, _, problemDetails := s.processor.UeAuthPostRequestProcedure(ctx, authInfo) + response, _, problemDetails := p.UeAuthPostRequestProcedure(ctx, authInfo) if problemDetails != nil { return ausf_authentication.EapAuthMethoddefaultApplicationProblemPlusJSONResponse{ StatusCode: problemDetails.Status, @@ -244,7 +237,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, if !eapOK { logger.AuthELog.Warnf("EAP-AKA' failure: %s", eapErrStr) - if sendErr := s.processor.Consumer().SendAuthResultToUDM(ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, false, + if sendErr := p.Consumer().SendAuthResultToUDM(ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ @@ -274,7 +267,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, eapSession.Links = &map[string]models.LinksValueSchema{} (*eapSession.Links)["eap-session"] = linksValue } else if ausfCurrentContext.AuthStatus == models.AUTHENTICATIONFAILURE { - if sendErr := s.processor.Consumer().SendAuthResultToUDM(ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, false, + if sendErr := p.Consumer().SendAuthResultToUDM(ctx, eapSessionID, models.AuthTypeEAPAKAPRIME, false, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.AuthELog.Infoln(sendErr.Error()) var problemDetails models.ProblemDetails @@ -291,7 +284,7 @@ func (s *ausfAuthenticationStrictServer) EapAuthMethod(ctx context.Context, } // (POST /ue-authentications) -func (s *ausfAuthenticationStrictServer) PostUeAuthentications(ctx context.Context, +func (p *Processor) PostUeAuthentications(ctx context.Context, request ausf_authentication.PostUeAuthenticationsRequestObject) ( ausf_authentication.PostUeAuthenticationsResponseObject, error, ) { @@ -306,7 +299,7 @@ func (s *ausfAuthenticationStrictServer) PostUeAuthentications(ctx context.Conte updateAuthenticationInfo := *request.Body - response, locationURI, problemDetails := s.processor.UeAuthPostRequestProcedure(ctx, updateAuthenticationInfo) + response, locationURI, problemDetails := p.UeAuthPostRequestProcedure(ctx, updateAuthenticationInfo) if response != nil { return ausf_authentication.PostUeAuthentications201Application3gppHalPlusJSONResponse{ @@ -617,7 +610,7 @@ func (p *Processor) UeAuthPostRequestProcedure(ctx context.Context, updateAuthen } // (PUT /ue-authentications/{authCtxId}/5g-aka-confirmation) -func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfirmation(ctx context.Context, +func (p *Processor) PutUeAuthenticationsAuthCtxId5gAkaConfirmation(ctx context.Context, request ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationRequestObject) ( ausf_authentication.PutUeAuthenticationsAuthCtxId5gAkaConfirmationResponseObject, error, ) { @@ -672,11 +665,11 @@ func (s *ausfAuthenticationStrictServer) PutUeAuthenticationsAuthCtxId5gAkaConfi } else { ausfCurrentContext.AuthStatus = models.AUTHENTICATIONFAILURE confirmDataRsp.AuthResult = models.AUTHENTICATIONFAILURE - s.processor.logConfirmFailureAndInformUDM(ctx, ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, + p.logConfirmFailureAndInformUDM(ctx, ConfirmationDataResponseID, models.AuthTypeN5GAKA, servingNetworkName, "5G AKA confirmation failed", ausfCurrentContext.UdmUeauUrl) } - if sendErr := s.processor.Consumer().SendAuthResultToUDM(ctx, currentSupi, models.AuthTypeN5GAKA, success, + if sendErr := p.Consumer().SendAuthResultToUDM(ctx, currentSupi, models.AuthTypeN5GAKA, success, servingNetworkName, ausfCurrentContext.UdmUeauUrl); sendErr != nil { logger.Auth5gAkaLog.Infoln(sendErr.Error()) problemDetails := models.ProblemDetails{ diff --git a/internal/sbi/processor/upu_protection.go b/internal/sbi/processor/upu_protection.go index fb56a8c..89db078 100644 --- a/internal/sbi/processor/upu_protection.go +++ b/internal/sbi/processor/upu_protection.go @@ -11,20 +11,12 @@ import ( func NewServerAusfUpuProtection(processor *Processor) ausf_upu_protection.ServerInterface { return ausf_upu_protection.NewStrictHandler( - &ausfUpuProtectionStrictServer{ - processor: processor, - }, - []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, + processor, []strictgin.StrictGinMiddlewareFunc{middleware.GinStrictServerMiddleware}, ) } -type ausfUpuProtectionStrictServer struct { - processor *Processor -} - // (POST /{supi}/ue-upu) -func (s *ausfUpuProtectionStrictServer) PostSupiUeUpu(ctx context.Context, - request ausf_upu_protection.PostSupiUeUpuRequestObject, +func (p *Processor) PostSupiUeUpu(ctx context.Context, request ausf_upu_protection.PostSupiUeUpuRequestObject, ) (ausf_upu_protection.PostSupiUeUpuResponseObject, error) { return nil, errors.New("not implemented") }