Example usage for java.security.cert CertificateException getMessage

List of usage examples for java.security.cert CertificateException getMessage

Introduction

In this page you can find the example usage for java.security.cert CertificateException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:be.apsu.extremon.probes.ocsp.OCSPProbe.java

public OCSPProbe() {
    CertificateFactory certificateFactory = null;

    try {/*from  w w  w .  j  a v a 2 s . c o  m*/
        certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException cex) {
        log("Don't Have Crypto Libs:" + cex.getMessage());
        System.exit(1);
    }

    try {
        certificate = (X509Certificate) certificateFactory
                .generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(confStr("certificate"))));
        trustAnchorCert = (X509Certificate) certificateFactory
                .generateCertificate(new ByteArrayInputStream(Base64.decodeBase64(confStr("trustanchor"))));
    } catch (CertificateException cex) {
        log("certificate and trustanchor required in config:" + cex.getMessage());
        System.exit(2);
    }

    this.delay = confInt("delay", DEFAULT_DELAY);

    try {
        List<X509Certificate> certs = new ArrayList<X509Certificate>();
        certs.add(this.certificate);
        this.certificatePath = (CertPath) certificateFactory.generateCertPath(certs);

        TrustAnchor trustAnchor = new TrustAnchor(this.trustAnchorCert, null);
        Set<TrustAnchor> trustedCertsSet = new HashSet<TrustAnchor>();
        trustedCertsSet.add(trustAnchor);

        Set<X509Certificate> certSet = new HashSet<X509Certificate>();
        certSet.add(this.trustAnchorCert);
        CertStoreParameters storeParams = new CollectionCertStoreParameters(certSet);
        CertStore store = CertStore.getInstance("Collection", storeParams);

        pkixParams = new PKIXParameters(trustedCertsSet);
        pkixParams.addCertStore(store);

        Security.setProperty("ocsp.enable", "true");
        Security.setProperty("ocsp.responderURL", confStr("url"));
        Security.setProperty("ocsp.responderCertSubjectName",
                this.trustAnchorCert.getSubjectX500Principal().getName());

        this.certificatePathValidator = CertPathValidator.getInstance("PKIX");
    } catch (InvalidAlgorithmParameterException iaex) {
        log("Invalid Algorithm Parameter:" + iaex.getMessage());
        System.exit(3);
    } catch (CertificateException cex) {
        log("Certificate Exception:" + cex.getMessage());
        System.exit(4);
    } catch (NoSuchAlgorithmException nsaex) {
        log("No Such Algorithm:" + nsaex.getMessage());
        System.exit(5);
    } catch (Exception ex) {
        log(ex.getMessage());
        System.exit(6);
    }

    start();
    log("Initialized");
}

From source file:be.fedict.hsm.ws.impl.WSSecurityCrypto.java

public WSSecurityCrypto() {
    try {/*from   w  w w.  ja v a2s  .co m*/
        this.certificateFactory = CertificateFactory.getInstance("X.509");
    } catch (CertificateException e) {
        throw new RuntimeException("X.509 algo not available: " + e.getMessage());
    }
}

From source file:com.vmware.identity.openidconnect.client.AuthenticationFrameworkHelper.java

private X509Certificate convertToX509Certificate(String base64PEMCertificate) throws OIDCClientException {
    X509Certificate x509Certificate = null;
    InputStream is = new ByteArrayInputStream(Base64.decodeBase64(base64PEMCertificate.getBytes()));
    CertificateFactory cf;/*ww w. java  2s  . co m*/
    try {
        cf = CertificateFactory.getInstance("X509");
        x509Certificate = (X509Certificate) cf.generateCertificate(is);
    } catch (CertificateException e) {
        throw new OIDCClientException("Failed to convert to X509 certificate: " + e.getMessage(), e);
    }
    return x509Certificate;
}

From source file:be.fedict.hsm.ws.impl.WSSecurityCrypto.java

public X509Certificate loadCertificate(InputStream in) throws WSSecurityException {
    LOG.debug("loadCertificate");
    X509Certificate certificate;/*from  w  ww  . ja  v  a2s. co  m*/
    try {
        certificate = (X509Certificate) this.certificateFactory.generateCertificate(in);
    } catch (CertificateException e) {
        throw new WSSecurityException("error loading certificate: " + e.getMessage(), e);
    }
    LOG.debug("certificate subject: " + certificate.getSubjectX500Principal());
    /*
     * JAX-WS is not supposed to be used in a multi-threaded fashion, so
     * this should be OK to do.
     */
    this.certificate = certificate;
    return certificate;
}

From source file:org.security4java.X509CertificateRetrieverImpl.java

