|
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, and $type.
28 if (array_key_exists(
'metadata.sign.privatekey', $entityMetadata)
29 || array_key_exists(
'metadata.sign.certificate', $entityMetadata)
31 if (!array_key_exists(
'metadata.sign.privatekey', $entityMetadata)
32 || !array_key_exists(
'metadata.sign.certificate', $entityMetadata)
35 'Missing either the "metadata.sign.privatekey" or the'.
36 ' "metadata.sign.certificate" configuration option in the metadata for'.
37 ' the '.
$type.
' "'.$entityMetadata[
'entityid'].
'". If one of'.
38 ' these options is specified, then the other must also be specified.' 43 'privatekey' => $entityMetadata[
'metadata.sign.privatekey'],
44 'certificate' => $entityMetadata[
'metadata.sign.certificate']
47 if (array_key_exists(
'metadata.sign.privatekey_pass', $entityMetadata)) {
48 $ret[
'privatekey_pass'] = $entityMetadata[
'metadata.sign.privatekey_pass'];
55 $privatekey =
$config->getString(
'metadata.sign.privatekey', null);
60 'Missing either the "metadata.sign.privatekey" or the'.
61 ' "metadata.sign.certificate" configuration option in the global'.
62 ' configuration. If one of these options is specified, then the other'.
63 ' must also be specified.' 68 $privatekey_pass =
$config->getString(
'metadata.sign.privatekey_pass', null);
69 if ($privatekey_pass !== null) {
70 $ret[
'privatekey_pass'] = $privatekey_pass;
77 if (array_key_exists(
'privatekey', $entityMetadata)
78 || array_key_exists(
'certificate', $entityMetadata)
80 if (!array_key_exists(
'privatekey', $entityMetadata)
81 || !array_key_exists(
'certificate', $entityMetadata)
84 'Both the "privatekey" and the "certificate" option must'.
85 ' be set in the metadata for the '.
$type.
' "'.
86 $entityMetadata[
'entityid'].
'" before it is possible to sign metadata'.
92 'privatekey' => $entityMetadata[
'privatekey'],
93 'certificate' => $entityMetadata[
'certificate']
96 if (array_key_exists(
'privatekey_pass', $entityMetadata)) {
97 $ret[
'privatekey_pass'] = $entityMetadata[
'privatekey_pass'];
104 'Could not find what key & certificate should be used to sign the metadata'.
105 ' for the '.
$type.
' "'.$entityMetadata[
'entityid'].
'".'
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
◆ 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 157 of file Signer.php.
References $config, and $type.
160 if (array_key_exists(
'metadata.sign.algorithm', $entityMetadata)) {
161 if (!is_string($entityMetadata[
'metadata.sign.algorithm'])) {
162 throw new \SimpleSAML\Error\CriticalConfigurationError(
163 "Invalid value for the 'metadata.sign.algorithm' configuration option for the ".
$type.
164 "'".$entityMetadata[
'entityid'].
"'. This option has restricted values" 167 $alg = $entityMetadata[
'metadata.sign.algorithm'];
169 $alg =
$config->getString(
'metadata.sign.algorithm', XMLSecurityKey::RSA_SHA256);
172 $supported_algs = array(
173 XMLSecurityKey::RSA_SHA1,
174 XMLSecurityKey::RSA_SHA256,
175 XMLSecurityKey::RSA_SHA384,
176 XMLSecurityKey::RSA_SHA512,
179 if (!in_array($alg, $supported_algs,
true)) {
180 throw new \SimpleSAML\Error\CriticalConfigurationError(
"Unknown signature algorithm '$alg'");
184 case XMLSecurityKey::RSA_SHA256:
185 $digest = XMLSecurityDSig::SHA256;
187 case XMLSecurityKey::RSA_SHA384:
188 $digest = XMLSecurityDSig::SHA384;
190 case XMLSecurityKey::RSA_SHA512:
191 $digest = XMLSecurityDSig::SHA512;
194 $digest = XMLSecurityDSig::SHA1;
◆ 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 121 of file Signer.php.
References $config, and $type.
124 if (array_key_exists(
'metadata.sign.enable', $entityMetadata)) {
125 if (!is_bool($entityMetadata[
'metadata.sign.enable'])) {
127 'Invalid value for the "metadata.sign.enable" configuration option for'.
128 ' the '.
$type.
' "'.$entityMetadata[
'entityid'].
'". This option'.
129 ' should be a boolean.' 133 return $entityMetadata[
'metadata.sign.enable'];
136 $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 214 of file Signer.php.
References $config, $type, $xml, SAML2\DOMDocumentFactory\fromString(), SimpleSAML\Utils\Config\getCertPath(), and SimpleSAML_Configuration\getInstance().
219 if (!self::isMetadataSigningEnabled(
$config, $entityMetadata,
$type)) {
220 return $metadataString;
224 $keyCertFiles = self::findKeyCert(
$config, $entityMetadata,
$type);
227 if (!file_exists($keyFile)) {
228 throw new Exception(
'Could not find private key file ['.$keyFile.
'], which is needed to sign the metadata');
230 $keyData = file_get_contents($keyFile);
233 if (!file_exists($certFile)) {
235 'Could not find certificate file ['.$certFile.
'], which is needed to sign the metadata' 238 $certData = file_get_contents($certFile);
245 throw new Exception(
'Error parsing self-generated metadata.');
248 $signature_cf = self::getMetadataSigningAlgorithm(
$config, $entityMetadata,
$type);
251 $objKey =
new XMLSecurityKey($signature_cf[
'algorithm'], array(
'type' =>
'private'));
252 if (array_key_exists(
'privatekey_pass', $keyCertFiles)) {
253 $objKey->passphrase = $keyCertFiles[
'privatekey_pass'];
255 $objKey->loadKey($keyData,
false);
258 $rootNode =
$xml->firstChild;
261 $objXMLSecDSig =
new XMLSecurityDSig();
263 $objXMLSecDSig->setCanonicalMethod(XMLSecurityDSig::EXC_C14N);
265 $objXMLSecDSig->addReferenceList(
267 $signature_cf[
'digest'],
268 array(
'http://www.w3.org/2000/09/xmldsig#enveloped-signature', XMLSecurityDSig::EXC_C14N),
269 array(
'id_name' =>
'ID')
272 $objXMLSecDSig->sign($objKey);
275 $objXMLSecDSig->add509Cert($certData,
true);
278 $objXMLSecDSig->insertSignature($rootNode, $rootNode->firstChild);
281 return $xml->saveXML();
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