Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
- 8.5

steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/phpunit-unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ jobs:
- 7.4
- 8.0
- 8.1
- 8.2
- 8.3
- 8.4
- 8.5

steps:
- name: Checkout
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"ext-openssl": "*",
"phpseclib/phpseclib": "^3.0",
"spomky-labs/php-aes-gcm": "^1.2",
"symfony/process": "^4.1|^5.0|^6.0|^7.0"
"symfony/process": "^5.0|^6.0|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^7.5|^9.0",
Expand Down
25 changes: 16 additions & 9 deletions tests/Decoding/OpenSSL/OpenSslServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,27 @@ public function testVerifySignatureFail(): void

public function testGetCertificatesFromPkcs7Success()
{
$leafHeader = 'subject=C = RO, ST = BUH, L = Bucuresti, O = Internet Widgits Pty Ltd, CN = leaflet' .
PHP_EOL . 'issuer=C = RO, ST = BUH, O = PayU, CN = intermediate-cert' . PHP_EOL;
$leafCert = file_get_contents(__DIR__ . '/leaf.crt');
$intermediateHeader = 'subject=C = RO, ST = BUH, O = PayU, CN = intermediate-cert' . PHP_EOL .
'issuer=C = RO, ST = BUH, O = PayU ROOT, CN = root-cert' . PHP_EOL;
$intermediateCert = file_get_contents(__DIR__ . '/intermediate.crt');

$expectedResponse = $leafHeader . $leafCert . PHP_EOL . PHP_EOL . $intermediateHeader . $intermediateCert;
$leafCert = trim(file_get_contents(__DIR__ . '/leaf.crt'));
$intermediateCert = trim(file_get_contents(__DIR__ . '/intermediate.crt'));

$pkcs7DerCert = realpath(__DIR__ . '/leaf.p7b');

$response = $this->openSslService->getCertificatesFromPkcs7($pkcs7DerCert);

$this->assertEquals($expectedResponse, $response);
// Assert subject/issuer headers are present for both certificates.
// OpenSSL < 3.x formats as "C = RO", OpenSSL >= 3.x formats as "C=RO" — accept both.
$this->assertMatchesRegularExpression(
'/^subject=.*CN\s*=\s*leaflet\nissuer=.*CN\s*=\s*intermediate-cert\n/m',
$response
);
$this->assertMatchesRegularExpression(
'/^subject=.*CN\s*=\s*intermediate-cert\nissuer=.*CN\s*=\s*root-cert\n/m',
$response
);

// Assert both PEM certificate bodies are present verbatim.
$this->assertStringContainsString($leafCert, $response);
$this->assertStringContainsString($intermediateCert, $response);
}

public function testGetCertificatesFromPkcs7Fail()
Expand Down