ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SAML2\SignedElementHelper Class Reference
+ Inheritance diagram for SAML2\SignedElementHelper:
+ Collaboration diagram for SAML2\SignedElementHelper:

Public Member Functions

 addValidator ($function, $data)
 Add a method for validating this element. More...
 
 validate (XMLSecurityKey $key)
 Validate this element against a public key. More...
 
 getSignatureKey ()
 Retrieve the private key we should use to sign the message. More...
 
 setSignatureKey (XMLSecurityKey $signatureKey=null)
 Set the private key we should use to sign the message. More...
 
 setCertificates (array $certificates)
 Set the certificates that should be included in the message. More...
 
 getCertificates ()
 Retrieve the certificates that are included in the message. More...
 
 getValidatingCertificates ()
 Retrieve certificates that sign this element. More...
 

Protected Member Functions

 __construct (\DOMElement $xml=null)
 Initialize the helper class. More...
 
 signElement (\DOMElement $root, \DOMElement $insertBefore=null)
 Sign the given XML element. More...
 

Private Attributes

 $signatureKey
 
 $certificates
 
 $validators
 

Detailed Description

Definition at line 14 of file SignedElementHelper.php.

Constructor & Destructor Documentation

◆ __construct()

SAML2\SignedElementHelper::__construct ( \DOMElement  $xml = null)
protected

Initialize the helper class.

Parameters
\DOMElement | null$xmlThe XML element which may be signed.

Definition at line 44 of file SignedElementHelper.php.

References $xml, and array.

45  {
46  $this->certificates = array();
47  $this->validators = array();
48 
49  if ($xml === null) {
50  return;
51  }
52 
53  /* Validate the signature element of the message. */
54  try {
55  $sig = Utils::validateElement($xml);
56 
57  if ($sig !== false) {
58  $this->certificates = $sig['Certificates'];
59  $this->validators[] = array(
60  'Function' => array('\SAML2\Utils', 'validateSignature'),
61  'Data' => $sig,
62  );
63  }
64  } catch (\Exception $e) {
65  /* Ignore signature validation errors. */
66  }
67  }
$xml
Definition: metadata.php:240
Create styles array
The data for the language used.

Member Function Documentation

◆ addValidator()

SAML2\SignedElementHelper::addValidator (   $function,
  $data 
)

Add a method for validating this element.

This function is used for custom validation extensions

Parameters
callback$functionThe function which should be called.
mixed$dataThe data that should be included as the first parameter to the function.

Definition at line 77 of file SignedElementHelper.php.

References $data, $function, and array.

78  {
79  assert(is_callable($function));
80 
81  $this->validators[] = array(
82  'Function' => $function,
83  'Data' => $data,
84  );
85  }
Create styles array
The data for the language used.
$function
Definition: cas.php:28

◆ getCertificates()

SAML2\SignedElementHelper::getCertificates ( )

Retrieve the certificates that are included in the message.

Returns
array An array of certificates.

Implements SAML2\SignedElement.

Definition at line 163 of file SignedElementHelper.php.

References $certificates.

164  {
165  return $this->certificates;
166  }

◆ getSignatureKey()

SAML2\SignedElementHelper::getSignatureKey ( )

Retrieve the private key we should use to sign the message.

Returns
XMLSecurityKey|null The key, or NULL if no key is specified.

Implements SAML2\SignedElement.

Definition at line 129 of file SignedElementHelper.php.

130  {
131  return $this->signatureKey;
132  }

◆ getValidatingCertificates()

SAML2\SignedElementHelper::getValidatingCertificates ( )

Retrieve certificates that sign this element.

Returns
array Array with certificates.

Definition at line 173 of file SignedElementHelper.php.

References $key, $ret, and array.

