Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Commit

Permalink
Encode correctly OCSP NONCE extension
Browse files Browse the repository at this point in the history
WE2-819

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored and mrts committed Mar 6, 2024
1 parent d67af07 commit a8cdadc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/OcspRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function addNonceExtension(string $nonce): void
$nonceExtension = [
"extnId" => AsnUtil::ID_PKIX_OCSP_NONCE,
"critical" => false,
"extnValue" => $nonce,
"extnValue" => ASN1::encodeDER($nonce, ['type' => ASN1::TYPE_OCTET_STRING]),
];
$this->ocspRequest["tbsRequest"][
"requestExtensions"
Expand All @@ -72,14 +72,16 @@ public function addNonceExtension(string $nonce): void
*/
public function getNonceExtension(): string
{
return current(
$nonce = current(
array_filter(
$this->ocspRequest["tbsRequest"]["requestExtensions"],
function ($extension) {
return AsnUtil::ID_PKIX_OCSP_NONCE == $extension["extnId"];
}
)
)["extnValue"];
$decoded = ASN1::decodeBER($nonce);
return ASN1::asn1map($decoded[0], ['type' => ASN1::TYPE_OCTET_STRING]);
}

public function getEncodeDer(): string
Expand Down
3 changes: 2 additions & 1 deletion tests/OcspRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

namespace web_eid\ocsp_php;

use phpseclib3\File\ASN1;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use web_eid\ocsp_php\util\AsnUtil;
Expand All @@ -49,7 +50,7 @@ private function getNonce(): array
return [
'extnId' => AsnUtil::ID_PKIX_OCSP_NONCE,
'critical' => false,
'extnValue' => "nonce",
'extnValue' => ASN1::encodeDER("nonce", ['type' => ASN1::TYPE_OCTET_STRING]),
];
}

Expand Down

0 comments on commit a8cdadc

Please sign in to comment.