|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the LightSAML-Core package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Milos Tomic <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the MIT license that is bundled |
|
9
|
|
|
* with this source code in the file LICENSE. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace LightSaml\Store\Credential; |
|
13
|
|
|
|
|
14
|
|
|
use LightSaml\Credential\CredentialInterface; |
|
15
|
|
|
use LightSaml\Credential\KeyHelper; |
|
16
|
|
|
use LightSaml\Credential\X509Certificate; |
|
17
|
|
|
use LightSaml\Credential\X509Credential; |
|
18
|
|
|
|
|
19
|
|
|
class X509FileCredentialStore implements CredentialStoreInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $entityId; |
|
23
|
|
|
|
|
24
|
|
|
/** @var string */ |
|
25
|
|
|
private $certificatePath; |
|
26
|
|
|
|
|
27
|
|
|
/** @var string */ |
|
28
|
|
|
private $keyPath; |
|
29
|
|
|
|
|
30
|
|
|
/** @var string */ |
|
31
|
|
|
private $password; |
|
32
|
|
|
|
|
33
|
|
|
/** @var X509Credential */ |
|
34
|
|
|
private $credential; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @param string $entityId |
|
38
|
|
|
* @param string $certificatePath |
|
39
|
|
|
* @param string $keyPath |
|
40
|
|
|
* @param string $password |
|
41
|
|
|
*/ |
|
42
|
|
|
public function __construct($entityId, $certificatePath, $keyPath, $password) |
|
43
|
|
|
{ |
|
44
|
|
|
$this->entityId = $entityId; |
|
45
|
|
|
$this->certificatePath = $certificatePath; |
|
46
|
|
|
$this->keyPath = $keyPath; |
|
47
|
|
|
$this->password = $password; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $entityId |
|
52
|
|
|
* |
|
53
|
|
|
* @return CredentialInterface[] |
|
54
|
|
|
*/ |
|
55
|
|
|
public function getByEntityId($entityId) |
|
56
|
|
|
{ |
|
57
|
|
|
if ($entityId != $this->entityId) { |
|
58
|
|
|
return []; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
if (null == $this->credential) { |
|
62
|
|
|
$certificate = X509Certificate::fromFile($this->certificatePath); |
|
63
|
|
|
$this->credential = new X509Credential( |
|
64
|
|
|
$certificate, |
|
65
|
|
|
KeyHelper::createPrivateKey($this->keyPath, $this->password, true, $certificate->getSignatureAlgorithm()) |
|
66
|
|
|
); |
|
67
|
|
|
$this->credential->setEntityId($this->entityId); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return [$this->credential]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|