ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
SAML2\Certificate\KeyLoader Class Reference

KeyLoader. More...

+ Collaboration diagram for SAML2\Certificate\KeyLoader:

Public Member Functions

 __construct ()
 
 loadKeysFromConfiguration (CertificateProvider $config, $usage=null, $required=false)
 
 loadKeys (array $configuredKeys, $usage)
 Loads the keys given, optionally excluding keys when a usage is given and they are not configured to be used with the usage given. More...
 
 loadCertificateData ($certificateData)
 Attempts to load a key based on the given certificateData. More...
 
 loadCertificateFile ($certificateFile)
 Loads the certificate in the file given. More...
 
 getKeys ()
 
 hasKeys ()
 

Static Public Member Functions

static extractPublicKeys (CertificateProvider $config, $usage=null, $required=false)
 Extracts the public keys given by the configuration. More...
 

Private Attributes

 $loadedKeys
 

Detailed Description

KeyLoader.

Definition at line 15 of file KeyLoader.php.

Constructor & Destructor Documentation

◆ __construct()

SAML2\Certificate\KeyLoader::__construct ( )

Definition at line 22 of file KeyLoader.php.

23 {
24 $this->loadedKeys = new KeyCollection();
25 }

Member Function Documentation

◆ extractPublicKeys()

static SAML2\Certificate\KeyLoader::extractPublicKeys ( CertificateProvider  $config,
  $usage = null,
  $required = false 
)
static

Extracts the public keys given by the configuration.

Mainly exists for BC purposes. Prioritisation order is keys > certData > certificate

Parameters
\SAML2\Configuration\CertificateProvider$config
null$usage
bool$required
Returns
\SAML2\Certificate\KeyCollection

Definition at line 37 of file KeyLoader.php.

41 {
42 $keyLoader = new self();
43
44 return $keyLoader->loadKeysFromConfiguration($config, $usage, $required);
45 }

References $config.

◆ getKeys()

SAML2\Certificate\KeyLoader::getKeys ( )
Returns
\SAML2\Certificate\KeyCollection

Definition at line 143 of file KeyLoader.php.

144 {
145 return $this->loadedKeys;
146 }

References SAML2\Certificate\KeyLoader\$loadedKeys.

Referenced by SAML2\Certificate\KeyLoader\loadKeysFromConfiguration().

+ Here is the caller graph for this function:

◆ hasKeys()

SAML2\Certificate\KeyLoader::hasKeys ( )
Returns
bool

Definition at line 151 of file KeyLoader.php.

152 {
153 return !!count($this->loadedKeys);
154 }

Referenced by SAML2\Certificate\KeyLoader\loadKeysFromConfiguration().

+ Here is the caller graph for this function:

◆ loadCertificateData()

SAML2\Certificate\KeyLoader::loadCertificateData (   $certificateData)

Attempts to load a key based on the given certificateData.

Parameters
string$certificateData

Definition at line 110 of file KeyLoader.php.

111 {
112 if (!is_string($certificateData)) {
113 throw InvalidArgumentException::invalidType('string', $certificateData);
114 }
115
116 $this->loadedKeys->add(X509::createFromCertificateData($certificateData));
117 }
static createFromCertificateData($certificateContents)
Definition: X509.php:15

References SAML2\Certificate\X509\createFromCertificateData(), and SAML2\Exception\InvalidArgumentException\invalidType().

Referenced by SAML2\Certificate\KeyLoader\loadKeysFromConfiguration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadCertificateFile()

SAML2\Certificate\KeyLoader::loadCertificateFile (   $certificateFile)

Loads the certificate in the file given.

Parameters
string$certificateFilethe full path to the cert file.

Definition at line 124 of file KeyLoader.php.

