mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 06:40:19 +00:00
NOISSUE - Update callouts client tls config (#3068)
Check License Header / check-license (push) Has been cancelled
Continuous Delivery / Build and Push (push) Has been cancelled
Check the consistency of generated files / check-generated-files (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
Check License Header / check-license (push) Has been cancelled
Continuous Delivery / Build and Push (push) Has been cancelled
Check the consistency of generated files / check-generated-files (push) Has been cancelled
Deploy GitHub Pages / swagger-ui (push) Has been cancelled
Signed-off-by: Jilks Smith <smithjilks@gmail.com>
This commit is contained in:
+5
-13
@@ -7,18 +7,16 @@ import (
|
||||
"bytes"
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"crypto/x509"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"maps"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/absmach/supermq/pkg/errors"
|
||||
svcerr "github.com/absmach/supermq/pkg/errors/service"
|
||||
"github.com/absmach/supermq/pkg/server"
|
||||
)
|
||||
|
||||
var errFailedToRead = errors.New("failed to read callout response body")
|
||||
@@ -82,22 +80,16 @@ func newCalloutClient(ctls bool, certPath, keyPath, caPath string, timeout time.
|
||||
InsecureSkipVerify: !ctls,
|
||||
}
|
||||
if certPath != "" || keyPath != "" {
|
||||
clientTLSCert, err := tls.LoadX509KeyPair(certPath, keyPath)
|
||||
clientTLSCert, err := server.LoadX509KeyPair(certPath, keyPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
certPool, err := x509.SystemCertPool()
|
||||
|
||||
caCert, err := server.LoadRootCACerts(caPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
caCert, err := os.ReadFile(caPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !certPool.AppendCertsFromPEM(caCert) {
|
||||
return nil, errors.Wrap(errors.New("failed to append CA certificate"), svcerr.ErrCreateEntity)
|
||||
}
|
||||
tlsConfig.RootCAs = certPool
|
||||
tlsConfig.RootCAs = caCert
|
||||
tlsConfig.Certificates = []tls.Certificate{clientTLSCert}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user