Skip to content

Commit

Permalink
fix: use absolute paths for TLS certificate and private key (#284)
Browse files Browse the repository at this point in the history
* fix: use absolute paths for TLS certificate and private key

Signed-off-by: Dario Faccin <[email protected]>

* use default path if key and pem are not provided

Signed-off-by: Dario Faccin <[email protected]>

---------

Signed-off-by: Dario Faccin <[email protected]>
Co-authored-by: Ajay Lotan Thakur <[email protected]>
  • Loading branch information
dariofaccin and thakurajayL authored Jul 20, 2024
1 parent 1aab524 commit 622f6b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
4 changes: 2 additions & 2 deletions config/smfcfg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ configuration:
bindingIPv4: smf # IP used to bind the service
port: 29502 # Port used to bind the service
tls: # the local path of TLS key
key: free5gc/support/TLS/smf.key # SMF TLS Certificate
pem: free5gc/support/TLS/smf.pem # SMF TLS Private key
key: /support/TLS/smf.key # SMF TLS Certificate
pem: /support/TLS/smf.pem # SMF TLS Private key
serviceNameList: # the SBI services provided by this SMF, refer to TS 29.502
- nsmf-pdusession # Nsmf_PDUSession service
- nsmf-event-exposure # Nsmf_EventExposure service
Expand Down
12 changes: 10 additions & 2 deletions context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/omec-project/smf/factory"
"github.com/omec-project/smf/logger"
"github.com/omec-project/smf/metrics"
"github.com/omec-project/smf/util"
"github.com/omec-project/util/drsm"
)

Expand Down Expand Up @@ -148,6 +149,9 @@ func InitSmfContext(config *factory.Config) *SMFContext {
smfContext.URIScheme = models.UriScheme(sbi.Scheme)
smfContext.RegisterIPv4 = factory.SMF_DEFAULT_IPV4 // default localhost
smfContext.SBIPort = factory.SMF_DEFAULT_PORT_INT // default port
smfContext.Key = util.SmfKeyPath // default key path
smfContext.PEM = util.SmfPemPath // default PEM path

if sbi.RegisterIPv4 != "" {
// smfContext.RegisterIPv4 = sbi.RegisterIPv4
sbi.RegisterIPv4 = localIp
Expand All @@ -160,8 +164,12 @@ func InitSmfContext(config *factory.Config) *SMFContext {
}

if tls := sbi.TLS; tls != nil {
smfContext.Key = tls.Key
smfContext.PEM = tls.PEM
if tls.Key != "" {
smfContext.Key = tls.Key
}
if tls.PEM != "" {
smfContext.PEM = tls.PEM
}
}

smfContext.BindingIPv4 = os.Getenv(sbi.BindingIPv4)
Expand Down
4 changes: 1 addition & 3 deletions service/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,10 @@ func (smf *SMF) Start() {
}

serverScheme := factory.SmfConfig.Configuration.Sbi.Scheme
smfPemPath := path_util.Free5gcPath(factory.SmfConfig.Configuration.Sbi.TLS.PEM)
smfKeyPath := path_util.Free5gcPath(factory.SmfConfig.Configuration.Sbi.TLS.Key)
if serverScheme == "http" {
err = server.ListenAndServe()
} else if serverScheme == "https" {
err = server.ListenAndServeTLS(smfPemPath, smfKeyPath)
err = server.ListenAndServeTLS(context.SMF_Self().PEM, context.SMF_Self().Key)
}

if err != nil {
Expand Down

0 comments on commit 622f6b2

Please sign in to comment.