gen.addRequest(new CertificateID(CertificateID.HASH_SHA1, cacert, ocspTestCert.getSerialNumber()));
Hashtable exts = new Hashtable();
X509Extension ext = new X509Extension(false, new DEROctetString("123456789".getBytes()));
exts.put(OCSPObjectIdentifiers.id_pkix_ocsp_nonce, ext);
gen.setRequestExtensions(new X509Extensions(exts));
OCSPReq req = gen.generate();
// Request 1
//
// Send the request and receive a singleResponse
byte[] orgbytes = req.getEncoded(); // Save original bytes, so we can
// make different strange values
byte[] bytes = req.getEncoded();
// Switch the first byte, now it's a really corrupted request
bytes[0] = 0x44;
SingleResp[] singleResps = helper.sendOCSPPost(bytes, "123456789", OCSPRespGenerator.MALFORMED_REQUEST, 200); // error
// code
// 1
// means
// malformed
// request
assertNull("SingleResps should be null.", singleResps);
// Request 2
//
// Remove the last byte, should still be quite corrupted
// bytes = Arrays.copyOf(orgbytes, orgbytes.length-1); only works in
// Java 6
bytes = ArrayUtils.remove(orgbytes, orgbytes.length - 1);
singleResps = helper.sendOCSPPost(bytes, "123456789", OCSPRespGenerator.MALFORMED_REQUEST, 200); // error
// code
// 1
// means
// malformed
// request
assertNull("SingleResps should be null.", singleResps);
// Request 3
//
// more than 1 million bytes
// bytes = Arrays.copyOf(orgbytes, 1000010); only works in Java 6
bytes = ArrayUtils.addAll(orgbytes, new byte[1000010]);
singleResps = helper.sendOCSPPost(bytes, "123456789", OCSPRespGenerator.MALFORMED_REQUEST, 200); // //
// error
// code
// 1
// means
// malformed
// request
assertNull("SingleResps should be null.", singleResps);
// Request 4
//
//
// A completely empty request with no question in it
gen = new OCSPReqGenerator();
req = gen.generate();
bytes = req.getEncoded();
singleResps = helper.sendOCSPPost(bytes, "123456789", 1, 200); //
assertNull("SingleResps should be null.", singleResps);
log.trace("<test12CorruptRequests()");
}