Skip to content

Commit e83f031

Browse files
authored
Merge pull request #2 from minvws/decrypt-key-fix
Trying keyfile during decryption, not during construction
2 parents 37b3d94 + 5fc3da5 commit e83f031

File tree

4 files changed

+8
-23
lines changed

4 files changed

+8
-23
lines changed

src/Service/Cms/NativeService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ public function __construct(array $encryptionCertsPath, string $decryptionCertPa
3636
$this->encryptionCertsPath = $paths;
3737
$this->decryptionCertPath = "file://" . $decryptionCertPath;
3838
$this->decryptionCertKeyPath = "file://" . $decryptionCertKeyPath;
39-
40-
if (!is_readable($decryptionCertKeyPath)) {
41-
throw CryptoException::cannotReadFile($decryptionCertKeyPath);
42-
}
4339
}
4440

4541
public function encrypt(string $plainText): string
@@ -93,6 +89,10 @@ public function decrypt(string $cipherText): string
9389
{
9490
$outFile = $inFile = null;
9591

92+
if (!is_readable($this->decryptionCertKeyPath)) {
93+
throw CryptoException::cannotReadFile($this->decryptionCertKeyPath);
94+
}
95+
9696
try {
9797
$inFile = tmpfile();
9898
if (!is_resource($inFile)) {

src/Service/Cms/ProcessSpawnService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public function __construct(array $encryptionCertsPath, string $decryptionCertPa
3232
$this->encryptionCertsPath = $encryptionCertsPath;
3333
$this->decryptionCertPath = $decryptionCertPath;
3434
$this->decryptionCertKeyPath = $decryptionCertKeyPath;
35-
36-
if (!is_readable($decryptionCertKeyPath)) {
37-
throw CryptoException::cannotReadFile($decryptionCertKeyPath);
38-
}
3935
}
4036

4137

@@ -67,6 +63,10 @@ public function encrypt(string $plainText): string
6763
*/
6864
public function decrypt(string $cipherText): string
6965
{
66+
if (!is_readable($this->decryptionCertKeyPath)) {
67+
throw CryptoException::cannotReadFile($this->decryptionCertKeyPath);
68+
}
69+
7070
$args = [
7171
'openssl', 'cms', '-decrypt', '-inform', 'PEM', '-inkey',
7272
$this->decryptionCertKeyPath, $this->decryptionCertPath

tests/Service/Signature/ServiceTest.php

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,6 @@ public function testCorrectDetached(string $serviceType, string $serviceTypeOthe
5252
$this->assertFalse($serviceOther->verify($signedData));
5353
}
5454

55-
/**
56-
* @dataProvider serviceTypeProvider
57-
*/
58-
public function testAllPurpose(string $serviceType, string $serviceTypeOther): void
59-
{
60-
$data = json_decode(file_get_contents(__DIR__ . "/../../mockdata/mock-signature.json"), true);
61-
62-
$service = $this->getService($serviceType);
63-
$this->assertTrue($service->verify($data['signature'], base64_decode($data['payload'])));
64-
}
65-
6655
private function getService(string $serviceType): SignatureCryptoInterface
6756
{
6857
$args = [

0 commit comments

Comments
 (0)