android.net.http.SslCertificate Java Examples

The following examples show how to use android.net.http.SslCertificate. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SslUtil.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates an SslError object from a chromium net error code.
 */
public static SslError sslErrorFromNetErrorCode(int error, SslCertificate cert, String url) {
    assert (error >= NetError.ERR_CERT_END && error <= NetError.ERR_CERT_COMMON_NAME_INVALID);
    switch(error) {
        case NetError.ERR_CERT_COMMON_NAME_INVALID:
            return new SslError(SslError.SSL_IDMISMATCH, cert, url);
        case NetError.ERR_CERT_DATE_INVALID:
            return new SslError(SslError.SSL_DATE_INVALID, cert, url);
        case NetError.ERR_CERT_AUTHORITY_INVALID:
            return new SslError(SslError.SSL_UNTRUSTED, cert, url);
        default:
            break;
    }
    // Map all other codes to SSL_INVALID.
    return new SslError(SslError.SSL_INVALID, cert, url);
}
 
Example #2
Source File: AwContentsClientBridge.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@CalledByNative
private boolean allowCertificateError(int certError, byte[] derBytes, final String url,
        final int id) {
    final SslCertificate cert = SslUtil.getCertificateFromDerBytes(derBytes);
    if (cert == null) {
        // if the certificate or the client is null, cancel the request
        return false;
    }
    final SslError sslError = SslUtil.sslErrorFromNetErrorCode(certError, cert, url);
    ValueCallback<Boolean> callback = new ValueCallback<Boolean>() {
        @Override
        public void onReceiveValue(Boolean value) {
            proceedSslError(value.booleanValue(), id);
        }
    };
    mClient.onReceivedSslError(callback, sslError);
    return true;
}
 
Example #3
Source File: SslUtil.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates an SslError object from a chromium net error code.
 */
public static SslError sslErrorFromNetErrorCode(int error, SslCertificate cert, String url) {
    assert (error >= NetError.ERR_CERT_END && error <= NetError.ERR_CERT_COMMON_NAME_INVALID);
    switch(error) {
        case NetError.ERR_CERT_COMMON_NAME_INVALID:
            return new SslError(SslError.SSL_IDMISMATCH, cert, url);
        case NetError.ERR_CERT_DATE_INVALID:
            return new SslError(SslError.SSL_DATE_INVALID, cert, url);
        case NetError.ERR_CERT_AUTHORITY_INVALID:
            return new SslError(SslError.SSL_UNTRUSTED, cert, url);
        default:
            break;
    }
    // Map all other codes to SSL_INVALID.
    return new SslError(SslError.SSL_INVALID, cert, url);
}
 
Example #4
Source File: AwContentsClientBridge.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@CalledByNative
private boolean allowCertificateError(int certError, byte[] derBytes, final String url,
        final int id) {
    final SslCertificate cert = SslUtil.getCertificateFromDerBytes(derBytes);
    if (cert == null) {
        // if the certificate or the client is null, cancel the request
        return false;
    }
    final SslError sslError = SslUtil.sslErrorFromNetErrorCode(certError, cert, url);
    ValueCallback<Boolean> callback = new ValueCallback<Boolean>() {
        @Override
        public void onReceiveValue(Boolean value) {
            proceedSslError(value.booleanValue(), id);
        }
    };
    mClient.onReceivedSslError(callback, sslError);
    return true;
}
 
Example #5
Source File: WebViewActivity.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
@Override
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) {
    int primaryError = error.getPrimaryError();
    String url = error.getUrl();
    SslCertificate cert = error.getCertificate();
    mLogger.warning("onReceivedSslError: error = " + primaryError
            + ", url = " + url + ", certificate = " + cert);

    if (primaryError == SslError.SSL_UNTRUSTED && url != null && cert != null) {
        SslCertificate.DName subjectName = cert.getIssuedTo();
        if (subjectName != null
                && "localhost".equals(subjectName.getCName())
                && url.startsWith("https://localhost") ) {
            handler.proceed();
            mLogger.warning("SSL Proceeded: url = " + url);
            return;
        }
    }
    handler.cancel();
    mLogger.severe("SSL Canceled: url = " + url);
}
 
