use of java.security.cert.X509Certificate in project nutz by nutzam.
the class Http method nopSSLSocketFactory.
public static SSLSocketFactory nopSSLSocketFactory() throws Exception {
SSLContext sc = SSLContext.getInstance("SSL");
TrustManager[] tmArr = { new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
sc.init(null, tmArr, new SecureRandom());
return sc.getSocketFactory();
}
use of java.security.cert.X509Certificate in project android by owncloud.
the class SsoWebViewClient method getX509CertificateFromError.
/**
* 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;
}
use of java.security.cert.X509Certificate in project android by owncloud.
the class SsoWebViewClient method onReceivedSslError.
@Override
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, SslError error) {
Log_OC.e(TAG, "onReceivedSslError : " + error);
// Test 1
X509Certificate x509Certificate = getX509CertificateFromError(error);
boolean isKnownServer = false;
if (x509Certificate != null) {
try {
isKnownServer = NetworkUtils.isCertInKnownServersStore((Certificate) x509Certificate, mContext);
} catch (Exception e) {
Log_OC.e(TAG, "Exception: " + e.getMessage());
}
}
if (isKnownServer) {
handler.proceed();
} else {
((AuthenticatorActivity) mContext).showUntrustedCertDialog(x509Certificate, error, handler);
}
}
use of java.security.cert.X509Certificate in project scdl by passy.
the class PinningTrustManagerImpl method checkServerTrusted.
@Override
public void checkServerTrusted(final X509Certificate[] chain, final String authType) throws CertificateException {
Log.d(TAG, "Checking if server is trusted");
for (final TrustManager systemTrustManager : systemTrustManagers) {
((X509TrustManager) systemTrustManager).checkServerTrusted(chain, authType);
}
Log.d(TAG, "Getting trust root");
final X509Certificate anchor = systemKeyStore.getTrustRoot(chain);
Log.d(TAG, "checking certs for valid pin");
for (final X509Certificate certificate : chain) {
if (isValidPin(certificate)) {
Log.d(TAG, "Success!");
return;
}
}
Log.d(TAG, "checking anchor for valid pin");
if (anchor != null && isValidPin(anchor)) {
Log.d(TAG, "Success!");
return;
}
throw new CertificateException("No valid Pins found in Certificate Chain!");
}
use of java.security.cert.X509Certificate in project platformlayer by platformlayer.
the class PkiServiceImpl method signCsr.
@Override
public List<X509Certificate> signCsr(ProjectEntity project, String csr) throws OpsException {
CertificateAndKey projectPki;
try {
projectPki = repository.getProjectPki(project);
} catch (RepositoryException e) {
throw new OpsException("Error getting project PKI info", e);
}
SimpleCertificateAuthority ca = new SimpleCertificateAuthority();
ca.caCertificate = projectPki.getCertificateChain();
ca.caPrivateKey = projectPki.getPrivateKey();
X509Certificate certificate = ca.signCsr(csr);
List<X509Certificate> chain = Lists.newArrayList();
chain.add(certificate);
for (X509Certificate cert : projectPki.getCertificateChain()) {
chain.add(cert);
}
return chain;
}
Aggregations