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

Use GetDigestOIDForSignatureAlgorithm to set the digest algorithm OID #18

Merged
merged 5 commits into from
Aug 21, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- name: Get dependencies
run: go get -v -t -d ./...
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.46
version: v1.53

# Optional: working directory, useful for monorepos
# working-directory: somedir
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ module github.com/digitorus/timestamp

go 1.16

require github.com/digitorus/pkcs7 v0.0.0-20221019075359-21b8b40e6bb4
require github.com/digitorus/pkcs7 v0.0.0-20230713084857-e76b763bdc49
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
github.com/digitorus/pkcs7 v0.0.0-20221019075359-21b8b40e6bb4 h1:MxNIia2F3bgFyNsOZy9UbNlpKAxbtCudkVmlJBNuvmg=
github.com/digitorus/pkcs7 v0.0.0-20221019075359-21b8b40e6bb4/go.mod h1:SKVExuS+vpu2l9IoOc0RwqE7NYnb0JlcFHFnEJkVDzc=
github.com/digitorus/pkcs7 v0.0.0-20230713084857-e76b763bdc49 h1:h+XMRXf+WLY0h/3itqE8OT3TgjCMHK4nq2FNGi0au2c=
github.com/digitorus/pkcs7 v0.0.0-20230713084857-e76b763bdc49/go.mod h1:SKVExuS+vpu2l9IoOc0RwqE7NYnb0JlcFHFnEJkVDzc=
2 changes: 1 addition & 1 deletion rfc3161_struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (s pkiStatusInfo) FailureInfo() FailureInfo {
}
}

return UnkownFailureInfo
return UnknownFailureInfo
}

// eContent within SignedData is TSTInfo
Expand Down
18 changes: 12 additions & 6 deletions timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
type FailureInfo int

const (
// UnkownFailureInfo mean that no known failure info was provided
UnkownFailureInfo FailureInfo = -1
// UnknownFailureInfo mean that no known failure info was provided
UnknownFailureInfo FailureInfo = -1
// BadAlgorithm defines an unrecognized or unsupported Algorithm Identifier
BadAlgorithm FailureInfo = 0
// BadRequest indicates that the transaction not permitted or supported
Expand Down Expand Up @@ -268,7 +268,7 @@ func ParseResponse(bytes []byte) (*Timestamp, error) {
if resp.Status.Status > 0 {
var fis string
fi := resp.Status.FailureInfo()
if fi != UnkownFailureInfo {
if fi != UnknownFailureInfo {
fis = fi.String()
}
return nil, fmt.Errorf("%s: %s (%v)",
Expand Down Expand Up @@ -553,7 +553,7 @@ func (t *Timestamp) populateSigningCertificateV2Ext(certificate *x509.Certificat
return nil, x509.ErrUnsupportedAlgorithm
}
if t.HashAlgorithm.HashFunc() == crypto.SHA1 {
return nil, fmt.Errorf("for SHA1 usae ESSCertID instead of ESSCertIDv2")
return nil, fmt.Errorf("for SHA1 use ESSCertID instead of ESSCertIDv2")
}

h := t.HashAlgorithm.HashFunc().New()
Expand Down Expand Up @@ -596,7 +596,13 @@ func (t *Timestamp) generateSignedData(tstInfo []byte, signer crypto.Signer, cer
if err != nil {
return nil, err
}
signedData.SetDigestAlgorithm(pkcs7.OIDDigestAlgorithmSHA256)

digestAlgOID, err := pkcs7.GetDigestOIDForSignatureAlgorithm(certificate.SignatureAlgorithm)
if err != nil {
return nil, err
}

signedData.SetDigestAlgorithm(digestAlgOID)
signedData.SetContentType(asn1.ObjectIdentifier{1, 2, 840, 113549, 1, 9, 16, 1, 4})

signingCertV2Bytes, err := t.populateSigningCertificateV2Ext(certificate)
Expand Down Expand Up @@ -632,7 +638,7 @@ func (t *Timestamp) generateSignedData(tstInfo []byte, signer crypto.Signer, cer
return signature, nil
}

// copied from cryto/x509 package
// copied from crypto/x509 package
// oidNotInExtensions reports whether an extension with the given oid exists in
// extensions.
func oidInExtensions(oid asn1.ObjectIdentifier, extensions []pkix.Extension) bool {
Expand Down
Loading