use of java.security.cert.CertificateFactory in project tomcat by apache.
the class AjpProcessor method populateSslRequestAttributes.
@Override
protected final void populateSslRequestAttributes() {
if (!certificates.isNull()) {
ByteChunk certData = certificates.getByteChunk();
X509Certificate[] jsseCerts = null;
ByteArrayInputStream bais = new ByteArrayInputStream(certData.getBytes(), certData.getStart(), certData.getLength());
// Fill the elements.
try {
CertificateFactory cf;
String clientCertProvider = protocol.getClientCertProvider();
if (clientCertProvider == null) {
cf = CertificateFactory.getInstance("X.509");
} else {
cf = CertificateFactory.getInstance("X.509", clientCertProvider);
}
while (bais.available() > 0) {
X509Certificate cert = (X509Certificate) cf.generateCertificate(bais);
if (jsseCerts == null) {
jsseCerts = new X509Certificate[1];
jsseCerts[0] = cert;
} else {
X509Certificate[] temp = new X509Certificate[jsseCerts.length + 1];
System.arraycopy(jsseCerts, 0, temp, 0, jsseCerts.length);
temp[jsseCerts.length] = cert;
jsseCerts = temp;
}
}
} catch (java.security.cert.CertificateException e) {
getLog().error(sm.getString("ajpprocessor.certs.fail"), e);
return;
} catch (NoSuchProviderException e) {
getLog().error(sm.getString("ajpprocessor.certs.fail"), e);
return;
}
request.setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts);
}
}
use of java.security.cert.CertificateFactory in project tomcat by apache.
the class JSSESupport method getPeerCertificateChain.
@Override
public java.security.cert.X509Certificate[] getPeerCertificateChain() throws IOException {
// Look up the current SSLSession
if (session == null)
return null;
Certificate[] certs = null;
try {
certs = session.getPeerCertificates();
} catch (Throwable t) {
log.debug(sm.getString("jsseSupport.clientCertError"), t);
return null;
}
if (certs == null)
return null;
java.security.cert.X509Certificate[] x509Certs = new java.security.cert.X509Certificate[certs.length];
for (int i = 0; i < certs.length; i++) {
if (certs[i] instanceof java.security.cert.X509Certificate) {
// always currently true with the JSSE 1.1.x
x509Certs[i] = (java.security.cert.X509Certificate) certs[i];
} else {
try {
byte[] buffer = certs[i].getEncoded();
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream stream = new ByteArrayInputStream(buffer);
x509Certs[i] = (java.security.cert.X509Certificate) cf.generateCertificate(stream);
} catch (Exception ex) {
log.info(sm.getString("jseeSupport.certTranslationError", certs[i]), ex);
return null;
}
}
if (log.isTraceEnabled())
log.trace("Cert #" + i + " = " + x509Certs[i]);
}
if (x509Certs.length < 1)
return null;
return x509Certs;
}
use of java.security.cert.CertificateFactory in project cw-omnibus by commonsguy.
the class SignatureFragment method show.
void show(byte[] raw) {
CertificateFactory cf = null;
try {
cf = CertificateFactory.getInstance("X509");
} catch (CertificateException e) {
Log.e(getClass().getSimpleName(), "Exception getting CertificateFactory", e);
return;
}
X509Certificate c = null;
ByteArrayInputStream bin = new ByteArrayInputStream(raw);
try {
c = (X509Certificate) cf.generateCertificate(bin);
} catch (CertificateException e) {
Log.e(getClass().getSimpleName(), "Exception getting X509Certificate", e);
return;
}
TextView tv = (TextView) getView().findViewById(R.id.subject);
tv.setText(c.getSubjectDN().toString());
tv = (TextView) getView().findViewById(R.id.issuer);
tv.setText(c.getIssuerDN().toString());
tv = (TextView) getView().findViewById(R.id.valid);
tv.setText(fmt.format(c.getNotBefore()) + " to " + fmt.format(c.getNotAfter()));
}
use of java.security.cert.CertificateFactory in project UltimateAndroid by cymcsg.
the class HttpsUtils method getX509CertifaceteFromCrtFile.
/**
* Get X509 Certificate
*
* @param certFilePath
* @return Certificate
*/
public static Certificate getX509CertifaceteFromCrtFile(String certFilePath) {
InputStream inStream = null;
X509Certificate cert = null;
try {
inStream = new FileInputStream(certFilePath);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
cert = (X509Certificate) cf.generateCertificate(inStream);
inStream.close();
} catch (Exception e) {
e.printStackTrace();
Logs.e(e, "");
} finally {
return cert;
}
}
use of java.security.cert.CertificateFactory in project vert.x by eclipse.
the class SSLHelper method getTrustMgrFactory.
private TrustManagerFactory getTrustMgrFactory(VertxInternal vertx) throws Exception {
TrustManagerFactory fact;
if (trustAll) {
TrustManager[] mgrs = new TrustManager[] { createTrustAllTrustManager() };
fact = new VertxTrustManagerFactory(mgrs);
} else if (trustOptions != null) {
fact = trustOptions.getTrustManagerFactory(vertx);
} else {
return null;
}
if (crlPaths != null && crlValues != null && (crlPaths.size() > 0 || crlValues.size() > 0)) {
Stream<Buffer> tmp = crlPaths.stream().map(path -> vertx.resolveFile(path).getAbsolutePath()).map(vertx.fileSystem()::readFileBlocking);
tmp = Stream.concat(tmp, crlValues.stream());
CertificateFactory certificatefactory = CertificateFactory.getInstance("X.509");
ArrayList<CRL> crls = new ArrayList<>();
for (Buffer crlValue : tmp.collect(Collectors.toList())) {
crls.addAll(certificatefactory.generateCRLs(new ByteArrayInputStream(crlValue.getBytes())));
}
TrustManager[] mgrs = createUntrustRevokedCertTrustManager(fact.getTrustManagers(), crls);
fact = new VertxTrustManagerFactory(mgrs);
}
return fact;
}
Aggregations