Search in sources :

Example 76 with CertificateException

use of java.security.cert.CertificateException in project robovm by robovm.

the class CertificateExceptionTest method testCertificateException01.

/**
     * Test for <code>CertificateException()</code> constructor Assertion:
     * constructs CertificateException with no detail message
     */
public void testCertificateException01() {
    CertificateException tE = new CertificateException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
Also used : CertificateException(java.security.cert.CertificateException)

Example 77 with CertificateException

use of java.security.cert.CertificateException in project robovm by robovm.

the class CertificateExceptionTest method testCertificateException08.

/**
     * Test for <code>CertificateException(String, Throwable)</code>
     * constructor Assertion: constructs CertificateException when
     * <code>cause</code> is not null <code>msg</code> is null
     */
public void testCertificateException08() {
    CertificateException tE = new CertificateException(null, tCause);
    if (tE.getMessage() != null) {
        String toS = tCause.toString();
        String getM = tE.getMessage();
        assertTrue("getMessage() must should ".concat(toS), (getM.indexOf(toS) != -1));
    }
    assertNotNull("getCause() must not return null", tE.getCause());
    assertEquals("getCause() must return ".concat(tCause.toString()), tE.getCause(), tCause);
}
Also used : CertificateException(java.security.cert.CertificateException)

Example 78 with CertificateException

use of java.security.cert.CertificateException in project Conversations by siacs.

the class IqParser method verification.

public Pair<X509Certificate[], byte[]> verification(final IqPacket packet) {
    Element item = getItem(packet);
    Element verification = item != null ? item.findChild("verification", AxolotlService.PEP_PREFIX) : null;
    Element chain = verification != null ? verification.findChild("chain") : null;
    Element signature = verification != null ? verification.findChild("signature") : null;
    if (chain != null && signature != null) {
        List<Element> certElements = chain.getChildren();
        X509Certificate[] certificates = new X509Certificate[certElements.size()];
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            int i = 0;
            for (Element cert : certElements) {
                certificates[i] = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(Base64.decode(cert.getContent(), Base64.DEFAULT)));
                ++i;
            }
            return new Pair<>(certificates, Base64.decode(signature.getContent(), Base64.DEFAULT));
        } catch (CertificateException e) {
            return null;
        }
    } else {
        return null;
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Element(eu.siacs.conversations.xml.Element) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) X509Certificate(java.security.cert.X509Certificate) Pair(android.util.Pair)

Example 79 with CertificateException

use of java.security.cert.CertificateException in project android-app by spark.

the class WebHelpers method disableTLSforStaging.

private static OkHttpClient disableTLSforStaging() {
    log.e("WARNING: TLS DISABLED FOR STAGING!");
    OkHttpClient client = new OkHttpClient();
    client.setHostnameVerifier(new HostnameVerifier() {

        public boolean verify(String hostname, SSLSession session) {
            return true;
        }
    });
    try {
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, new X509TrustManager[] { new X509TrustManager() {

            public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
            }

            public X509Certificate[] getAcceptedIssuers() {
                return new X509Certificate[0];
            }
        } }, new SecureRandom());
        client.setSslSocketFactory(context.getSocketFactory());
    } catch (Exception e) {
        e.printStackTrace();
    }
    return client;
}
Also used : OkHttpClient(com.squareup.okhttp.OkHttpClient) X509TrustManager(javax.net.ssl.X509TrustManager) SSLSession(javax.net.ssl.SSLSession) SecureRandom(java.security.SecureRandom) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) CertificateException(java.security.cert.CertificateException) HostnameVerifier(javax.net.ssl.HostnameVerifier)

Example 80 with CertificateException

use of java.security.cert.CertificateException in project platform_frameworks_base by android.

the class OSUManager method readCertsFromDisk.

private static Set<X509Certificate> readCertsFromDisk(String dir) throws CertificateException {
    Set<X509Certificate> certs = new HashSet<>();
    CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
    File caDir = new File(dir);
    File[] certFiles = caDir.listFiles();
    if (certFiles != null) {
        for (File certFile : certFiles) {
            try {
                try (FileInputStream in = new FileInputStream(certFile)) {
                    Certificate cert = certFactory.generateCertificate(in);
                    if (cert instanceof X509Certificate) {
                        certs.add((X509Certificate) cert);
                    }
                }
            } catch (CertificateException | IOException e) {
            /* Ignore */
            }
        }
    }
    return certs;
}
Also used : CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) File(java.io.File) X509Certificate(java.security.cert.X509Certificate) FileInputStream(java.io.FileInputStream) HashSet(java.util.HashSet) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

CertificateException (java.security.cert.CertificateException)456 IOException (java.io.IOException)221 X509Certificate (java.security.cert.X509Certificate)215 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)141 KeyStoreException (java.security.KeyStoreException)123 CertificateFactory (java.security.cert.CertificateFactory)103 ByteArrayInputStream (java.io.ByteArrayInputStream)97 Certificate (java.security.cert.Certificate)75 KeyStore (java.security.KeyStore)58 InputStream (java.io.InputStream)55 UnrecoverableKeyException (java.security.UnrecoverableKeyException)53 ArrayList (java.util.ArrayList)49 InvalidKeyException (java.security.InvalidKeyException)44 X509TrustManager (javax.net.ssl.X509TrustManager)41 SSLContext (javax.net.ssl.SSLContext)36 FileInputStream (java.io.FileInputStream)34 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)34 RemoteException (android.os.RemoteException)33 FileNotFoundException (java.io.FileNotFoundException)30 KeyManagementException (java.security.KeyManagementException)30