SignatureVerifier

Verifies the signature of a DER structure that follows the X.509 shape of a signed body, an AlgorithmIdentifier, and a signature BIT STRING.

Namespace: Com\Tecnick\Pdf\Sign\Cms

final class SignatureVerifier

Source: src/Cms/SignatureVerifier.php:43

Verifies the signature of a DER structure that follows the X.509 shape of a signed body, an AlgorithmIdentifier, and a signature BIT STRING. An OCSP BasicOCSPResponse and a CRL CertificateList are both built that way, and both are accepted as validation material only once the signature over them checks out against the certificate that produced it.

The accepted algorithms are SHA-256 and above. SHA-1 is refused unless the caller passes $allowSha1.

Constants

ALGORITHMS

Signature AlgorithmIdentifier OID to the openssl digest constant.

RSASSA-PSS (1.2.840.113549.1.1.10) is absent because openssl_verify() cannot express its parameters, so a structure signed with it is reported as unsupported rather than accepted unchecked.

public const ALGORITHMS = [
    '1.2.840.113549.1.1.11' => OPENSSL_ALGO_SHA256,
    // sha256WithRSAEncryption
    '1.2.840.113549.1.1.12' => OPENSSL_ALGO_SHA384,
    // sha384WithRSAEncryption
    '1.2.840.113549.1.1.13' => OPENSSL_ALGO_SHA512,
    // sha512WithRSAEncryption
    '1.2.840.10045.4.3.2' => OPENSSL_ALGO_SHA256,
    // ecdsa-with-SHA256
    '1.2.840.10045.4.3.3' => OPENSSL_ALGO_SHA384,
    // ecdsa-with-SHA384
// … truncated, see source

Source: src/Cms/SignatureVerifier.php:77

LEGACY_ALGORITHMS

SHA-1 signature algorithms, accepted only when the caller opts in.

Reachable for a legacy responder or CRL distribution point that emits nothing else.

public const LEGACY_ALGORITHMS = [
    '1.2.840.113549.1.1.5' => OPENSSL_ALGO_SHA1,
    // sha1WithRSAEncryption
    '1.2.840.10045.4.1' => OPENSSL_ALGO_SHA1,
]

Source: src/Cms/SignatureVerifier.php:94

OID_RSA_ENCRYPTION

rsaEncryption, the PKCS #1 v1.5 signature value identifier that names no digest.

RFC 3370 section 3.2, repeated by RFC 5754 section 3.2: in CMS an RSA signature value is identified by rsaEncryption whatever the digest, which the structure carries in a field of its own and the caller passes to verify(). It is what Builder emits. RFC 5280 section 4.1.1.2 requires the shaWith form of a certificate, a CRL, or an OCSP response instead.

public const OID_RSA_ENCRYPTION = '1.2.840.113549.1.1.1'

Source: src/Cms/SignatureVerifier.php:54

Methods

__construct()

public __construct(?Asn1 $asn1 = null, bool $allowSha1 = false)

Parameters:

  • $asn1 (?Asn1)
  • $allowSha1 (bool): Accept the SHA-1 signature algorithms as well.

Source: src/Cms/SignatureVerifier.php:104

verify()

Verify a signature against the certificate that is said to have produced it.

public verify(
    string $signedDer,
    string $algorithmIdDer,
    string $signature,
    string $signerCertDer,
    string|null $digestName = null
): void

Parameters:

  • $signedDer (string): Complete DER of the signed body, as the signature covers it.
  • $algorithmIdDer (string): Complete DER of the signature AlgorithmIdentifier.
  • $signature (string): Signature octets, without the BIT STRING unused-bits count.
  • $signerCertDer (string): DER of the certificate holding the verifying public key.
  • $digestName (string|null): Digest the structure names in a field of its own, for a signature identifier that names none. Required for rsaEncryption and ignored otherwise, since every other identifier here implies its digest.

Throws:

  • Exception: If the algorithm is unsupported, the certificate is unreadable, or the signature does not verify.

Source: src/Cms/SignatureVerifier.php:126