125 {
126 $certificate = File::getFileContents($certificateFile);
127
129 throw new InvalidCertificateStructureException(sprintf(
130 'Could not find PEM encoded certificate in "%s"',
131 $certificateFile
132 ));
133 }
134
135 // capture the certificate contents without the delimiters
136 preg_match(Certificate::CERTIFICATE_PATTERN, $certificate, $matches);
137 $this->loadedKeys->add(X509::createFromCertificateData($matches[1]));
138 }
sprintf('%.4f', $callTime)
static hasValidStructure($certificate)
Definition: Certificate.php:20
const CERTIFICATE_PATTERN
The pattern that the contents of a certificate should adhere to.
Definition: Certificate.php:13
static getFileContents($file)
Definition: File.php:18
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77

References $certificate, SAML2\Utilities\Certificate\CERTIFICATE_PATTERN, SAML2\Certificate\X509\createFromCertificateData(), SAML2\Utilities\File\getFileContents(), SAML2\Utilities\Certificate\hasValidStructure(), and sprintf.

Referenced by SAML2\Certificate\KeyLoader\loadKeysFromConfiguration().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ loadKeys()

SAML2\Certificate\KeyLoader::loadKeys ( array  $configuredKeys,
  $usage 
)

Loads the keys given, optionally excluding keys when a usage is given and they are not configured to be used with the usage given.

Parameters
array$configuredKeys
$usage

Definition at line 88 of file KeyLoader.php.

89 {
90 foreach ($configuredKeys as $keyData) {
91 if (isset($keyData['X509Certificate'])) {
92 $key = new X509($keyData);
93 } else {
94 $key = new Key($keyData);
95 }
96
97 if ($usage && !$key->canBeUsedFor($usage)) {
98 continue;
99 }
100
101 $this->loadedKeys->add($key);
102 }
103 }
$key
Definition: croninfo.php:18

References $key.

Referenced by SAML2\Certificate\KeyLoader\loadKeysFromConfiguration().

+ Here is the caller graph for this function:

◆ loadKeysFromConfiguration()

SAML2\Certificate\KeyLoader::loadKeysFromConfiguration ( CertificateProvider  $config,
  $usage = null,
  $required = false 
)
Parameters
\SAML2\Configuration\CertificateProvider$config
null | string$usage
bool$required
Returns
\SAML2\Certificate\KeyCollection

Definition at line 54 of file KeyLoader.php.

58 {
59 $keys = $config->getKeys();
60 $certificateData = $config->getCertificateData();
61 $certificateFile = $config->getCertificateFile();
62
63 if ($keys !== null) {
64 $this->loadKeys($keys, $usage);
65 } elseif ($certificateData !== null) {
66 $this->loadCertificateData($certificateData);
67 } elseif ($certificateFile !== null) {
68 $this->loadCertificateFile($certificateFile);
69 }
70
71 if ($required && !$this->hasKeys()) {
72 throw new NoKeysFoundException(
73 'No keys found in configured metadata, please ensure that either the "keys", "certData" or '
74 . '"certificate" entries is available.'
75 );
76 }
77
78 return $this->getKeys();
79 }
loadCertificateFile($certificateFile)
Loads the certificate in the file given.
Definition: KeyLoader.php:124
loadKeys(array $configuredKeys, $usage)
Loads the keys given, optionally excluding keys when a usage is given and they are not configured to ...
Definition: KeyLoader.php:88
loadCertificateData($certificateData)
Attempts to load a key based on the given certificateData.
Definition: KeyLoader.php:110
$keys

References $config, $keys, SAML2\Certificate\KeyLoader\getKeys(), SAML2\Certificate\KeyLoader\hasKeys(), SAML2\Certificate\KeyLoader\loadCertificateData(), SAML2\Certificate\KeyLoader\loadCertificateFile(), and SAML2\Certificate\KeyLoader\loadKeys().

+ Here is the call graph for this function:

Field Documentation

◆ $loadedKeys

SAML2\Certificate\KeyLoader::$loadedKeys
private

Definition at line 20 of file KeyLoader.php.

Referenced by SAML2\Certificate\KeyLoader\getKeys().


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