use of javax.security.cert.CertificateException in project j2objc by google.
the class X509CertificateTest method testGetInstance2.
/**
* getInstance(byte[] certData) method testing.
* @throws CertificateEncodingException
* @throws java.security.cert.CertificateEncodingException
*/
public void testGetInstance2() throws java.security.cert.CertificateEncodingException, CertificateEncodingException {
boolean certificateException = false;
X509Certificate c = null;
if (this.cert == null) {
// Test can not be applied.
return;
}
try {
c = X509Certificate.getInstance(cert.getEncoded());
} catch (java.security.cert.CertificateEncodingException e) {
fail("Unexpected CertificateEncodingException was thrown.");
} catch (CertificateException e) {
// The requested certificate type is not available.
// Test pass..
certificateException = true;
}
if (!certificateException) {
assertNotNull(c);
assertTrue(Arrays.equals(c.getEncoded(), cert.getEncoded()));
}
try {
X509Certificate.getInstance(new byte[] { (byte) 1 });
} catch (CertificateException e) {
//ok
}
// Regression for HARMONY-756
try {
X509Certificate.getInstance((byte[]) null);
fail("No expected CertificateException");
} catch (CertificateException e) {
// expected;
}
}
use of javax.security.cert.CertificateException in project robovm by robovm.
the class OpenSSLSessionImpl method createPeerCertificateChain.
/**
* Provide a value to initialize the volatile peerCertificateChain
* field based on the native SSL_SESSION
*/
private javax.security.cert.X509Certificate[] createPeerCertificateChain() throws SSLPeerUnverifiedException {
try {
javax.security.cert.X509Certificate[] chain = new javax.security.cert.X509Certificate[peerCertificates.length];
for (int i = 0; i < peerCertificates.length; i++) {
byte[] encoded = peerCertificates[i].getEncoded();
chain[i] = javax.security.cert.X509Certificate.getInstance(encoded);
}
return chain;
} catch (CertificateEncodingException e) {
SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage());
exception.initCause(exception);
throw exception;
} catch (CertificateException e) {
SSLPeerUnverifiedException exception = new SSLPeerUnverifiedException(e.getMessage());
exception.initCause(exception);
throw exception;
}
}
use of javax.security.cert.CertificateException in project robovm by robovm.
the class X509CertificateTest method testGetInstance2.
/**
* getInstance(byte[] certData) method testing.
* @throws CertificateEncodingException
* @throws java.security.cert.CertificateEncodingException
*/
public void testGetInstance2() throws java.security.cert.CertificateEncodingException, CertificateEncodingException {
boolean certificateException = false;
X509Certificate c = null;
if (this.cert == null) {
// Test can not be applied.
return;
}
try {
c = X509Certificate.getInstance(cert.getEncoded());
} catch (java.security.cert.CertificateEncodingException e) {
fail("Unexpected CertificateEncodingException was thrown.");
} catch (CertificateException e) {
// The requested certificate type is not available.
// Test pass..
certificateException = true;
}
if (!certificateException) {
assertNotNull(c);
assertTrue(Arrays.equals(c.getEncoded(), cert.getEncoded()));
}
try {
X509Certificate.getInstance(new byte[] { (byte) 1 });
} catch (CertificateException e) {
//ok
}
// Regression for HARMONY-756
try {
X509Certificate.getInstance((byte[]) null);
fail("No expected CertificateException");
} catch (CertificateException e) {
// expected;
}
}
use of javax.security.cert.CertificateException in project robovm by robovm.
the class X509CertificateTest method testGetInstance1.
/**
* getInstance(InputStream inStream) method testing.
*/
public void testGetInstance1() {
if (this.cert == null) {
// Test can not be applied.
return;
}
try {
ByteArrayInputStream bais = new ByteArrayInputStream(cert.getEncoded());
X509Certificate.getInstance(bais);
} catch (java.security.cert.CertificateEncodingException e) {
fail("Unexpected CertificateEncodingException was thrown.");
} catch (CertificateEncodingException e) {
fail("Unexpected CertificateEncodingException was thrown.");
} catch (CertificateException e) {
// The requested certificate type is not available.
// Test pass..
}
// Regression for HARMONY-756
try {
X509Certificate.getInstance((InputStream) null);
fail("No expected CertificateException");
} catch (CertificateException e) {
// expected;
}
}
use of javax.security.cert.CertificateException in project undertow by undertow-io.
the class SSLHeaderHandler method handleRequest.
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
HeaderMap requestHeaders = exchange.getRequestHeaders();
final String sessionId = requestHeaders.getFirst(SSL_SESSION_ID);
final String cipher = requestHeaders.getFirst(SSL_CIPHER);
String clientCert = requestHeaders.getFirst(SSL_CLIENT_CERT);
//the proxy client replaces \n with ' '
if (clientCert != null && clientCert.length() > 28) {
StringBuilder sb = new StringBuilder(clientCert.length() + 1);
sb.append(Certificates.BEGIN_CERT);
sb.append('\n');
//core certificate data
sb.append(clientCert.replace(' ', '\n').substring(28, clientCert.length() - 26));
sb.append('\n');
sb.append(Certificates.END_CERT);
clientCert = sb.toString();
}
if (clientCert != null || sessionId != null || cipher != null) {
try {
SSLSessionInfo info = new BasicSSLSessionInfo(sessionId, cipher, clientCert);
exchange.setRequestScheme(HTTPS);
exchange.getConnection().setSslSessionInfo(info);
exchange.addExchangeCompleteListener(CLEAR_SSL_LISTENER);
} catch (java.security.cert.CertificateException | CertificateException e) {
UndertowLogger.REQUEST_LOGGER.debugf(e, "Could not create certificate from header %s", clientCert);
}
}
next.handleRequest(exchange);
}
Aggregations