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

Commit

Permalink
Add tests for nonces that contain null bytes, control characters, hig…
Browse files Browse the repository at this point in the history
…h-byte values or an ASN.1 OID

WE2-879

Signed-off-by: Mart Somermaa <[email protected]>
  • Loading branch information
mrts committed Mar 27, 2024
1 parent 6a2aa24 commit dd7eac7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tests/OcspRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,29 @@ public function testWhenGetNonceExtensionSuccess(): void

$this->assertEquals("nonce", $request->getNonceExtension());
}

public function testBinaryNonce(): void
{
// Create a nonce with a mixture of potentially problematic bytes,
// null bytes, control characters and high-byte values (e.g., above 0x7F),
// which are common sources of string decoding problems.
$nonce = "\0\1\2\3\4\5\6\7\x08\x09\x10\0"
. "\x0A\x0D\x1B"
. "\xE2\x82\xAC"
. "\xFF";
$request = new OcspRequest();
$request->addNonceExtension($nonce);

$this->assertEquals($nonce, $request->getNonceExtension());
}

public function testAsnOidNonce(): void
{
// Create a nonce that contains ASN.1 DER-encoded OID for SHA-256: 2.16.840.1.101.3.4.2.1.
$nonce = "\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01";
$request = new OcspRequest();
$request->addNonceExtension($nonce);

$this->assertEquals($nonce, $request->getNonceExtension());
}
}

0 comments on commit dd7eac7

Please sign in to comment.