Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Zheng <[email protected]>
  • Loading branch information
Two-Hearts committed Nov 29, 2024
1 parent 23b80a5 commit 91c5e83
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions internal/timestamp/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ func Timestamp(req *signature.SignRequest, opts tspclient.RequestOptions) ([]byt
CertChain: tsaCertChain,
})
if err != nil {
return nil, fmt.Errorf("after timestamping: failed to check timestamping certificate chain revocation with error: %w", err)
return nil, fmt.Errorf("failed to validate the revocation status of timestamping certificate chain with error: %w", err)
}
if err := revocationFinalResult(certResults, tsaCertChain); err != nil {
return nil, fmt.Errorf("after timestamping: %w", err)
if err := revocationResult(certResults, tsaCertChain); err != nil {
return nil, err
}
}
return resp.TimestampToken.FullBytes, nil
}

// revocationFinalResult returns an error if any cert in the cert chain has
// revocationResult returns an error if any cert in the cert chain has
// a revocation status other than ResultOK or ResultNonRevokable.
// When ResultRevoked presents, always return the revoked error.
func revocationFinalResult(certResults []*result.CertRevocationResult, certChain []*x509.Certificate) error {
func revocationResult(certResults []*result.CertRevocationResult, certChain []*x509.Certificate) error {
//sanity check
if len(certResults) == 0 {
return errors.New("certificate revocation result cannot be empty")
Expand Down
20 changes: 10 additions & 10 deletions internal/timestamp/timestamp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func TestTimestamp(t *testing.T) {
Content: []byte("notation"),
HashAlgorithm: crypto.SHA256,
}
expectedErr := "after timestamping: failed to check timestamping certificate chain revocation with error: failed in ValidateContext"
expectedErr := "failed to validate the revocation status of timestamping certificate chain with error: failed in ValidateContext"
_, err = Timestamp(req, opts)
assertErrorEqual(expectedErr, err, t)
})
Expand All @@ -167,14 +167,14 @@ func TestTimestamp(t *testing.T) {
Content: []byte("notation"),
HashAlgorithm: crypto.SHA256,
}
expectedErr := `after timestamping: timestamping certificate with subject "CN=DigiCert Timestamp 2024,O=DigiCert,C=US" is revoked`
expectedErr := `timestamping certificate with subject "CN=DigiCert Timestamp 2024,O=DigiCert,C=US" is revoked`
_, err = Timestamp(req, opts)
assertErrorEqual(expectedErr, err, t)
})

}

func TestRevocationFinalResult(t *testing.T) {
func TestRevocationResult(t *testing.T) {
certResult := []*result.CertRevocationResult{
{
// update leaf cert result in each sub-test
Expand Down Expand Up @@ -211,7 +211,7 @@ func TestRevocationFinalResult(t *testing.T) {
},
},
}
err := revocationFinalResult(certResult, certChain)
err := revocationResult(certResult, certChain)
assertErrorEqual(`timestamping certificate with subject "CN=leafCert" revocation status is unknown`, err, t)
})

Expand All @@ -231,7 +231,7 @@ func TestRevocationFinalResult(t *testing.T) {
},
RevocationMethod: result.RevocationMethodOCSPFallbackCRL,
}
if err := revocationFinalResult(certResult, certChain); err != nil {
if err := revocationResult(certResult, certChain); err != nil {
t.Fatal(err)
}
})
Expand All @@ -253,7 +253,7 @@ func TestRevocationFinalResult(t *testing.T) {
},
RevocationMethod: result.RevocationMethodOCSPFallbackCRL,
}
err := revocationFinalResult(certResult, certChain)
err := revocationResult(certResult, certChain)
assertErrorEqual(`timestamping certificate with subject "CN=leafCert" revocation status is unknown`, err, t)
})

Expand All @@ -268,7 +268,7 @@ func TestRevocationFinalResult(t *testing.T) {
},
},
}
err := revocationFinalResult(certResult, certChain)
err := revocationResult(certResult, certChain)
assertErrorEqual(`timestamping certificate with subject "CN=leafCert" is revoked`, err, t)
})

Expand All @@ -283,17 +283,17 @@ func TestRevocationFinalResult(t *testing.T) {
},
},
}
err := revocationFinalResult(certResult, certChain)
err := revocationResult(certResult, certChain)
assertErrorEqual(`timestamping certificate with subject "CN=leafCert" revocation status is unknown`, err, t)
})

t.Run("empty cert result", func(t *testing.T) {
err := revocationFinalResult([]*result.CertRevocationResult{}, certChain)
err := revocationResult([]*result.CertRevocationResult{}, certChain)
assertErrorEqual("certificate revocation result cannot be empty", err, t)
})

t.Run("cert result length does not equal to cert chain", func(t *testing.T) {
err := revocationFinalResult([]*result.CertRevocationResult{
err := revocationResult([]*result.CertRevocationResult{
certResult[1],
}, certChain)
assertErrorEqual("length of certificate revocation result 1 does not match length of the certificate chain 2", err, t)
Expand Down

0 comments on commit 91c5e83

Please sign in to comment.