Example usage for java.security.cert CertificateException printStackTrace

List of usage examples for java.security.cert CertificateException printStackTrace

Introduction

In this page you can find the example usage for java.security.cert CertificateException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:Main.java

private static KeyManager[] prepareKeyManager(InputStream bksFile, String password) {
    try {/* w w w.  j  a v  a  2s .c o m*/
        if (bksFile != null && password != null) {
            KeyStore e = KeyStore.getInstance("BKS");
            e.load(bksFile, password.toCharArray());
            KeyManagerFactory keyManagerFactory = KeyManagerFactory
                    .getInstance(KeyManagerFactory.getDefaultAlgorithm());
            keyManagerFactory.init(e, password.toCharArray());
            return keyManagerFactory.getKeyManagers();
        }

        return null;
    } catch (KeyStoreException var4) {
        var4.printStackTrace();
    } catch (NoSuchAlgorithmException var5) {
        var5.printStackTrace();
    } catch (UnrecoverableKeyException var6) {
        var6.printStackTrace();
    } catch (CertificateException var7) {
        var7.printStackTrace();
    } catch (IOException var8) {
        var8.printStackTrace();
    } catch (Exception var9) {
        var9.printStackTrace();
    }

    return null;
}

From source file:Main.java

private static TrustManager[] prepareTrustManager(InputStream... certificates) {
    if (certificates != null && certificates.length > 0) {
        try {/*  ww  w .ja va 2s  .c  o m*/
            CertificateFactory e = CertificateFactory.getInstance("X.509");
            KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
            keyStore.load((KeyStore.LoadStoreParameter) null);
            int index = 0;
            InputStream[] trustManagerFactory = certificates;
            int trustManagers = certificates.length;

            for (int i$ = 0; i$ < trustManagers; ++i$) {
                InputStream certificate = trustManagerFactory[i$];
                String certificateAlias = Integer.toString(index++);
                keyStore.setCertificateEntry(certificateAlias, e.generateCertificate(certificate));

                try {
                    if (certificate != null) {
                        certificate.close();
                    }
                } catch (IOException var10) {
                    ;
                }
            }

            trustManagerFactory = null;
            TrustManagerFactory var15 = TrustManagerFactory
                    .getInstance(TrustManagerFactory.getDefaultAlgorithm());
            var15.init(keyStore);
            TrustManager[] var16 = var15.getTrustManagers();
            return var16;
        } catch (NoSuchAlgorithmException var11) {
            var11.printStackTrace();
        } catch (CertificateException var12) {
            var12.printStackTrace();
        } catch (KeyStoreException var13) {
            var13.printStackTrace();
        } catch (Exception var14) {
            var14.printStackTrace();
        }

        return null;
    } else {
        return null;
    }
}

From source file:com.aqnote.shared.cryptology.cert.util.X509CertFileUtil.java

/**
 * ??? ?N/*from www. j  a v  a  2 s.c o  m*/
 * 
 * @param crtPath
 * @return
 */
