Skip to content

Commit

Permalink
Allow to pass middle params like -engine gost through toolPath
Browse files Browse the repository at this point in the history
  • Loading branch information
garex committed Sep 25, 2020
1 parent eec4fc2 commit b559eef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/Security/Signer/OpensslCli.php
Expand Up @@ -8,6 +8,7 @@
class OpensslCli extends Signer
{
private $toolPath;
private $middleParams;

public function __construct(
$certificatePath,
Expand All @@ -16,13 +17,18 @@ public function __construct(
$toolPath = 'openssl'
) {
parent::__construct($certificatePath, $privateKeyPath, $privateKeyPassword);
if (is_array($toolPath) && count($toolPath) == 2) {
$this->middleParams = end($toolPath);
$toolPath = reset($toolPath);
}
$this->toolPath = $toolPath;
}

public function sign($message)
{
return $this->runParameters([
'smime -sign -binary -outform DER -noattr',
$this->middleParams,
'-signer '.escapeshellarg($this->certificatePath),
'-inkey '.escapeshellarg($this->privateKeyPath),
'-passin '.escapeshellarg('pass:'.$this->privateKeyPassword),
Expand Down
2 changes: 1 addition & 1 deletion tests/Provider/EsiaProviderTest.php
Expand Up @@ -42,7 +42,7 @@ protected function setUp()
Factory::KEYS.$certificate,
Factory::KEYS.$privateKey,
null,
getenv('ESIA_CLIENT_OPENSSL_TOOL_PATH') ?: 'openssl'
getenv('ESIA_CLIENT_OPENSSL_TOOL_PATH') ?: ['openssl', '-engine gost']
);
$this->provider = new EsiaProvider([
'clientId' => 'EKAP01',
Expand Down
2 changes: 1 addition & 1 deletion tests/Security/Signer/OpensslCliTest.php
Expand Up @@ -17,7 +17,7 @@ protected function create(
$certificatePath ?: $this->pathToCertificate(),
$privateKeyPath ?: Factory::KEYS.'ekapusta.gost.test.key',
$privateKeyPassword,
getenv('ESIA_CLIENT_OPENSSL_TOOL_PATH') ?: 'openssl'
getenv('ESIA_CLIENT_OPENSSL_TOOL_PATH') ?: ['openssl', '-engine gost']
);
}

Expand Down

0 comments on commit b559eef

Please sign in to comment.