Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename GetCertificate to Certificate #349

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/bundle/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ func (b *Bundle) VerificationContent() (verify.VerificationContent, error) {
return nil, ErrValidationError(err)
}
cert := &Certificate{
Certificate: parsedCert,
certificate: parsedCert,
}
return cert, nil
case *protobundle.VerificationMaterial_Certificate:
Expand All @@ -267,7 +267,7 @@ func (b *Bundle) VerificationContent() (verify.VerificationContent, error) {
return nil, ErrValidationError(err)
}
cert := &Certificate{
Certificate: parsedCert,
certificate: parsedCert,
}
return cert, nil
case *protobundle.VerificationMaterial_PublicKey:
Expand Down
2 changes: 1 addition & 1 deletion pkg/bundle/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,7 @@ func TestVerificationContent(t *testing.T) {
}
require.NoError(t, gotErr)
if tt.wantCertificate {
require.NotNil(t, got.GetCertificate())
require.NotNil(t, got.Certificate())
return
}
if tt.wantPublicKey {
Expand Down
16 changes: 10 additions & 6 deletions pkg/bundle/verification_content.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ import (
)

type Certificate struct {
*x509.Certificate
certificate *x509.Certificate
}

func NewCertificate(cert *x509.Certificate) *Certificate {
return &Certificate{certificate: cert}
}

type PublicKey struct {
Expand All @@ -41,15 +45,15 @@ func (c *Certificate) CompareKey(key any, _ root.TrustedMaterial) bool {
return false
}

return c.Certificate.Equal(x509Key)
return c.certificate.Equal(x509Key)
}

func (c *Certificate) ValidAtTime(t time.Time, _ root.TrustedMaterial) bool {
return !(c.Certificate.NotAfter.Before(t) || c.Certificate.NotBefore.After(t))
return !(c.certificate.NotAfter.Before(t) || c.certificate.NotBefore.After(t))
}

func (c *Certificate) GetCertificate() *x509.Certificate {
return c.Certificate
func (c *Certificate) Certificate() *x509.Certificate {
return c.certificate
}

func (c *Certificate) HasPublicKey() (verify.PublicKeyProvider, bool) {
Expand Down Expand Up @@ -79,7 +83,7 @@ func (pk *PublicKey) ValidAtTime(t time.Time, tm root.TrustedMaterial) bool {
return verifier.ValidAtTime(t)
}

func (pk *PublicKey) GetCertificate() *x509.Certificate {
func (pk *PublicKey) Certificate() *x509.Certificate {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/fulcio/certificate/summarize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestSummarizeCertificateWithActionsBundle(t *testing.T) {
t.Fatalf("failed to get verification content: %v", err)
}

leaf := vc.GetCertificate()
leaf := vc.Certificate()

if leaf == nil {
t.Fatalf("expected verification content to be a certificate chain")
Expand Down Expand Up @@ -79,7 +79,7 @@ func TestSummarizeCertificateWithOauthBundle(t *testing.T) {
t.Fatalf("failed to get verification content: %v", err)
}

leaf := vc.GetCertificate()
leaf := vc.Certificate()

if leaf == nil {
t.Fatalf("expected verification content to be a certificate chain")
Expand Down Expand Up @@ -108,7 +108,7 @@ func TestSummarizeCertificateWithOtherNameSAN(t *testing.T) {
t.Fatalf("failed to get verification content: %v", err)
}

leaf := vc.GetCertificate()
leaf := vc.Certificate()

if leaf == nil {
t.Fatalf("expected verification content to be a certificate chain")
Expand Down
2 changes: 1 addition & 1 deletion pkg/testing/ca/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ type TestEntity struct {
}

func (e *TestEntity) VerificationContent() (verify.VerificationContent, error) {
return &bundle.Certificate{Certificate: e.certChain[0]}, nil
return bundle.NewCertificate(e.certChain[0]), nil
}

func (e *TestEntity) HasInclusionPromise() bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/verify/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type SignedEntity interface {
type VerificationContent interface {
CompareKey(any, root.TrustedMaterial) bool
ValidAtTime(time.Time, root.TrustedMaterial) bool
GetCertificate() *x509.Certificate
Certificate() *x509.Certificate
HasPublicKey() (PublicKeyProvider, bool)
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/verify/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func VerifySignatureWithArtifactDigest(sigContent SignatureContent, verification
}

func getSignatureVerifier(verificationContent VerificationContent, tm root.TrustedMaterial) (signature.Verifier, error) {
if leafCert := verificationContent.GetCertificate(); leafCert != nil {
if leafCert := verificationContent.Certificate(); leafCert != nil {
// TODO: Inspect certificate's SignatureAlgorithm to determine hash function
return signature.LoadVerifier(leafCert.PublicKey, crypto.SHA256)
} else if pk, ok := verificationContent.HasPublicKey(); ok {
Expand Down
4 changes: 2 additions & 2 deletions pkg/verify/signed_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func (v *SignedEntityVerifier) Verify(entity SignedEntity, pb PolicyBuilder) (*V

// If the bundle was signed with a long-lived key, and does not have a Fulcio certificate,
// then skip the certificate verification steps
if leafCert := verificationContent.GetCertificate(); leafCert != nil {
if leafCert := verificationContent.Certificate(); leafCert != nil {
if policy.WeExpectSigningKey() {
return nil, errors.New("expected key signature, not certificate")
}
Expand Down Expand Up @@ -719,7 +719,7 @@ func (v *SignedEntityVerifier) VerifyObserverTimestamps(entity SignedEntity, log
return nil, err
}

if leafCert := verificationContent.GetCertificate(); leafCert != nil {
if leafCert := verificationContent.Certificate(); leafCert != nil {
verifiedTimestamps = append(verifiedTimestamps, TimestampVerificationResult{Type: "LeafCert.NotBefore", URI: "", Timestamp: leafCert.NotBefore})
} else {
// no cert? use current time
Expand Down
Loading