public static String getModulusByCrt(String crtPath) {
    String crt = "";
    try {
        crt = readX509CertificatePublicKey(crtPath);
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String modulus = crt.substring(crt.indexOf("modulus:") + "modulus:".length(),
            crt.indexOf("publicexponent:"));
    return modulus.trim().replace(" ", "");
}

From source file:com.aqnote.shared.cryptology.cert.util.X509CertFileUtil.java

/**
 * ???e//ww  w.j ava 2s.  c o  m
 * 
 * @param crtPath
 * @return
 */
public static String getPubExponentByCrt(String crtPath) {

    String crt = "";
    try {
        crt = readX509CertificatePublicKey(crtPath);
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    String pubExponent = crt.substring(crt.indexOf("publicexponent:") + "publicexponent:".length(),
            crt.length());
    return pubExponent.trim().replace(" ", "");

}

From source file:me.xiaopan.android.gohttp.httpclient.MySSLSocketFactory.java

/**
 * Gets a KeyStore containing the Certificate
 *
 * @param cert InputStream of the Certificate
 * @return KeyStore//ww  w.j a va 2s  .  c  o m
 */
public static KeyStore getKeystoreOfCA(InputStream cert) {

    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = (Certificate) cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            caInput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", (Certificate) ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}

From source file:cn.com.loopj.android.http.MySSLSocketFactory.java

/**
 * Gets a KeyStore containing the Certificate
 *
 * @param cert InputStream of the Certificate
 * @return KeyStore//w ww.  j a v  a  2s.  c o  m
 */
public static KeyStore getKeystoreOfCA(InputStream cert) {

    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            if (caInput != null) {
                caInput.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}

From source file:se.leap.bitmaskclient.ConfigHelper.java

/**
 * Adds a new X509 certificate given its input stream and its provider name
 *
 * @param provider    used to store the certificate in the keystore
 * @param inputStream from which X509 certificate must be generated.
 *//*from   ww w.  jav  a2  s.c  o  m*/
public static void addTrustedCertificate(String provider, InputStream inputStream) {
    CertificateFactory cf;
    try {
        cf = CertificateFactory.getInstance("X.509");
        X509Certificate cert = (X509Certificate) cf.generateCertificate(inputStream);
        keystore_trusted.setCertificateEntry(provider, cert);
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (KeyStoreException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.shalzz.attendance.wrapper.MySSLSocketFactory.java

/**
 * Gets a KeyStore containing the Certificate
 * //from w w w.j a  v a2 s. c  o  m
 * @param cert InputStream of the Certificate
 * @return KeyStore
 */
public static KeyStore getKeystoreOfCA(InputStream cert) {

    // Load CAs from an InputStream
    InputStream caInput = null;
    Certificate ca = null;
    try {
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
        caInput = new BufferedInputStream(cert);
        ca = cf.generateCertificate(caInput);
    } catch (CertificateException e1) {
        e1.printStackTrace();
    } finally {
        try {
            caInput.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = null;
    try {
        keyStore = KeyStore.getInstance(keyStoreType);
        keyStore.load(null, null);
        keyStore.setCertificateEntry("ca", ca);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return keyStore;
}

From source file:se.leap.bitmaskclient.ConfigHelper.java

public static X509Certificate parseX509CertificateFromString(String certificate_string) {
    java.security.cert.Certificate certificate = null;
    CertificateFactory cf;//  ww w.  j  a va2 s .co  m
    try {
        cf = CertificateFactory.getInstance("X.509");

        certificate_string = certificate_string.replaceFirst("-----BEGIN CERTIFICATE-----", "")
                .replaceFirst("-----END CERTIFICATE-----", "").trim();
        byte[] cert_bytes = Base64.decode(certificate_string, Base64.DEFAULT);
        InputStream caInput = new ByteArrayInputStream(cert_bytes);
        try {
            certificate = cf.generateCertificate(caInput);
            System.out.println("ca=" + ((X509Certificate) certificate).getSubjectDN());
        } finally {
            caInput.close();
        }
    } catch (CertificateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        return null;
    } catch (IllegalArgumentException e) {
        return null;
    }

    return (X509Certificate) certificate;
}

From source file:com.wso2.mobile.mdm.utils.ServerUtilities.java

public static HttpsURLConnection getTrustedConnection(Context context, HttpsURLConnection conn) {
    HttpsURLConnection urlConnection = conn;
    try {/*w  w  w. j  a v  a2 s . c om*/
        KeyStore localTrustStore;

        localTrustStore = KeyStore.getInstance("BKS");

        InputStream in = context.getResources().openRawResource(R.raw.emm_truststore);

        localTrustStore.load(in, CommonUtilities.TRUSTSTORE_PASSWORD.toCharArray());

        TrustManagerFactory tmf;
        tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());

        tmf.init(localTrustStore);

        SSLContext sslCtx;

        sslCtx = SSLContext.getInstance("TLS");

        sslCtx.init(null, tmf.getTrustManagers(), null);

        urlConnection.setSSLSocketFactory(sslCtx.getSocketFactory());
        return urlConnection;
    } catch (KeyManagementException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (NoSuchAlgorithmException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    } catch (CertificateException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return null;
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return null;
    } catch (KeyStoreException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
        return null;
    }

}