@@ -30,11 +30,13 @@ func ParseCertificate(c *cert.Certificate) *Certificate {
30
30
return nil
31
31
}
32
32
33
- func (c * Config ) loadSelfCertPool () (* x509.CertPool , error ) {
33
+ func (c * Config ) loadSelfCertPool (usage Certificate_Usage ) (* x509.CertPool , error ) {
34
34
root := x509 .NewCertPool ()
35
35
for _ , cert := range c .Certificate {
36
- if ! root .AppendCertsFromPEM (cert .Certificate ) {
37
- return nil , newError ("failed to append cert" ).AtWarning ()
36
+ if cert .Usage == usage {
37
+ if ! root .AppendCertsFromPEM (cert .Certificate ) {
38
+ return nil , newError ("failed to append cert" ).AtWarning ()
39
+ }
38
40
}
39
41
}
40
42
return root , nil
@@ -209,13 +211,19 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
209
211
}
210
212
}
211
213
214
+ clientRoot , err := c .loadSelfCertPool (Certificate_AUTHORITY_VERIFY_CLIENT )
215
+ if err != nil {
216
+ newError ("failed to load client root certificate" ).AtError ().Base (err ).WriteToLog ()
217
+ }
218
+
212
219
config := & tls.Config {
213
220
ClientSessionCache : globalSessionCache ,
214
221
RootCAs : root ,
215
222
InsecureSkipVerify : c .AllowInsecure ,
216
223
NextProtos : c .NextProtocol ,
217
224
SessionTicketsDisabled : ! c .EnableSessionResumption ,
218
225
VerifyPeerCertificate : c .verifyPeerCert ,
226
+ ClientCAs : clientRoot ,
219
227
}
220
228
221
229
for _ , opt := range opts {
@@ -238,6 +246,9 @@ func (c *Config) GetTLSConfig(opts ...Option) *tls.Config {
238
246
config .NextProtos = []string {"h2" , "http/1.1" }
239
247
}
240
248
249
+ if c .VerifyClientCertificate {
250
+ config .ClientAuth = tls .RequireAndVerifyClientCert
251
+ }
241
252
return config
242
253
}
243
254
0 commit comments