Skip to content

Commit 206f659

Browse files
authored
fix: Config.InsecureSkipTimeVerify did not skip peerCertificate expiry check (#303)
Signed-off-by: adotkhan <[email protected]> Reviewed-by: Gaukas Wang <[email protected]>
1 parent 925bfb3 commit 206f659

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

handshake_client.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -368,33 +368,29 @@ func (c *Conn) loadSession(hello *clientHelloMsg) (
368368
// Check that the cached server certificate is not expired, and that it's
369369
// valid for the ServerName. This should be ensured by the cache key, but
370370
// protect the application from a faulty ClientSessionCache implementation.
371-
if c.config.time().After(session.peerCertificates[0].NotAfter) {
372-
// Expired certificate, delete the entry.
373-
c.config.ClientSessionCache.Put(cacheKey, nil)
374-
return nil, nil, nil, nil
371+
// [UTLS SECTION START]
372+
if !c.config.InsecureSkipTimeVerify {
373+
if c.config.time().After(session.peerCertificates[0].NotAfter) {
374+
// Expired certificate, delete the entry.
375+
c.config.ClientSessionCache.Put(cacheKey, nil)
376+
return nil, nil, nil, nil
377+
}
375378
}
379+
// [UTLS SECTION END]
376380
if !c.config.InsecureSkipVerify {
377381
if len(session.verifiedChains) == 0 {
378382
// The original connection had InsecureSkipVerify, while this doesn't.
379383
return nil, nil, nil, nil
380384
}
381-
serverCert := session.peerCertificates[0]
382385
// [UTLS SECTION START]
383-
if !c.config.InsecureSkipTimeVerify {
384-
if c.config.time().After(serverCert.NotAfter) {
385-
// Expired certificate, delete the entry.
386-
c.config.ClientSessionCache.Put(cacheKey, nil)
387-
return nil, nil, nil, nil
388-
}
389-
}
390386
var dnsName string
391387
if len(c.config.InsecureServerNameToVerify) == 0 {
392388
dnsName = c.config.ServerName
393389
} else if c.config.InsecureServerNameToVerify != "*" {
394390
dnsName = c.config.InsecureServerNameToVerify
395391
}
396392
if len(dnsName) > 0 {
397-
if err := serverCert.VerifyHostname(dnsName); err != nil {
393+
if err := session.peerCertificates[0].VerifyHostname(dnsName); err != nil {
398394
return nil, nil, nil, nil
399395
}
400396
}

0 commit comments

Comments
 (0)