OCSPResponseParser { public static OCSPResponse parseResponse(byte[] encodedResponse) throws ParserException, IOException { Asn1ToolInitializer.initAsn1Tool(); OCSPResponse responseMessage = new OCSPResponse(); responseMessage.setEncodedResponse(encodedResponse); Asn1Parser asn1Parser = new Asn1Parser(encodedResponse, false); List<Asn1Encodable> decodedResponse = asn1Parser.parse(ParseOcspTypesContext.NAME); Asn1Sequence outerSequence = (Asn1Sequence) decodedResponse.get(0); Asn1Enumerated responseStatusObject = (Asn1Enumerated) outerSequence.getChildren().get(0); int responseStatus = responseStatusObject.getValue().intValue(); if (responseStatus != 0) { return responseMessage; } Asn1Explicit responseBytesObject = (Asn1Explicit) outerSequence.getChildren().get(1); Asn1Sequence responseBytesSequence = (Asn1Sequence) responseBytesObject.getChildren().get(0); Asn1ObjectIdentifier responseTypeObject = (Asn1ObjectIdentifier) responseBytesSequence.getChildren().get(0); String responseTypeIdentifier = responseTypeObject.getValue(); responseMessage.setResponseStatus(responseStatus); responseMessage.setResponseTypeIdentifier(responseTypeIdentifier); if (!responseTypeIdentifier.equals(BASIC.getOID())) { throw new NotImplementedException("This response type is not supported. Identifier: " + responseTypeIdentifier); } parseBasicResponse(responseBytesSequence, responseMessage); return responseMessage; }  static OCSPResponse parseResponse(byte[] encodedResponse);  }
@Test public void testParseResponse() { Assert.assertEquals(new Integer(0), response.getResponseStatus()); Assert.assertNull(response.getResponseDataVersion()); Assert.assertNull(response.getNonce()); Assert.assertEquals("20200615155900Z", response.getProducedAt()); Assert.assertEquals("1.3.6.1.5.5.7.48.1.1", response.getResponseTypeIdentifier()); Assert.assertEquals("1.2.840.113549.1.1.11", response.getSignatureAlgorithmIdentifier()); Assert.assertTrue(response.getCertificateStatusList().get(0) instanceof CertificateStatus); Assert.assertNull(response.getCertificate()); byte[] expectedSignature = { -101, -64, -19, -21, 28, -104, 57, 92, -27, 69, -5, -88, -102, 28, 71, 66, -37, -110, -24, 73, 65, 35, 92, -1, -27, -34, -28, -77, -44, 40, -25, 36, -4, -87, -128, -92, -127, -74, 61, -54, 90, -36, -113, 24, -83, 50, -117, -77, -77, 111, 112, 47, -95, -119, 116, -123, 34, 13, 98, 62, 86, 6, 107, 125, -127, -1, 63, 69, -95, 40, 83, 65, 93, -32, 101, 123, -63, 41, -104, -97, 119, 16, 21, -118, 83, 40, 21, -47, 65, -21, 41, 11, 22, -123, 7, 77, 28, 17, 28, -12, 6, -121, -81, -22, -77, -110, -54, -89, 39, 21, -7, -52, -114, -60, -94, 59, -122, 64, -15, 38, -101, -6, 124, 73, -36, 17, 66, -16, 30, -5, 64, 44, 97, 38, 25, -65, 17, -109, -43, -7, -45, -44, -73, -66, 4, -57, -99, -103, -104, -18, 71, -128, -96, -83, -37, 84, -1, -89, -13, -26, -11, 20, 13, 81, 21, 30, 13, 62, -97, 6, -33, 119, 101, 78, -6, 54, -3, 125, 26, 34, -9, 4, -65, -35, 100, 108, -119, -40, -51, 54, -127, 70, 119, -32, -117, -101, -59, -84, -45, 117, 31, 102, 59, -99, 11, -79, -58, -98, -105, 62, 2, -111, 118, -68, -126, 92, 121, -94, 85, 90, -64, 63, -125, 81, 36, -26, 29, 94, 99, -29, -127, -58, -13, 33, 14, 115, -114, 57, 12, -75, 33, 57, 119, -64, 17, 68, 27, 27, -8, 20, 29, 107, -101, -32, 94, -68 }; Assert.assertArrayEquals(expectedSignature, response.getSignature()); }