smimesign/ietf-cms
Kevin Jones 3d9275d0bd
Merge branch 'main' into tsa-inclusive
2024-09-17 11:04:37 -04:00
..
oid Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
protocol Update some documentation links. 2021-10-09 21:12:46 -07:00
timestamp Make TSA timestamp checks inclusive. 2022-11-10 18:08:16 -05:00
.gitignore Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
LICENSE.md Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
README.md Fix README for ietf-cms 2021-10-10 14:01:27 +05:30
main_test.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
sign.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
sign_test.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
signed_data.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
timestamp.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
timestamp_test.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
verify.go Consolidate `smimesign`-specific dependencies into a monorepo. 2021-10-04 12:35:32 -07:00
verify_test.go Add skip for failing tests for now 2024-09-16 14:47:56 -04:00

README.md

CMS PkgGoDev

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.