Skip to content

Commit

Permalink
Merge pull request #2 from minvws/decrypt-key-fix
Browse files Browse the repository at this point in the history
Trying keyfile during decryption, not during construction
  • Loading branch information
jaytaph authored Feb 3, 2022
2 parents 37b3d94 + 5fc3da5 commit e83f031
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 23 deletions.
8 changes: 4 additions & 4 deletions src/Service/Cms/NativeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ public function __construct(array $encryptionCertsPath, string $decryptionCertPa
$this->encryptionCertsPath = $paths;
$this->decryptionCertPath = "file://" . $decryptionCertPath;
$this->decryptionCertKeyPath = "file://" . $decryptionCertKeyPath;

if (!is_readable($decryptionCertKeyPath)) {
throw CryptoException::cannotReadFile($decryptionCertKeyPath);
}
}

public function encrypt(string $plainText): string
Expand Down Expand Up @@ -93,6 +89,10 @@ public function decrypt(string $cipherText): string
{
$outFile = $inFile = null;

if (!is_readable($this->decryptionCertKeyPath)) {
throw CryptoException::cannotReadFile($this->decryptionCertKeyPath);
}

try {
$inFile = tmpfile();
if (!is_resource($inFile)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Service/Cms/ProcessSpawnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public function __construct(array $encryptionCertsPath, string $decryptionCertPa
$this->encryptionCertsPath = $encryptionCertsPath;
$this->decryptionCertPath = $decryptionCertPath;
$this->decryptionCertKeyPath = $decryptionCertKeyPath;

if (!is_readable($decryptionCertKeyPath)) {
throw CryptoException::cannotReadFile($decryptionCertKeyPath);
}
}


Expand Down Expand Up @@ -67,6 +63,10 @@ public function encrypt(string $plainText): string
*/
public function decrypt(string $cipherText): string
{
if (!is_readable($this->decryptionCertKeyPath)) {
throw CryptoException::cannotReadFile($this->decryptionCertKeyPath);
}

$args = [
'openssl', 'cms', '-decrypt', '-inform', 'PEM', '-inkey',
$this->decryptionCertKeyPath, $this->decryptionCertPath
Expand Down
11 changes: 0 additions & 11 deletions tests/Service/Signature/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,6 @@ public function testCorrectDetached(string $serviceType, string $serviceTypeOthe
$this->assertFalse($serviceOther->verify($signedData));
}

/**
* @dataProvider serviceTypeProvider
*/
public function testAllPurpose(string $serviceType, string $serviceTypeOther): void
{
$data = json_decode(file_get_contents(__DIR__ . "/../../mockdata/mock-signature.json"), true);

$service = $this->getService($serviceType);
$this->assertTrue($service->verify($data['signature'], base64_decode($data['payload'])));
}

private function getService(string $serviceType): SignatureCryptoInterface
{
$args = [
Expand Down
Loading

0 comments on commit e83f031

Please sign in to comment.