1 | <?php |
||||
2 | |||||
3 | require_once 'test/smimeTest.php'; |
||||
4 | require_once 'php/class.certificate.php'; |
||||
5 | require_once 'php/util.php'; |
||||
6 | |||||
7 | /** |
||||
8 | * @internal |
||||
9 | * |
||||
10 | * @coversNothing |
||||
11 | */ |
||||
12 | class CertificateTest extends SMIMETest { |
||||
13 | protected function setUp() { |
||||
14 | $this->countryName = "NL"; |
||||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||||
15 | $this->stateOrProvinceName = "Zuid Holland"; |
||||
0 ignored issues
–
show
|
|||||
16 | $this->localityName = "Delft"; |
||||
0 ignored issues
–
show
|
|||||
17 | $this->organizationName = "grommunio"; |
||||
0 ignored issues
–
show
|
|||||
18 | $this->organizationalUnitName = "Dev"; |
||||
0 ignored issues
–
show
|
|||||
19 | $this->commonName = "John"; |
||||
0 ignored issues
–
show
|
|||||
20 | $this->emailAddress = "[email protected]"; |
||||
0 ignored issues
–
show
|
|||||
21 | $dn = [ |
||||
22 | "countryName" => $this->countryName, |
||||
23 | "stateOrProvinceName" => $this->stateOrProvinceName, |
||||
24 | "localityName" => $this->localityName, |
||||
25 | "organizationName" => $this->organizationName, |
||||
26 | "organizationalUnitName" => $this->organizationalUnitName, |
||||
27 | "commonName" => $this->commonName, |
||||
28 | "emailAddress" => $this->emailAddress, |
||||
29 | ]; |
||||
30 | $config = ['config' => OPENSSL_CONF_PATH]; |
||||
31 | $daysvalid = 365; |
||||
32 | $privkey = openssl_pkey_new(); |
||||
33 | $csr = openssl_csr_new($dn, $privkey, $config); |
||||
0 ignored issues
–
show
It seems like
$privkey can also be of type resource ; however, parameter $private_key of openssl_csr_new() does only seem to accept OpenSSLAsymmetricKey , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
34 | $this->validFrom = time(); |
||||
0 ignored issues
–
show
|
|||||
35 | $this->validTo = time() + (86400 * 365); |
||||
0 ignored issues
–
show
|
|||||
36 | $sscert = openssl_csr_sign($csr, null, $privkey, $daysvalid, $config); |
||||
37 | openssl_x509_export($sscert, $publickey); |
||||
38 | |||||
39 | $this->certdata = $publickey; |
||||
0 ignored issues
–
show
|
|||||
40 | $this->cert = new Certificate($this->certdata); |
||||
0 ignored issues
–
show
|
|||||
41 | } |
||||
42 | |||||
43 | public function testEmailaddress() { |
||||
44 | $this->assertEquals($this->cert->emailAddress(), $this->emailAddress); |
||||
45 | } |
||||
46 | |||||
47 | public function testDerPem() { |
||||
48 | $pem = $this->cert->pem(); |
||||
49 | $der = $this->cert->der(); |
||||
50 | |||||
51 | // FIXME: remove der2pem |
||||
52 | $this->assertEquals($pem, der2pem($der)); |
||||
53 | $this->assertEquals($this->certdata, $pem); |
||||
54 | } |
||||
55 | |||||
56 | public function testValidFrom() { |
||||
57 | $this->assertEquals($this->cert->validFrom(), $this->validFrom); |
||||
58 | } |
||||
59 | |||||
60 | public function testValidTo() { |
||||
61 | $this->assertEquals($this->cert->validTo(), $this->validTo); |
||||
62 | } |
||||
63 | |||||
64 | public function testExpired() { |
||||
65 | $this->assertEquals($this->cert->valid(), false); |
||||
66 | } |
||||
67 | |||||
68 | public function testCAURL() { |
||||
69 | $this->assertEmpty($this->cert->caURL()); |
||||
70 | } |
||||
71 | |||||
72 | public function testOCSPURL() { |
||||
73 | $this->assertEmpty($this->cert->ocspURL()); |
||||
74 | } |
||||
75 | |||||
76 | public function testIssuer() { |
||||
77 | $issuer = $this->cert->issuer(true); |
||||
78 | $this->assertInternalType('object', $issuer); |
||||
79 | } |
||||
80 | |||||
81 | public function testFingerprint() { |
||||
82 | $this->assertNotEmpty($this->cert->fingerprint()); |
||||
83 | $this->assertNotEmpty($this->cert->fingerprint('md5')); |
||||
84 | } |
||||
85 | |||||
86 | public function testGetName() { |
||||
87 | $name = $this->cert->getName(); |
||||
88 | $this->assertContains($this->emailAddress, $name); |
||||
89 | $this->assertContains($this->countryName, $name); |
||||
90 | $this->assertContains($this->stateOrProvinceName, $name); |
||||
91 | } |
||||
92 | } |
||||
93 |