public X509Certificate getClientCertificate(HttpServletRequest request) {
    X509Certificate ret = null;/*ww  w  .  j a v a2s .c o m*/
    if (logger.isDebugEnabled()) {
        logger.debug("getClientCertificate(HttpServletRequest) - start");
    }

    Object attribute = request.getAttribute(certAttrName);
    if (attribute instanceof X509Certificate[]) {
        X509Certificate[] certs = (X509Certificate[]) attribute;
        if (certs != null && certs.length > 0) {
            ret = certs[0];
            if (logger.isDebugEnabled()) {
                logger.debug("Success to get ClientCertificate [" + ret + "].");
            }
        }
    } else if (attribute instanceof String) {
        if (logger.isDebugEnabled()) {
            logger.debug("Received a String. Try to convert the string [" + attribute + "] into certificate.");
        }
        String certificateString = (String) attribute;
        byte[] certificateData = certificateString.getBytes();
        ByteArrayInputStream certificateInputStream = new ByteArrayInputStream(certificateData);
        X509Certificate certificates[] = null;
        try {
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
            X509Certificate x509Certificate = (X509Certificate) certificateFactory
                    .generateCertificate(certificateInputStream);
            certificates = new X509Certificate[1];
            certificates[0] = x509Certificate;
            ret = certificates[0];
            if (logger.isDebugEnabled()) {
                logger.debug("Success to convert string to client certificate [" + ret + "].");
            }
        } catch (CertificateException e) {
            logger.info("Failed to convert the string into certificate [" + attribute + "]. " + e.getMessage());
        }
    } else if (logger.isDebugEnabled()) {
        logger.debug("No client certificate found in the request.");
    }

    return ret;
}

From source file:be.fedict.hsm.jca.HSMProxyKeyStore.java

@Override
public Certificate engineGetCertificate(String alias) {
    try {/*from  w ww .  jav  a 2s . c  o m*/
        List<X509Certificate> certificateChain = this.keyStoreParameter.getHSMProxyClient()
                .getCertificateChain(alias);
        return certificateChain.get(0);
    } catch (CertificateException e) {
        LOG.error("certificate error: " + e.getMessage(), e);
        return null;
    }
}

From source file:be.fedict.hsm.jca.HSMProxyKeyStore.java

@Override
public Certificate[] engineGetCertificateChain(String alias) {
    List<X509Certificate> certificateChain;
    try {//from   w w  w.jav a  2 s  .  com
        certificateChain = this.keyStoreParameter.getHSMProxyClient().getCertificateChain(alias);
    } catch (CertificateException e) {
        LOG.error("certificate error: " + e.getMessage(), e);
        return null;
    }
    Certificate[] result = new Certificate[certificateChain.size()];
    return certificateChain.toArray(result);
}

From source file:com.vmware.o11n.plugin.crypto.model.CryptoCertificate.java

/**
 *
 * @return/*from  ww  w .j  av a2  s .c o m*/
 */
@VsoProperty(name = "encodedBase64", description = "Encoded form of the certificate encoded as a Base64 string.  Hashing this can create a fingerprint")
public String getEncodedBase64() {
    String toReturn = null;
    try {
        toReturn = service.getEncodedBase64(this.cert);
    } catch (CertificateException ce) {
        log.error(ce.getMessage());
    } catch (Throwable e) {
        log.error("Unexpected exception: " + e.getMessage());
    }
    return toReturn;
}

From source file:com.vmware.o11n.plugin.crypto.model.CryptoCertificate.java

/**
 *
 * @return/*from   ww  w  .  j a  va 2  s  . com*/
 */
@VsoProperty(name = "sha1Fingerprint", description = "SHA1 fingerprint of the certificate")
public String getSha1Fingerprint() {
    String toReturn = null;
    try {
        toReturn = service.getSha1Fingerprint(this.cert);
    } catch (CertificateException ce) {
        log.error(ce.getMessage());
    } catch (Throwable e) {
        log.error("Unexpected exception: " + e.getMessage());
    }
    return toReturn;
}

From source file:com.vmware.o11n.plugin.crypto.model.CryptoCertificate.java

/**
 *
 * @return//from   w  w w.java 2  s . co  m
 */
@VsoProperty(name = "sha256Fingerprint", description = "SHA256 fingerprint of the certificate")
public String getSha256Fingerprint() {
    String toReturn = null;
    try {
        toReturn = service.getSha256Fingerprint(this.cert);
    } catch (CertificateException ce) {
        log.error(ce.getMessage());
    } catch (Throwable e) {
        log.error("Unexpected exception: " + e.getMessage());
    }
    return toReturn;
}