Skip to content

Commit b457cca

Browse files
committed
TUN-6780: Add support for certReload to also include support for client certificates
1 parent a0b6ba9 commit b457cca

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

tlsconfig/certreloader.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,21 @@ func NewCertReloader(certPath, keyPath string) (*CertReloader, error) {
4040
}
4141

4242
// Cert returns the TLS certificate most recently read by the CertReloader.
43+
// This method works as a direct utility method for tls.Config#Cert.
4344
func (cr *CertReloader) Cert(clientHello *tls.ClientHelloInfo) (*tls.Certificate, error) {
4445
cr.Lock()
4546
defer cr.Unlock()
4647
return cr.certificate, nil
4748
}
4849

50+
// ClientCert returns the TLS certificate most recently read by the CertReloader.
51+
// This method works as a direct utility method for tls.Config#ClientCert.
52+
func (cr *CertReloader) ClientCert(certRequestInfo *tls.CertificateRequestInfo) (*tls.Certificate, error) {
53+
cr.Lock()
54+
defer cr.Unlock()
55+
return cr.certificate, nil
56+
}
57+
4958
// LoadCert loads a TLS certificate from the CertReloader's specified filepath.
5059
// Call this after writing a new certificate to the disk (e.g. after renewing a certificate)
5160
func (cr *CertReloader) LoadCert() error {

tlsconfig/tlsconfig.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,16 @@ import (
1212

1313
// Config is the user provided parameters to create a tls.Config
1414
type TLSParameters struct {
15-
Cert string
16-
Key string
17-
GetCertificate *CertReloader
18-
ClientCAs []string
19-
RootCAs []string
20-
ServerName string
21-
CurvePreferences []tls.CurveID
22-
MinVersion uint16 // min tls version. If zero, TLS1.0 is defined as minimum.
23-
MaxVersion uint16 // max tls version. If zero, last TLS version is used defined as limit (currently TLS1.3)
15+
Cert string
16+
Key string
17+
GetCertificate *CertReloader
18+
GetClientCertificate *CertReloader
19+
ClientCAs []string
20+
RootCAs []string
21+
ServerName string
22+
CurvePreferences []tls.CurveID
23+
MinVersion uint16 // min tls version. If zero, TLS1.0 is defined as minimum.
24+
MaxVersion uint16 // max tls version. If zero, last TLS version is used defined as limit (currently TLS1.3)
2425
}
2526

2627
// GetConfig returns a TLS configuration according to the Config set by the user.
@@ -43,6 +44,11 @@ func GetConfig(p *TLSParameters) (*tls.Config, error) {
4344
tlsconfig.GetCertificate = p.GetCertificate.Cert
4445
}
4546

47+
if p.GetClientCertificate != nil {
48+
// GetClientCertificate is called when using an HTTP client library and mTLS is required.
49+
tlsconfig.GetClientCertificate = p.GetClientCertificate.ClientCert
50+
}
51+
4652
if len(p.ClientCAs) > 0 {
4753
// set of root certificate authorities that servers use if required to verify a client certificate
4854
// by the policy in ClientAuth

0 commit comments

Comments
 (0)