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: CMS content type check #35

Merged
merged 4 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 10 additions & 5 deletions internal/cms/signed.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,14 +248,19 @@ func (d *ParsedSignedData) verifySignedAttributes(signerInfo *SignerInfo, chains

// verify attributes if present
if len(signerInfo.SignedAttributes) == 0 {
if d.ContentType.Equal(oid.Data) {
return nil, nil
}
// signed attributes MUST be present if the content type of the
// EncapsulatedContentInfo value being signed is not id-data.
// According to RFC 5652, if the Content Type is id-data, signed
// attributes can be empty. However, this cms package is designed for
// timestamp (RFC 3161) and the content type must be id-ct-TSTInfo,
// so we require signed attributes to be present.
return nil, VerificationError{Message: "missing signed attributes"}
}

// this CMS package is designed for timestamping (RFC 3161), so checking the
// content type to be id-ct-TSTInfo is an optimization for tspclient to
// fail fast.
if !oid.TSTInfo.Equal(d.ContentType) {
return nil, fmt.Errorf("unexpected content type: %v", d.ContentType)
JeyJeyGao marked this conversation as resolved.
Show resolved Hide resolved
}
var contentType asn1.ObjectIdentifier
if err := signerInfo.SignedAttributes.Get(oid.ContentType, &contentType); err != nil {
return nil, VerificationError{Message: "invalid content type", Detail: err}
Expand Down
7 changes: 6 additions & 1 deletion internal/cms/signed_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,12 @@ func TestVerify(t *testing.T) {
{
name: "id-data content type without signed attributes",
filePath: "testdata/SignedDataWithoutSignedAttributes.p7s",
wantErr: false,
wantErr: true,
},
{
name: "invalid content type",
filePath: "testdata/TimeStampTokenWithInvalidContentType.p7s",
wantErr: true,
},
{
name: "an invalid and a valid signer info",
Expand Down
Binary file not shown.
Loading