Skip to content

Commit 11087a3

Browse files
Mihkel Kivisildmrts
authored andcommitted
Add tests for nonces that contain null bytes, control characters, high-byte values or an ASN.1 OID
WE2-879 Signed-off-by: Mart Somermaa <[email protected]>
1 parent de7575b commit 11087a3

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/ocsp/OcspRequestTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,29 @@ public function testWhenGetNonceExtensionSuccess(): void
101101

102102
$this->assertEquals("nonce", $request->getNonceExtension());
103103
}
104+
105+
public function testBinaryNonce(): void
106+
{
107+
// Create a nonce with a mixture of potentially problematic bytes,
108+
// null bytes, control characters and high-byte values (above 0x7F),
109+
// which are common sources of string decoding problems.
110+
$nonce = "\0\1\2\3\4\5\6\7\x08\x09\x10\0"
111+
. "\x0A\x0D\x1B"
112+
. "\xE2\x82\xAC"
113+
. "\xFF";
114+
$request = new OcspRequest();
115+
$request->addNonceExtension($nonce);
116+
117+
$this->assertEquals($nonce, $request->getNonceExtension());
118+
}
119+
120+
public function testOidNonce(): void
121+
{
122+
// Create a nonce that contains DER-encoded OID for SHA-256: 2.16.840.1.101.3.4.2.1.
123+
$nonce = "\x06\x09\x60\x86\x48\x01\x65\x03\x04\x02\x01";
124+
$request = new OcspRequest();
125+
$request->addNonceExtension($nonce);
126+
127+
$this->assertEquals($nonce, $request->getNonceExtension());
128+
}
104129
}

0 commit comments

Comments
 (0)