use of android.net.http.SslCertificate in project android_frameworks_base by ParanoidAndroid.
the class BrowserFrame method setCertificate.
/**
* Called by JNI when we recieve a certificate for the page's main resource.
* Used by the Chromium HTTP stack only.
*/
private void setCertificate(byte[] cert_der) {
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(cert_der));
mCallbackProxy.onReceivedCertificate(new SslCertificate(cert));
} catch (Exception e) {
// Can't get the certificate, not much to do.
Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
return;
}
}
use of android.net.http.SslCertificate in project android_frameworks_base by ParanoidAndroid.
the class BrowserFrame method reportSslCertError.
/**
* Called by JNI when the Chromium HTTP stack gets an invalid certificate chain.
*
* We delegate the request to CallbackProxy, and route its response to
* {@link #nativeSslCertErrorProceed(int)} or
* {@link #nativeSslCertErrorCancel(int, int)}.
*/
private void reportSslCertError(final int handle, final int certError, byte[] certDER, String url) {
final SslError sslError;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(new ByteArrayInputStream(certDER));
SslCertificate sslCert = new SslCertificate(cert);
sslError = SslError.SslErrorFromChromiumErrorCode(certError, sslCert, url);
} catch (Exception e) {
// Can't get the certificate, not much to do.
Log.e(LOGTAG, "Can't get the certificate from WebKit, canceling");
nativeSslCertErrorCancel(handle, certError);
return;
}
if (SslCertLookupTable.getInstance().isAllowed(sslError)) {
nativeSslCertErrorProceed(handle);
mCallbackProxy.onProceededAfterSslError(sslError);
return;
}
SslErrorHandler handler = new SslErrorHandler() {
@Override
public void proceed() {
SslCertLookupTable.getInstance().setIsAllowed(sslError);
post(new Runnable() {
public void run() {
nativeSslCertErrorProceed(handle);
}
});
}
@Override
public void cancel() {
post(new Runnable() {
public void run() {
nativeSslCertErrorCancel(handle, certError);
}
});
}
};
mCallbackProxy.onReceivedSslError(handler, sslError);
}
use of android.net.http.SslCertificate in project platform_frameworks_base by android.
the class SslCertificateTest method testSslCertificateWithEmptyIssuer.
@LargeTest
public void testSslCertificateWithEmptyIssuer() throws Exception {
X509Certificate x509Certificate = generateCertificate(Issue1597Certificate);
assertEquals("", x509Certificate.getSubjectDN().getName());
SslCertificate sslCertificate = new SslCertificate(x509Certificate);
assertEquals("", sslCertificate.getIssuedBy().getDName());
}
use of android.net.http.SslCertificate in project WordPress-Android by wordpress-mobile.
the class SelfSignedSSLUtils method sslCertificateToX509.
public static X509Certificate sslCertificateToX509(@Nullable SslCertificate cert) {
if (cert == null) {
return null;
}
Bundle bundle = SslCertificate.saveState(cert);
X509Certificate x509Certificate = null;
byte[] bytes = bundle.getByteArray("x509-certificate");
if (bytes == null) {
AppLog.e(T.API, "Cannot load the SSLCertificate bytes from the bundle");
} else {
try {
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Certificate certX509 = certFactory.generateCertificate(new ByteArrayInputStream(bytes));
x509Certificate = (X509Certificate) certX509;
} catch (CertificateException e) {
AppLog.e(T.API, "Cannot generate the X509Certificate with the bytes provided", e);
}
}
return x509Certificate;
}
use of android.net.http.SslCertificate in project android_frameworks_base by DirtyUnicorns.
the class SslCertificateTest method testSslCertificateWithEmptyIssuer.
@LargeTest
public void testSslCertificateWithEmptyIssuer() throws Exception {
X509Certificate x509Certificate = generateCertificate(Issue1597Certificate);
assertEquals("", x509Certificate.getSubjectDN().getName());
SslCertificate sslCertificate = new SslCertificate(x509Certificate);
assertEquals("", sslCertificate.getIssuedBy().getDName());
}
Aggregations