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

📄 localcertificatestoresessionbean.java

📁 用来生成java证书
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
     * Checks if a certificate is revoked.     *     * @param admin    Administrator performing the operation     * @param issuerDN the DN of the issuer.     * @param serno    the serialnumber of the certificate that will be checked     * @return RevokedCertInfo with revocation information, with reason RevokedCertInfo.NOT_REVOKED if NOT revoked. Returns null if certificate is not found.     * @ejb.interface-method     */    public RevokedCertInfo isRevoked(Admin admin, String issuerDN, BigInteger serno) {        return CertificateDataUtil.isRevoked(admin, issuerDN, serno, certHome, protecthome, adapter);    } //isRevoked    /**     * Checks if a certificate is revoked.     *     * @param admin    Administrator performing the operation     * @param fingerprint SHA1 fingerprint of the certificate.     * @return RevokedCertInfo with revocation information, with reason RevokedCertInfo.NOT_REVOKED if NOT revoked. Returns null if certificate is not found.     * @ejb.interface-method     */    public RevokedCertInfo isRevoked(Admin admin, String fingerprint) {        RevokedCertInfo revinfo = null;		try {			log.debug("Checking revocation for certificate with fp: "+fingerprint);			CertificateDataLocal data = certHome.findByPrimaryKey(new CertificateDataPK(fingerprint));	        Certificate cert = data.getCertificate();	        revinfo = new RevokedCertInfo(data.getFingerprint(), CertTools.getSerialNumber(cert), new Date(data.getRevocationDate()), data.getRevocationReason(), new Date(data.getExpireDate()));	        log.debug("isRevoked: "+revinfo.isRevoked());	    	// Make sure we have it as NOT revoked if it isn't	    	if (data.getStatus() != CertificateDataBean.CERT_REVOKED) {	    		revinfo.setReason(RevokedCertInfo.NOT_REVOKED);	    	}		} catch (FinderException e) {			log.debug("Certificate does not exists with fp: "+fingerprint);		}    	return revinfo;    } //isRevoked    /**     * Retrieves the latest CRL issued by this CA.     *     * @param admin Administrator performing the operation     * @param issuerdn the CRL issuers DN (CAs subject DN)     * @param deltaCRL true to get the latest deltaCRL, false to get the latestcomplete CRL     * @return byte[] with DER encoded X509CRL or null of no CRLs have been issued.     * @ejb.interface-method     */    public byte[] getLastCRL(Admin admin, String issuerdn, boolean deltaCRL) {        debug(">getLastCRL(" + issuerdn + ", "+deltaCRL+")");        try {            int maxnumber = getLastCRLNumber(admin, issuerdn, deltaCRL);            X509CRL crl = null;            try {                CRLDataLocal data = crlHome.findByIssuerDNAndCRLNumber(issuerdn, maxnumber);                crl = data.getCRL();            } catch (FinderException e) {                crl = null;            }            debug("<getLastCRL()");            if (crl == null) {            	String msg = intres.getLocalizedMessage("store.errorgetcrl", issuerdn, maxnumber);            	                getLogSession().log(admin, admin.getCaId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_GETLASTCRL, msg);                return null;            }        	String msg = intres.getLocalizedMessage("store.getcrl", issuerdn, new Integer(maxnumber));            	            getLogSession().log(admin, crl.getIssuerDN().toString().hashCode(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_INFO_GETLASTCRL, msg);            return crl.getEncoded();        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorgetcrl", issuerdn);            	            getLogSession().log(admin, admin.getCaId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_GETLASTCRL, msg);            throw new EJBException(e);        }    } //getLastCRL    /**     * Retrieves the information about the lastest CRL issued by this CA. Retreives less information than getLastCRL, i.e. not the actual CRL data.     *     * @param admin Administrator performing the operation     * @param issuerdn the CRL issuers DN (CAs subject DN)     * @param deltaCRL true to get the latest deltaCRL, false to get the latestcomplete CRL     * @return CRLInfo of last CRL by CA.     * @ejb.interface-method     */    public CRLInfo getLastCRLInfo(Admin admin, String issuerdn, boolean deltaCRL) {        debug(">getLastCRLInfo(" + issuerdn + ", "+deltaCRL+")");        int crlnumber = 0;        try {            crlnumber = getLastCRLNumber(admin, issuerdn, deltaCRL);            CRLInfo crlinfo = null;            try {                CRLDataLocal data = crlHome.findByIssuerDNAndCRLNumber(issuerdn, crlnumber);                crlinfo = new CRLInfo(data.getIssuerDN(), crlnumber, data.getThisUpdate(), data.getNextUpdate());            } catch (FinderException e) {            	if (deltaCRL && (crlnumber == 0)) {            		log.debug("No delta CRL exists for CA with dn '"+issuerdn+"'");            	} else if (crlnumber == 0) {            		log.debug("No CRL exists for CA with dn '"+issuerdn+"'");            	} else {                	String msg = intres.getLocalizedMessage("store.errorgetcrl", issuerdn, new Integer(crlnumber));            	                    log.error(msg, e);            		            	}                crlinfo = null;            }            debug("<getLastCRLInfo()");            return crlinfo;        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorgetcrlinfo", issuerdn);            	            getLogSession().log(admin, issuerdn.hashCode(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_GETLASTCRL, msg);            throw new EJBException(e);        }    } //getLastCRLInfo    /**     * Retrieves the highest CRLNumber issued by the CA.     *     * @param admin    Administrator performing the operation     * @param issuerdn the subjectDN of a CA certificate     * @param deltaCRL true to get the latest deltaCRL, false to get the latest complete CRL     * @ejb.interface-method     */    public int getLastCRLNumber(Admin admin, String issuerdn, boolean deltaCRL) {        debug(">getLastCRLNumber(" + issuerdn + ", "+deltaCRL+")");        Connection con = null;        PreparedStatement ps = null;        ResultSet result = null;        try {            con = JDBCUtil.getDBConnection(JNDINames.DATASOURCE);            String sql = "select MAX(cRLNumber) from CRLData where issuerDN=? and deltaCRLIndicator=?";            String deltaCRLSql = "select MAX(cRLNumber) from CRLData where issuerDN=? and deltaCRLIndicator>?";            int deltaCRLIndicator = -1;            if (deltaCRL) {            	sql = deltaCRLSql;            	deltaCRLIndicator = 0;            }            ps = con.prepareStatement(sql);            ps.setString(1, issuerdn);            ps.setInt(2, deltaCRLIndicator);            	            result = ps.executeQuery();            int maxnumber = 0;            if (result.next())                maxnumber = result.getInt(1);            debug("<getLastCRLNumber(" + maxnumber + ")");            return maxnumber;        } catch (Exception e) {            throw new EJBException(e);        } finally {            JDBCUtil.close(con, ps, result);        }    } //getLastCRLNumber    /**     * Method used to add a CertReqHistory to database     *      * @param admin calling the methods     * @param cert the certificate to store (Only X509Certificate used for now)     * @param useradmindata the user information used when issuing the certificate.     * @ejb.transaction type="Required"     * @ejb.interface-method          */    public void addCertReqHistoryData(Admin admin, Certificate cert, UserDataVO useradmindata){        debug(">addCertReqHistData(" + CertTools.getSerialNumberAsString(cert) + ", " + CertTools.getIssuerDN(cert) + ", " + useradmindata.getUsername() + ")");        try {            CertReqHistoryDataPK pk = new CertReqHistoryDataPK();            pk.fingerprint = CertTools.getFingerprintAsString(cert);            certReqHistoryHome.create(cert,useradmindata);        	String msg = intres.getLocalizedMessage("store.storehistory", useradmindata.getUsername());            	            getLogSession().log(admin, cert, LogConstants.MODULE_CA, new java.util.Date(), useradmindata.getUsername(), cert, LogConstants.EVENT_INFO_STORECERTIFICATE, msg);                    } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorstorehistory", useradmindata.getUsername());            	            getLogSession().log(admin, cert, LogConstants.MODULE_CA, new java.util.Date(), useradmindata.getUsername(), cert, LogConstants.EVENT_ERROR_STORECERTIFICATE, msg);            throw new EJBException(e);        }        debug("<addCertReqHistData()");    	    }        /**     * Method to remove CertReqHistory data.     * @param admin     * @param certFingerprint the primary key.     * @ejb.transaction type="Required"         * @ejb.interface-method       */    public void removeCertReqHistoryData(Admin admin, String certFingerprint){    	debug(">removeCertReqHistData(" + certFingerprint + ")");        try {                      CertReqHistoryDataPK pk = new CertReqHistoryDataPK();            pk.fingerprint = certFingerprint;        	String msg = intres.getLocalizedMessage("store.removehistory", certFingerprint);            	            getLogSession().log(admin, admin.getCaId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_INFO_STORECERTIFICATE, msg);            this.certReqHistoryHome.remove(pk);        } catch (Exception e) {        	String msg = intres.getLocalizedMessage("store.errorremovehistory", certFingerprint);            	            getLogSession().log(admin, admin.getCaId(), LogConstants.MODULE_CA, new java.util.Date(), null, null, LogConstants.EVENT_ERROR_STORECERTIFICATE, msg);            throw new EJBException(e);        }        debug("<removeCertReqHistData()");       	    }        /**     * Retrieves the certificate request data belonging to given certificate serialnumber and issuerdn     *      * @param admin     * @param certificateSN serial number of the certificate     * @param issuerDN     * @return the CertReqHistory or null if no data is stored with the certificate.     * @ejb.interface-method     */    public CertReqHistory getCertReqHistory(Admin admin, BigInteger certificateSN, String issuerDN){    	CertReqHistory retval = null;    	    	try{    	  Collection result = certReqHistoryHome.findByIssuerDNSerialNumber(issuerDN, certificateSN.toString());    	  if(result.iterator().hasNext())    	    retval = ((CertReqHistoryDataLocal) result.iterator().next()).getCertReqHistory();    	}catch(FinderException fe){    		// Do nothing but return null    	}    	    	return retval;    }            /**     * Retrieves all cert request datas belonging to a user.     * @param admin     * @param username     * @return a collection of CertReqHistory     * @ejb.interface-method     */    public List getCertReqHistory(Admin admin, String username){    	ArrayList retval = new ArrayList();    	    	try{    	  Collection result = certReqHistoryHome.findByUsername(username);    	  Iterator iter = result.iterator();    	  while(iter.hasNext()){    	    retval.add(((CertReqHistoryDataLocal) iter.next()).getCertReqHistory());    	  }    	}catch(FinderException fe){    		// Do nothing but return null    	}    	    	return retval;    }        /**     * A method designed to be called at startuptime to (possibly) upgrade certificate profiles.     * This method will read all Certificate Profiles and as a side-effect upgrade them if the version if changed for upgrade.     * Can have a side-effect of upgrading a profile, therefore the Required transaction setting.     *      * @param admin administrator calling the method     *      * @ejb.transaction type="Required"     * @ejb.interface-method     */    public void initializeAndUpgradeProfiles(Admin admin) {    	try {    		Collection result = certprofilehome.findAll();    		Iterator iter = result.iterator();    		while(iter.hasNext()){    			CertificateProfileDataLocal pdata = (CertificateProfileDataLocal)iter.next();    			String name = pdata.getCertificateProfileName();    			pdata.upgradeProfile();    			log.debug("Loaded certificate profile: "+name);    		}    	} catch (FinderException e) {    		log.error("FinderException trying to load profiles: ", e);    	}    }        /**     * Adds a certificate profile to the database.     *     * @param admin                  administrator performing the task     * @param certificateprofilename readable name of new certificate profile     * @param certificateprofile     the profile to be added     * @ejb.transaction type="Required"     * @ejb.interface-method     */    public void addCertificateProfile(Admin admin, String certificateprofilename,                                      CertificateProfile certificateprofile) throws CertificateProfileExistsException {        addCertificateProfile(admin, findFreeCertificateProfileId(), certificatepro

⌨️ 快捷键说明

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