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:com.connectsdk.service.config.WebOSTVServiceConfig.java

private X509Certificate loadCertificateFromPEM(String pemString) {
    CertificateFactory certFactory;
    try {// w w w.  j a  va 2s.co m
        certFactory = CertificateFactory.getInstance("X.509");
        ByteArrayInputStream inputStream = new ByteArrayInputStream(pemString.getBytes("US-ASCII"));

        return (X509Certificate) certFactory.generateCertificate(inputStream);
    } catch (CertificateException e) {
        e.printStackTrace();
        return null;
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:hivemall.mix.server.MixServer.java

@Override
public void run() {
    try {// www  .j  a  va 2 s  .  co m
        start();
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (SSLException e) {
        e.printStackTrace();
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

From source file:com.appfirst.communication.AFHttpClient.java

public DefaultHttpClient getAFHttpClient() {
    try {/*from  w  ww. j av a 2s .com*/
        KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
        try {
            trustStore.load(null, null);
        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        SSLSocketFactory sf = new AFSSLSocketFactory(trustStore);
        sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        registry.register(new Scheme("https", sf, 443));
        ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
        return new DefaultHttpClient(ccm, params);
    } catch (NoSuchAlgorithmException nsae) {
        Log.e(TAG, nsae.getMessage());
        return new DefaultHttpClient();
    } catch (KeyManagementException kme) {
        Log.e(TAG, kme.getMessage());
        return new DefaultHttpClient();
    } catch (KeyStoreException kse) {
        Log.e(TAG, kse.getMessage());
        return new DefaultHttpClient();
    } catch (UnrecoverableKeyException uke) {
        Log.e(TAG, uke.getMessage());
        return new DefaultHttpClient();
    }
}

From source file:org.strongswan.android.ui.activity.TrustedCertificateImportActivity.java

/**
 * Load the file from the given URI and try to parse it as X.509 certificate.
 *
 * @param uri// w w w  . j a  v a 2 s  .c o  m
 * @return certificate or null
 */
private X509Certificate parseCertificate(Uri uri) {
    X509Certificate certificate = null;
    try {
        CertificateFactory factory = CertificateFactory.getInstance("X.509");
        InputStream in = getContentResolver().openInputStream(uri);
        certificate = (X509Certificate) factory.generateCertificate(in);
        /* we don't check whether it's actually a CA certificate or not */
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    return certificate;
}

From source file:com.google.samples.apps.abelana.AbelanaThings.java

public AbelanaThings(Context ctx, String phint) {
    final JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
    final HttpTransport httpTransport = new NetHttpTransport();
    Resources r = ctx.getResources();
    byte[] android, server;
    byte[] password = new byte[32];

    android = Base64.decode("vW7CmbQWdPjpdfpBU39URsjHQV50KEKoSfafHdQPSh8",
            Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP);
    server = Base64.decode(phint, Base64.URL_SAFE);

    int i = 0;//w  w  w  .  ja  v  a  2 s . c om
    for (byte b : android) {
        password[i] = (byte) (android[i] ^ server[i]);
        i++;
    }
    byte[] pw = Base64.encode(password, Base64.URL_SAFE + Base64.NO_PADDING + Base64.NO_WRAP);
    String pass = new String(pw);

    if (storage == null) {
        try {
            KeyStore keystore = KeyStore.getInstance("PKCS12");
            keystore.load(r.openRawResource(R.raw.abelananew), pass.toCharArray());

            credential = new GoogleCredential.Builder().setTransport(httpTransport).setJsonFactory(jsonFactory)
                    .setServiceAccountId(r.getString(R.string.service_account))
                    .setServiceAccountScopes(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL))
                    .setServiceAccountPrivateKey((PrivateKey) keystore.getKey("privatekey", pass.toCharArray()))
                    .build();

            storage = new Storage.Builder(httpTransport, jsonFactory, credential)
                    .setApplicationName(r.getString(R.string.app_name) + "/1.0").build();

        } catch (CertificateException e) {
            e.printStackTrace();
        } catch (UnrecoverableKeyException e) {
            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyStoreException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("loaded");
    }
}

From source file:damo.three.ie.prepay.UsageFetcher.java

/**
 * Begin fetching the usage/*w w w. java  2  s . c o m*/
 */
public JSONArray getUsages() throws IOException, AccountException, JSONException, PrepayException {

    // Some change on 22-08-2014 means that when we have cookies cached from previous login and this login session
    // is expired, if we perform a login and go through login steps, we are greeted with login page again. Clear
    // cookies prior to prevent this.
    try {
        ThreeHttpClient.getInstance(context).getHttpClient().getCookieStore().clear();
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    }
    // Attempt to log in.
    pageContent = processRequest.process(Constants.MY3_ACCOUNT_PAGE);
    Log.d(Constants.TAG, "using: my3account.three.ie");

    // Were we brought to the login page? If so, login. We sometimes skip this if our cookie still holds a valid
    // session.
    if (pageContent.contains("<label for=\"username\" class=\"portlet-form-input-label\">")) {
        Pattern p1 = Pattern.compile(Constants.LOGIN_TOKEN_REGEX, Pattern.DOTALL);
        Matcher m1 = p1.matcher(pageContent);
        if (m1.matches()) {
            Log.d(Constants.TAG, "Logging in...");
            addPropertyToPostData("lt", m1.group(1));
            pageContent = processRequest.process(Constants.MY3_ACCOUNT_PAGE, postData);
            if (pageContent.contains("Sorry, you've entered an invalid")) {
                throw new AccountException("Invalid 3 mobile number or password.");
            } else if (pageContent.contains("You have entered your login details incorrectly too many times")) {
                throw new AccountException("Account is temporarily disabled due to too many incorrect logins. "
                        + "Please try again later.");
            }
        }
    }

    // We end up here if we have logged in, or if our cookie was still valid.
    if (pageContent.contains("here</a> to access the service you requested.</p>")) {
        Pattern p1 = Pattern.compile(Constants.MY3_SERVICE_REGEX, Pattern.DOTALL);
        Matcher m1 = p1.matcher(pageContent);
        if (m1.matches()) {
            pageContent = processRequest.process(m1.group(1));
        }

        //As of 22-08-2014, this page comes up a second time, with a new token. This time without SSL!
        if (pageContent.contains("here</a> to access the service you requested.</p>")) {
            Pattern p2 = Pattern.compile(Constants.MY3_SERVICE_REGEX, Pattern.DOTALL);
            Matcher m2 = p2.matcher(pageContent);
            if (m2.matches()) {
                pageContent = processRequest.process(m2.group(1));
            }
        }

        if (pageContent.contains("<p><strong>Your account balance.</strong></p>")) {
            parseUsage();
        } else {
            if (!runningInBackground) {
                reportErrorFetchingUsage();
            }
        }

    } else if (pageContent.contains("This service is currently unavailable. Please try again later.")) {
        // Known service error from three.
        throw new PrepayException("my3account.three.ie is reporting: \"This service is currently unavailable. "
                + "Please try again later.\"");
    } else {
        // Unknown response
        if (!runningInBackground) {
            reportErrorFetchingUsage();
        }
    }
    return jsonArray;
}

From source file:com.salesmanager.core.service.common.impl.EasySSLProtocolSocketFactory.java

public void checkServerTrusted(X509Certificate[] certificates, String string) throws CertificateException {

    if ((certificates != null) && (certificates.length == 1)) {
        X509Certificate certificate = certificates[0];

        try {//from   w w  w.  j av  a2 s.c o m
            certificate.checkValidity();
        } catch (CertificateException e) {
            e.printStackTrace();
        }
    } else {
        this.standardTrustManager.checkServerTrusted(certificates, string);
    }
}

From source file:IntergrationTest.OCSPIntegrationTest.java

/**
 * Read PEM certificate into javax.security.x509Certificate.
 *
 * @param pemCert/*from   www  .  ja  va  2 s  .co  m*/
 *
 * @return
 */
private X509Certificate readPemCert(byte[] pemCert) {
    CertificateFactory certificateFactory = null;
    try {
        certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        e.printStackTrace();
    }
    X509Certificate x509cert;
    InputStream stream = new ByteArrayInputStream(pemCert);
    try {
        x509cert = (X509Certificate) certificateFactory.generateCertificate(stream);
        return x509cert;
    } catch (CertificateException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:com.evilisn.DAO.CertMapper.java

@Override
public Object mapRow(ResultSet resultSet, int i) throws SQLException {
    Cert crt = new Cert();
    crt.setCertificate(resultSet.getString("certificate"));
    CertificateFactory fact = null;
    try {/*w  ww. j ava  2 s.co  m*/
        fact = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        e.printStackTrace();
    }
    X509Certificate x509cert = null;
    InputStream stream = new ByteArrayInputStream(crt.getCertificate().getBytes(StandardCharsets.UTF_8));
    try {
        x509cert = (X509Certificate) fact.generateCertificate(stream);
        crt.setClient_cert(x509cert);
    } catch (CertificateException e) {
        e.printStackTrace();
    }
    crt.setResponder_uri(OCSP.getResponderURI(x509cert));
    X509Certificate issuerCert;
    if (!cached_issuers.containsKey(getIssuerCertURL(x509cert))) {
        //download and set the issuers.
        try {
            issuerCert = getX509Certificate(httpGetBin(getIssuerCertURL(x509cert), true));
            cached_issuers.put(getIssuerCertURL(x509cert), issuerCert);
            crt.setIssuer_cert(issuerCert);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        issuerCert = cached_issuers.get(getIssuerCertURL(x509cert));
        crt.setIssuer_cert(issuerCert);
    }

    Principal principal = x509cert.getIssuerDN();
    String issuerDn = principal.getName();
    crt.setIssuer_dn(issuerDn);
    return crt;
}

From source file:damo.three.ie.activity.PrepayCreditActivity.java

private void logOut() {
    SharedPreferences.Editor sharedPrefsEditor = sharedPreferences.edit();
    sharedPrefsEditor.remove("mobile");
    sharedPrefsEditor.remove("password");
    sharedPrefsEditor.commit();/*w  ww  .  j a  va2  s  .com*/

    SharedPreferences.Editor usageSharedPrefsEditor = usageSharedPreferences.edit();
    usageSharedPrefsEditor.remove("last_refreshed_milliseconds");
    usageSharedPrefsEditor.remove("usage_info");
    usageSharedPrefsEditor.commit();

    try {
        ThreeHttpClient.getInstance(getApplicationContext()).getHttpClient().getCookieStore().clear();
    } catch (CertificateException e) {
        e.printStackTrace();
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyStoreException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    Intent i = new Intent(this, LoginActivity.class);
    startActivity(i);
    finish();
}