⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsasignsessionbean.java

📁 一个免费的CA,基于EJB平台的,老师叫我们测试,现把之共享出来让大家参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
				if ( (cert == null) && (status == ResponseStatus.SUCCESS) ) {					status = ResponseStatus.FAILURE;					failInfo = FailInfo.BAD_REQUEST;                } else {                    ret.setCertificate(cert);                }                ret.setStatus(status);                if (failInfo != null) {                    ret.setFailInfo(failInfo);                     ret.setFailText(failText);                }            }            ret.create();            // Call authentication session and tell that we are finished with this user            if (ca.getFinishUser() == true) {            	finishUser(admin, req.getUsername(), req.getPassword());            }            	        } catch (NotFoundException oe) {            throw oe;        } catch (AuthStatusException se) {            throw se;        } catch (AuthLoginException le) {            throw le;        } catch (IllegalKeyException ke) {            log.error("Key is of unknown type: ", ke);            throw ke;        } 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 (IOException e) {            log.error("Cannot create response message: ", e);        } catch (CATokenOfflineException ctoe) {        	String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN());            log.error(msg, ctoe);            getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe);            throw new CADoesntExistsException(msg);        }        debug("<createCertificate(IRequestMessage)");        return ret;    }        /**     * Method that generates a request failed response message. The request     * should already have been decrypted and verified.     *     * @param admin         Information about the administrator or admin preforming the event.     * @param req           a Certification Request message, containing the public key to be put in the     *                      created certificate. Currently no additional parameters in requests are considered!     * @param responseClass The implementation class that will be used as the response message.     *      * @return A decrypted and verified IReqeust message     * @throws AuthStatusException           If the users status is incorrect.     * @throws AuthLoginException            If the password is incorrect.     * @throws CADoesntExistsException       if the targeted CA does not exist     * @throws SignRequestException          if the provided request is invalid.     * @throws SignRequestSignatureException if the the request couldn't be verified.     * @throws IllegalKeyException      * @ejb.permission unchecked="true"     * @ejb.interface-method view-type="both"     * @see se.anatom.ejbca.protocol.IRequestMessage     * @see se.anatom.ejbca.protocol.IResponseMessage     * @see se.anatom.ejbca.protocol.X509ResponseMessage     */    public IResponseMessage createRequestFailedResponse(Admin admin, IRequestMessage req,  Class responseClass) throws  AuthLoginException, AuthStatusException, IllegalKeyException, CADoesntExistsException, SignRequestSignatureException, SignRequestException {        debug(">createRequestFailedResponse(IRequestMessage)");        IResponseMessage ret = null;                    CADataLocal cadata = null;        try {        	cadata = getCAFromRequest(admin, req);            CA ca = cadata.getCA();            CAToken catoken = ca.getCAToken();                     // See if we need some key material to decrypt request            if (req.requireKeyInfo()) {                // You go figure...scep encrypts message with the public CA-cert                req.setKeyInfo((X509Certificate)ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());            }            // Verify the request            if (req.verify() == false) {            	String msg = intres.getLocalizedMessage("signsession.popverificationfailed");                getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, intres.getLocalizedMessage("signsession.popverificationfailed"));                throw new SignRequestSignatureException(msg);            }                        //Create the response message with all nonces and checks etc            ret = req.createResponseMessage(responseClass, req, ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_KEYENCRYPT), catoken.getProvider());                        ret.setStatus(ResponseStatus.FAILURE);            ret.setFailInfo(FailInfo.BAD_REQUEST);            ret.create();        } catch (AuthStatusException se) {            throw se;        } catch (AuthLoginException le) {            throw le;        } catch (IllegalKeyStoreException e) {            throw new IllegalKeyException(e);        } catch (NotFoundException e) {        	// This can actually not happen here?            throw new CADoesntExistsException(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 (IOException e) {            log.error("Cannot create response message: ", e);        } catch (CATokenOfflineException ctoe) {        	String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN());            log.error(msg, ctoe);            getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe);            throw new CADoesntExistsException(msg);        }        debug("<createRequestFailedResponse(IRequestMessage)");        return ret;    }    /**     * Method that just decrypts and verifies a request and should be used in those cases     * a when encrypted information needs to be extracted and presented to an RA for approval.     *     * @param admin         Information about the administrator or admin preforming the event.     * @param req           a Certification Request message, containing the public key to be put in the     *                      created certificate. Currently no additional parameters in requests are considered!     *      * @return A decrypted and verified IReqeust message     * @throws AuthStatusException           If the users status is incorrect.     * @throws AuthLoginException            If the password is incorrect.     * @throws IllegalKeyException           if the public key is of wrong type.     * @throws CADoesntExistsException       if the targeted CA does not exist     * @throws SignRequestException          if the provided request is invalid.     * @throws SignRequestSignatureException if the the request couldn't be verified.     * @ejb.permission unchecked="true"     * @ejb.interface-method view-type="both"     * @see se.anatom.ejbca.protocol.IRequestMessage     * @see se.anatom.ejbca.protocol.IResponseMessage     * @see se.anatom.ejbca.protocol.X509ResponseMessage     */    public IRequestMessage decryptAndVerifyRequest(Admin admin, IRequestMessage req) throws ObjectNotFoundException, AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException {        debug(">decryptAndVerifyRequest(IRequestMessage)");        // Get CA that will receive request        CADataLocal cadata = null;                    try {        	cadata = getCAFromRequest(admin, req);            CA ca = cadata.getCA();            CAToken catoken = ca.getCAToken();                        // See if we need some key material to decrypt request            if (req.requireKeyInfo()) {                // You go figure...scep encrypts message with the public CA-cert                req.setKeyInfo((X509Certificate)ca.getCACertificate(), catoken.getPrivateKey(SecConst.CAKEYPURPOSE_CERTSIGN), catoken.getProvider());            }            // Verify the request            if (req.verify() == false) {            	String msg = intres.getLocalizedMessage("signsession.popverificationfailed");            	getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), req.getUsername(), null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg);                throw new SignRequestSignatureException(msg);            }          } catch (AuthStatusException se) {            throw se;        } catch (AuthLoginException le) {            throw le;        } 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 (CATokenOfflineException ctoe) {        	String msg = intres.getLocalizedMessage("error.catokenoffline", cadata.getSubjectDN());            log.error(msg, ctoe);            getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_CREATECERTIFICATE, msg, ctoe);            throw new CADoesntExistsException(msg);        }        debug("<decryptAndVerifyRequest(IRequestMessage)");        return req;    }        /**     * Implements ISignSession::getCRL     *     * @param admin         Information about the administrator or admin preforming the event.     * @param req           a CRL Request message     * @param responseClass the implementation class of the desired response     * @return The newly created certificate or null.     * @throws IllegalKeyException           if the public key is of wrong type.     * @throws CADoesntExistsException       if the targeted CA does not exist     * @throws SignRequestException          if the provided request is invalid.     * @throws SignRequestSignatureException if the provided client certificate was not signed by     *                                       the CA.     * @ejb.interface-method view-type="both"     */    public IResponseMessage getCRL(Admin admin, IRequestMessage req, Class responseClass) throws AuthStatusException, AuthLoginException, IllegalKeyException, CADoesntExistsException, SignRequestException, SignRequestSignatureException, UnsupportedEncodingException {        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 = getCAFromRequest(admin, req);        try {            CA ca = cadata.getCA();            CAToken catoken = ca.getCAToken();            if (ca.getStatus() != SecConst.CA_ACTIVE) {            	String msg = intres.getLocalizedMessage("signsession.canotactive", cadata.getSubjectDN());            	getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg);                throw new EJBException(msg);            }            // 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);                ca.setStatus(SecConst.CA_EXPIRED);                String msg = intres.getLocalizedMessage("signsession.caexpired", cadata.getSubjectDN());                getLogSession().log(admin, cadata.getCaId().intValue(), LogEntry.MODULE_CA, new java.util.Date(), null, null, LogEntry.EVENT_ERROR_GETLASTCRL, msg, cee);                throw new CADoesntExistsException(msg);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -