ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FingerprintValidator.php
Go to the documentation of this file.
1<?php
2
3namespace SAML2\Signature;
4
10
17{
22
27
31 public function __construct(
34 ) {
35 $this->fingerprintLoader = $fingerprintLoader;
36
37 parent::__construct($logger);
38 }
39
40 public function canValidate(
41 SignedElement $signedElement,
42 CertificateProvider $configuration
43 ) {
44 if ($configuration->getCertificateFingerprints() === null) {
45 $this->logger->debug(
46 'Configuration does not have "certFingerprint" value, cannot validate signature with fingerprint'
47 );
48 return false;
49 }
50
51 // use internal cache to prevent doing certificate extraction twice.
52 $this->certificates = $signedElement->getCertificates();
53 if (empty($this->certificates)) {
54 $this->logger->debug(
55 'Signed element does not have certificates, cannot validate signature with fingerprint'
56 );
57 return false;
58 }
59
60 return true;
61 }
62
69 public function hasValidSignature(
70 SignedElement $signedElement,
71 CertificateProvider $configuration
72 ) {
73 $this->certificates = array_map(function ($certificate) {
76
77 $fingerprintCollection = $this->fingerprintLoader->loadFromConfiguration($configuration);
78
79 $pemCandidates = array();
80 foreach ($this->certificates as $certificate) {
82 $certificateFingerprint = $certificate->getFingerprint();
83 if ($fingerprintCollection->contains($certificateFingerprint)) {
84 $pemCandidates[] = $certificate;
85 }
86 }
87
88 if (empty($pemCandidates)) {
89 $this->logger->debug(
90 'Unable to match a certificate of the SignedElement matching a configured fingerprint'
91 );
92
93 return false;
94 }
95
96 return $this->validateElementWithKeys($signedElement, $pemCandidates);
97 }
98}
An exception for terminatinating execution or to throw for unit testing.
Specific Certificate Key.
Definition: X509.php:9
static createFromCertificateData($certificateContents)
Definition: X509.php:15
validateElementWithKeys(SignedElement $element, $pemCandidates)
BC compatible version of the signature check.
Validates the signature based on the fingerprint of the certificate.
canValidate(SignedElement $signedElement, CertificateProvider $configuration)
Test whether or not this link in the chain can validate the signedElement signature.
__construct(LoggerInterface $logger, FingerprintLoader $fingerprintLoader)
if(@file_exists(dirname(__FILE__).'/lang/eng.php')) $certificate
Definition: example_052.php:77
Describes a logger instance.
getCertificateFingerprints()
Returns an array or \Traversable where each element represents a certificate fingerprint.
hasValidSignature(SignedElement $signedElement, CertificateProvider $configuration)
Validate the signature of the signed Element based on the configuration.
getCertificates()
Retrieve the certificates that are included in the element (if any).