@@ -19,7 +19,7 @@ import (
19
19
20
20
// GetClientTLSConfig returns a tls.Config for client use configured with the
21
21
// sign certificate, and a new certificate pool with the sign root certificate.
22
- // The certificate will automatically rotate before expiring.
22
+ // The client certificate will automatically rotate before expiring.
23
23
func (c * Client ) GetClientTLSConfig (ctx context.Context , sign * api.SignResponse , pk crypto.PrivateKey ) (* tls.Config , error ) {
24
24
cert , err := TLSCertificate (sign , pk )
25
25
if err != nil {
@@ -32,16 +32,14 @@ func (c *Client) GetClientTLSConfig(ctx context.Context, sign *api.SignResponse,
32
32
33
33
tlsConfig := getDefaultTLSConfig (sign )
34
34
// Note that with GetClientCertificate tlsConfig.Certificates is not used.
35
+ // Without tlsConfig.Certificates there's not need to use tlsConfig.BuildNameToCertificate()
35
36
tlsConfig .GetClientCertificate = renewer .GetClientCertificate
36
37
tlsConfig .PreferServerCipherSuites = true
37
38
// Build RootCAs with given root certificate
38
39
if pool := c .getCertPool (sign ); pool != nil {
39
40
tlsConfig .RootCAs = pool
40
41
}
41
42
42
- // Parse Certificates and build NameToCertificate
43
- tlsConfig .BuildNameToCertificate ()
44
-
45
43
// Update renew function with transport
46
44
tr , err := getDefaultTransport (tlsConfig )
47
45
if err != nil {
@@ -56,7 +54,8 @@ func (c *Client) GetClientTLSConfig(ctx context.Context, sign *api.SignResponse,
56
54
57
55
// GetServerTLSConfig returns a tls.Config for server use configured with the
58
56
// sign certificate, and a new certificate pool with the sign root certificate.
59
- // The certificate will automatically rotate before expiring.
57
+ // The returned tls.Config will only verify the client certificate if provided.
58
+ // The server certificate will automatically rotate before expiring.
60
59
func (c * Client ) GetServerTLSConfig (ctx context.Context , sign * api.SignResponse , pk crypto.PrivateKey ) (* tls.Config , error ) {
61
60
cert , err := TLSCertificate (sign , pk )
62
61
if err != nil {
@@ -70,6 +69,7 @@ func (c *Client) GetServerTLSConfig(ctx context.Context, sign *api.SignResponse,
70
69
tlsConfig := getDefaultTLSConfig (sign )
71
70
// Note that GetCertificate will only be called if the client supplies SNI
72
71
// information or if tlsConfig.Certificates is empty.
72
+ // Without tlsConfig.Certificates there's not need to use tlsConfig.BuildNameToCertificate()
73
73
tlsConfig .GetCertificate = renewer .GetCertificate
74
74
tlsConfig .GetClientCertificate = renewer .GetClientCertificate
75
75
tlsConfig .PreferServerCipherSuites = true
@@ -93,6 +93,19 @@ func (c *Client) GetServerTLSConfig(ctx context.Context, sign *api.SignResponse,
93
93
return tlsConfig , nil
94
94
}
95
95
96
+ // GetServerMutualTLSConfig returns a tls.Config for server use configured with
97
+ // the sign certificate, and a new certificate pool with the sign root certificate.
98
+ // The returned tls.Config will always require and verify a client certificate.
99
+ // The server certificate will automatically rotate before expiring.
100
+ func (c * Client ) GetServerMutualTLSConfig (ctx context.Context , sign * api.SignResponse , pk crypto.PrivateKey ) (* tls.Config , error ) {
101
+ tlsConfig , err := c .GetServerTLSConfig (ctx , sign , pk )
102
+ if err != nil {
103
+ return nil , err
104
+ }
105
+ tlsConfig .ClientAuth = tls .RequireAndVerifyClientCert
106
+ return tlsConfig , nil
107
+ }
108
+
96
109
// Transport returns an http.Transport configured to use the client certificate from the sign response.
97
110
func (c * Client ) Transport (ctx context.Context , sign * api.SignResponse , pk crypto.PrivateKey ) (* http.Transport , error ) {
98
111
tlsConfig , err := c .GetClientTLSConfig (ctx , sign , pk )
0 commit comments