1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace EasyRSA; |
6
|
|
|
|
7
|
|
|
use EasyRSA\Interfaces\CommandsInterface; |
8
|
|
|
|
9
|
|
|
class Commands extends Worker implements CommandsInterface |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* If need to make certificate without password |
13
|
|
|
*/ |
14
|
|
|
protected const NOPASS = 'nopass'; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Instantiate Public Key Infrastructure (PKI) |
18
|
|
|
* |
19
|
|
|
* @return array<string> |
20
|
|
|
*/ |
21
|
|
|
public function initPKI(): array |
22
|
|
|
{ |
23
|
|
|
return $this->exec('init-pki'); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Build Certificate Authority (CA) |
28
|
|
|
* |
29
|
|
|
* @param bool $nopass |
30
|
|
|
* |
31
|
|
|
* @return array<string> |
32
|
|
|
*/ |
33
|
|
|
public function buildCA(bool $nopass = false): array |
34
|
|
|
{ |
35
|
|
|
$param = $nopass ? self::NOPASS : ''; |
36
|
|
|
|
37
|
|
|
return $this->exec("build-ca $param"); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Generate Diffie-Hellman certificate (DH) |
42
|
|
|
* |
43
|
|
|
* @return array<string> |
44
|
|
|
*/ |
45
|
|
|
public function genDH(): array |
46
|
|
|
{ |
47
|
|
|
return $this->exec('gen-dh'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Generate request for certificate |
52
|
|
|
* |
53
|
|
|
* @param string $name |
54
|
|
|
* @param bool $nopass |
55
|
|
|
* |
56
|
|
|
* @return array<string> |
57
|
|
|
*/ |
58
|
|
|
public function genReq(string $name, bool $nopass = false): array |
59
|
|
|
{ |
60
|
|
|
$param = $nopass ? self::NOPASS : ''; |
61
|
|
|
|
62
|
|
|
return $this->exec("gen-req $name $param"); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Sign request for client certificate |
67
|
|
|
* |
68
|
|
|
* @param string $filename |
69
|
|
|
* |
70
|
|
|
* @return array<string> |
71
|
|
|
*/ |
72
|
|
|
public function signReqClient(string $filename): array |
73
|
|
|
{ |
74
|
|
|
return $this->exec("sign-req client $filename"); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* Sign request for server certificate |
79
|
|
|
* |
80
|
|
|
* @param string $filename |
81
|
|
|
* |
82
|
|
|
* @return array<string> |
83
|
|
|
*/ |
84
|
|
|
public function signReqServer(string $filename): array |
85
|
|
|
{ |
86
|
|
|
return $this->exec("sign-req server $filename"); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
/** |
90
|
|
|
* Build public and private key of client |
91
|
|
|
* |
92
|
|
|
* @param string $name |
93
|
|
|
* @param bool $nopass |
94
|
|
|
* |
95
|
|
|
* @return array<string> |
96
|
|
|
*/ |
97
|
|
|
public function buildClientFull(string $name, bool $nopass = false): array |
98
|
|
|
{ |
99
|
|
|
$param = $nopass ? self::NOPASS : ''; |
100
|
|
|
|
101
|
|
|
return $this->exec("build-client-full $name $param"); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Build public and private key of client |
106
|
|
|
* |
107
|
|
|
* @param string $name |
108
|
|
|
* @param bool $nopass |
109
|
|
|
* |
110
|
|
|
* @return array<string> |
111
|
|
|
*/ |
112
|
|
|
public function buildServerFull(string $name, bool $nopass = false): array |
113
|
|
|
{ |
114
|
|
|
$param = $nopass ? self::NOPASS : ''; |
115
|
|
|
|
116
|
|
|
return $this->exec("build-server-full $name $param"); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Revoke certificate |
121
|
|
|
* |
122
|
|
|
* @param string $filename |
123
|
|
|
* |
124
|
|
|
* @return array<string> |
125
|
|
|
*/ |
126
|
|
|
public function revoke(string $filename): array |
127
|
|
|
{ |
128
|
|
|
return $this->exec("revoke $filename"); |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Generate Certificate Revocation List (CRL) |
133
|
|
|
* |
134
|
|
|
* @return array<string> |
135
|
|
|
*/ |
136
|
|
|
public function genCRL(): array |
137
|
|
|
{ |
138
|
|
|
return $this->exec('gen-crl'); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
/** |
142
|
|
|
* Update certificates database |
143
|
|
|
* |
144
|
|
|
* @return array<string> |
145
|
|
|
*/ |
146
|
|
|
public function updateDB(): array |
147
|
|
|
{ |
148
|
|
|
return $this->exec('update-db'); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Display information about certificate |
153
|
|
|
* |
154
|
|
|
* @param string $filename |
155
|
|
|
* |
156
|
|
|
* @return array<string> |
157
|
|
|
*/ |
158
|
|
|
public function showCert(string $filename): array |
159
|
|
|
{ |
160
|
|
|
return $this->exec("show-cert $filename"); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
/** |
164
|
|
|
* Display information about request |
165
|
|
|
* |
166
|
|
|
* @param string $filename |
167
|
|
|
* |
168
|
|
|
* @return array<string> |
169
|
|
|
*/ |
170
|
|
|
public function showReq(string $filename): array |
171
|
|
|
{ |
172
|
|
|
return $this->exec("show-req $filename"); |
173
|
|
|
} |
174
|
|
|
|
175
|
|
|
/** |
176
|
|
|
* Import request |
177
|
|
|
* |
178
|
|
|
* @param string $filename |
179
|
|
|
* @param string $short_basename |
180
|
|
|
* |
181
|
|
|
* @return array<string> |
182
|
|
|
*/ |
183
|
|
|
public function importReq(string $filename, string $short_basename): array |
184
|
|
|
{ |
185
|
|
|
return $this->exec("import-req $filename $short_basename"); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* Export file in format of Public-Key Cryptography Standards (PKCS) v7 (P7) |
190
|
|
|
* |
191
|
|
|
* @param string $filename |
192
|
|
|
* |
193
|
|
|
* @return array<string> |
194
|
|
|
*/ |
195
|
|
|
public function exportP7(string $filename): array |
196
|
|
|
{ |
197
|
|
|
return $this->exec("export-p7 $filename"); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Export file in format of Public-Key Cryptography Standards (PKCS) v12 (P12) |
202
|
|
|
* |
203
|
|
|
* @param string $filename |
204
|
|
|
* |
205
|
|
|
* @return array<string> |
206
|
|
|
*/ |
207
|
|
|
public function exportP12(string $filename): array |
208
|
|
|
{ |
209
|
|
|
return $this->exec("export-p12 $filename"); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
/** |
213
|
|
|
* Set password in Rivest–Shamir–Adleman (RSA) format |
214
|
|
|
* |
215
|
|
|
* @param string $filename |
216
|
|
|
* |
217
|
|
|
* @return array<string> |
218
|
|
|
*/ |
219
|
|
|
public function setRSAPass(string $filename): array |
220
|
|
|
{ |
221
|
|
|
return $this->exec("set-rsa-pass $filename"); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
/** |
225
|
|
|
* Set password in Elliptic Curve (EC) format |
226
|
|
|
* |
227
|
|
|
* @param string $filename |
228
|
|
|
* |
229
|
|
|
* @return array<string> |
230
|
|
|
*/ |
231
|
|
|
public function setECPass(string $filename): array |
232
|
|
|
{ |
233
|
|
|
return $this->exec("set-ec-pass $filename"); |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|