Example #6
Source File: SslCertificateViewAdapter.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
private void showIssuer(SslCertificate.DName issuer, View dialogView) {
    TextView cnView = ((TextView)dialogView.findViewById(R.id.value_issuer_CN));
    cnView.setText(issuer.getCName());
    cnView.setVisibility(View.VISIBLE);
    
    TextView oView = ((TextView)dialogView.findViewById(R.id.value_issuer_O));
    oView.setText(issuer.getOName());
    oView.setVisibility(View.VISIBLE);

    TextView ouView = ((TextView)dialogView.findViewById(R.id.value_issuer_OU));
    ouView.setText(issuer.getUName());
    ouView.setVisibility(View.VISIBLE);
    
    // SslCertificates don't offer this information
    dialogView.findViewById(R.id.value_issuer_C).setVisibility(View.GONE);
    dialogView.findViewById(R.id.value_issuer_ST).setVisibility(View.GONE);
    dialogView.findViewById(R.id.value_issuer_L).setVisibility(View.GONE);
    dialogView.findViewById(R.id.label_issuer_C).setVisibility(View.GONE);
    dialogView.findViewById(R.id.label_issuer_ST).setVisibility(View.GONE);
    dialogView.findViewById(R.id.label_issuer_L).setVisibility(View.GONE);
}
 
Example #7
Source File: SslCertificateViewAdapter.java    From Cirrus_depricated with GNU General Public License v2.0 6 votes vote down vote up
private void showSubject(SslCertificate.DName subject, View dialogView) {
    TextView cnView = ((TextView)dialogView.findViewById(R.id.value_subject_CN));
    cnView.setText(subject.getCName());
    cnView.setVisibility(View.VISIBLE);
    
    TextView oView = ((TextView)dialogView.findViewById(R.id.value_subject_O));
    oView.setText(subject.getOName());
    oView.setVisibility(View.VISIBLE);
    
    TextView ouView = ((TextView)dialogView.findViewById(R.id.value_subject_OU));
    ouView.setText(subject.getUName());
    ouView.setVisibility(View.VISIBLE);

    // SslCertificates don't offer this information
    dialogView.findViewById(R.id.value_subject_C).setVisibility(View.GONE);
    dialogView.findViewById(R.id.value_subject_ST).setVisibility(View.GONE);
    dialogView.findViewById(R.id.value_subject_L).setVisibility(View.GONE);
    dialogView.findViewById(R.id.label_subject_C).setVisibility(View.GONE);
    dialogView.findViewById(R.id.label_subject_ST).setVisibility(View.GONE);
    dialogView.findViewById(R.id.label_subject_L).setVisibility(View.GONE);
}
 
Example #8
Source File: CertificateManager.java    From habpanelviewer with GNU General Public License v3.0 6 votes vote down vote up
public synchronized void addCertificate(SslCertificate certificate) throws GeneralSecurityException, IOException {
    KeyStore localTrustStore = loadTrustStore();
    X509Certificate x509Certificate = getX509CertFromSslCertHack(certificate);

    String alias = hashName(x509Certificate.getSubjectX500Principal());
    localTrustStore.setCertificateEntry(alias, x509Certificate);

    saveTrustStore(localTrustStore);

    // notify listeners
    synchronized (mListeners) {
        for (ICertChangedListener l : mListeners) {
            l.certAdded();
        }
    }
}
 
Example #9
Source File: WebViewAssert.java    From assertj-android with Apache License 2.0 5 votes vote down vote up
public WebViewAssert hasCertificate(SslCertificate certificate) {
  isNotNull();
  SslCertificate actualCertificate = actual.getCertificate();
  assertThat(actualCertificate) //
      .overridingErrorMessage("Expected certificate <%s> but was <%s>.", certificate,
          actualCertificate) //
      .isSameAs(certificate);
  return this;
}
 
