Skip to content

Commit af2fa1b

Browse files
Address comments
1 parent 5c73869 commit af2fa1b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

pkg/smokescreen/config.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ type Config struct {
8484
SupportProxyProtocol bool
8585
TlsConfig *tls.Config
8686
CrlByAuthorityKeyId map[string]*pkix.CertificateList
87+
revokedCertSerials map[string]map[string]bool
8788
RoleFromRequest func(subject *http.Request) (string, error)
8889
clientCasBySubjectKeyId map[string]*x509.Certificate
8990
AdditionalErrorMessageOnDeny string
@@ -390,6 +391,7 @@ func NewConfig() *Config {
390391
return &Config{
391392
Resolver: &net.Resolver{},
392393
CrlByAuthorityKeyId: make(map[string]*pkix.CertificateList),
394+
revokedCertSerials: make(map[string]map[string]bool),
393395
clientCasBySubjectKeyId: make(map[string]*x509.Certificate),
394396
Log: log.New(),
395397
Port: DefaultPort,
@@ -523,6 +525,13 @@ func (config *Config) SetupCrls(crlFiles []string) error {
523525

524526
// At this point, we have a new CRL which we trust. Let's evict the old one.
525527
config.CrlByAuthorityKeyId[crlIssuerId] = certList
528+
529+
serialSet := make(map[string]bool, len(certList.TBSCertList.RevokedCertificates))
530+
for _, revoked := range certList.TBSCertList.RevokedCertificates {
531+
serialSet[revoked.SerialNumber.String()] = true
532+
}
533+
config.revokedCertSerials[crlIssuerId] = serialSet
534+
526535
fmt.Printf("info: Loaded CRL for Authority ID '%s'\n", hex.EncodeToString([]byte(crlIssuerId)))
527536
}
528537

@@ -627,7 +636,7 @@ func (config *Config) SetupTls(certFile, keyFile string, clientCAFiles []string)
627636
ClientAuth: clientAuth,
628637
ClientCAs: clientCAs,
629638
VerifyConnection: func(cs tls.ConnectionState) error {
630-
if len(config.CrlByAuthorityKeyId) == 0 {
639+
if len(config.revokedCertSerials) == 0 {
631640
return nil
632641
}
633642

@@ -638,15 +647,13 @@ func (config *Config) SetupTls(certFile, keyFile string, clientCAFiles []string)
638647
}
639648

640649
issuerKeyId := string(cert.AuthorityKeyId)
641-
crl, ok := config.CrlByAuthorityKeyId[issuerKeyId]
650+
serials, ok := config.revokedCertSerials[issuerKeyId]
642651
if !ok {
643652
continue
644653
}
645654

646-
for _, revoked := range crl.TBSCertList.RevokedCertificates {
647-
if cert.SerialNumber.Cmp(revoked.SerialNumber) == 0 {
648-
return fmt.Errorf("certificate with serial %s has been revoked", cert.SerialNumber.String())
649-
}
655+
if serials[cert.SerialNumber.String()] {
656+
return fmt.Errorf("certificate with serial %s has been revoked", cert.SerialNumber.String())
650657
}
651658
}
652659
}

0 commit comments

Comments
 (0)