Search in sources :

Example 21 with HexDumpEncoder

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

the class UnparseableExtension method parseExtension.

// Parse the encoded extension
private void parseExtension(Extension ext) throws IOException {
    try {
        Class<?> extClass = OIDMap.getClass(ext.getExtensionId());
        if (extClass == null) {
            // Unsupported extension
            if (ext.isCritical()) {
                unsupportedCritExt = true;
            }
            if (map.put(ext.getExtensionId().toString(), ext) == null) {
                return;
            } else {
                throw new IOException("Duplicate extensions not allowed");
            }
        }
        Constructor<?> cons = extClass.getConstructor(PARAMS);
        Object[] passed = new Object[] { Boolean.valueOf(ext.isCritical()), ext.getExtensionValue() };
        CertAttrSet<?> certExt = (CertAttrSet<?>) cons.newInstance(passed);
        if (map.put(certExt.getName(), (Extension) certExt) != null) {
            throw new IOException("Duplicate extensions not allowed");
        }
    } catch (InvocationTargetException invk) {
        Throwable e = invk.getTargetException();
        if (ext.isCritical() == false) {
            // ignore errors parsing non-critical extensions
            if (unparseableExtensions == null) {
                unparseableExtensions = new TreeMap<String, Extension>();
            }
            unparseableExtensions.put(ext.getExtensionId().toString(), new UnparseableExtension(ext, e));
            if (debug != null) {
                debug.println("Error parsing extension: " + ext);
                e.printStackTrace();
                HexDumpEncoder h = new HexDumpEncoder();
                System.err.println(h.encodeBuffer(ext.getExtensionValue()));
            }
            return;
        }
        if (e instanceof IOException) {
            throw (IOException) e;
        } else {
            throw new IOException(e);
        }
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new IOException(e);
    }
}
Also used : IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) InvocationTargetException(java.lang.reflect.InvocationTargetException) HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 22 with HexDumpEncoder

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

the class X509CRLEntryImpl method toString.

/**
     * Returns a printable string of this revoked certificate.
     *
     * @return value of this revoked certificate in a printable form.
     */
@Override
public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append(serialNumber.toString());
    sb.append("  On: " + revocationDate.toString());
    if (certIssuer != null) {
        sb.append("\n    Certificate issuer: " + certIssuer);
    }
    if (extensions != null) {
        Collection<Extension> allEntryExts = extensions.getAllExtensions();
        Extension[] exts = allEntryExts.toArray(new Extension[0]);
        sb.append("\n    CRL Entry Extensions: " + exts.length);
        for (int i = 0; i < exts.length; i++) {
            sb.append("\n    [" + (i + 1) + "]: ");
            Extension ext = exts[i];
            try {
                if (OIDMap.getClass(ext.getExtensionId()) == null) {
                    sb.append(ext.toString());
                    byte[] extValue = ext.getExtensionValue();
                    if (extValue != null) {
                        DerOutputStream out = new DerOutputStream();
                        out.putOctetString(extValue);
                        extValue = out.toByteArray();
                        HexDumpEncoder enc = new HexDumpEncoder();
                        sb.append("Extension unknown: " + "DER encoded OCTET string =\n" + enc.encodeBuffer(extValue) + "\n");
                    }
                } else
                    //sub-class exists
                    sb.append(ext.toString());
            } catch (Exception e) {
                sb.append(", Error parsing this extension");
            }
        }
    }
    sb.append("\n");
    return sb.toString();
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder) IOException(java.io.IOException) CRLException(java.security.cert.CRLException)

Example 23 with HexDumpEncoder

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

the class X509CertInfo method toString.

/**
     * Returns a printable representation of the certificate.
     */
public String toString() {
    if (subject == null || pubKey == null || interval == null || issuer == null || algId == null || serialNum == null) {
        throw new NullPointerException("X.509 cert is incomplete");
    }
    StringBuilder sb = new StringBuilder();
    sb.append("[\n");
    sb.append("  " + version.toString() + "\n");
    sb.append("  Subject: " + subject.toString() + "\n");
    sb.append("  Signature Algorithm: " + algId.toString() + "\n");
    sb.append("  Key:  " + pubKey.toString() + "\n");
    sb.append("  " + interval.toString() + "\n");
    sb.append("  Issuer: " + issuer.toString() + "\n");
    sb.append("  " + serialNum.toString() + "\n");
    // optional v2, v3 extras
    if (issuerUniqueId != null) {
        sb.append("  Issuer Id:\n" + issuerUniqueId.toString() + "\n");
    }
    if (subjectUniqueId != null) {
        sb.append("  Subject Id:\n" + subjectUniqueId.toString() + "\n");
    }
    if (extensions != null) {
        Collection<Extension> allExts = extensions.getAllExtensions();
        Extension[] exts = allExts.toArray(new Extension[0]);
        sb.append("\nCertificate Extensions: " + exts.length);
        for (int i = 0; i < exts.length; i++) {
            sb.append("\n[" + (i + 1) + "]: ");
            Extension ext = exts[i];
            try {
                if (OIDMap.getClass(ext.getExtensionId()) == null) {
                    sb.append(ext.toString());
                    byte[] extValue = ext.getExtensionValue();
                    if (extValue != null) {
                        DerOutputStream out = new DerOutputStream();
                        out.putOctetString(extValue);
                        extValue = out.toByteArray();
                        HexDumpEncoder enc = new HexDumpEncoder();
                        sb.append("Extension unknown: " + "DER encoded OCTET string =\n" + enc.encodeBuffer(extValue) + "\n");
                    }
                } else
                    //sub-class exists
                    sb.append(ext.toString());
            } catch (Exception e) {
                sb.append(", Error parsing this extension");
            }
        }
        Map<String, Extension> invalid = extensions.getUnparseableExtensions();
        if (invalid.isEmpty() == false) {
            sb.append("\nUnparseable certificate extensions: " + invalid.size());
            int i = 1;
            for (Extension ext : invalid.values()) {
                sb.append("\n[" + (i++) + "]: ");
                sb.append(ext);
            }
        }
    }
    sb.append("\n]");
    return sb.toString();
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder) IOException(java.io.IOException)

Example 24 with HexDumpEncoder

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

the class PBEParameters method engineToString.

/*
     * Returns a formatted string describing the parameters.
     */
protected String engineToString() {
    String LINE_SEP = System.getProperty("line.separator");
    String saltString = LINE_SEP + "    salt:" + LINE_SEP + "[";
    HexDumpEncoder encoder = new HexDumpEncoder();
    saltString += encoder.encodeBuffer(salt);
    saltString += "]";
    return saltString + LINE_SEP + "    iterationCount:" + LINE_SEP + Debug.toHexString(BigInteger.valueOf(iCount)) + LINE_SEP;
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

Example 25 with HexDumpEncoder

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

the class RC2Parameters 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) + "]");
    if (version != 0) {
        sb.append(LINE_SEP + "version:" + LINE_SEP + version + LINE_SEP);
    }
    return sb.toString();
}
Also used : HexDumpEncoder(sun.misc.HexDumpEncoder)

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