65 if (array_key_exists(
'privatekey',
$options)) {
67 if (array_key_exists(
'privatekey_pass',
$options)) {
74 if (array_key_exists(
'certificate',
$options)) {
78 if (array_key_exists(
'privatekey_array',
$options)) {
82 if (array_key_exists(
'publickey_array',
$options)) {
86 if (array_key_exists(
'id',
$options)) {
87 $this->setIdAttribute(
$options[
'id']);
102 assert(is_array($privatekey));
103 assert(array_key_exists(
'PEM', $privatekey));
106 if (array_key_exists(
'password', $privatekey)) {
107 $this->privateKey->passphrase = $privatekey[
'password'];
109 $this->privateKey->loadKey($privatekey[
'PEM'],
false);
128 assert(is_string($file));
130 assert(is_bool($full_path));
138 if (!file_exists($keyFile)) {
139 throw new \Exception(
'Could not find private key file "' . $keyFile .
'".');
141 $keyData = file_get_contents($keyFile);
142 if ($keyData ===
false) {
143 throw new \Exception(
'Unable to read private key file "' . $keyFile .
'".');
146 $privatekey = array(
'PEM' => $keyData);
147 if (
$pass !== null) {
148 $privatekey[
'password'] =
$pass;
165 assert(is_array($publickey));
167 if (!array_key_exists(
'PEM', $publickey)) {
169 throw new \Exception(
'Tried to add a certificate fingerprint in a signature.');
173 $this->certificate = $publickey[
'PEM'];
191 assert(is_string($file));
192 assert(is_bool($full_path));
200 if (!file_exists($certFile)) {
201 throw new \Exception(
'Could not find certificate file "' . $certFile .
'".');
204 $cert = file_get_contents($certFile);
205 if ($cert ===
false) {
206 throw new \Exception(
'Unable to read certificate file "' . $certFile .
'".');
208 $this->certificate = $cert;
238 assert(is_string($file));
239 assert(is_bool($full_path));
247 if (!file_exists($certFile)) {
248 throw new \Exception(
'Could not find extra certificate file "' . $certFile .
'".');
253 throw new \Exception(
'Unable to read extra certificate file "' . $certFile .
'".');
272 public function sign($node, $insertInto, $insertBefore = null)
275 assert($insertInto instanceof DOMElement);
276 assert($insertBefore === null || $insertBefore instanceof DOMElement ||
279 if ($this->privateKey ===
false) {
280 throw new \Exception(
'Private key not set.');
288 if (!empty($this->idAttrName)) {
292 $objXMLSecDSig->addReferenceList(
300 $objXMLSecDSig->sign($this->privateKey);
304 $objXMLSecDSig->add509Cert($this->certificate,
true);
308 $objXMLSecDSig->add509Cert($certificate,
true);
311 $objXMLSecDSig->insertSignature($insertInto, $insertBefore);
__construct($options=array())
Constructor for the metadata signer.
loadPublicKeyArray($publickey)
Set the public key / certificate we should include in the signature.
loadPrivateKey($file, $pass=null, $full_path=false)
Set the private key.
setIDAttribute($idAttrName)
Set the attribute name for the ID value.
loadCertificate($file, $full_path=false)
Set the certificate we should include in the signature.
addCertificate($file, $full_path=false)
Add an extra certificate to the certificate chain in the signature.
loadPrivateKeyArray($privatekey)
Set the private key from an array.
static getCertPath($path)
Resolves a path that may be relative to the cert-directory.