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

refactor!: update revocation #215

Merged
merged 25 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 20 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
40 changes: 17 additions & 23 deletions revocation/ocsp/ocsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,18 @@ import (
"golang.org/x/crypto/ocsp"
)

// Purpose is an enum for purpose of the certificate chain whose OCSP status
// is checked
type Purpose int

const (
// PurposeCodeSigning means the certificate chain is a code signing chain
PurposeCodeSigning Purpose = iota

// PurposeTimestamping means the certificate chain is a timestamping chain
PurposeTimestamping
)

// Options specifies values that are needed to check OCSP revocation
type Options struct {
CertChain []*x509.Certificate
CertChainPurpose Purpose // default value is `PurposeCodeSigning`
SigningTime time.Time
HTTPClient *http.Client
CertChain []*x509.Certificate

// CertChainPurpose is the purpose of the certificate chain. Supported
// values are x509.ExtKeyUsageCodeSigning and x509.ExtKeyUsageTimeStamping.
// When not provided, the default value x509.ExtKeyUsageAny is also taken as
// a code signing certificate chain.
CertChainPurpose x509.ExtKeyUsage
Two-Hearts marked this conversation as resolved.
Show resolved Hide resolved

SigningTime time.Time
HTTPClient *http.Client
}

const (
Expand All @@ -73,21 +67,21 @@ func CheckStatus(opts Options) ([]*result.CertRevocationResult, error) {
return nil, result.InvalidChainError{Err: errors.New("chain does not contain any certificates")}
}

// Validate cert chain structure
// Since this is using authentic signing time, signing time may be zero.
// Thus, it is better to pass nil here than fail for a cert's NotBefore
// being after zero time
switch opts.CertChainPurpose {
case PurposeCodeSigning:
case x509.ExtKeyUsageAny, x509.ExtKeyUsageCodeSigning:
// Since ValidateCodeSigningCertChain is using authentic signing time,
// signing time may be zero.
// Thus, it is better to pass nil here than fail for a cert's NotBefore
// being after zero time
if err := coreX509.ValidateCodeSigningCertChain(opts.CertChain, nil); err != nil {
return nil, result.InvalidChainError{Err: err}
}
case PurposeTimestamping:
case x509.ExtKeyUsageTimeStamping:
if err := coreX509.ValidateTimestampingCertChain(opts.CertChain); err != nil {
return nil, result.InvalidChainError{Err: err}
}
default:
return nil, result.InvalidChainError{Err: fmt.Errorf("unknown certificate chain purpose %v", opts.CertChainPurpose)}
return nil, result.InvalidChainError{Err: fmt.Errorf("unsupported certificate chain purpose %v", opts.CertChainPurpose)}
}

certResults := make([]*result.CertRevocationResult, len(opts.CertChain))
Expand Down
Loading
Loading