1--TEST--
2openssl_x509_parse() tests
3--EXTENSIONS--
4openssl
5--SKIPIF--
6<?php
7if (OPENSSL_VERSION_NUMBER >= 0x30200000) die('skip For OpenSSL < 3.2');
8?>
9--FILE--
10<?php
11$cert = "file://" . __DIR__ . "/cert.crt";
12
13$parsedCert = openssl_x509_parse($cert);
14var_dump($parsedCert === openssl_x509_parse(openssl_x509_read($cert)));
15var_dump($parsedCert);
16var_dump(openssl_x509_parse($cert, false));
17?>
18--EXPECTF--
19bool(true)
20array(16) {
21  ["name"]=>
22  string(96) "/C=BR/ST=Rio Grande do Sul/L=Porto Alegre/CN=Henrique do N. Angelo/emailAddress=hnangelo@php.net"
23  ["subject"]=>
24  array(5) {
25    ["C"]=>
26    string(2) "BR"
27    ["ST"]=>
28    string(17) "Rio Grande do Sul"
29    ["L"]=>
30    string(12) "Porto Alegre"
31    ["CN"]=>
32    string(21) "Henrique do N. Angelo"
33    ["emailAddress"]=>
34    string(16) "hnangelo@php.net"
35  }
36  ["hash"]=>
37  string(8) "%s"
38  ["issuer"]=>
39  array(5) {
40    ["C"]=>
41    string(2) "BR"
42    ["ST"]=>
43    string(17) "Rio Grande do Sul"
44    ["L"]=>
45    string(12) "Porto Alegre"
46    ["CN"]=>
47    string(21) "Henrique do N. Angelo"
48    ["emailAddress"]=>
49    string(16) "hnangelo@php.net"
50  }
51  ["version"]=>
52  int(2)
53  ["serialNumber"]=>
54  string(20) "12593567369101004962"
55  ["serialNumberHex"]=>
56  string(16) "AEC556CC723750A2"
57  ["validFrom"]=>
58  string(13) "080630102843Z"
59  ["validTo"]=>
60  string(13) "080730102843Z"
61  ["validFrom_time_t"]=>
62  int(1214821723)
63  ["validTo_time_t"]=>
64  int(1217413723)
65  ["signatureTypeSN"]=>
66  string(8) "RSA-SHA1"
67  ["signatureTypeLN"]=>
68  string(21) "sha1WithRSAEncryption"
69  ["signatureTypeNID"]=>
70  int(65)
71  ["purposes"]=>
72  array(9) {
73    [1]=>
74    array(3) {
75      [0]=>
76      bool(true)
77      [1]=>
78      bool(true)
79      [2]=>
80      string(9) "sslclient"
81    }
82    [2]=>
83    array(3) {
84      [0]=>
85      bool(true)
86      [1]=>
87      bool(true)
88      [2]=>
89      string(9) "sslserver"
90    }
91    [3]=>
92    array(3) {
93      [0]=>
94      bool(true)
95      [1]=>
96      bool(true)
97      [2]=>
98      string(11) "nssslserver"
99    }
100    [4]=>
101    array(3) {
102      [0]=>
103      bool(true)
104      [1]=>
105      bool(true)
106      [2]=>
107      string(9) "smimesign"
108    }
109    [5]=>
110    array(3) {
111      [0]=>
112      bool(true)
113      [1]=>
114      bool(true)
115      [2]=>
116      string(12) "smimeencrypt"
117    }
118    [6]=>
119    array(3) {
120      [0]=>
121      bool(true)
122      [1]=>
123      bool(true)
124      [2]=>
125      string(7) "crlsign"
126    }
127    [7]=>
128    array(3) {
129      [0]=>
130      bool(true)
131      [1]=>
132      bool(true)
133      [2]=>
134      string(3) "any"
135    }
136    [8]=>
137    array(3) {
138      [0]=>
139      bool(true)
140      [1]=>
141      bool(true)
142      [2]=>
143      string(10) "ocsphelper"
144    }
145    [9]=>
146    array(3) {
147      [0]=>
148      bool(false)
149      [1]=>
150      bool(true)
151      [2]=>
152      string(13) "timestampsign"
153    }
154  }
155  ["extensions"]=>
156  array(3) {
157    ["subjectKeyIdentifier"]=>
158    string(59) "DB:7E:40:72:BD:5C:35:85:EC:29:29:81:12:E8:62:68:6A:B7:3F:7D"
159    ["authorityKeyIdentifier"]=>
160    string(%d) "keyid:DB:7E:40:72:BD:5C:35:85:EC:29:29:81:12:E8:62:68:6A:B7:3F:7D
161DirName:/C=BR/ST=Rio Grande do Sul/L=Porto Alegre/CN=Henrique do N. Angelo/emailAddress=hnangelo@php.net
162serial:AE:C5:56:CC:72:37:50:A2%A"
163    ["basicConstraints"]=>
164    string(7) "CA:TRUE"
165  }
166}
167array(16) {
168  ["name"]=>
169  string(96) "/C=BR/ST=Rio Grande do Sul/L=Porto Alegre/CN=Henrique do N. Angelo/emailAddress=hnangelo@php.net"
170  ["subject"]=>
171  array(5) {
172    ["countryName"]=>
173    string(2) "BR"
174    ["stateOrProvinceName"]=>
175    string(17) "Rio Grande do Sul"
176    ["localityName"]=>
177    string(12) "Porto Alegre"
178    ["commonName"]=>
179    string(21) "Henrique do N. Angelo"
180    ["emailAddress"]=>
181    string(16) "hnangelo@php.net"
182  }
183  ["hash"]=>
184  string(8) "%s"
185  ["issuer"]=>
186  array(5) {
187    ["countryName"]=>
188    string(2) "BR"
189    ["stateOrProvinceName"]=>
190    string(17) "Rio Grande do Sul"
191    ["localityName"]=>
192    string(12) "Porto Alegre"
193    ["commonName"]=>
194    string(21) "Henrique do N. Angelo"
195    ["emailAddress"]=>
196    string(16) "hnangelo@php.net"
197  }
198  ["version"]=>
199  int(2)
200  ["serialNumber"]=>
201  string(20) "12593567369101004962"
202  ["serialNumberHex"]=>
203  string(16) "AEC556CC723750A2"
204  ["validFrom"]=>
205  string(13) "080630102843Z"
206  ["validTo"]=>
207  string(13) "080730102843Z"
208  ["validFrom_time_t"]=>
209  int(1214821723)
210  ["validTo_time_t"]=>
211  int(1217413723)
212  ["signatureTypeSN"]=>
213  string(8) "RSA-SHA1"
214  ["signatureTypeLN"]=>
215  string(21) "sha1WithRSAEncryption"
216  ["signatureTypeNID"]=>
217  int(65)
218  ["purposes"]=>
219  array(9) {
220    [1]=>
221    array(3) {
222      [0]=>
223      bool(true)
224      [1]=>
225      bool(true)
226      [2]=>
227      string(10) "SSL client"
228    }
229    [2]=>
230    array(3) {
231      [0]=>
232      bool(true)
233      [1]=>
234      bool(true)
235      [2]=>
236      string(10) "SSL server"
237    }
238    [3]=>
239    array(3) {
240      [0]=>
241      bool(true)
242      [1]=>
243      bool(true)
244      [2]=>
245      string(19) "Netscape SSL server"
246    }
247    [4]=>
248    array(3) {
249      [0]=>
250      bool(true)
251      [1]=>
252      bool(true)
253      [2]=>
254      string(14) "S/MIME signing"
255    }
256    [5]=>
257    array(3) {
258      [0]=>
259      bool(true)
260      [1]=>
261      bool(true)
262      [2]=>
263      string(17) "S/MIME encryption"
264    }
265    [6]=>
266    array(3) {
267      [0]=>
268      bool(true)
269      [1]=>
270      bool(true)
271      [2]=>
272      string(11) "CRL signing"
273    }
274    [7]=>
275    array(3) {
276      [0]=>
277      bool(true)
278      [1]=>
279      bool(true)
280      [2]=>
281      string(11) "Any Purpose"
282    }
283    [8]=>
284    array(3) {
285      [0]=>
286      bool(true)
287      [1]=>
288      bool(true)
289      [2]=>
290      string(11) "OCSP helper"
291    }
292    [9]=>
293    array(3) {
294      [0]=>
295      bool(false)
296      [1]=>
297      bool(true)
298      [2]=>
299      string(18) "Time Stamp signing"
300    }
301  }
302  ["extensions"]=>
303  array(3) {
304    ["subjectKeyIdentifier"]=>
305    string(59) "DB:7E:40:72:BD:5C:35:85:EC:29:29:81:12:E8:62:68:6A:B7:3F:7D"
306    ["authorityKeyIdentifier"]=>
307    string(%d) "keyid:DB:7E:40:72:BD:5C:35:85:EC:29:29:81:12:E8:62:68:6A:B7:3F:7D
308DirName:/C=BR/ST=Rio Grande do Sul/L=Porto Alegre/CN=Henrique do N. Angelo/emailAddress=hnangelo@php.net
309serial:AE:C5:56:CC:72:37:50:A2%A"
310    ["basicConstraints"]=>
311    string(7) "CA:TRUE"
312  }
313}
314