当前位置: 首页>>代码示例>>Java>>正文


Java SslCertificate类代码示例

本文整理汇总了Java中android.net.http.SslCertificate的典型用法代码示例。如果您正苦于以下问题:Java SslCertificate类的具体用法?Java SslCertificate怎么用?Java SslCertificate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SslCertificate类属于android.net.http包,在下文中一共展示了SslCertificate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: addCertificate

import android.net.http.SslCertificate; //导入依赖的package包/类
public static 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);

    // reset fields so the keystore gets read again
    mTrustManager = null;
    mSslContext = null;

    // notify listeners
    synchronized (mListeners) {
        for (CertChangedListener l : mListeners) {
            l.certAdded();
        }
    }
}
 
开发者ID:vbier,项目名称:habpanelviewer,代码行数:21,代码来源:ConnectionUtil.java

示例2: getX509CertificateFromError

import android.net.http.SslCertificate; //导入依赖的package包/类
/**
 * Obtain the X509Certificate from SslError
 * @param   error     SslError
 * @return  X509Certificate from error
 */
public X509Certificate getX509CertificateFromError (SslError error) {
    Bundle bundle = SslCertificate.saveState(error.getCertificate());
    X509Certificate x509Certificate;
    byte[] bytes = bundle.getByteArray("x509-certificate");
    if (bytes == null) {
        x509Certificate = null;
    } else {
        try {
            CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
            Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
            x509Certificate = (X509Certificate) cert;
        } catch (CertificateException e) {
            x509Certificate = null;
        }
    }        
    return x509Certificate;
}
 
开发者ID:skymania,项目名称:Cirrus,代码行数:23,代码来源:SsoWebViewClient.java

示例3: showSubject

import android.net.http.SslCertificate; //导入依赖的package包/类
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);
}
 
开发者ID:skymania,项目名称:Cirrus,代码行数:22,代码来源:SslCertificateViewAdapter.java

示例4: showIssuer

import android.net.http.SslCertificate; //导入依赖的package包/类
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);
}
 
开发者ID:skymania,项目名称:Cirrus,代码行数:22,代码来源:SslCertificateViewAdapter.java

示例5: allowCertificateError

import android.net.http.SslCertificate; //导入依赖的package包/类
@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;
}
 
开发者ID:mogoweb,项目名称:chromium_webview,代码行数:19,代码来源:AwContentsClientBridge.java

示例6: sslErrorFromNetErrorCode

import android.net.http.SslCertificate; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:mogoweb,项目名称:chromium_webview,代码行数:19,代码来源:SslUtil.java

示例7: isTrusted

import android.net.http.SslCertificate; //导入依赖的package包/类
public static 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;
}
 
开发者ID:vbier,项目名称:habpanelviewer,代码行数:15,代码来源:ConnectionUtil.java

示例8: saveState

import android.net.http.SslCertificate; //导入依赖的package包/类
void saveState(SystemWebView 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));
    }
}
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:8,代码来源:FocusWebViewClient.java

示例9: onPageFinished

import android.net.http.SslCertificate; //导入依赖的package包/类
@Override
    public void onPageFinished(AmazonWebView 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 +
//
//                "})();");
    }
 
开发者ID:mozilla-mobile,项目名称:firefox-tv,代码行数:38,代码来源:FocusWebViewClient.java

示例10: saveState

import android.net.http.SslCertificate; //导入依赖的package包/类
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));
    }
}
 
开发者ID:mozilla-mobile,项目名称:focus-android,代码行数:8,代码来源:FocusWebViewClient.java

示例11: onPageFinished

import android.net.http.SslCertificate; //导入依赖的package包/类
@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);

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

            CLEAR_VISITED_CSS +

            "})();",

            null);
}
 
开发者ID:mozilla-mobile,项目名称:focus-android,代码行数:40,代码来源:FocusWebViewClient.java

示例12: onReceivedSslError

import android.net.http.SslCertificate; //导入依赖的package包/类
/**
 * 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();
    }
}
 
开发者ID:syncthing,项目名称:syncthing-android,代码行数:33,代码来源:WebGuiActivity.java

示例13: getCertificate

import android.net.http.SslCertificate; //导入依赖的package包/类
@Override
public SslCertificate getCertificate() {
    mFactory.startYourEngines(true);
    if (checkNeedsPost()) {
        SslCertificate ret = runOnUiThreadBlocking(new Callable<SslCertificate>() {
            @Override
            public SslCertificate call() {
                return getCertificate();
            }
        });
        return ret;
    }
    return mAwContents.getCertificate();
}
 
开发者ID:mogoweb,项目名称:chromium_webview,代码行数:15,代码来源:WebViewChromium.java

示例14: getCertificateFromError

import android.net.http.SslCertificate; //导入依赖的package包/类
private X509Certificate getCertificateFromError(SslError error) throws NoSuchFieldException, IllegalAccessException {
    SslCertificate sslCertificate = error.getCertificate();
    Field mX509CertificateField =  sslCertificate.getClass().getDeclaredField("mX509Certificate");
    mX509CertificateField.setAccessible(true);

    return (X509Certificate) mX509CertificateField.get(sslCertificate);
}
 
开发者ID:silverbullet-dk,项目名称:opentele-client-android,代码行数:8,代码来源:WebViewNode.java

示例15: hasCertificate

import android.net.http.SslCertificate; //导入依赖的package包/类
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;
}
 
开发者ID:square,项目名称:assertj-android,代码行数:10,代码来源:WebViewAssert.java


注:本文中的android.net.http.SslCertificate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。