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'].
'".' 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);
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;
219 public static function sign($metadataString, $entityMetadata,
$type)
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();
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
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.