CMS (PKCS#7) library for Go
Перейти к файлу
Michael Ryan Dempsey 9676f6c2aa
fix verify_test on go1.16
DSAWithSHA1 removed from crypto/x509 in go1.16, check for unsupported
error
2021-06-14 01:12:50 +00:00
.github/workflows fix interoperability with Go 1.15 encoding/asn1 SET OF ordering 2021-06-14 01:11:29 +00:00
oid Add mapping from algo OID to x509 SignatureAlgorithm for DSAWithSHA1 2019-05-17 10:27:50 -05:00
protocol fix interoperability with Go 1.15 encoding/asn1 SET OF ordering 2021-06-14 01:11:29 +00:00
timestamp sort certlist in digicert timestamp signed data 2021-06-14 01:12:46 +00:00
.gitignore Initial commit 2015-04-09 11:53:02 -04:00
LICENSE.md add license/readmme 2017-11-21 08:51:58 -07:00
README.md Fix typo in a badge. 2020-08-11 17:52:43 -07:00
go.mod fix verify_test on go1.16 2021-06-14 01:12:50 +00:00
go.sum fix verify_test on go1.16 2021-06-14 01:12:50 +00:00
main_test.go Update dependencies and references for v0.1.0 2020-08-11 17:05:36 -07:00
sign.go allow intermediates to be added in addition to leaf cert 2017-11-27 16:22:30 -07:00
sign_test.go fix interoperability with Go 1.15 encoding/asn1 SET OF ordering 2021-06-14 01:11:29 +00:00
signed_data.go Update dependencies and references for v0.1.0 2020-08-11 17:05:36 -07:00
timestamp.go Update dependencies and references for v0.1.0 2020-08-11 17:05:36 -07:00
timestamp_test.go Merge pull request #23 from josephlr/ci 2020-08-11 17:20:45 -07:00
verify.go fix interoperability with Go 1.15 encoding/asn1 SET OF ordering 2021-06-14 01:11:29 +00:00
verify_test.go fix verify_test on go1.16 2021-06-14 01:12:50 +00:00

README.md

CMS PkgGoDev Report card

Test (recent Go versions)
Test (Go 1.10)

CMS (Cryptographic Message Syntax) is a syntax for signing, digesting, and encrypting arbitrary messages. It evolved from PKCS#7 and is the basis for higher level protocols such as S/MIME. This package implements the SignedData CMS content-type, allowing users to digitally sign data as well as verify data signed by others.

Signing and Verifying Data

High level APIs are provided for signing a message with a certificate and key:

msg := []byte("some data")
cert, _ := x509.ParseCertificate(someCertificateData)
key, _ := x509.ParseECPrivateKey(somePrivateKeyData)

der, _ := cms.Sign(msg, []*x509.Certificate{cert}, key)

////
/// At another time, in another place...
//

sd, _ := ParseSignedData(der)
if err, _ := sd.Verify(x509.VerifyOptions{}); err != nil {
  panic(err)
}

By default, CMS SignedData includes the original message. High level APIs are also available for creating and verifying detached signatures:

msg := []byte("some data")
cert, _ := x509.ParseCertificate(someCertificateData)
key, _ := x509.ParseECPrivateKey(somePrivateKeyData)

der, _ := cms.SignDetached(msg, cert, key)

////
/// At another time, in another place...
//

sd, _ := ParseSignedData(der)
if err, _ := sd.VerifyDetached(msg, x509.VerifyOptions{}); err != nil {
  panic(err)
}

Timestamping

Because certificates expire and can be revoked, it is may be helpful to attach certified timestamps to signatures, proving that they existed at a given time. RFC3161 timestamps can be added to signatures like so:

signedData, _ := NewSignedData([]byte("Hello, world!"))
signedData.Sign(identity.Chain(), identity.PrivateKey)
signedData.AddTimestamps("http://timestamp.digicert.com")

derEncoded, _ := signedData.ToDER()
io.Copy(os.Stdout, bytes.NewReader(derEncoded))

Verification functions implicitly verify timestamps as well. Without a timestamp, verification will fail if the certificate is no longer valid.