Search in sources :

Example 46 with HexDumpEncoder

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

the class UnknownAttribute method main.

public static void main(String[] args) throws Exception {
    // Unknown attr
    PKCS9Attribute p1 = new PKCS9Attribute(PKCS9Attribute.CHALLENGE_PASSWORD_STR, "t0p5ecr3t");
    if (!p1.isKnown()) {
        throw new Exception();
    }
    // Unknown attr from DER
    byte[] data = { // SEQUENCE OF
    0x30, // SEQUENCE OF
    0x08, // OID 1.2.3 and
    0x06, // OID 1.2.3 and
    0x02, // OID 1.2.3 and
    0x2A, // OID 1.2.3 and
    0x03, // an empty SET
    0x31, // an empty SET
    0x02, // an empty SET
    0x05, // an empty SET
    0x00 };
    PKCS9Attribute p2 = new PKCS9Attribute(new DerValue(data));
    if (p2.isKnown()) {
        throw new Exception();
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    p2.derEncode(bout);
    new HexDumpEncoder().encodeBuffer(bout.toByteArray(), System.err);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
    // Unknown attr from value
    try {
        new PKCS9Attribute(new ObjectIdentifier("1.2.3"), "hello");
        throw new Exception();
    } catch (IllegalArgumentException iae) {
    // Good. Unknown attr must have byte[] value type
    }
    PKCS9Attribute p3 = new PKCS9Attribute(new ObjectIdentifier("1.2.3"), new byte[] { 0x31, 0x02, 0x05, 0x00 });
    if (p3.isKnown()) {
        throw new Exception();
    }
    bout = new ByteArrayOutputStream();
    p3.derEncode(bout);
    if (!Arrays.equals(data, bout.toByteArray())) {
        throw new Exception();
    }
}
Also used : PKCS9Attribute(sun.security.pkcs.PKCS9Attribute) HexDumpEncoder(sun.misc.HexDumpEncoder) DerValue(sun.security.util.DerValue) ObjectIdentifier(sun.security.util.ObjectIdentifier)

Example 47 with HexDumpEncoder

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

the class Ber method dumpBER.

public static void dumpBER(OutputStream outStream, String tag, byte[] bytes, int from, int to) {
    try {
        outStream.write('\n');
        outStream.write(tag.getBytes("UTF8"));
        new HexDumpEncoder().encodeBuffer(new ByteArrayInputStream(bytes, from, to), outStream);
        outStream.write('\n');
    } catch (IOException e) {
        try {
            outStream.write("Ber.dumpBER(): error encountered\n".getBytes("UTF8"));
        } catch (IOException e2) {
        // ignore
        }
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder) ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException)

Example 48 with HexDumpEncoder

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

the class GCMParameters method engineToString.

/*
     * Returns a formatted string describing the parameters.
     */
protected String engineToString() {
    String LINE_SEP = System.getProperty("line.separator");
    HexDumpEncoder encoder = new HexDumpEncoder();
    StringBuilder sb = new StringBuilder(LINE_SEP + "    iv:" + LINE_SEP + "[" + encoder.encodeBuffer(iv) + "]");
    sb.append(LINE_SEP + "tLen(bits):" + LINE_SEP + tLen * 8 + LINE_SEP);
    return sb.toString();
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 49 with HexDumpEncoder

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

the class Krb5LoginModule method attemptAuthentication.

/**
     * process the configuration options
     * Get the TGT either out of
     * cache or from the KDC using the password entered
     * Check the  permission before getting the TGT
     */
private void attemptAuthentication(boolean getPasswdFromSharedState) throws LoginException {
    /*
         * Check the creds cache to see whether
         * we have TGT for this client principal
         */
    if (krb5PrincName != null) {
        try {
            principal = new PrincipalName(krb5PrincName.toString(), PrincipalName.KRB_NT_PRINCIPAL);
        } catch (KrbException e) {
            LoginException le = new LoginException(e.getMessage());
            le.initCause(e);
            throw le;
        }
    }
    try {
        if (useTicketCache) {
            // ticketCacheName == null implies the default cache
            if (debug)
                System.out.println("Acquire TGT from Cache");
            cred = Credentials.acquireTGTFromCache(principal, ticketCacheName);
            if (cred != null) {
                // check to renew credentials
                if (!isCurrent(cred)) {
                    if (renewTGT) {
                        cred = renewCredentials(cred);
                    } else {
                        // credentials have expired
                        cred = null;
                        if (debug)
                            System.out.println("Credentials are" + " no longer valid");
                    }
                }
            }
            if (cred != null) {
                // get the principal name from the ticket cache
                if (principal == null) {
                    principal = cred.getClient();
                }
            }
            if (debug) {
                System.out.println("Principal is " + principal);
                if (cred == null) {
                    System.out.println("null credentials from Ticket Cache");
                }
            }
        }
        if (cred == null) {
            // or AS Exchange
            if (principal == null) {
                promptForName(getPasswdFromSharedState);
                principal = new PrincipalName(krb5PrincName.toString(), PrincipalName.KRB_NT_PRINCIPAL);
            }
            /*
                 * Before dynamic KeyTab support (6894072), here we check if
                 * the keytab contains keys for the principal. If no, keytab
                 * will not be used and password is prompted for.
                 *
                 * After 6894072, we normally don't check it, and expect the
                 * keys can be populated until a real connection is made. The
                 * check is still done when isInitiator == true, where the keys
                 * will be used right now.
                 *
                 * Probably tricky relations:
                 *
                 * useKeyTab is config flag, but when it's true but the ktab
                 * does not contains keys for principal, we would use password
                 * and keep the flag unchanged (for reuse?). In this method,
                 * we use (ktab != null) to check whether keytab is used.
                 * After this method (and when storeKey == true), we use
                 * (encKeys == null) to check.
                 */
            if (useKeyTab) {
                if (!unboundServer) {
                    KerberosPrincipal kp = new KerberosPrincipal(principal.getName());
                    ktab = (keyTabName == null) ? KeyTab.getInstance(kp) : KeyTab.getInstance(kp, new File(keyTabName));
                } else {
                    ktab = (keyTabName == null) ? KeyTab.getUnboundInstance() : KeyTab.getUnboundInstance(new File(keyTabName));
                }
                if (isInitiator) {
                    if (Krb5Util.keysFromJavaxKeyTab(ktab, principal).length == 0) {
                        ktab = null;
                        if (debug) {
                            System.out.println("Key for the principal " + principal + " not available in " + ((keyTabName == null) ? "default key tab" : keyTabName));
                        }
                    }
                }
            }
            KrbAsReqBuilder builder;
            if (ktab == null) {
                promptForPass(getPasswdFromSharedState);
                builder = new KrbAsReqBuilder(principal, password);
                if (isInitiator) {
                    // XXX Even if isInitiator=false, it might be
                    // better to do an AS-REQ so that keys can be
                    // updated with PA info
                    cred = builder.action().getCreds();
                }
                if (storeKey) {
                    encKeys = builder.getKeys(isInitiator);
                // When encKeys is empty, the login actually fails.
                // For compatibility, exception is thrown in commit().
                }
            } else {
                builder = new KrbAsReqBuilder(principal, ktab);
                if (isInitiator) {
                    cred = builder.action().getCreds();
                }
            }
            builder.destroy();
            if (debug) {
                System.out.println("principal is " + principal);
                HexDumpEncoder hd = new HexDumpEncoder();
                if (ktab != null) {
                    System.out.println("Will use keytab");
                } else if (storeKey) {
                    for (int i = 0; i < encKeys.length; i++) {
                        System.out.println("EncryptionKey: keyType=" + encKeys[i].getEType() + " keyBytes (hex dump)=" + hd.encodeBuffer(encKeys[i].getBytes()));
                    }
                }
            }
            // we should hava a non-null cred
            if (isInitiator && (cred == null)) {
                throw new LoginException("TGT Can not be obtained from the KDC ");
            }
        }
    } catch (KrbException e) {
        LoginException le = new LoginException(e.getMessage());
        le.initCause(e);
        throw le;
    } catch (IOException ioe) {
        LoginException ie = new LoginException(ioe.getMessage());
        ie.initCause(ioe);
        throw ie;
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 50 with HexDumpEncoder

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

the class AbstractSaslImpl method traceOutput.

protected static final void traceOutput(String srcClass, String srcMethod, String traceTag, byte[] output, int offset, int len) {
    try {
        int origlen = len;
        Level lev;
        if (!logger.isLoggable(Level.FINEST)) {
            len = Math.min(16, len);
            lev = Level.FINER;
        } else {
            lev = Level.FINEST;
        }
        String content;
        if (output != null) {
            ByteArrayOutputStream out = new ByteArrayOutputStream(len);
            new HexDumpEncoder().encodeBuffer(new ByteArrayInputStream(output, offset, len), out);
            content = out.toString();
        } else {
            content = "NULL";
        }
        // Message id supplied by caller as part of traceTag
        logger.logp(lev, srcClass, srcMethod, "{0} ( {1} ): {2}", new Object[] { traceTag, new Integer(origlen), content });
    } catch (Exception e) {
        logger.logp(Level.WARNING, srcClass, srcMethod, "SASLIMPL09:Error generating trace output: {0}", e);
    }
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder) Level(java.util.logging.Level)

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