174  {
175  $ret = array();
176  foreach ($this->certificates as $cert) {
177 
178  /* Construct a PEM formatted certificate */
179  $pemCert = "-----BEGIN CERTIFICATE-----\n" .
180  chunk_split($cert, 64) .
181  "-----END CERTIFICATE-----\n";
182 
183  /* Extract the public key from the certificate for validation. */
184  $key = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type'=>'public'));
185  $key->loadKey($pemCert);
186 
187  try {
188  /* Check the signature. */
189  if ($this->validate($key)) {
190  $ret[] = $cert;
191  }
192  } catch (\Exception $e) {
193  /* This certificate does not sign this element. */
194  }
195  }
196 
197  return $ret;
198  }
validate(XMLSecurityKey $key)
Validate this element against a public key.
Create styles array
The data for the language used.
$ret
Definition: parser.php:6
$key
Definition: croninfo.php:18

◆ setCertificates()

SAML2\SignedElementHelper::setCertificates ( array  $certificates)

Set the certificates that should be included in the message.

The certificates should be strings with the PEM encoded data.

Parameters
array$certificatesAn array of certificates.

Implements SAML2\SignedElement.

Definition at line 153 of file SignedElementHelper.php.

References $certificates.

154  {
155  $this->certificates = $certificates;
156  }

◆ setSignatureKey()

SAML2\SignedElementHelper::setSignatureKey ( XMLSecurityKey  $signatureKey = null)

Set the private key we should use to sign the message.

If the key is null, the message will be sent unsigned.

Parameters
XMLSecurityKey | null$signatureKey

Implements SAML2\SignedElement.

Definition at line 141 of file SignedElementHelper.php.

142  {
143  $this->signatureKey = $signatureKey;
144  }

◆ signElement()

SAML2\SignedElementHelper::signElement ( \DOMElement  $root,
\DOMElement  $insertBefore = null 
)
protected

Sign the given XML element.

Parameters
\DOMElement$rootThe element we should sign.
\DOMElement | null$insertBeforeThe element we should insert the signature node before.
Returns
|null

Definition at line 207 of file SignedElementHelper.php.

Referenced by SAML2\XML\md\EntitiesDescriptor\__construct(), SAML2\XML\md\EntityDescriptor\__construct(), and SAML2\XML\md\AffiliationDescriptor\toXML().

208  {
209  if ($this->signatureKey === null) {
210  /* We cannot sign this element. */
211 
212  return null;
213  }
214 
215  Utils::insertSignature($this->signatureKey, $this->certificates, $root, $insertBefore);
216 
217  return $root;
218  }
static insertSignature(XMLSecurityKey $key, array $certificates, \DOMElement $root, \DOMNode $insertBefore=null)
Insert a Signature-node.
Definition: Utils.php:364
+ Here is the caller graph for this function:

◆ validate()

SAML2\SignedElementHelper::validate ( XMLSecurityKey  $key)

Validate this element against a public key.

true is returned on success, false is returned if we don't have any signature we can validate. An exception is thrown if the signature validation fails.

Parameters
XMLSecurityKey$keyThe key we should check against.
Returns
boolean true on success, false when we don't have a signature.
Exceptions

Implements SAML2\SignedElement.

Definition at line 98 of file SignedElementHelper.php.

References $data, $exceptions, $function, and array.

99  {
100  if (count($this->validators) === 0) {
101  return false;
102  }
103 
104  $exceptions = array();
105 
106  foreach ($this->validators as $validator) {
107  $function = $validator['Function'];
108  $data = $validator['Data'];
109 
110  try {
111  call_user_func($function, $data, $key);
112  /* We were able to validate the message with this validator. */
113 
114  return true;
115  } catch (\Exception $e) {
116  $exceptions[] = $e;
117  }
118  }
119 
120  /* No validators were able to validate the message. */
121  throw $exceptions[0];
122  }
Create styles array
The data for the language used.
$function
Definition: cas.php:28
$exceptions
Definition: Utf8Test.php:67
$key
Definition: croninfo.php:18

Field Documentation

◆ $certificates

SAML2\SignedElementHelper::$certificates
private

Definition at line 30 of file SignedElementHelper.php.

◆ $signatureKey

SAML2\SignedElementHelper::$signatureKey
private

Definition at line 23 of file SignedElementHelper.php.

◆ $validators

SAML2\SignedElementHelper::$validators
private

Definition at line 37 of file SignedElementHelper.php.


The documentation for this class was generated from the following file: