Example usage for java.security.cert CRLException toString

List of usage examples for java.security.cert CRLException toString

Introduction

In this page you can find the example usage for java.security.cert CRLException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.netscape.ca.CertificateAuthority.java

/**
 * Signs CRL using the specified signature algorithm.
 * If no algorithm is specified the CA's default signing algorithm
 * is used./*from  www. j a v  a 2  s .com*/
 * <P>
 *
 * @param crl the CRL to be signed.
 * @param algname the algorithm name to use. This is a JCA name such
 *            as MD5withRSA, etc. If set to null the default signing algorithm
 *            is used.
 *
 * @return the signed CRL
 */
public X509CRLImpl sign(X509CRLImpl crl, String algname) throws EBaseException {
    ensureReady();
    X509CRLImpl signedcrl = null;

    IStatsSubsystem statsSub = (IStatsSubsystem) CMS.getSubsystem("stats");
    if (statsSub != null) {
        statsSub.startTiming("signing");
    }

    try (DerOutputStream out = new DerOutputStream()) {
        DerOutputStream tmp = new DerOutputStream();

        if (algname == null) {
            algname = mSigningUnit.getDefaultAlgorithm();
        }

        crl.encodeInfo(tmp);
        AlgorithmId.get(algname).encode(tmp);

        byte[] tbsCertList = crl.getTBSCertList();

        byte[] signature = mCRLSigningUnit.sign(tbsCertList, algname);

        if (crl.setSignature(signature)) {
            tmp.putBitString(signature);
            out.write(DerValue.tag_Sequence, tmp);

            if (crl.setSignedCRL(out.toByteArray())) {
                signedcrl = crl;
                // signedcrl = new X509CRLImpl(out.toByteArray());
            } else {
                logger.warn("Failed to add signed-CRL to CRL object.");
            }
        } else {
            logger.warn("Failed to add signature to CRL object.");
        }
    } catch (CRLException e) {
        log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_CA_SIGN_CRL", e.toString(), e.getMessage()));
        throw new ECAException(CMS.getUserMessage("CMS_CA_SIGNING_CRL_FAILED", e.getMessage()));
    } catch (X509ExtensionException e) {
        log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_CA_SIGN_CRL", e.toString(), e.getMessage()));
        throw new ECAException(CMS.getUserMessage("CMS_CA_SIGNING_CRL_FAILED", e.getMessage()));
    } catch (NoSuchAlgorithmException e) {
        log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_CA_SIGN_CRL", e.toString(), e.getMessage()));
        throw new ECAException(CMS.getUserMessage("CMS_CA_SIGNING_CRL_FAILED", e.getMessage()));
    } catch (IOException e) {
        log(ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_CA_CA_SIGN_CRL", e.toString(), e.getMessage()));
        throw new ECAException(CMS.getUserMessage("CMS_CA_SIGNING_CRL_FAILED", e.getMessage()));
    } finally {
        if (statsSub != null) {
            statsSub.endTiming("signing");
        }
    }

    return signedcrl;
}