62 assert(
'is_array($options)');
64 $this->idAttrName =
false;
65 $this->privateKey =
false;
66 $this->certificate =
false;
67 $this->extraCertificates =
array();
69 if (array_key_exists(
'privatekey',
$options)) {
71 if (array_key_exists(
'privatekey_pass',
$options)) {
78 if (array_key_exists(
'certificate',
$options)) {
82 if (array_key_exists(
'privatekey_array',
$options)) {
86 if (array_key_exists(
'publickey_array',
$options)) {
90 if (array_key_exists(
'id',
$options)) {
91 $this->setIdAttribute(
$options[
'id']);
106 assert(
'is_array($privatekey)');
107 assert(
'array_key_exists("PEM", $privatekey)');
110 if (array_key_exists(
'password', $privatekey)) {
111 $this->privateKey->passphrase = $privatekey[
'password'];
113 $this->privateKey->loadKey($privatekey[
'PEM'],
false);
132 assert(
'is_string($file)');
133 assert(
'is_string($pass) || is_null($pass)');
134 assert(
'is_bool($full_path)');
142 if (!file_exists($keyFile)) {
143 throw new \Exception(
'Could not find private key file "' . $keyFile .
'".');
145 $keyData = file_get_contents($keyFile);
146 if ($keyData ===
false) {
147 throw new \Exception(
'Unable to read private key file "' . $keyFile .
'".');
150 $privatekey =
array(
'PEM' => $keyData);
151 if (
$pass !== null) {
152 $privatekey[
'password'] =
$pass;
169 assert(
'is_array($publickey)');
171 if (!array_key_exists(
'PEM', $publickey)) {
173 throw new \Exception(
'Tried to add a certificate fingerprint in a signature.');
177 $this->certificate = $publickey[
'PEM'];
195 assert(
'is_string($file)');
196 assert(
'is_bool($full_path)');
204 if (!file_exists($certFile)) {
205 throw new \Exception(
'Could not find certificate file "' . $certFile .
'".');
208 $this->certificate = file_get_contents($certFile);
209 if ($this->certificate ===
false) {
210 throw new \Exception(
'Unable to read certificate file "' . $certFile .
'".');
222 assert(
'is_string($idAttrName)');
241 assert(
'is_string($file)');
242 assert(
'is_bool($full_path)');
250 if (!file_exists($certFile)) {
251 throw new \Exception(
'Could not find extra certificate file "' . $certFile .
'".');
256 throw new \Exception(
'Unable to read extra certificate file "' . $certFile .
'".');
275 public function sign($node, $insertInto, $insertBefore = null)
277 assert(
'$node instanceof DOMElement');
278 assert(
'$insertInto instanceof DOMElement');
279 assert(
'is_null($insertBefore) || $insertBefore instanceof DOMElement ' .
280 '|| $insertBefore instanceof DOMComment || $insertBefore instanceof DOMText');
282 if ($this->privateKey ===
false) {
283 throw new \Exception(
'Private key not set.');
291 if ($this->idAttrName !==
false) {
295 $objXMLSecDSig->addReferenceList(
302 $objXMLSecDSig->sign($this->privateKey);
305 if ($this->certificate !==
false) {
307 $objXMLSecDSig->add509Cert($this->certificate,
true);
312 $objXMLSecDSig->add509Cert($certificate,
true);
315 $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.
sign($node, $insertInto, $insertBefore=null)
Signs the given DOMElement and inserts the signature at the given position.
loadPrivateKeyArray($privatekey)
Set the private key from an array.
Create styles array
The data for the language used.
static getCertPath($path)
Resolves a path that may be relative to the cert-directory.
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
if(!isset($_REQUEST['ReturnTo'])) if(!isset($_REQUEST['AuthId'])) $options