本文整理汇总了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();
}
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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));
}
}
示例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 +
//
// "})();");
}
示例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));
}
}
示例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);
}
示例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();
}
}
示例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();
}
示例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);
}
示例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;
}