| Methods |
public
static
|
verifySeal(string $container, array $options): SealVerification
Verify a seal.
The structure is read strictly: every element of the signature is
where the baseline puts it, once, and anything this library does not
process (a signature policy, a manifest of references, a transform)
makes the seal invalid rather than ignored. A seal is valid only if
every file of the container outside META-INF is covered, so that a
file added to a sealed container cannot pass for a sealed one.
The signing certificate is trusted at the time of the signature
time-stamp, if any, and at the current date otherwise: SigningTime is
claimed by the signer, and cannot date the check of its certificate.
The certificate of the time-stamping authority is checked at the
current date. The revocation of the certificates is checked, by CRLs
or OCSP responses, unless 'revocation' is FALSE: the library sends no
request, the data come from the seal (level LT) and from the options.
Parameters
| $container |
The ASiC-E container.
|
Returns
The result. An invalid seal does not throw:
see its getError().
Throws
Exception |
On a misuse: the options are not valid, or a CA
certificate cannot be read.
|
|
#
|
public
static
|
createSeal(array $files, string $signKey, string $signCert, string|null $signKeyPassword, array $options = []): string
Seal files: an ASiC-E container that holds them, its manifest, and a
XAdES-B-B signature over them.
Seal files: an ASiC-E container that holds them, its manifest, and a
XAdES-B-B signature over them.
Parameters
| $files |
The files to seal, in the order of the container:
each an array with 'name' (its path in the container, /
separated, outside META-INF/), 'content' (its bytes) and,
optionally, 'mimeType' (by default, from the extension of its
name, see MEDIA_TYPES).
|
| $signKey |
The private key: the path of a PEM file, or its
content.
|
| $signCert |
The certificate of the key: the path of a PEM
file, or its content; the certificates that follow the first
one are embedded as its chain.
|
| $signKeyPassword |
The password of the key, or NULL.
|
Returns
Throws
Exception |
On a misuse: no file, a name or a media type that
cannot be sealed, a key that does not match the certificate,
an algorithm that does not suit the key, a certificate that
cannot sign at the signing time.
|
|
#
|
public
static
|
timestampRequest(string $container, string $digestAlgorithm = Algorithms::SHA256): string
The time-stamp request of a seal (RFC 3161 TimeStampReq, DER), to send
to a time-stamping authority, with the media type
application/timestamp-query. The library sends no request: the
caller sends it to the authority of its choice, and gives the response
to addSignatureTimestamp().
The time-stamp request of a seal (RFC 3161 TimeStampReq, DER), to send
to a time-stamping authority, with the media type
application/timestamp-query. The library sends no request: the
caller sends it to the authority of its choice, and gives the response
to addSignatureTimestamp().
Parameters
| $container |
The container.
|
| $digestAlgorithm |
The digest of the imprint: SHA256
(default), SHA384 or SHA512 of Algorithms.
|
Returns
Throws
Exception |
If the container does not hold one XAdES signature.
|
|
#
|
public
static
|
addSignatureTimestamp(string $container, string $response, array $options): string
Add the signature time-stamp of a response to a seal: level B becomes
level T (EN 319 132-1, 5.3). The signed parts of the signature file
are left byte for byte as they are: the unsigned properties are
inserted after the signed ones.
Add the signature time-stamp of a response to a seal: level B becomes
level T (EN 319 132-1, 5.3). The signed parts of the signature file
are left byte for byte as they are: the unsigned properties are
inserted after the signed ones.
Parameters
| $container |
The container.
|
| $response |
The response of the authority (RFC 3161
TimeStampResp, DER).
|
| $options |
'tsaCertPath' (required): the trusted
certificates of the time-stamping authority, its root and its
intermediate CAs if the token does not embed them.
|
Returns
The container, with the time-stamp in its signature.
Throws
Exception |
If the authority did not grant the time-stamp, if
the token is not valid, is not over this seal, or its
authority is not trusted, or if the seal is already
time-stamped.
|
|
#
|
public
static
|
validationDataRequests(string $container, array $options): array
The revocation data a seal needs: for each certificate of the chains
of the signer and of the time-stamping authority, their trust anchors
excepted, the CRL to fetch, and the OCSP request to send if the
certificate names a responder. One of the two suffices for a
certificate. Also useful at level B or T, to get the data
verifySeal() needs.
The revocation data a seal needs: for each certificate of the chains
of the signer and of the time-stamping authority, their trust anchors
excepted, the CRL to fetch, and the OCSP request to send if the
certificate names a responder. One of the two suffices for a
certificate. Also useful at level B or T, to get the data
verifySeal() needs.
Parameters
| $container |
The container.
|
| $options |
'caCertPath' and 'tsaCertPath', as for
verifySeal() (both required).
|
Returns
'crls': the CRLs to fetch, one per certificate, each
with 'certificate', 'issuer' (X509Cert) and 'urls' (the http
and https URLs of its CRL distribution points, empty if it
names none); 'ocsp': the OCSP requests to send, each with
'certificate', 'issuer', 'urls' (of its responders) and
'request' (the OCSPRequest, DER, to POST with the media type
application/ocsp-request).
Throws
Exception |
If the seal is not valid, revocation aside.
|
|
#
|
public
static
|
addValidationData(string $container, array $options): string
Add to a seal of level T the certificates, CRLs and OCSP responses
that validate it: it becomes a seal of level LT (EN 319 132-1, 5.4,
5.5.1, 6.3), which a third party can validate without reaching the
CAs. The answers are checked before they are embedded, only those that
told the status of a certificate; they must be issued after the
time-stamp. The signed parts of the signature file are left byte for
byte as they are.
Add to a seal of level T the certificates, CRLs and OCSP responses
that validate it: it becomes a seal of level LT (EN 319 132-1, 5.4,
5.5.1, 6.3), which a third party can validate without reaching the
CAs. The answers are checked before they are embedded, only those that
told the status of a certificate; they must be issued after the
time-stamp. The signed parts of the signature file are left byte for
byte as they are.
What goes where: xades141:TimeStampValidationData, right after the
time-stamp, the certificates of the chain of the time-stamping
authority the token does not hold, and their CRLs or OCSP responses;
xades:CertificateValues, the certificates of the chain of the signer
ds:KeyInfo does not hold, its trust anchor included;
xades:RevocationValues, a CRL or an OCSP response for each certificate
of that chain, its trust anchor excepted. Each one is embedded once.
Parameters
| $container |
The container.
|
| $options |
'caCertPath' and 'tsaCertPath', as for
verifySeal(), and at least one of 'crls' (in DER or PEM) and
'ocspResponses' (DER), fetched as validationDataRequests()
lists.
|
Returns
The container, with the validation data in its
signature.
Throws
Exception |
If the seal is not valid, is not of level T, or if
the data do not tell the status of every certificate after the
time-stamp.
|
|
#
|
| Constants |
public
|
|
XMLDSIG_NS = 'http://www.w3.org/2000/09/xmldsig#'
|
#
|
public
|
|
ASIC_NS = 'http://uri.etsi.org/02918/v1.2.1#'
|
#
|
public
|
|
XADES_NS = 'http://uri.etsi.org/01903/v1.3.2#'
|
#
|
public
|
|
XADES141_NS = 'http://uri.etsi.org/01903/v1.4.1#'
The namespace of the properties XAdES 1.4.1 added, such as TimeStampValidationData.
The namespace of the properties XAdES 1.4.1 added, such as TimeStampValidationData.
|
#
|
public
|
|
MANIFEST_NS = 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'
|
#
|
public
|
|
SIGNED_PROPERTIES_TYPE = 'http://uri.etsi.org/01903#SignedProperties'
|
#
|
public
|
|
ASICE_MIMETYPE = 'application/vnd.etsi.asic-e+zip'
|
#
|
public
|
|
SIGNATURE_PATH = 'META-INF/signatures001.xml'
The path of the signature in the container.
The path of the signature in the container.
|
#
|
public
|
|
MANIFEST_PATH = 'META-INF/manifest.xml'
|
#
|
public
|
|
CANONICALIZATIONS = [Algorithms::EXC_C14N, Algorithms::C14N]
The canonicalizations accepted for SignedInfo and the signed properties.
The canonicalizations accepted for SignedInfo and the signed properties.
|
#
|
public
|
|
MEDIA_TYPES = [
'pdf' => 'application/pdf',
'txt' => 'text/plain',
'md' => 'text/markdown',
'html' => 'text/html',
'htm' => 'text/html',
'xml' => 'application/xml',
'json' => 'application/json',
'csv' => 'text/csv',
'png' => 'image/png',
'jpg' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'svg' => 'image/svg+xml',
'odt' => 'application/vnd.oasis.opendocument.text',
'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
]
The media types written for the most common extensions; any other file is application/octet-stream.
The media types written for the most common extensions; any other file is application/octet-stream.
|
#
|
public
|
|
MEDIA_TYPE = '/\A[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}\/[A-Za-z0-9][A-Za-z0-9!#$&^_.+-]{0,126}(\s*;\s*[A-Za-z0-9!#$&^_.+-]+=("[^"\\\\\r\n]*"|[A-Za-z0-9!#$&^_.+-]+))*\z/'
A media type: type/subtype, then parameters (RFC 6838, 4.2).
A media type: type/subtype, then parameters (RFC 6838, 4.2).
|
#
|
public
|
|
TIMESTAMP_CANONICALIZATION = Algorithms::EXC_C14N
The canonicalization of ds:SignatureValue for its time-stamp.
The canonicalization of ds:SignatureValue for its time-stamp.
|
#
|
public
|
|
CRL_DISTRIBUTION_POINTS = '2.5.29.31'
|
#
|
public
|
|
AUTHORITY_INFO_ACCESS = '1.3.6.1.5.5.7.1.1'
|
#
|
public
|
|
ID_AD_OCSP = '1.3.6.1.5.5.7.48.1'
|
#
|