use of java.security.cert.CertificateException in project robovm by robovm.
the class OpenSSLSocketImpl method verifyCertificateChain.
// used by NativeCrypto.SSLHandshakeCallbacks
@SuppressWarnings("unused")
@Override
public void verifyCertificateChain(byte[][] bytes, String authMethod) throws CertificateException {
try {
if (bytes == null || bytes.length == 0) {
throw new SSLException("Peer sent no certificate");
}
X509Certificate[] peerCertificateChain = new X509Certificate[bytes.length];
for (int i = 0; i < bytes.length; i++) {
peerCertificateChain[i] = OpenSSLX509Certificate.fromX509Der(bytes[i]);
}
boolean client = sslParameters.getUseClientMode();
if (client) {
X509TrustManager x509tm = sslParameters.getTrustManager();
if (x509tm instanceof TrustManagerImpl) {
TrustManagerImpl tm = (TrustManagerImpl) x509tm;
tm.checkServerTrusted(peerCertificateChain, authMethod, wrappedHost);
} else {
x509tm.checkServerTrusted(peerCertificateChain, authMethod);
}
} else {
String authType = peerCertificateChain[0].getPublicKey().getAlgorithm();
sslParameters.getTrustManager().checkClientTrusted(peerCertificateChain, authType);
}
} catch (CertificateException e) {
throw e;
} catch (Exception e) {
throw new CertificateException(e);
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class X509V2AttributeCertificate method verify.
public final void verify(PublicKey key, String provider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
Signature signature = null;
if (!cert.getSignatureAlgorithm().equals(cert.getAcinfo().getSignature())) {
throw new CertificateException("Signature algorithm in certificate info not same as outer certificate");
}
signature = Signature.getInstance(cert.getSignatureAlgorithm().getObjectId().getId(), provider);
signature.initVerify(key);
try {
signature.update(cert.getAcinfo().getEncoded());
} catch (IOException e) {
throw new SignatureException("Exception encoding certificate info object");
}
if (!signature.verify(this.getSignature())) {
throw new InvalidKeyException("Public key presented not for certificate signature");
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class X509CertificateObject method verify.
public final void verify(PublicKey key) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
Signature signature;
String sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
try {
signature = Signature.getInstance(sigName, BouncyCastleProvider.PROVIDER_NAME);
} catch (Exception e) {
signature = Signature.getInstance(sigName);
}
checkSignature(key, signature);
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class X509TrustManagerTest method test_checkClientTrusted_02.
/**
* javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[] chain, String authType)
*/
public void test_checkClientTrusted_02() throws Exception {
X509TrustManagerImpl xtm = new X509TrustManagerImpl();
X509Certificate[] xcert = setInvalid();
try {
xtm.checkClientTrusted(xcert, "SSL");
fail("CertificateException wasn't thrown");
} catch (CertificateException expected) {
}
}
use of java.security.cert.CertificateException in project robovm by robovm.
the class myTrustManagerFactory method test_getTrustManagers.
/**
* Test for <code>geTrustManagers()</code>
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws NoSuchAlgorithmException
*/
public void test_getTrustManagers() {
try {
TrustManagerFactory trustMF = TrustManagerFactory.getInstance(getDefaultAlgorithm());
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(null, null);
trustMF.init(ks);
TrustManager[] tm = trustMF.getTrustManagers();
assertNotNull("Result has not be null", tm);
assertTrue("Length of result TrustManager array should not be 0", (tm.length > 0));
} catch (Exception ex) {
fail("Unexpected exception " + ex.toString());
}
}
Aggregations