Java Code Examples for java.security.cert.Extension#encode()
The following examples show how to use
java.security.cert.Extension#encode() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OCSPStatusRequest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Send the encoded {@code OCSPStatusRequest} out through the provided * {@code HandshakeOutputStream} * * @param s the {@code HandshakeOutputStream} on which to send the encoded * data * * @throws IOException if any encoding errors occur */ @Override public void send(HandshakeOutStream s) throws IOException { s.putInt16(ridListLen); for (ResponderId rid : responderIds) { s.putBytes16(rid.getEncoded()); } DerOutputStream seqOut = new DerOutputStream(); DerOutputStream extBytes = new DerOutputStream(); if (extensions.size() > 0) { for (Extension ext : extensions) { ext.encode(extBytes); } seqOut.write(DerValue.tag_Sequence, extBytes); } s.putBytes16(seqOut.toByteArray()); }
Example 2
Source File: OCSPStatusRequest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * Obtain the length of the {@code OCSPStatusRequest} object in its * encoded form * * @return the length of the {@code OCSPStatusRequest} object in its * encoded form */ @Override public int length() { // If we've previously calculated encodedLen simply return it if (encodedLen != 0) { return encodedLen; } ridListLen = 0; for (ResponderId rid : responderIds) { ridListLen += rid.length() + 2; } extListLen = 0; if (!extensions.isEmpty()) { try { DerOutputStream extSequence = new DerOutputStream(); DerOutputStream extEncoding = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extEncoding); } extSequence.write(DerValue.tag_Sequence, extEncoding); extListLen = extSequence.size(); } catch (IOException ioe) { // Not sure what to do here } } // Total length is the responder ID list length and extensions length // plus each lists' 2-byte length fields. encodedLen = ridListLen + extListLen + 4; return encodedLen; }
Example 3
Source File: SimpleOCSPServer.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void encodeExtensions(DerOutputStream tbsStream) throws IOException { DerOutputStream extSequence = new DerOutputStream(); DerOutputStream extItems = new DerOutputStream(); for (Extension ext : responseExtensions.values()) { ext.encode(extItems); } extSequence.write(DerValue.tag_Sequence, extItems); tbsStream.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)1), extSequence); }
Example 4
Source File: OCSPRequest.java From j2objc with Apache License 2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 5
Source File: OCSPRequest.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 6
Source File: OCSPRequest.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 7
Source File: OCSPRequest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 8
Source File: OCSPRequest.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 9
Source File: OCSPRequest.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 10
Source File: OCSPRequest.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 11
Source File: OCSPRequest.java From hottub with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 12
Source File: OCSPRequest.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 13
Source File: OCSPNonceExtensionTests.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
@Override public Map.Entry<Boolean, String> runTest() { Boolean pass = Boolean.FALSE; String message = null; try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { Extension nonceByDer = new sun.security.x509.Extension( new DerValue(OCSP_NONCE_DER)); // Verify overall encoded extension structure nonceByDer.encode(baos); verifyExtStructure(baos.toByteArray()); // Verify the name, elements, and data conform to // expected values for this specific object. boolean crit = nonceByDer.isCritical(); String oid = nonceByDer.getId(); DerValue nonceData = new DerValue(nonceByDer.getValue()); if (!crit) { message = "Extension lacks expected criticality setting"; } else if (!oid.equals(OCSP_NONCE_OID)) { message = "Incorrect OID (Got " + oid + ", Expected " + OCSP_NONCE_OID + ")"; } else if (nonceData.getTag() != DerValue.tag_OctetString) { message = "Incorrect nonce data tag type (Got " + String.format("0x%02X", nonceData.getTag()) + ", Expected 0x04)"; } else if (nonceData.getOctetString().length != 48) { message = "Incorrect nonce byte length (Got " + nonceData.getOctetString().length + ", Expected 48)"; } else { pass = Boolean.TRUE; } } catch (Exception e) { e.printStackTrace(System.out); message = e.getClass().getName(); } return new AbstractMap.SimpleEntry<>(pass, message); }
Example 14
Source File: OCSPRequest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 15
Source File: OCSPRequest.java From Bytecoder with Apache License 2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 16
Source File: OCSPRequest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 17
Source File: OCSPRequest.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 18
Source File: OCSPRequest.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals(OCSP.NONCE_EXTENSION_OID.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 19
Source File: OCSPRequest.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
byte[] encodeBytes() throws IOException { // encode tbsRequest DerOutputStream tmp = new DerOutputStream(); DerOutputStream requestsOut = new DerOutputStream(); for (CertId certId : certIds) { DerOutputStream certIdOut = new DerOutputStream(); certId.encode(certIdOut); requestsOut.write(DerValue.tag_Sequence, certIdOut); } tmp.write(DerValue.tag_Sequence, requestsOut); if (!extensions.isEmpty()) { DerOutputStream extOut = new DerOutputStream(); for (Extension ext : extensions) { ext.encode(extOut); if (ext.getId().equals( PKIXExtensions.OCSPNonce_Id.toString())) { nonce = ext.getValue(); } } DerOutputStream extsOut = new DerOutputStream(); extsOut.write(DerValue.tag_Sequence, extOut); tmp.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)2), extsOut); } DerOutputStream tbsRequest = new DerOutputStream(); tbsRequest.write(DerValue.tag_Sequence, tmp); // OCSPRequest without the signature DerOutputStream ocspRequest = new DerOutputStream(); ocspRequest.write(DerValue.tag_Sequence, tbsRequest); byte[] bytes = ocspRequest.toByteArray(); if (dump) { HexDumpEncoder hexEnc = new HexDumpEncoder(); debug.println("OCSPRequest bytes...\n\n" + hexEnc.encode(bytes) + "\n"); } return bytes; }
Example 20
Source File: CertificateBuilder.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Encode the extensions segment for an X.509 Certificate: * * <PRE> * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension * * Extension ::= SEQUENCE { * extnID OBJECT IDENTIFIER, * critical BOOLEAN DEFAULT FALSE, * extnValue OCTET STRING * -- contains the DER encoding of an ASN.1 value * -- corresponding to the extension type identified * -- by extnID * } * </PRE> * * @param tbsStream The {@code DerOutputStream} that holds the * TBSCertificate contents. * * @throws IOException if an encoding error occurs. */ private void encodeExtensions(DerOutputStream tbsStream) throws IOException { DerOutputStream extSequence = new DerOutputStream(); DerOutputStream extItems = new DerOutputStream(); for (Extension ext : extensions.values()) { ext.encode(extItems); } extSequence.write(DerValue.tag_Sequence, extItems); tbsStream.write(DerValue.createTag(DerValue.TAG_CONTEXT, true, (byte)3), extSequence); }