use of com.adaptris.security.exc.CertException in project interlok by adaptris.
the class TestCertificateHandler method testExpiredCertificateRevocationCache.
@Test
public void testExpiredCertificateRevocationCache() throws Exception {
try {
InputStream input = new FileInputStream(config.getProperties().getProperty(Config.CERTHANDLER_EXPIRED));
CertificateHandler handler = CertificateHandlerFactory.getInstance().generateHandler(input);
input.close();
assertEquals("Revocation", handler.isRevoked(), false);
Calendar lastExpiredCheck = handler.getLastRevocationCheck();
assertEquals("Calendar", handler.getLastRevocationCheck(), lastExpiredCheck);
} catch (CertException e) {
if (!(e.getCause() != null && e.getCause() instanceof UnknownHostException)) {
throw e;
}
}
}
use of com.adaptris.security.exc.CertException in project interlok by adaptris.
the class TestCertificateHandler method testExpiredCertificateRevocation.
@Test
public void testExpiredCertificateRevocation() throws Exception {
try {
InputStream input = new FileInputStream(config.getProperties().getProperty(Config.CERTHANDLER_EXPIRED));
CertificateHandler handler = CertificateHandlerFactory.getInstance().generateHandler(input);
input.close();
assertEquals("Revocation", handler.isRevoked(), false);
assertNotNull(handler.getLastRevocationCheck());
} catch (CertException e) {
if (!(e.getCause() != null && e.getCause() instanceof UnknownHostException)) {
throw e;
}
}
}
use of com.adaptris.security.exc.CertException in project interlok by adaptris.
the class KeystoreProxyImp method importCertificateChain.
/**
* Import a certificate chain from a file, giving it the assigned alias.
* <p>
* This deals with certificate chains as used by Netscape Navigator and
* Microsoft Internet Explorer.
* <p>
* Certificate Chains are only appropriate for keystore <code>keyEntry</code>
* types.
* <p>
* This assumes that a <code>keyEntry</code> with the alias
* <code>alias</code> has already been created, and the secret key
* associated with this <code>keyEntry</code> is protected by
* <code>keyPassword</code>
*
* @param keyPassword the password to access the private key
* @param alias the alias to be assigned
* @param in the Certificate Chain file to be imported
* @throws AdaptrisSecurityException for any error
* @see #setPrivateKey(String, PrivateKey, char[], Certificate[])
*/
public void importCertificateChain(String alias, char[] keyPassword, InputStream in) throws AdaptrisSecurityException {
try (PemReader pemReader = new PemReader(new InputStreamReader(in))) {
// ,, Constants.SECURITY_PROVIDER);
CertificateFactory cf = CertificateFactory.getInstance(Constants.KEYSTORE_X509);
Collection<?> certs = cf.generateCertificates(in);
Certificate[] pkcs7b = certs.toArray(new Certificate[0]);
PrivateKey pkey = this.getPrivateKey(alias, keyPassword);
if (pkey == null) {
throw new Exception("No Private key for alias " + alias);
}
this.setPrivateKey(alias, pkey, keyPassword, pkcs7b);
} catch (AdaptrisSecurityException e) {
throw e;
} catch (Exception e) {
throw new CertException(e.getMessage(), e);
}
}
use of com.adaptris.security.exc.CertException in project interlok by adaptris.
the class CertRequestHandler method createRequest.
/**
* Create a certificate request based on the provided certificate.
* <p>
* The certificate request is returned as a printable string.
* <p>
* The default implementation returns a PEM string which is bounded by <code>-----BEGIN NEW CERTIFICATE REQUEST-----</code> and
* <code>-----END NEW CERTIFICATE REQUEST-----</code> with each line terminated by a \n, e.g.
* <p>
*
* <pre>
* {@code
* -----BEGIN NEW CERTIFICATE REQUEST-----
* MIIC1zCCAb8CAQAwgZMxGTAXBgNVBAMTEEdoaWxhaW5lIFd5bnlhcmQxFTATBgNV
* BAsTDElyaXMgU3VwcG9ydDENMAsGA1UEChMESXJpczEQMA4GA1UEBxMHRGF0Y2hl
* dDESMBAGA1UECBMJQmVya3NoaXJlMQswCQYDVQQGEwJVSzEdMBsGCSqGSIb3DQEJ
* ARYOZ2x3QGlyaXMuY28udWswggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB
* AQCRQMSX5HCu25aQ+dtozxoGP1QtYC6JXuyGQkQ2MX2JsF1y+WM4NWUvhZvCKjmg
* jsQL2c/rBzXifZCDRzMuHymOcmWXBaFJJr3b2XZQykzhKZKvTx6X1oU7PPcf+ws0
* fNRQ3c1ZekPRYTUmSKyswJwIJDmpx4folU348taHwqcnK/LizekgjwrcZwSmFkk6
* zhGTji2Ris4NMGvm/gDPGGmstxXTQIT62zOP1c61IhkKqxTtMZqmuB2HgQ8MRAza
* xAxm7uoGbSCgUrWOjb92BHYxvQw8LKKkqKmKWRmDPPQKlBP4iR7vPUqXlb4G/keN
* jR2EdByCJbkCUCwuVU124lJbAgMBAAEwDQYJKoZIhvcNAQEEBQADggEBADHpHomV
* ZItNOeXjBDQGWNX9SpA9QV5IvEzm4u5mRI+XFsgYXvybeLMYC6Vrpxl9INVI6hpx
* Nblq09Cq8lHQusyJNVEW3ibc73T5OZrCSnPTD7DUoKpwLwkDOwze7NHu+7NceUm1
* pHCdiVe9Q3AC3+qlIdOhXGB3L5/Tn+8rYFNMAV8TQl7yRAz0g4lm+CdXQWaozTLY
* /1MifSidgYoOq2lCE6l6JsVUv7mBTgaA52GuL0XvfopMOJrEuVUfFy7xVZMqD92L
* ThcZUaIq5/Z3PUGLi8txXXb0Ga81SkLAHpBljgED0pV06EsrDz/N+12aH75zDcE+
* Odt/GdYzfpeYvBg=
* -----END NEW CERTIFICATE REQUEST-----
* }
* </pre>
*
* @param c the certificate
* @param key the private key
* @return the PEM encoded string
* @throws AdaptrisSecurityException if any error occurs
* @see AdaptrisSecurityException
*/
public static String createRequest(Certificate c, PrivateKey key) throws AdaptrisSecurityException {
String pemRequest = null;
ByteArrayOutputStream out = null;
try {
CertificationRequest req = createCertRequest(c, key);
out = new ByteArrayOutputStream();
out.write("-----BEGIN NEW CERTIFICATE REQUEST-----".getBytes());
out.write(req.getEncoded());
out.write("-----END NEW CERTIFICATE REQUEST-----".getBytes());
out.close();
pemRequest = out.toString();
} catch (Exception e) {
throw new CertException(e);
}
return pemRequest;
}
use of com.adaptris.security.exc.CertException in project interlok by adaptris.
the class CertRequestHandler method createRequest.
/**
* Create a CertificateRequest based on the provided certificate and write it
* to the supplied outputStream.
* <p>
* The default implementation writes out the request as a DER encoded ASN.1
* data structure
*
* @param c the certificate
* @param out the OutputStream to write to
* @param key the Private key
* @throws AdaptrisSecurityException if any error occurs
* @see AdaptrisSecurityException
*/
public static void createRequest(Certificate c, PrivateKey key, OutputStream out) throws AdaptrisSecurityException {
try {
CertificationRequest req = createCertRequest(c, key);
out.write(req.getEncoded());
} catch (Exception e) {
throw new CertException(e);
}
}
Aggregations