Skip to content

Commit 10cfd1d

Browse files
committed
delete more things + change how we remove extensions
1 parent 20c4dbd commit 10cfd1d

File tree

4 files changed

+9
-81
lines changed

4 files changed

+9
-81
lines changed

internal/ct/chain_validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ func chainsEquivalent(inChain []*x509.Certificate, verifiedChain []*x509.Certifi
336336
}
337337

338338
// removeExtension removes a given extension from a list.
339-
func removeExtension(oid asn1.ObjectIdentifier, extensions []pkix.Extension) {
339+
func removeExtension(extensions []pkix.Extension, oid asn1.ObjectIdentifier) []pkix.Extension {
340340
i := 0
341341
for _, e := range extensions {
342342
if !e.Id.Equal(oid) {
343343
extensions[i] = e
344344
i++
345345
}
346346
}
347-
extensions = extensions[:i]
347+
return extensions[:i]
348348
}
349349

350350
// relaxCert modifies parsed certificates fields to relax verification constraints.
@@ -354,7 +354,7 @@ func relaxCert(cert *x509.Certificate) {
354354
cert.UnknownExtKeyUsage = nil
355355

356356
// Name constraints
357-
removeExtension(oidExtensionNameConstraints, cert.Extensions)
357+
cert.Extensions = removeExtension(cert.Extensions, oidExtensionNameConstraints)
358358
cert.PermittedDNSDomainsCritical = false
359359
cert.PermittedDNSDomains = nil
360360
cert.ExcludedDNSDomains = nil
@@ -372,7 +372,7 @@ func relaxCert(cert *x509.Certificate) {
372372
cert.MaxPathLenZero = false
373373

374374
// Policies
375-
removeExtension(oidExtensionCertificatePolicies, cert.Extensions)
375+
cert.Extensions = removeExtension(cert.Extensions, oidExtensionCertificatePolicies)
376376
cert.Policies = []x509.OID{mustNewOIDFromInts(oidAnyPolicyExtension)}
377377
cert.PolicyIdentifiers = nil
378378
cert.PolicyMappings = nil

internal/lax509/cert_pool.go

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package lax509
66

77
import (
8-
"bytes"
98
"crypto/sha256"
109
"crypto/x509"
1110
"encoding/pem"
@@ -78,12 +77,6 @@ func (s *CertPool) len() int {
7877
return len(s.lazyCerts)
7978
}
8079

81-
// cert returns cert index n in s.
82-
func (s *CertPool) cert(n int) (*x509.Certificate, func([]*x509.Certificate) error, error) {
83-
cert, err := s.lazyCerts[n].getCert()
84-
return cert, s.lazyCerts[n].constraint, err
85-
}
86-
8780
// Clone returns a copy of s.
8881
func (s *CertPool) Clone() *CertPool {
8982
p := &CertPool{
@@ -104,60 +97,6 @@ func (s *CertPool) Clone() *CertPool {
10497
return p
10598
}
10699

107-
type potentialParent struct {
108-
cert *x509.Certificate
109-
constraint func([]*x509.Certificate) error
110-
}
111-
112-
// findPotentialParents returns the certificates in s which might have signed
113-
// cert.
114-
func (s *CertPool) findPotentialParents(cert *x509.Certificate) []potentialParent {
115-
if s == nil {
116-
return nil
117-
}
118-
119-
// consider all candidates where cert.Issuer matches cert.Subject.
120-
// when picking possible candidates the list is built in the order
121-
// of match plausibility as to save cycles in buildChains:
122-
// AKID and SKID match
123-
// AKID present, SKID missing / AKID missing, SKID present
124-
// AKID and SKID don't match
125-
var matchingKeyID, oneKeyID, mismatchKeyID []potentialParent
126-
for _, c := range s.byName[string(cert.RawIssuer)] {
127-
candidate, constraint, err := s.cert(c)
128-
if err != nil {
129-
continue
130-
}
131-
kidMatch := bytes.Equal(candidate.SubjectKeyId, cert.AuthorityKeyId)
132-
switch {
133-
case kidMatch:
134-
matchingKeyID = append(matchingKeyID, potentialParent{candidate, constraint})
135-
case (len(candidate.SubjectKeyId) == 0 && len(cert.AuthorityKeyId) > 0) ||
136-
(len(candidate.SubjectKeyId) > 0 && len(cert.AuthorityKeyId) == 0):
137-
oneKeyID = append(oneKeyID, potentialParent{candidate, constraint})
138-
default:
139-
mismatchKeyID = append(mismatchKeyID, potentialParent{candidate, constraint})
140-
}
141-
}
142-
143-
found := len(matchingKeyID) + len(oneKeyID) + len(mismatchKeyID)
144-
if found == 0 {
145-
return nil
146-
}
147-
candidates := make([]potentialParent, 0, found)
148-
candidates = append(candidates, matchingKeyID...)
149-
candidates = append(candidates, oneKeyID...)
150-
candidates = append(candidates, mismatchKeyID...)
151-
return candidates
152-
}
153-
154-
func (s *CertPool) contains(cert *x509.Certificate) bool {
155-
if s == nil {
156-
return false
157-
}
158-
return s.haveSum[sha256.Sum224(cert.Raw)]
159-
}
160-
161100
// AddCert adds a certificate to a pool.
162101
func (s *CertPool) AddCert(cert *x509.Certificate) {
163102
if cert == nil {

internal/x509util/pem_cert_pool.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"os"
2424

25-
"github.com/transparency-dev/tesseract/internal/lax509"
2625
"k8s.io/klog/v2"
2726
)
2827

@@ -37,12 +36,12 @@ type PEMCertPool struct {
3736
// maps from sha-256 to certificate, used for dup detection
3837
fingerprintToCertMap map[[sha256.Size]byte]x509.Certificate
3938
rawCerts []*x509.Certificate
40-
certPool *lax509.CertPool
39+
certPool *x509.CertPool
4140
}
4241

4342
// NewPEMCertPool creates a new, empty, instance of PEMCertPool.
4443
func NewPEMCertPool() *PEMCertPool {
45-
return &PEMCertPool{fingerprintToCertMap: make(map[[sha256.Size]byte]x509.Certificate), certPool: lax509.NewCertPool()}
44+
return &PEMCertPool{fingerprintToCertMap: make(map[[sha256.Size]byte]x509.Certificate), certPool: x509.NewCertPool()}
4645
}
4746

4847
// AddCert adds a certificate to a pool. Uses fingerprint to weed out duplicates.
@@ -105,16 +104,6 @@ func (p *PEMCertPool) AppendCertsFromPEMFile(pemFile string) error {
105104
return nil
106105
}
107106

108-
// Subjects returns a list of the DER-encoded subjects of all of the certificates in the pool.
109-
func (p *PEMCertPool) Subjects() (res [][]byte) {
110-
return p.certPool.Subjects()
111-
}
112-
113-
// CertPool returns the underlying CertPool.
114-
func (p *PEMCertPool) CertPool() *lax509.CertPool {
115-
return p.certPool
116-
}
117-
118107
// RawCertificates returns a list of the raw bytes of certificates that are in this pool
119108
func (p *PEMCertPool) RawCertificates() []*x509.Certificate {
120109
return p.rawCerts

internal/x509util/pem_cert_pool_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestLoadSingleCertFromPEMs(t *testing.T) {
3030
if !ok {
3131
t.Fatal("Expected to append a certificate ok")
3232
}
33-
if got, want := len(pool.Subjects()), 1; got != want {
33+
if got, want := len(pool.RawCertificates()), 1; got != want {
3434
t.Fatalf("Got %d cert(s) in the pool, expected %d", got, want)
3535
}
3636
}
@@ -44,7 +44,7 @@ func TestBadOrEmptyCertificateRejected(t *testing.T) {
4444
if ok {
4545
t.Fatal("Expected appending no certs")
4646
}
47-
if got, want := len(pool.Subjects()), 0; got != want {
47+
if got, want := len(pool.RawCertificates()), 0; got != want {
4848
t.Fatalf("Got %d cert(s) in pool, expected %d", got, want)
4949
}
5050
}
@@ -57,7 +57,7 @@ func TestLoadMultipleCertsFromPEM(t *testing.T) {
5757
if !ok {
5858
t.Fatal("Rejected valid multiple certs")
5959
}
60-
if got, want := len(pool.Subjects()), 2; got != want {
60+
if got, want := len(pool.RawCertificates()), 2; got != want {
6161
t.Fatalf("Got %d certs in pool, expected %d", got, want)
6262
}
6363
}

0 commit comments

Comments
 (0)