Search in sources :

Example 11 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class OCSPRequest method encodeBytes.

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;
}
Also used : Extension(java.security.cert.Extension) HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 12 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class LDAPCertStore method getCertificates.

/*
     * Gets certificates from an attribute id and location in the LDAP
     * directory. Returns a Collection containing only the Certificates that
     * match the specified CertSelector.
     *
     * @param name the location holding the attribute
     * @param id the attribute identifier
     * @param sel a CertSelector that the Certificates must match
     * @return a Collection of Certificates found
     * @throws CertStoreException       if an exception occurs
     */
private Collection<X509Certificate> getCertificates(LDAPRequest request, String id, X509CertSelector sel) throws CertStoreException {
    /* fetch encoded certs from storage */
    byte[][] encodedCert;
    try {
        encodedCert = request.getValues(id);
    } catch (NamingException namingEx) {
        throw new CertStoreException(namingEx);
    }
    int n = encodedCert.length;
    if (n == 0) {
        return Collections.emptySet();
    }
    List<X509Certificate> certs = new ArrayList<>(n);
    /* decode certs and check if they satisfy selector */
    for (int i = 0; i < n; i++) {
        ByteArrayInputStream bais = new ByteArrayInputStream(encodedCert[i]);
        try {
            Certificate cert = cf.generateCertificate(bais);
            if (sel.match(cert)) {
                certs.add((X509Certificate) cert);
            }
        } catch (CertificateException e) {
            if (debug != null) {
                debug.println("LDAPCertStore.getCertificates() encountered " + "exception while parsing cert, skipping the bad data: ");
                HexDumpEncoder encoder = new HexDumpEncoder();
                debug.println("[ " + encoder.encodeBuffer(encodedCert[i]) + " ]");
            }
        }
    }
    return certs;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HexDumpEncoder(sun.misc.HexDumpEncoder) NamingException(javax.naming.NamingException) Certificate(java.security.cert.Certificate)

Example 13 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class LDAPCertStore method getCertPairs.

/*
     * Gets certificate pairs from an attribute id and location in the LDAP
     * directory.
     *
     * @param name the location holding the attribute
     * @param id the attribute identifier
     * @return a Collection of X509CertificatePairs found
     * @throws CertStoreException       if an exception occurs
     */
private Collection<X509CertificatePair> getCertPairs(LDAPRequest request, String id) throws CertStoreException {
    /* fetch the encoded cert pairs from storage */
    byte[][] encodedCertPair;
    try {
        encodedCertPair = request.getValues(id);
    } catch (NamingException namingEx) {
        throw new CertStoreException(namingEx);
    }
    int n = encodedCertPair.length;
    if (n == 0) {
        return Collections.emptySet();
    }
    List<X509CertificatePair> certPairs = new ArrayList<>(n);
    /* decode each cert pair and add it to the Collection */
    for (int i = 0; i < n; i++) {
        try {
            X509CertificatePair certPair = X509CertificatePair.generateCertificatePair(encodedCertPair[i]);
            certPairs.add(certPair);
        } catch (CertificateException e) {
            if (debug != null) {
                debug.println("LDAPCertStore.getCertPairs() encountered exception " + "while parsing cert, skipping the bad data: ");
                HexDumpEncoder encoder = new HexDumpEncoder();
                debug.println("[ " + encoder.encodeBuffer(encodedCertPair[i]) + " ]");
            }
        }
    }
    return certPairs;
}
Also used : X509CertificatePair(sun.security.provider.certpath.X509CertificatePair) HexDumpEncoder(sun.misc.HexDumpEncoder) NamingException(javax.naming.NamingException)

Example 14 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class EngineWriter method dumpPacket.

/*
     * Output the packet info.
     */
private void dumpPacket(EngineArgs ea, boolean hsData) {
    try {
        HexDumpEncoder hd = new HexDumpEncoder();
        ByteBuffer bb = ea.netData.duplicate();
        int pos = bb.position();
        bb.position(pos - ea.deltaNet());
        bb.limit(pos);
        System.out.println("[Raw write" + (hsData ? "" : " (bb)") + "]: length = " + bb.remaining());
        hd.encodeBuffer(bb, System.out);
    } catch (IOException e) {
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 15 with HexDumpEncoder

use of sun.misc.HexDumpEncoder in project jdk8u_jdk by JetBrains.

the class Handshaker method calculateMasterSecret.

/*
     * Calculate the master secret from its various components.  This is
     * used for key exchange by all cipher suites.
     *
     * The master secret is the catenation of three MD5 hashes, each
     * consisting of the pre-master secret and a SHA1 hash.  Those three
     * SHA1 hashes are of (different) constant strings, the pre-master
     * secret, and the nonces provided by the client and the server.
     */
private SecretKey calculateMasterSecret(SecretKey preMasterSecret, ProtocolVersion requestedVersion) {
    if (debug != null && Debug.isOn("keygen")) {
        HexDumpEncoder dump = new HexDumpEncoder();
        System.out.println("SESSION KEYGEN:");
        System.out.println("PreMaster Secret:");
        printHex(dump, preMasterSecret.getEncoded());
    // Nonces are dumped with connection keygen, no
    // benefit to doing it twice
    }
    // What algs/params do we need to use?
    String masterAlg;
    PRF prf;
    if (protocolVersion.v >= ProtocolVersion.TLS12.v) {
        masterAlg = "SunTls12MasterSecret";
        prf = cipherSuite.prfAlg;
    } else {
        masterAlg = "SunTlsMasterSecret";
        prf = P_NONE;
    }
    String prfHashAlg = prf.getPRFHashAlg();
    int prfHashLength = prf.getPRFHashLength();
    int prfBlockSize = prf.getPRFBlockSize();
    TlsMasterSecretParameterSpec spec = new TlsMasterSecretParameterSpec(preMasterSecret, protocolVersion.major, protocolVersion.minor, clnt_random.random_bytes, svr_random.random_bytes, prfHashAlg, prfHashLength, prfBlockSize);
    try {
        KeyGenerator kg = JsseJce.getKeyGenerator(masterAlg);
        kg.init(spec);
        return kg.generateKey();
    } catch (InvalidAlgorithmParameterException | NoSuchAlgorithmException iae) {
        // due to the Bleichenbacher attack. See comments further down.
        if (debug != null && Debug.isOn("handshake")) {
            System.out.println("RSA master secret generation error:");
            iae.printStackTrace(System.out);
        }
        throw new ProviderException(iae);
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder) PRF(sun.security.ssl.CipherSuite.PRF) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Aggregations

HexDumpEncoder (sun.misc.HexDumpEncoder)51 IOException (java.io.IOException)15 ByteArrayInputStream (java.io.ByteArrayInputStream)6 CRLException (java.security.cert.CRLException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 CertificateException (java.security.cert.CertificateException)3 NamingException (javax.naming.NamingException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchProviderException (java.security.NoSuchProviderException)2 SignatureException (java.security.SignatureException)2 X509CRLEntry (java.security.cert.X509CRLEntry)2 PRF (sun.security.ssl.CipherSuite.PRF)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Constructor (java.lang.reflect.Constructor)1 ByteBuffer (java.nio.ByteBuffer)1 AccessControlContext (java.security.AccessControlContext)1 GeneralSecurityException (java.security.GeneralSecurityException)1 PrivilegedActionException (java.security.PrivilegedActionException)1