setasign\SetaPDF2\Signer\Signature\Module

Cms A signature module to create CMS signatures.

File: /SetaPDF v2/Signer/Signature/Module/Cms.php
Old class name (alias): \SetaPDF_Signer_Signature_Module_Cms

This module creates a signature using the Cryptographic Message Syntax (CMS - described in RFC3852).

It allows a low level access to the ASN.1 structure, including signed and unsigned attributes. The final signature makes use of the openssl_sign() function.

To add additional signed or unsigned attributes this class needs to be extended and own implementations of the _getSignedAttributes() and _getUnsignedAttributes() needs to be implemented.

By default the class makes use of signed attributes to reduce the overhead data that needs to be signed (see getDataToSign()).

Class hierarchy

Implements

Summary

Properties

$_certificate

The signing certificate

$_cms

The CMS structure

$_crls

CRL responses instances to be embedded in the RevocationInfoArchival attribute.

$_digest

protected string Cms::$_digest = 'sha256'

The digest algorithm to use when signing

$_extraCertificates

Additional certificates to be specified

$_hashValue

The signature hash value object in the CMS structure

$_oCertificate

Get the original signing certificate argument

$_ocspResponses

OCSP response instances to be embedded in the RevocationInfoArchival attribute.

$_privateKey

protected resource|string Cms::$_privateKey

The private key to use when signing

$_signatureValue

The signature value object in the CMS structure


Static Methods

getParsedCertificate()

WARNING: This method is marked as deprecated!

public static Cms::getParsedCertificate (
string $certificate
): \SetaPDF_Signer_Asn1_Element

Ensures a certificate parameter and parses it into an ASN.1 element object structure.

Parameters
$certificate : string

A PEM encoded string or path to a PEM encoded X.509 certificate.

Exceptions

Throws \InvalidArgumentException

Throws \setasign\SetaPDF2\Signer\Asn1\Exception


Methods

_getSignatureAlgorithmIdentifier()

protected Cms::_getSignatureAlgorithmIdentifier (
void
): void

_getSignedAttributes()

Creates and returns all signed attribues.

Overwrite this method to add individual signed attributes.

_getUnsignedAttributes()

Creates and returns unsigned attributes.

addCrl()

public Cms::addCrl (): void

Adds an CRL which will be embedded in the CMS structure.

Parameters
$crl : string|\SetaPDF_Signer_X509_Crl
 

addOcspResponse()

public Cms::addOcspResponse (
string|\SetaPDF_Signer_Ocsp_Response $ocspResponse
): void

Adds an OCSP response which will be embedded in the CMS structure.

Parameters
$ocspResponse : string|\SetaPDF_Signer_Ocsp_Response

DER encoded OCSP response or OCSP response instance.

Exceptions

Throws \setasign\SetaPDF2\Signer\Exception

createSignature()

Create a signature for the file in the given $tmpPath.

Parameters
$tmpPath : \SetaPDF_Core_Reader_FilePath
 
Exceptions

Throws \BadMethodCallException

Throws \setasign\SetaPDF2\Signer\Exception

getCertificate()

Get the certificate value.

getCms()

Get the complete Cryptographic Message Syntax structure.

Exceptions

Throws \setasign\SetaPDF2\Signer\Exception

getDataToSign()

public Cms::getDataToSign (): string

Get the data which needs to be digitally signed.

Parameters
$tmpPath : \SetaPDF_Core_Reader_FilePath
 
Exceptions

Throws \setasign\SetaPDF2\Signer\Exception

getDigest()

public Cms::getDigest (
void
): string

Get the digest algorithm.

setCertificate()

public Cms::setCertificate (
string|\SetaPDF_Signer_X509_Certificate $certificate
): void

Set the signing certificate (PEM).

Parameters
$certificate : string|\SetaPDF_Signer_X509_Certificate

PEM encoded certificate, path to the PEM encoded certificate or a certificate instance.

Exceptions

Throws \InvalidArgumentException

Throws \setasign\SetaPDF2\Signer\Asn1\Exception

setDigest()

public Cms::setDigest (
string $digest
): void

Set the digest algorithm to use when signing.

Possible values are defined in \setasign\SetaPDF2\Signer\Digest.

Parameters
$digest : string
 
See

setExtraCertificates()

public Cms::setExtraCertificates (
array|\SetaPDF_Signer_X509_Collection $extraCertificates
): void

Add additional certificates which are placed into the CMS structure.

Parameters
$extraCertificates : array|\SetaPDF_Signer_X509_Collection

PEM encoded certificates or pathes to PEM encoded certificates.

Exceptions

Throws \setasign\SetaPDF2\Signer\Asn1\Exception

setOcspResponse()

WARNING: This method is marked as deprecated!

public Cms::setOcspResponse (
string $ocspResponse
): void

Alias for addOcspResponse().

Parameters
$ocspResponse : string

DER encoded OCSP response.

Exceptions

Throws \setasign\SetaPDF2\Signer\Exception

setPrivateKey()

public Cms::setPrivateKey (
resource|\OpenSSLAsymmetricKey|string|array $privateKey,
string $passphrase = ''
): void

Set the the private key or a path to the private key file and password argument.

Parameters
$privateKey : resource|\OpenSSLAsymmetricKey|string|array

A key, returned by openssl_get_privatekey() or a PEM formatted key as a string. Or a string having the format file://path/to/file.pem

$passphrase : string

The optional parameter passphrase must be used if the specified key is encrypted (protected by a passphrase).

Exceptions

Throws \InvalidArgumentException

setSignatureValue()

public Cms::setSignatureValue (
string $signatureValue
): void

Set the signature value.

By default this needs to be the binary string of an RSASSA-PKCS1-v1_5 signature operation.

Parameters
$signatureValue : string