Skip to content

Commit 248b708

Browse files
authored
NOISSUE - Update callouts client tls config (#3068)
Signed-off-by: Jilks Smith <[email protected]>
1 parent c63c936 commit 248b708

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

pkg/callout/callout.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@ import (
77
"bytes"
88
"context"
99
"crypto/tls"
10-
"crypto/x509"
1110
"encoding/json"
1211
"fmt"
1312
"io"
1413
"maps"
1514
"net/http"
1615
"net/url"
17-
"os"
1816
"time"
1917

2018
"github.com/absmach/supermq/pkg/errors"
21-
svcerr "github.com/absmach/supermq/pkg/errors/service"
19+
"github.com/absmach/supermq/pkg/server"
2220
)
2321

2422
var errFailedToRead = errors.New("failed to read callout response body")
@@ -82,22 +80,16 @@ func newCalloutClient(ctls bool, certPath, keyPath, caPath string, timeout time.
8280
InsecureSkipVerify: !ctls,
8381
}
8482
if certPath != "" || keyPath != "" {
85-
clientTLSCert, err := tls.LoadX509KeyPair(certPath, keyPath)
83+
clientTLSCert, err := server.LoadX509KeyPair(certPath, keyPath)
8684
if err != nil {
8785
return nil, err
8886
}
89-
certPool, err := x509.SystemCertPool()
90-
if err != nil {
91-
return nil, err
92-
}
93-
caCert, err := os.ReadFile(caPath)
87+
88+
caCert, err := server.LoadRootCACerts(caPath)
9489
if err != nil {
9590
return nil, err
9691
}
97-
if !certPool.AppendCertsFromPEM(caCert) {
98-
return nil, errors.Wrap(errors.New("failed to append CA certificate"), svcerr.ErrCreateEntity)
99-
}
100-
tlsConfig.RootCAs = certPool
92+
tlsConfig.RootCAs = caCert
10193
tlsConfig.Certificates = []tls.Certificate{clientTLSCert}
10294
}
10395

0 commit comments

Comments
 (0)