Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,14 @@ MGATE_COAP_WITH_DTLS_TARGET_PORT=5683
MGATE_COAP_WITH_DTLS_CERT_FILE=ssl/certs/server.crt
MGATE_COAP_WITH_DTLS_KEY_FILE=ssl/certs/server.key
MGATE_COAP_WITH_DTLS_SERVER_CA_FILE=ssl/certs/ca.crt
MGATE_COAP_WITH_DTLS_CLIENT_CA_FILE=ssl/certs/ca.crt

MGATE_COAP_WITH_MDTLS_HOST=
MGATE_COAP_WITH_MDTLS_PORT=5685
MGATE_COAP_WITH_MDTLS_TARGET_HOST=localhost
MGATE_COAP_WITH_MDTLS_TARGET_PORT=5683
MGATE_COAP_WITH_MDTLS_CERT_FILE=ssl/certs/server.crt
MGATE_COAP_WITH_MDTLS_KEY_FILE=ssl/certs/server.key
MGATE_COAP_WITH_MDTLS_SERVER_CA_FILE=ssl/certs/ca.crt
MGATE_COAP_WITH_MDTLS_CLIENT_CA_FILE=ssl/certs/ca.crt
MGATE_COAP_WITH_MDTLS_CERT_VERIFICATION_METHODS=ocsp
MGATE_COAP_WITH_MDTLS_OCSP_RESPONDER_URL=http://localhost:8880/ocsp
13 changes: 13 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (

coapWithoutDTLS = "MGATE_COAP_WITHOUT_DTLS_"
coapWithDTLS = "MGATE_COAP_WITH_DTLS_"
coapWithmDTLS = "MGATE_COAP_WITH_MDTLS_"
)

func main() {
Expand Down Expand Up @@ -200,6 +201,18 @@ func main() {
return coapDTLSProxy.Listen(ctx)
})

// mGate server Configuration for CoAP with mDTLS
coapmDTLSConfig, err := mgate.NewConfig(env.Options{Prefix: coapWithmDTLS})
if err != nil {
panic(err)
}

// mGate server for CoAP with mDTLS
coapmDTLSProxy := coap.NewProxy(coapmDTLSConfig, handler, logger)
g.Go(func() error {
return coapmDTLSProxy.Listen(ctx)
})

g.Go(func() error {
return StopSignalHandler(ctx, cancel, logger)
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/coap/coap.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *Proxy) Listen(ctx context.Context) error {
}

status := mptls.SecurityStatus(p.config.DTLSConfig)
p.logger.Info(fmt.Sprintf("COAP proxy server started at %s with %s", net.JoinHostPort(p.config.Host, p.config.Port), status))
p.logger.Info(fmt.Sprintf("COAP proxy server started at %s with %s", net.JoinHostPort(p.config.Host, p.config.Port), status))

if err := g.Wait(); err != nil {
p.logger.Info(fmt.Sprintf("COAP proxy server at %s exiting with errors", net.JoinHostPort(p.config.Host, p.config.Port)), slog.String("error", err.Error()))
Expand Down
24 changes: 23 additions & 1 deletion pkg/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ func SecurityStatus[sc TLSConfig](s sc) string {
}
return ret
case *dtls.Config:
return "DTLS"
ret := "DTLS"

if c.ClientCAs != nil {
ret += " and " + toClientAuthString(c.ClientAuth)
}
return ret
default:
return "no TLS"
}
Expand All @@ -155,3 +160,20 @@ func loadCertFile(certFile string) ([]byte, error) {
}
return []byte{}, nil
}

func toClientAuthString(cat dtls.ClientAuthType) string {
switch cat {
case dtls.NoClientCert:
return "NoClientCert"
case dtls.RequestClientCert:
return "RequestClientCert"
case dtls.RequireAnyClientCert:
return "RequestAnyClientCert"
case dtls.VerifyClientCertIfGiven:
return "VerifyClientCertIfGiven"
case dtls.RequireAndVerifyClientCert:
return "RequireAndVerifyClientCert"
default:
return ""
}
}