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

📄 ca.java

📁 JAVA做的J2EE下CA认证系统 基于EJB开发
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/************************************************************************* *                                                                       * *  EJBCA: The OpenSource Certificate Authority                          * *                                                                       * *  This software is free software; you can redistribute it and/or       * *  modify it under the terms of the GNU Lesser General Public           * *  License as published by the Free Software Foundation; either         * *  version 2.1 of the License, or any later version.                    * *                                                                       * *  See terms of license at gnu.org.                                     * *                                                                       * *************************************************************************/ package se.anatom.ejbca.ca.caadmin;import java.io.Serializable;import java.security.KeyPair;import java.security.PublicKey;import java.security.cert.CRL;import java.security.cert.Certificate;import java.util.ArrayList;import java.util.Collection;import java.util.Date;import java.util.HashMap;import java.util.Iterator;import java.util.Vector;import javax.ejb.EJBException;import org.apache.log4j.Logger;import org.bouncycastle.cms.CMSException;import se.anatom.ejbca.ca.caadmin.extendedcaservices.ExtendedCAService;import se.anatom.ejbca.ca.caadmin.extendedcaservices.ExtendedCAServiceInfo;import se.anatom.ejbca.ca.caadmin.extendedcaservices.ExtendedCAServiceNotActiveException;import se.anatom.ejbca.ca.caadmin.extendedcaservices.ExtendedCAServiceRequest;import se.anatom.ejbca.ca.caadmin.extendedcaservices.ExtendedCAServiceRequestException;import se.anatom.ejbca.ca.caadmin.extendedcaservices.ExtendedCAServiceResponse;import se.anatom.ejbca.ca.caadmin.extendedcaservices.IllegalExtendedCAServiceRequestException;import se.anatom.ejbca.ca.caadmin.extendedcaservices.KeyRecoveryCAServiceRequest;import se.anatom.ejbca.ca.caadmin.extendedcaservices.KeyRecoveryCAServiceResponse;import se.anatom.ejbca.ca.caadmin.extendedcaservices.OCSPCAService;import se.anatom.ejbca.ca.caadmin.extendedcaservices.OCSPCAServiceInfo;import se.anatom.ejbca.ca.caadmin.extendedcaservices.OCSPCAServiceRequest;import se.anatom.ejbca.ca.caadmin.hardcatokens.HardCATokenManager;import se.anatom.ejbca.ca.exception.IllegalKeyStoreException;import se.anatom.ejbca.ca.exception.SignRequestSignatureException;import se.anatom.ejbca.ca.store.certificateprofiles.CertificateProfile;import se.anatom.ejbca.common.UserDataVO;import se.anatom.ejbca.util.Base64;import se.anatom.ejbca.util.CertTools;import se.anatom.ejbca.util.UpgradeableDataHashMap;/** * CA is a base class that should be inherited by all CA types * * @version $Id: CA.java,v 1.19 2005/06/14 15:02:30 anatom Exp $ */public abstract class CA extends UpgradeableDataHashMap implements Serializable {    /** Log4j instance */    private static Logger log = Logger.getLogger(CA.class);	public static final String TRUE  = "true";    public static final String FALSE = "false";        // protected fields.    public    static final String CATYPE                         = "catype";    protected static final String SUBJECTDN                      = "subjectdn";    protected static final String CAID                           = "caid";    protected static final String NAME                           = "name";    protected static final String STATUS                         = "status";    protected static final String VALIDITY                       = "validity";    protected static final String EXPIRETIME                     = "expiretime";    protected static final String CERTIFICATECHAIN               = "certificatechain";    protected static final String CATOKENDATA                    = "catoken";    protected static final String SIGNEDBY                       = "signedby";    protected static final String DESCRIPTION                    = "description";    protected static final String REVOKATIONREASON               = "revokationreason";	protected static final String REVOKATIONDATE                 = "revokationdate";    protected static final String CERTIFICATEPROFILEID           = "certificateprofileid";    protected static final String CRLPERIOD                      = "crlperiod";    protected static final String CRLPUBLISHERS                  = "crlpublishers";	protected static final String FINISHUSER                     = "finishuser";	protected static final String REQUESTCERTCHAIN               = "requestcertchain";	protected static final String EXTENDEDCASERVICES             = "extendedcaservices";	protected static final String EXTENDEDCASERVICE              = "extendedcaservice";        // Public Methods    /** Creates a new instance of CA, this constuctor should be used when a new CA is created */    public CA(CAInfo cainfo){       data = new HashMap();              this.cainfo = cainfo;                     data.put(VALIDITY, new Integer(cainfo.getValidity()));       data.put(SIGNEDBY, new Integer(cainfo.getSignedBy()));       data.put(DESCRIPTION, cainfo.getDescription());       data.put(REVOKATIONREASON, new Integer(-1));       data.put(CERTIFICATEPROFILEID, new Integer(cainfo.getCertificateProfileId()));       setCRLPeriod(cainfo.getCRLPeriod());       setCRLPublishers(cainfo.getCRLPublishers());       setFinishUser(cainfo.getFinishUser());       	   extendedcaservicemap = new HashMap();	   Iterator iter = cainfo.getExtendedCAServiceInfos().iterator();	   ArrayList extendedservicetypes = new ArrayList(); 	   while(iter.hasNext()){	   	 ExtendedCAServiceInfo next = (ExtendedCAServiceInfo) iter.next();	   	 if(next instanceof OCSPCAServiceInfo){	   	   setExtendedCAService(new OCSPCAService(next));	   	   extendedservicetypes.add(new Integer(OCSPCAService.TYPE));	   	 }	   }	   data.put(EXTENDEDCASERVICES, extendedservicetypes);    }        /** Constructor used when retrieving existing CA from database. */    public CA(HashMap data, CADataBean owner){      loadData(data);      this.owner = owner;      	  extendedcaservicemap = new HashMap();    }    // Public Methods.    public String getSubjectDN(){    	if(owner == null)      	  return cainfo.getSubjectDN();    	    	return owner.getSubjectDN();    }        public int getCAId(){    	if(owner == null)    		return cainfo.getCAId();    	    	return owner.getCaId().intValue();    }            public int getCAType(){ return ((Integer)data.get(CATYPE)).intValue();}        public String getName(){    	if(owner == null)    	  return cainfo.getName();    	    	return owner.getName();    }        public void setName(String name) { owner.setName(name);}    public int getStatus(){    	    	    	    	if(owner == null)      	  return cainfo.getStatus();	    	    	return owner.getStatus();    }        public void setStatus(int status) {     	    	owner.setStatus(status);    	    }            public int getValidity(){ return ((Integer) data.get(VALIDITY)).intValue();}    public void setValidity(int validity){ data.put(VALIDITY,  new Integer(validity));}        public Date getExpireTime(){return ((Date)data.get(EXPIRETIME));}    public void setExpireTime(Date expiretime) { data.put(EXPIRETIME,expiretime);}           public int getSignedBy(){ return ((Integer) data.get(SIGNEDBY)).intValue();}        public String getDescription(){return ((String)data.get(DESCRIPTION));}    public void setDescription(String description) { data.put(DESCRIPTION,description);}          public int getRevokationReason(){return ((Integer) data.get(REVOKATIONREASON)).intValue();}    public void setRevokationReason(int reason){ data.put(REVOKATIONREASON,new Integer(reason));}        	public Date getRevokationDate(){return (Date) data.get(REVOKATIONDATE);}	public void setRevokationDate(Date date){ data.put(REVOKATIONDATE,date);}                    public int  getCRLPeriod(){return ((Integer)data.get(CRLPERIOD)).intValue();}    public void setCRLPeriod(int crlperiod) {data.put(CRLPERIOD, new Integer(crlperiod));}        public Collection  getCRLPublishers(){return ((Collection)data.get(CRLPUBLISHERS));}    public void setCRLPublishers(Collection crlpublishers) {data.put(CRLPUBLISHERS, crlpublishers);}                public int getCertificateProfileId() {return ((Integer) data.get(CERTIFICATEPROFILEID)).intValue();}        /** Returns the CAs token. The token is fetched from the token registry, or created and added to the token registry.     *      * @return The CAs token, be it soft or hard.     * @throws IllegalKeyStoreException If the token keystore is invalid (crypto error thrown by crypto provider), or the CA token type is undefined.     */    public CAToken getCAToken() throws IllegalKeyStoreException {        CAToken ret = HardCATokenManager.instance().getCAToken(getCAId());        if (ret == null) {            switch(((Integer) ((HashMap)data.get(CATOKENDATA)).get(CAToken.CATOKENTYPE)).intValue()) {            case CATokenInfo.CATOKENTYPE_P12:                ret = new SoftCAToken((HashMap)data.get(CATOKENDATA));                break;            case CATokenInfo.CATOKENTYPE_HSM:                ret = new HardCATokenContainer((HashMap)data.get(CATOKENDATA));                 break;            case CATokenInfo.CATOKENTYPE_NULL:                ret = new NullCAToken();                break;            default:                throw new IllegalKeyStoreException("No CA Token type defined!");            }            HardCATokenManager.instance().addCAToken(getCAId(), ret);        }                  return ret;    }                /** Sets the CA token. Adds or updates the token in the token registry.     *      * @param catoken The CAs token, be it soft or hard.     */    public void setCAToken(CAToken catoken){       data.put(CATOKENDATA, catoken.saveData());               HardCATokenManager.instance().addCAToken(getCAId(), catoken);    }        public Collection getRequestCertificateChain(){      if(requestcertchain == null){        Collection storechain = (Collection) data.get(REQUESTCERTCHAIN);        Iterator iter = storechain.iterator();        this.requestcertchain = new ArrayList();        while(iter.hasNext()){          String b64Cert = (String) iter.next();

⌨️ 快捷键说明

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