javax.security.cert.CertificateEncodingException Java Examples

The following examples show how to use javax.security.cert.CertificateEncodingException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MutualSSLCertificateHandler.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override
public boolean handleRequest(MessageContext messageContext) {

    org.apache.axis2.context.MessageContext axis2MsgContext =
            ((Axis2MessageContext) messageContext).getAxis2MessageContext();
    Map headers =
            (Map) axis2MsgContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
    try {
        X509Certificate clientCertificate = Utils.getClientCertificate(axis2MsgContext);
        headers.remove(Utils.getClientCertificateHeader());
        if (clientCertificate != null) {
            byte[] encoded = Base64.encodeBase64(clientCertificate.getEncoded());
            String base64EncodedString =
                    APIConstants.BEGIN_CERTIFICATE_STRING
                            .concat(new String(encoded)).concat("\n")
                            .concat(APIConstants.END_CERTIFICATE_STRING);
            base64EncodedString = Base64.encodeBase64URLSafeString(base64EncodedString.getBytes());
            headers.put(Utils.getClientCertificateHeader(), base64EncodedString);
        }
    } catch (APIManagementException | CertificateEncodingException e) {
        log.error("Error while converting client certificate", e);
    }
    return true;
}
 
Example #2
Source File: Certificates.java    From quarkus-http with Apache License 2.0 5 votes vote down vote up
public static String toPem(final X509Certificate certificate) throws CertificateEncodingException {
    final StringBuilder builder = new StringBuilder();
    builder.append(BEGIN_CERT);
    builder.append('\n');
    builder.append(FlexBase64.encodeString(certificate.getEncoded(), true));
    builder.append('\n');
    builder.append(END_CERT);
    return builder.toString();
}
 
Example #3
Source File: SslClientCertAttribute.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public static String toPem(final X509Certificate certificate) throws CertificateEncodingException {
    final StringBuilder builder = new StringBuilder();
    builder.append(BEGIN_CERT);
    builder.append('\n');
    builder.append(Base64.getEncoder().encodeToString(certificate.getEncoded()));
    builder.append('\n');
    builder.append(END_CERT);
    return builder.toString();
}
 
Example #4
Source File: CertificateUtils.java    From product-microgateway with Apache License 2.0 5 votes vote down vote up
/**
 *  Used to get the certificate alias for a certificate which is get from header send by payload.
 */
public static String getAliasFromTrustStore(X509Certificate certificate, KeyStore truststore) throws
        java.security.cert.CertificateException, CertificateEncodingException, KeyStoreException {
    KeyStore trustStore = truststore;
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    byte[] certificateEncoded = certificate.getEncoded();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(certificateEncoded);
    java.security.cert.X509Certificate x509Certificate =
            (java.security.cert.X509Certificate) cf.generateCertificate(byteArrayInputStream);
    x509Certificate.checkValidity();
    String certificateAlias = trustStore.getCertificateAlias(x509Certificate);
    return certificateAlias;
}
 
Example #5
Source File: Certificates.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static String toPem(final X509Certificate certificate) throws CertificateEncodingException {
    final StringBuilder builder = new StringBuilder();
    builder.append(BEGIN_CERT);
    builder.append('\n');
    builder.append(FlexBase64.encodeString(certificate.getEncoded(), true));
    builder.append('\n');
    builder.append(END_CERT);
    return builder.toString();
}
 
Example #6
Source File: X509CertificateTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * @throws CertificateEncodingException
 * {@link Certificate#getEncoded()}
 */
public void testGetEncoded()
        throws CertificateEncodingException, java.security.cert.CertificateException {
    // cert = DER encoding of the ASN1.0 structure
    assertTrue(Arrays.equals(cert.getEncoded(), tbt_cert.getEncoded()));
    assertFalse(Arrays.equals(javaxCert.getEncoded(), tbt_cert.getEncoded()));
}
 
Example #7
Source File: CertificateEncodingExceptionTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * Test for <code>CertificateEncodingException(String)</code> constructor
 * Assertion: constructs CertificateEncodingException when <code>msg</code>
 * is null
 */
public void testCertificateEncodingException03() {
    String msg = null;
    CertificateEncodingException tE = new CertificateEncodingException(msg);
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
 
Example #8
Source File: CrlStreamParserTest.java    From xipki with Apache License 2.0 5 votes vote down vote up
private static Certificate parseCert(String fileName)
    throws IOException, CertificateEncodingException {
  try {
    return Certificate.getInstance(
        X509Util.toDerEncoded(Files.readAllBytes(Paths.get(fileName))));
  } catch (RuntimeException ex) {
    throw new CertificateEncodingException("error decoding certificate: " + ex.getMessage());
  }
}
 
Example #9
Source File: X509CertificateTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] getEncoded() throws CertificateEncodingException {
    return null;
}
 
Example #10
Source File: CertificateEncodingExceptionTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
/**
 * Test for <code>CertificateEncodingException()</code> constructor
 * Assertion: constructs CertificateEncodingException with no detail message
 */
public void testCertificateEncodingException01() {
    CertificateEncodingException tE = new CertificateEncodingException();
    assertNull("getMessage() must return null.", tE.getMessage());
    assertNull("getCause() must return null", tE.getCause());
}
 
Example #11
Source File: CertificateTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public byte[] getEncoded() throws CertificateEncodingException {
    return null;
}