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. 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.

Namespace: Com\Tecnick\Pdf\Sign\Cms

Final: Yes

File: SignatureVerifier.php line 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.

Tags

Constants

ALGORITHMS

File: SignatureVerifier.php line 77

public array<string, int> 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 '1.2.840.10045.4.3.4' => OPENSSL_ALGO_SHA512, ]

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.

LEGACY_ALGORITHMS

File: SignatureVerifier.php line 94

public array<string, int> LEGACY_ALGORITHMS = [ '1.2.840.113549.1.1.5' => OPENSSL_ALGO_SHA1, // sha1WithRSAEncryption '1.2.840.10045.4.1' => OPENSSL_ALGO_SHA1, ]

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

OID_RSA_ENCRYPTION

File: SignatureVerifier.php line 54

public mixed OID_RSA_ENCRYPTION = '1.2.840.113549.1.1.1'

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.

Methods

__construct()

File: SignatureVerifier.php line 104

public __construct([Asn1|null $asn1 = null ][, bool $allowSha1 = false ]) : mixed

Parameters

  • $asn1 : Asn1|null = null
  • $allowSha1 : bool = false: Accept the SHA-1 signature algorithms as well.

verify()

File: SignatureVerifier.php line 126

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 = 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.

Tags

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