Search in sources :

Example 1 with URICertStoreParameters

use of java.security.cert.URICertStoreParameters in project Bytecoder by mirkosertic.

the class Pair method loadCRLs.

/**
 * Loads CRLs from a source. This method is also called in JarSigner.
 * @param src the source, which means System.in if null, or a URI,
 *        or a bare file path name
 */
public static Collection<? extends CRL> loadCRLs(String src) throws Exception {
    InputStream in = null;
    URI uri = null;
    if (src == null) {
        in = System.in;
    } else {
        try {
            uri = new URI(src);
            if (uri.getScheme().equals("ldap")) {
            // No input stream for LDAP
            } else {
                in = uri.toURL().openStream();
            }
        } catch (Exception e) {
            try {
                in = new FileInputStream(src);
            } catch (Exception e2) {
                if (uri == null || uri.getScheme() == null) {
                    // More likely a bare file path
                    throw e2;
                } else {
                    // More likely a protocol or network problem
                    throw e;
                }
            }
        }
    }
    if (in != null) {
        try {
            // Read the full stream before feeding to X509Factory,
            // otherwise, keytool -gencrl | keytool -printcrl
            // might not work properly, since -gencrl is slow
            // and there's no data in the pipe at the beginning.
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            byte[] b = new byte[4096];
            while (true) {
                int len = in.read(b);
                if (len < 0)
                    break;
                bout.write(b, 0, len);
            }
            return CertificateFactory.getInstance("X509").generateCRLs(new ByteArrayInputStream(bout.toByteArray()));
        } finally {
            if (in != System.in) {
                in.close();
            }
        }
    } else {
        // must be LDAP, and uri is not null
        URICertStoreParameters params = new URICertStoreParameters(uri);
        CertStore s = CertStore.getInstance("LDAP", params);
        return s.getCRLs(new X509CRLSelector());
    }
}
Also used : URICertStoreParameters(java.security.cert.URICertStoreParameters) URI(java.net.URI) SSLServerCertStore(sun.security.provider.certpath.ssl.SSLServerCertStore) CertStore(java.security.cert.CertStore) KeyStoreException(java.security.KeyStoreException) UnrecoverableEntryException(java.security.UnrecoverableEntryException) CertStoreException(java.security.cert.CertStoreException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) CertificateException(java.security.cert.CertificateException) X509CRLSelector(java.security.cert.X509CRLSelector)

Example 2 with URICertStoreParameters

use of java.security.cert.URICertStoreParameters in project Bytecoder by mirkosertic.

the class URICertStore method getInstance.

/**
 * Creates a CertStore from information included in the AccessDescription
 * object of a certificate's Authority Information Access Extension.
 */
static CertStore getInstance(AccessDescription ad) {
    if (!ad.getAccessMethod().equals(AccessDescription.Ad_CAISSUERS_Id)) {
        return null;
    }
    GeneralNameInterface gn = ad.getAccessLocation().getName();
    if (!(gn instanceof URIName)) {
        return null;
    }
    URI uri = ((URIName) gn).getURI();
    try {
        return URICertStore.getInstance(new URICertStoreParameters(uri));
    } catch (Exception ex) {
        if (debug != null) {
            debug.println("exception creating CertStore: " + ex);
            ex.printStackTrace();
        }
        return null;
    }
}
Also used : GeneralNameInterface(sun.security.x509.GeneralNameInterface) URICertStoreParameters(java.security.cert.URICertStoreParameters) URI(java.net.URI) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) CertStoreException(java.security.cert.CertStoreException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CRLException(java.security.cert.CRLException) URIName(sun.security.x509.URIName)

Aggregations

URI (java.net.URI)2 CertStoreException (java.security.cert.CertStoreException)2 CertificateException (java.security.cert.CertificateException)2 URICertStoreParameters (java.security.cert.URICertStoreParameters)2 IOException (java.io.IOException)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableEntryException (java.security.UnrecoverableEntryException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CRLException (java.security.cert.CRLException)1 CertStore (java.security.cert.CertStore)1 X509CRLSelector (java.security.cert.X509CRLSelector)1 SSLServerCertStore (sun.security.provider.certpath.ssl.SSLServerCertStore)1 GeneralNameInterface (sun.security.x509.GeneralNameInterface)1 URIName (sun.security.x509.URIName)1