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

fix: fix the certs validation in envelope.Sign() #51

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion signature/internal/base/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,16 @@ func (e *Envelope) Sign(req *signature.SignRequest) ([]byte, error) {
}

// validate certificate chain
if _, err := e.SignerInfo(); err != nil {
signerInfo, err := e.Envelope.SignerInfo()
if err != nil {
return nil, err
}

if err := validateCertificateChain(
signerInfo.CertificateChain,
signerInfo.SignedAttributes.SigningTime,
signerInfo.SignatureAlgorithm,
); err != nil {
return nil, err
}

Expand Down
20 changes: 16 additions & 4 deletions signature/internal/base/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func TestSign(t *testing.T) {
expectErr: true,
},
{
name: "err returned by internal envelope",
name: "internal envelope fails to sign",
req: signReq1,
env: &Envelope{
Raw: nil,
Expand All @@ -187,7 +187,7 @@ func TestSign(t *testing.T) {
expectErr: true,
},
{
name: "invalid certificate chain",
name: "internal envelope fails to get signerInfo",
req: validReq,
env: &Envelope{
Raw: nil,
Expand All @@ -196,16 +196,28 @@ func TestSign(t *testing.T) {
expect: nil,
expectErr: true,
},
{
name: "invalid certificate chain",
req: validReq,
env: &Envelope{
Raw: nil,
Envelope: mockEnvelope{
signerInfo: &signature.SignerInfo{},
},
},
expect: nil,
expectErr: true,
},
{
name: "successfully signed",
req: validReq,
req: validReq,
env: &Envelope{
Raw: validBytes,
Envelope: &mockEnvelope{
signerInfo: validSignerInfo,
},
},
expect: validBytes,
expect: validBytes,
expectErr: false,
},
}
Expand Down