Example #10
Source File: WebGuiActivity.java    From syncthing-android with Mozilla Public License 2.0 5 votes vote down vote up
/**
 * Catch (self-signed) SSL errors and test if they correspond to Syncthing's certificate.
 */
@Override
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
    try {
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
            // The mX509Certificate field is not available for ICS- devices
            Log.w(TAG, "Skipping certificate check for devices <ICS");
            handler.proceed();
            return;
        }
        // Use reflection to access the private mX509Certificate field of SslCertificate
        SslCertificate sslCert = error.getCertificate();
        Field f = sslCert.getClass().getDeclaredField("mX509Certificate");
        f.setAccessible(true);
        X509Certificate cert = (X509Certificate)f.get(sslCert);
        if (cert == null) {
            Log.w(TAG, "X509Certificate reference invalid");
            handler.cancel();
            return;
        }
        cert.verify(mCaCert.getPublicKey());
        handler.proceed();
    } catch (NoSuchFieldException|IllegalAccessException|CertificateException|
            NoSuchAlgorithmException|InvalidKeyException|NoSuchProviderException|
            SignatureException e) {
        Log.w(TAG, e);
        handler.cancel();
    }
}
 
Example #11
Source File: FocusWebViewClient.java    From focus-android with Mozilla Public License 2.0 5 votes vote down vote up
void saveState(WebView view, Bundle bundle) {
    final SslCertificate certificate = view.getCertificate();
    if (certificate != null) {
        bundle.putString(STATE_KEY_URL, view.getUrl());
        bundle.putBundle(STATE_KEY_CERTIFICATE, SslCertificate.saveState(certificate));
    }
}
 
Example #12
Source File: FocusWebViewClient.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
@Override
    public void onPageFinished(WebView view, final String url) {
        SslCertificate certificate = view.getCertificate();

        if (!TextUtils.isEmpty(restoredUrl)) {
            if (restoredUrl.equals(url) && certificate == null) {
                // We just restored the previous state. Let's re-use the certificate we restored.
                // The reason for that is that WebView doesn't restore the certificate itself.
                // Without restoring the certificate manually we'd lose the certificate when
                // switching tabs or restoring a previous session for other reasons.
                certificate = restoredCertificate;
            } else {
                // The URL has changed since we restored the last state. Let's just clear all
                // restored data because we do not need it anymore.
                restoredUrl = null;
                restoredCertificate = null;
            }
        }

        if (callback != null) {
            callback.onPageFinished(certificate != null);
            // The URL which is supplied in onPageFinished() could be fake (see #301), but webview's
            // URL is always correct _except_ for error pages
            final String viewURL = view.getUrl();
            if (!UrlUtils.isInternalErrorURL(viewURL) && viewURL != null) {
                callback.onURLChanged(viewURL);
            }
        }
        super.onPageFinished(view, url);

//        evaluateJavascript(view,
//                "(function() {" +
//
//                CLEAR_VISITED_CSS +
//
//                "})();");
    }
 
Example #13
Source File: CertificateManager.java    From habpanelviewer with GNU General Public License v3.0 5 votes vote down vote up
public synchronized boolean isTrusted(SslCertificate cert) {
    if (mTrustManager == null) {
        KeyStore trustStore = loadTrustStore();
        mTrustManager = new LocalTrustManager(trustStore);
    }

    try {
        mTrustManager.checkClientTrusted(new X509Certificate[]{getX509CertFromSslCertHack(cert)}, "generic");
    } catch (CertificateException e) {
        return false;
    }

    return true;
}
 
Example #14
Source File: FocusWebViewClient.java    From firefox-echo-show with Mozilla Public License 2.0 5 votes vote down vote up
void saveState(FirefoxWebView view, Bundle bundle) {
    final SslCertificate certificate = view.getCertificate();
    if (certificate != null) {
        bundle.putString(STATE_KEY_URL, view.getUrl());
        bundle.putBundle(STATE_KEY_CERTIFICATE, SslCertificate.saveState(certificate));
    }
}
 
