|
static | sign ($metadataString, $entityMetadata, $type) |
| Signs the given metadata if metadata signing is enabled. More...
|
|
|
static | findKeyCert ($config, $entityMetadata, $type) |
| This functions finds what key & certificate files should be used to sign the metadata for the given entity. More...
|
|
static | isMetadataSigningEnabled ($config, $entityMetadata, $type) |
| Determine whether metadata signing is enabled for the given metadata. More...
|
|
static | getMetadataSigningAlgorithm ($config, $entityMetadata, $type) |
| Determine the signature and digest algorithms to use when signing metadata. More...
|
|
Definition at line 10 of file Signer.php.
◆ findKeyCert()
static SimpleSAML_Metadata_Signer::findKeyCert |
( |
|
$config, |
|
|
|
$entityMetadata, |
|
|
|
$type |
|
) |
| |
|
staticprivate |
This functions finds what key & certificate files should be used to sign the metadata for the given entity.
- Parameters
-
- Returns
- array An associative array with the keys 'privatekey', 'certificate', and optionally 'privatekey_pass'.
- Exceptions
-
Exception | If the key and certificate used to sign is unknown. |
Definition at line 25 of file Signer.php.
References $certificate, $config, $ret, $type, and array.
28 if (array_key_exists(
'metadata.sign.privatekey', $entityMetadata)
29 || array_key_exists(
'metadata.sign.certificate', $entityMetadata)
32 if (!array_key_exists(
'metadata.sign.privatekey', $entityMetadata)
33 || !array_key_exists(
'metadata.sign.certificate', $entityMetadata)
37 'Missing either the "metadata.sign.privatekey" or the'.
38 ' "metadata.sign.certificate" configuration option in the metadata for'.
39 ' the '.
$type.
' "'.$entityMetadata[
'entityid'].
'". If one of'.
40 ' these options is specified, then the other must also be specified.' 45 'privatekey' => $entityMetadata[
'metadata.sign.privatekey'],
46 'certificate' => $entityMetadata[
'metadata.sign.certificate']
49 if (array_key_exists(
'metadata.sign.privatekey_pass', $entityMetadata)) {
50 $ret[
'privatekey_pass'] = $entityMetadata[
'metadata.sign.privatekey_pass'];
57 $privatekey =
$config->getString(
'metadata.sign.privatekey', null);
62 'Missing either the "metadata.sign.privatekey" or the'.
63 ' "metadata.sign.certificate" configuration option in the global'.
64 ' configuration. If one of these options is specified, then the other'.
65 ' must also be specified.' 70 $privatekey_pass =
$config->getString(
'metadata.sign.privatekey_pass', null);
71 if ($privatekey_pass !== null) {
72 $ret[
'privatekey_pass'] = $privatekey_pass;
79 if (array_key_exists(
'privatekey', $entityMetadata)
80 || array_key_exists(
'certificate', $entityMetadata)
83 if (!array_key_exists(
'privatekey', $entityMetadata)
84 || !array_key_exists(
'certificate', $entityMetadata)
87 'Both the "privatekey" and the "certificate" option must'.
88 ' be set in the metadata for the '.
$type.
' "'.
89 $entityMetadata[
'entityid'].
'" before it is possible to sign metadata'.
95 'privatekey' => $entityMetadata[
'privatekey'],
96 'certificate' => $entityMetadata[
'certificate']
99 if (array_key_exists(
'privatekey_pass', $entityMetadata)) {
100 $ret[
'privatekey_pass'] = $entityMetadata[
'privatekey_pass'];
107 'Could not find what key & certificate should be used to sign the metadata'.
108 ' for the '.
$type.
' "'.$entityMetadata[
'entityid'].
'".'
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Create styles array
The data for the language used.
◆ getMetadataSigningAlgorithm()
static SimpleSAML_Metadata_Signer::getMetadataSigningAlgorithm |
( |
|
$config, |
|
|
|
$entityMetadata, |
|
|
|
$type |
|
) |
| |
|
staticprivate |
Determine the signature and digest algorithms to use when signing metadata.
This method will look for the 'metadata.sign.algorithm' key in the $entityMetadata array, or look for such a configuration option in the $config object.
- Parameters
-
SimpleSAML_Configuration | $config | The global configuration. |
array | $entityMetadata | An array containing the metadata related to this entity. |
string | $type | A string describing the type of entity. E.g. 'SAML 2 IdP' or 'Shib 1.3 SP'. |
- Returns
- array An array with two keys, 'algorithm' and 'digest', corresponding to the signature and digest algorithms to use, respectively.
- Exceptions
-
Definition at line 162 of file Signer.php.
References $config, $type, and array.
165 if (array_key_exists(
'metadata.sign.algorithm', $entityMetadata)) {
166 if (!is_string($entityMetadata[
'metadata.sign.algorithm'])) {
167 throw new \SimpleSAML\Error\CriticalConfigurationError(
168 "Invalid value for the 'metadata.sign.algorithm' configuration option for the ".
$type.
169 "'".$entityMetadata[
'entityid'].
"'. This option has restricted values" 172 $alg = $entityMetadata[
'metadata.sign.algorithm'];
174 $alg =
$config->getString(
'metadata.sign.algorithm', XMLSecurityKey::RSA_SHA1);
177 $supported_algs =
array(
178 XMLSecurityKey::RSA_SHA1,
179 XMLSecurityKey::RSA_SHA256,
180 XMLSecurityKey::RSA_SHA384,
181 XMLSecurityKey::RSA_SHA512,
184 if (!in_array($alg, $supported_algs,
true)) {
185 throw new \SimpleSAML\Error\CriticalConfigurationError(
"Unknown signature algorithm '$alg'");
189 case XMLSecurityKey::RSA_SHA256:
190 $digest = XMLSecurityDSig::SHA256;
192 case XMLSecurityKey::RSA_SHA384:
193 $digest = XMLSecurityDSig::SHA384;
195 case XMLSecurityKey::RSA_SHA512:
196 $digest = XMLSecurityDSig::SHA512;
199 $digest = XMLSecurityDSig::SHA1;
Create styles array
The data for the language used.
◆ isMetadataSigningEnabled()
static SimpleSAML_Metadata_Signer::isMetadataSigningEnabled |
( |
|
$config, |
|
|
|
$entityMetadata, |
|
|
|
$type |
|
) |
| |
|
staticprivate |
Determine whether metadata signing is enabled for the given metadata.
- Parameters
-
- Returns
- boolean True if metadata signing is enabled, false otherwise.
- Exceptions
-
Exception | If the value of the 'metadata.sign.enable' option is not a boolean. |
Definition at line 124 of file Signer.php.
References $config, and $type.
127 if (array_key_exists(
'metadata.sign.enable', $entityMetadata)) {
128 if (!is_bool($entityMetadata[
'metadata.sign.enable'])) {
130 'Invalid value for the "metadata.sign.enable" configuration option for'.
131 ' the '.
$type.
' "'.$entityMetadata[
'entityid'].
'". This option'.
132 ' should be a boolean.' 136 return $entityMetadata[
'metadata.sign.enable'];
139 $enabled =
$config->getBoolean(
'metadata.sign.enable',
false);
◆ sign()
static SimpleSAML_Metadata_Signer::sign |
( |
|
$metadataString, |
|
|
|
$entityMetadata, |
|
|
|
$type |
|
) |
| |
|
static |
Signs the given metadata if metadata signing is enabled.
- Parameters
-
string | $metadataString | A string with the metadata. |
array | $entityMetadata | The metadata of the entity. |
string | $type | A string which describes the type entity this is, e.g. 'SAML 2 IdP' or 'Shib 1.3 SP'. |
- Returns
- string The $metadataString with the signature embedded.
- Exceptions
-
Exception | If the certificate or private key cannot be loaded, or the metadata doesn't parse properly. |
Definition at line 219 of file Signer.php.
References $config, $type, $xml, array, SAML2\DOMDocumentFactory\fromString(), SimpleSAML\Utils\Config\getCertPath(), and SimpleSAML_Configuration\getInstance().
224 if (!self::isMetadataSigningEnabled(
$config, $entityMetadata,
$type)) {
225 return $metadataString;
229 $keyCertFiles = self::findKeyCert(
$config, $entityMetadata,
$type);
232 if (!file_exists($keyFile)) {
233 throw new Exception(
'Could not find private key file ['.$keyFile.
'], which is needed to sign the metadata');
235 $keyData = file_get_contents($keyFile);
238 if (!file_exists($certFile)) {
240 'Could not find certificate file ['.$certFile.
'], which is needed to sign the metadata' 243 $certData = file_get_contents($certFile);
250 throw new Exception(
'Error parsing self-generated metadata.');
253 $signature_cf = self::getMetadataSigningAlgorithm(
$config, $entityMetadata,
$type);
256 $objKey =
new XMLSecurityKey($signature_cf[
'algorithm'],
array(
'type' =>
'private'));
257 if (array_key_exists(
'privatekey_pass', $keyCertFiles)) {
258 $objKey->passphrase = $keyCertFiles[
'privatekey_pass'];
260 $objKey->loadKey($keyData,
false);
263 $rootNode =
$xml->firstChild;
266 if (
$type ==
'ADFS IdP') {
272 $objXMLSecDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
274 $objXMLSecDSig->addReferenceList(
276 $signature_cf[
'digest'],
277 array(
'http://www.w3.org/2000/09/xmldsig#enveloped-signature', XMLSecurityDSig::EXC_C14N),
278 array(
'id_name' =>
'ID')
281 $objXMLSecDSig->sign($objKey);
284 $objXMLSecDSig->add509Cert($certData,
true);
287 $objXMLSecDSig->insertSignature($rootNode, $rootNode->firstChild);
290 return $xml->saveXML();
Create styles array
The data for the language used.
static getCertPath($path)
Resolves a path that may be relative to the cert-directory.
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.
The documentation for this class was generated from the following file:
- libs/composer/vendor/simplesamlphp/simplesamlphp/lib/SimpleSAML/Metadata/Signer.php