getLogSession().log(admin, cadata.getCAId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, "Signing CA " + cadata.getSubjectDN() + " has expired", cee);
getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, "Signing CA " + cadata.getSubjectDN() + " has expired", cee);
    public IResponseMessage getCRL(Admin admin, IRequestMessage req, Class responseClass) throws IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException {        debug(">getCRL(IRequestMessage)");        IResponseMessage ret = null;        ICertificateStoreSessionLocal certificateStore = null;        try {            certificateStore = storeHome.create();        } catch (CreateException e) {            error("Can not create certificate store session: ", e);            throw new EJBException(e);        }        // Get CA that will receive request        CADataLocal cadata = null;        try {            // See if we can get issuerDN directly from request            if (req.getIssuerDN() != null) {                cadata = cadatahome.findByPrimaryKey(new Integer(req.getIssuerDN().hashCode()));                debug("Using CA (from issuerDN) with id: " + cadata.getCAId() + " and DN: " + cadata.getSubjectDN());            } else {                throw new CADoesntExistsException();            }        } catch (javax.ejb.FinderException fe) {            error("Can not find CA Id from issuerDN: " + req.getIssuerDN() + " or username: " + req.getUsername());            getLogSession().log(admin, -1, LogEntry.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogEntry.EVENT_ERROR_GETLASTCRL, "Invalid CA Id", fe);            throw new CADoesntExistsException(fe);        }        try {            CA ca = cadata.getCA();            CAToken catoken = ca.getCAToken();            if (ca.getStatus() != SecConst.CA_ACTIVE) {                getLogSession().log(admin, cadata.getCAId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, "Signing CA " + cadata.getSubjectDN() + " isn't active.");                throw new EJBException("Signing CA " + cadata.getSubjectDN() + " isn't active.");            }            // Check that CA hasn't expired.            X509Certificate cacert = (X509Certificate) ca.getCACertificate();            try {                cacert.checkValidity();            } catch (CertificateExpiredException cee) {                // Signers Certificate has expired.                cadata.setStatus(SecConst.CA_EXPIRED);                getLogSession().log(admin, cadata.getCAId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, "Signing CA " + cadata.getSubjectDN() + " has expired", cee);                throw new CADoesntExistsException("Signing CA " + cadata.getSubjectDN() + " has expired");            } catch (CertificateNotYetValidException cve) {                throw new CADoesntExistsException(cve);            }            //Create the response message with all nonces and checks etc            ret = createResponseMessage(responseClass, req, ca, catoken);                        // Get the CRL, don't even bother digging into the encrypted CRLIssuerDN...since we already            // know that we are the CA (SCEP is soooo stupid!)            byte[] crl = certificateStore.getLastCRL(admin, req.getIssuerDN());            if (crl != null) {                ret.setCrl(CertTools.getCRLfromByteArray(crl));                ret.setStatus(ResponseStatus.SUCCESS);            } else {                ret.setStatus(ResponseStatus.FAILURE);                ret.setFailInfo(FailInfo.BAD_REQUEST);            }            ret.create();            // TODO: handle returning errors as response message,            // javax.ejb.ObjectNotFoundException and the others thrown...        } catch (IllegalKeyStoreException e) {            throw new IllegalKeyException(e);        } catch (UnsupportedEncodingException e) {            throw new CADoesntExistsException(e);        } catch (NoSuchProviderException e) {            log.error("NoSuchProvider provider: ", e);        } catch (InvalidKeyException e) {            log.error("Invalid key in request: ", e);        } catch (NoSuchAlgorithmException e) {            log.error("No such algorithm: ", e);        } catch (CRLException e) {            log.error("Cannot create response message: ", e);        } catch (CertificateException e) {            log.error("Cannot create response message: ", e);        } catch (IOException e) {            log.error("Cannot create response message: ", e);        } catch (CATokenOfflineException ctoe) {            log.error("CA Token is Offline: ", ctoe);            cadata.setStatus(SecConst.CA_OFFLINE);            getLogSession().log(admin, cadata.getCAId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, "Signing CA " + cadata.getSubjectDN() + " is offline.", ctoe);            throw new CADoesntExistsException("Signing CA " + cadata.getSubjectDN() + " is offline.");        }        debug("<getCRL(IRequestMessage)");        return ret;    }