Example #15
Source File: CertificateViewer.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.MEDIUM);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example #16
Source File: XWebView.java    From 12306XposedPlugin with GNU General Public License v3.0 4 votes vote down vote up
@Override
public SslCertificate getCertificate() {
    return null;
}
 
Example #17
Source File: AwContents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @see android.webkit.WebView#getCertificate()
 */
public SslCertificate getCertificate() {
    if (mNativeAwContents == 0) return null;
    return SslUtil.getCertificateFromDerBytes(nativeGetCertificate(mNativeAwContents));
}
 
Example #18
Source File: CertificateViewer.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example #19
Source File: AwContents.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @see android.webkit.WebView#getCertificate()
 */
public SslCertificate getCertificate() {
    if (mNativeAwContents == 0) return null;
    return SslUtil.getCertificateFromDerBytes(nativeGetCertificate(mNativeAwContents));
}
 
Example #20
Source File: CertificateViewer.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example #21
Source File: DSL.java    From anvil with MIT License 4 votes vote down vote up
public static Void certificate(SslCertificate arg) {
  return BaseDSL.attr("certificate", arg);
}
 
Example #22
Source File: OAuthWebView.java    From box-android-sdk with Apache License 2.0 4 votes vote down vote up
private View getCertErrorView(final Context context, final SslCertificate certificate){
    LayoutInflater factory = LayoutInflater.from(context);

    View certificateView = factory.inflate(
            R.layout.ssl_certificate, null);

    // issued to:
    SslCertificate.DName issuedTo = certificate.getIssuedTo();
    if (issuedTo != null) {
        ((TextView) certificateView.findViewById(R.id.to_common))
                .setText(issuedTo.getCName());
        ((TextView) certificateView.findViewById(R.id.to_org))
                .setText(issuedTo.getOName());
        ((TextView) certificateView.findViewById(R.id.to_org_unit))
                .setText(issuedTo.getUName());
    }


    // issued by:
    SslCertificate.DName issuedBy = certificate.getIssuedBy();
    if (issuedBy != null) {
        ((TextView) certificateView.findViewById(R.id.by_common))
                .setText(issuedBy.getCName());
        ((TextView) certificateView.findViewById(R.id.by_org))
                .setText(issuedBy.getOName());
        ((TextView) certificateView.findViewById(R.id.by_org_unit))
                .setText(issuedBy.getUName());
    }

    // issued on:
    String issuedOn = formatCertificateDate(context, certificate.getValidNotBeforeDate());
    ((TextView) certificateView.findViewById(R.id.issued_on))
            .setText(issuedOn);

    // expires on:
    String expiresOn = formatCertificateDate(context, certificate.getValidNotAfterDate());
    ((TextView) certificateView.findViewById(R.id.expires_on))
            .setText(expiresOn);

    return certificateView;

}
 
Example #23
Source File: SslError.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
 * @return The SSL certificate associated with the error set
 */
public SslCertificate getCertificate() {
    return mCertificate;
}
 
Example #24
Source File: FocusWebViewClient.java    From firefox-echo-show with Mozilla Public License 2.0 4 votes vote down vote up
void restoreState(Bundle bundle) {
    if (bundle != null && bundle.containsKey(STATE_KEY_CERTIFICATE)) {
        restoredUrl = bundle.getString(STATE_KEY_URL);
        restoredCertificate = SslCertificate.restoreState(bundle.getBundle("client_last_certificate"));
    }
}
 
