Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Impletest remote signer for GOST 2012 algos (inspired by @SergeySidorov)
* Inject remote signer into token * Update usage info * Pass algo into OpenSslCliJwtSigner: RS256, GOST3410_2012_256 * Add gost engine dinamically to cli params * Test possible combintaions of signer and remote signer with different algos
- Loading branch information
Showing
9 changed files
with
216 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Ekapusta\OAuth2Esia\Security\JWTSigner; | ||
|
||
use Ekapusta\OAuth2Esia\Transport\Process; | ||
use Lcobucci\JWT\Signer\BaseSigner; | ||
use Lcobucci\JWT\Signer\Key; | ||
|
||
final class OpenSslCliJwtSigner extends BaseSigner | ||
{ | ||
private $toolPath; | ||
private $algorythmId; | ||
private $postParams = ''; | ||
|
||
public function __construct($toolPath = 'openssl', $algorythmId = 'GOST3410_2012_256') | ||
{ | ||
$this->toolPath = $toolPath; | ||
$this->algorythmId = $algorythmId; | ||
|
||
if (false !== stristr($this->getAlgorithmId(), 'gost')) { | ||
$this->postParams = '-engine gost'; | ||
} | ||
} | ||
|
||
public function getAlgorithmId() | ||
{ | ||
return $this->algorythmId; | ||
} | ||
|
||
public function doVerify($expected, $payload, Key $key) | ||
{ | ||
$verify = new TmpFile($key->getContent()); | ||
$signature = new TmpFile($expected); | ||
|
||
Process::fromArray([ | ||
$this->toolPath, | ||
'dgst', | ||
'-verify '.escapeshellarg($verify), | ||
'-signature '.escapeshellarg($signature), | ||
$this->postParams, | ||
], $payload); | ||
|
||
return true; | ||
} | ||
|
||
public function createHash($payload, Key $key) | ||
{ | ||
$sign = new TmpFile($key->getContent()); | ||
|
||
return (string) Process::fromArray([ | ||
$this->toolPath, | ||
'dgst', | ||
'-sign '.escapeshellarg($sign), | ||
$this->postParams, | ||
], $payload); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Ekapusta\OAuth2Esia\Security\JWTSigner; | ||
|
||
final class TmpFile | ||
{ | ||
private $path; | ||
|
||
public function __construct($content) | ||
{ | ||
$this->handle = tmpfile(); | ||
fwrite($this->handle, $content); | ||
fseek($this->handle, 0); | ||
|
||
$this->path = stream_get_meta_data($this->handle)['uri']; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->path; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.