Documentation
¶
Overview ¶
Package sign provides signing primitives used by PDF signature workflows.
Index ¶
- Variables
- func AddDSS(pdfBytes []byte, dss *DSS) ([]byte, error)
- func AddDocumentTimestamp(pdfBytes []byte, tsaClient *TSAClient, hashFunc crypto.Hash) ([]byte, error)
- func BuildDetachedCMS(digest []byte, signer Signer, signingTime time.Time, tsaToken []byte) ([]byte, error)
- func CollectValidationData(chain []*x509.Certificate, ocspClient *OCSPClient) ([][]byte, error)
- func OIDSignedData() asn1.ObjectIdentifier
- func PDF(pdfBytes []byte, opts Options) ([]byte, error)
- type Algorithm
- type DSS
- type ExternalSigner
- type LocalSigner
- type OCSPClient
- type Options
- type PAdESLevel
- type Signer
- type TSAClient
- type VRIEntry
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoCertificates = errors.New("sign: no certificates provided") ErrNilSignFunction = errors.New("sign: signFn must not be nil") ErrUnsupportedKey = errors.New("sign: unsupported key type") ErrPKCS12Unsupported = errors.New( "sign: PKCS12 loading requires golang.org/x/crypto/pkcs12; use NewLocalSigner with pre-parsed key and certificate", ) )
Errors reported when a signer cannot be built from the given key material.
Functions ¶
func AddDocumentTimestamp ¶
func AddDocumentTimestamp(pdfBytes []byte, tsaClient *TSAClient, hashFunc crypto.Hash) ([]byte, error)
AddDocumentTimestamp appends a PAdES document timestamp signature.
func BuildDetachedCMS ¶
func BuildDetachedCMS(digest []byte, signer Signer, signingTime time.Time, tsaToken []byte) ([]byte, error)
BuildDetachedCMS constructs a DER-encoded CMS SignedData detached signature.
func CollectValidationData ¶
func CollectValidationData(chain []*x509.Certificate, ocspClient *OCSPClient) ([][]byte, error)
CollectValidationData fetches OCSP responses for chain when ocspClient is set.
func OIDSignedData ¶
func OIDSignedData() asn1.ObjectIdentifier
OIDSignedData returns the CMS signedData object identifier.
Types ¶
type Algorithm ¶
type Algorithm int
Algorithm identifies a hash and signature algorithm pair.
const ( SHA256WithRSA Algorithm = iota SHA384WithRSA SHA512WithRSA SHA256WithECDSA SHA384WithECDSA SHA512WithECDSA )
The hash and signature algorithm pairs available for signing.
func (Algorithm) DigestOID ¶
func (a Algorithm) DigestOID() asn1.ObjectIdentifier
DigestOID returns the digest algorithm OID.
func (Algorithm) SignatureOID ¶
func (a Algorithm) SignatureOID() asn1.ObjectIdentifier
SignatureOID returns the signature algorithm OID.
type DSS ¶
DSS holds Document Security Store validation data for PAdES B-LT/B-LTA.
func (*DSS) AddSignatureValidation ¶
func (d *DSS) AddSignatureValidation(sigContents []byte, chain []*x509.Certificate, ocspResponses, crls [][]byte)
AddSignatureValidation adds certificate and revocation data for sigContents.
type ExternalSigner ¶
type ExternalSigner struct {
// contains filtered or unexported fields
}
ExternalSigner delegates signing to a caller-supplied function.
func NewExternalSigner ¶
func NewExternalSigner( signFn func(digest []byte) ([]byte, error), certs []*x509.Certificate, algo Algorithm, ) (*ExternalSigner, error)
NewExternalSigner creates a signer backed by an external signing function.
func (*ExternalSigner) Algorithm ¶
func (s *ExternalSigner) Algorithm() Algorithm
Algorithm returns the signature algorithm.
func (*ExternalSigner) CertificateChain ¶
func (s *ExternalSigner) CertificateChain() []*x509.Certificate
CertificateChain returns a copy of the certificate chain.
type LocalSigner ¶
type LocalSigner struct {
// contains filtered or unexported fields
}
LocalSigner signs with a local private key.
func NewLocalSigner ¶
func NewLocalSigner(key crypto.Signer, certs []*x509.Certificate) (*LocalSigner, error)
NewLocalSigner creates a signer from a local RSA or ECDSA private key.
func ParsePKCS12 ¶
func ParsePKCS12(_ []byte, _ string) (*LocalSigner, error)
ParsePKCS12 is reserved for future PKCS#12 support.
func (*LocalSigner) Algorithm ¶
func (s *LocalSigner) Algorithm() Algorithm
Algorithm returns the signature algorithm.
func (*LocalSigner) CertificateChain ¶
func (s *LocalSigner) CertificateChain() []*x509.Certificate
CertificateChain returns a copy of the certificate chain.
func (*LocalSigner) SetAlgorithm ¶
func (s *LocalSigner) SetAlgorithm(algo Algorithm)
SetAlgorithm overrides the auto-detected algorithm.
type OCSPClient ¶
type OCSPClient struct {
HTTPClient *http.Client
// Timeout bounds one responder round trip. Zero uses a 30s default: the
// responder URL comes from the certificate being validated, so it is not
// necessarily a cooperative endpoint.
Timeout time.Duration
}
OCSPClient fetches OCSP responses for certificate revocation checking.
func (*OCSPClient) FetchChainResponses ¶
func (c *OCSPClient) FetchChainResponses(chain []*x509.Certificate) ([][]byte, error)
FetchChainResponses fetches OCSP responses for non-root certificates in chain.
func (*OCSPClient) FetchResponse ¶
func (c *OCSPClient) FetchResponse(cert, issuer *x509.Certificate) ([]byte, error)
FetchResponse fetches a DER-encoded OCSP response for cert from its first responder URL. issuer is required to build the request.
type Options ¶
type Options struct {
Signer Signer
Level PAdESLevel
Name string
Reason string
Location string
ContactInfo string
SigningTime time.Time
TSAClient *TSAClient
OCSPClient *OCSPClient
CRLs [][]byte
ExtraCerts [][]byte
}
Options configures PDF.
type PAdESLevel ¶
type PAdESLevel int
PAdESLevel specifies the requested PAdES conformance level.
const ( // LevelBB is PAdES B-B: a basic CMS detached signature. LevelBB PAdESLevel = iota // LevelBT is PAdES B-T: B-B plus a timestamp token from an RFC 3161 TSA. LevelBT // LevelBLT is reserved for PAdES B-LT validation data. LevelBLT // LevelBLTA is reserved for PAdES B-LTA archival timestamps. LevelBLTA )
type Signer ¶
type Signer interface {
Sign(digest []byte) ([]byte, error)
Algorithm() Algorithm
CertificateChain() []*x509.Certificate
}
Signer performs a cryptographic signing operation.
type TSAClient ¶
type TSAClient struct {
URL string
HTTPClient *http.Client
// Timeout bounds one timestamp round trip. Zero uses a 30s default so a
// stalled authority cannot hang signing forever.
Timeout time.Duration
}
TSAClient is an RFC 3161 Time-Stamp Authority client.
func NewTSAClient ¶
NewTSAClient creates a TSA client for url.