Example #25
Source File: CertificateViewer.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example #26
Source File: CertificateViewer.java    From delion with Apache License 2.0 4 votes vote down vote up
private void addCertificateDetails(Certificate cert, byte[] sha256Digest, byte[] sha1Digest) {
    LinearLayout certificateView = new LinearLayout(mContext);
    mViews.add(certificateView);
    certificateView.setOrientation(LinearLayout.VERTICAL);

    X509Certificate x509 = (X509Certificate) cert;
    SslCertificate sslCert = new SslCertificate(x509);

    mTitles.add(sslCert.getIssuedTo().getCName());

    addSectionTitle(certificateView, nativeGetCertIssuedToText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedTo().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedTo().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedTo().getUName());
    addItem(certificateView, nativeGetCertInfoSerialNumberText(),
            formatBytes(x509.getSerialNumber().toByteArray(), ':'));

    addSectionTitle(certificateView, nativeGetCertIssuedByText());
    addItem(certificateView, nativeGetCertInfoCommonNameText(),
            sslCert.getIssuedBy().getCName());
    addItem(certificateView, nativeGetCertInfoOrganizationText(),
            sslCert.getIssuedBy().getOName());
    addItem(certificateView, nativeGetCertInfoOrganizationUnitText(),
            sslCert.getIssuedBy().getUName());

    addSectionTitle(certificateView, nativeGetCertValidityText());
    java.text.DateFormat dateFormat = DateFormat.getDateFormat(mContext);
    addItem(certificateView, nativeGetCertIssuedOnText(),
            dateFormat.format(sslCert.getValidNotBeforeDate()));
    addItem(certificateView, nativeGetCertExpiresOnText(),
            dateFormat.format(sslCert.getValidNotAfterDate()));

    addSectionTitle(certificateView, nativeGetCertFingerprintsText());
    addItem(certificateView, nativeGetCertSHA256FingerprintText(),
            formatBytes(sha256Digest, ' '));
    addItem(certificateView, nativeGetCertSHA1FingerprintText(),
            formatBytes(sha1Digest, ' '));
}
 
Example #27
Source File: FocusWebViewClient.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public void onPageFinished(WebView view, final String url) {
    SslCertificate certificate = view.getCertificate();
    shouldReadURL = true;

    if (!TextUtils.isEmpty(restoredUrl)) {
        if (restoredUrl.equals(url) && certificate == null) {
            // We just restored the previous state. Let's re-use the certificate we restored.
            // The reason for that is that WebView doesn't restore the certificate itself.
            // Without restoring the certificate manually we'd lose the certificate when
            // switching tabs or restoring a previous session for other reasons.
            certificate = restoredCertificate;
        } else {
            // The URL has changed since we restored the last state. Let's just clear all
            // restored data because we do not need it anymore.
            restoredUrl = null;
            restoredCertificate = null;
        }
    }

    if (callback != null) {
        // The page is secure when the url is a localized content or when the certificate isn't null
        final boolean isSecure = certificate != null || UrlUtils.isLocalizedContent(view.getUrl());

        callback.onPageFinished(isSecure);

        String host = null;
        try {
            host = new URI(url).getHost();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
        callback.onSecurityChanged(isSecure, host, (certificate != null) ? certificate.getIssuedBy().getOName() : null);
        // The URL which is supplied in onPageFinished() could be fake (see #301), but webview's
        // URL is always correct _except_ for error pages
        final String viewURL = view.getUrl();
        if (!UrlUtils.isInternalErrorURL(viewURL) && viewURL != null) {
            callback.onURLChanged(viewURL);
        }
    }
    super.onPageFinished(view, url);

    view.evaluateJavascript(
            "(function() {" +

            CLEAR_VISITED_CSS +

            "})();",

            null);
}
 
Example #28
Source File: FocusWebViewClient.java    From focus-android with Mozilla Public License 2.0 4 votes vote down vote up
void restoreState(Bundle bundle) {
    if (bundle != null && bundle.containsKey(STATE_KEY_CERTIFICATE)) {
        restoredUrl = bundle.getString(STATE_KEY_URL);
        restoredCertificate = SslCertificate.restoreState(bundle.getBundle("client_last_certificate"));
    }
}
 
Example #29
Source File: SslError.java    From BigApp_Discuz_Android with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new SSL error set object
 * @param error The SSL error
 * @param certificate The associated SSL certificate
 */
public SslError(int error, X509Certificate certificate) {
    addError(error);
    mCertificate = new SslCertificate(certificate);
}
 
Example #30
Source File: SslError.java    From BigApp_Discuz_Android with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new SSL error set object
 * @param error The SSL error
 * @param certificate The associated SSL certificate
 */
public SslError(int error, SslCertificate certificate) {
    addError(error);
    mCertificate = certificate;
}