1 13 14 package org.ejbca.core.model.hardtoken.profiles; 15 16 import java.io.ObjectInputStream ; 17 import java.io.ObjectOutputStream ; 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.HashMap ; 21 import java.util.Iterator ; 22 import java.util.List ; 23 24 import javax.ejb.EJBException ; 25 26 import org.ejbca.core.model.SecConst; 27 import org.ejbca.core.model.ca.caadmin.CAInfo; 28 29 30 31 32 39 public abstract class EIDProfile extends HardTokenProfileWithAdressLabel { 40 41 public static final String KEYTYPE_RSA = "RSA"; 42 43 public static final int CAID_USEUSERDEFINED = SecConst.CAID_USEUSERDEFINED; 44 45 protected static final String CERTIFICATEPROFILEID = "certificateprofileid"; 47 protected static final String CAID = "caid"; 48 protected static final String ISKEYRECOVERABLE = "iskeyrecoverable"; 49 protected static final String REUSEOLDCERTIFICATE = "reuseoldcertificate"; 50 protected static final String MINIMUMKEYLENGTH = "minimunkeylength"; 51 protected static final String KEYTYPES = "keytypes"; 52 protected static final String CERTWRITABLE = "certwritable"; 53 54 55 56 public EIDProfile() { 58 super(); 59 60 } 61 62 70 public int getCertificateProfileId(int certusage){return ((Integer ) ((List ) data.get(CERTIFICATEPROFILEID)).get(certusage)).intValue();} 71 72 73 81 public boolean getCertWritable(int certusage){ return ((Boolean ) ((List ) data.get(CERTWRITABLE)).get(certusage)).booleanValue();} 82 83 92 public int getCAId (int certusage){return ((Integer ) ((List ) data.get(CAID)).get(certusage)).intValue();} 93 94 95 101 public boolean getIsKeyRecoverable (int certusage){return ((Boolean ) ((List ) data.get(ISKEYRECOVERABLE)).get(certusage)).booleanValue();} 102 103 110 public boolean getReuseOldCertificate (int certusage){return ((Boolean ) ((List ) data.get(REUSEOLDCERTIFICATE)).get(certusage)).booleanValue();} 111 112 119 public int getMinimumKeyLength (int certusage){return ((Integer ) ((List ) data.get(MINIMUMKEYLENGTH)).get(certusage)).intValue(); } 120 121 129 public String getKeyType (int certusage){return ((String ) ((List ) data.get(KEYTYPES)).get(certusage)); } 130 131 133 136 public void setCertificateProfileId(int certusage, int certprofileid){ 137 List list = (List ) data.get(CERTIFICATEPROFILEID); 138 list.set(certusage, new Integer (certprofileid)); 139 data.put(CERTIFICATEPROFILEID, list); 140 } 141 142 143 146 public void setCertWritable(int certusage, boolean certWritable){ 147 List list = (List ) data.get(CERTWRITABLE); 148 list.set(certusage, Boolean.valueOf(certWritable)); 149 data.put(CERTWRITABLE, list); 150 } 151 152 155 public void setCAId (int certusage, int caid){ 156 List list = (List ) data.get(CAID); 157 list.set(certusage, new Integer (caid)); 158 data.put(CAID, list); 159 } 160 161 164 public void setIsKeyRecoverable (int certusage, boolean iskeyrecoverable){ 165 List list = (List ) data.get(ISKEYRECOVERABLE); 166 list.set(certusage, Boolean.valueOf(iskeyrecoverable)); 167 data.put(ISKEYRECOVERABLE, list); 168 } 169 170 173 public void setReuseOldCertificate (int certusage, boolean reuseoldcertificate){ 174 List list = (List ) data.get(REUSEOLDCERTIFICATE); 175 list.set(certusage, Boolean.valueOf(reuseoldcertificate)); 176 data.put(REUSEOLDCERTIFICATE, list); 177 } 178 179 182 public void setMinimumKeyLength (int certusage, int minimumkeylength){ 183 List list = (List ) data.get(MINIMUMKEYLENGTH); 184 list.set(certusage, new Integer (minimumkeylength)); 185 data.put(MINIMUMKEYLENGTH, list); 186 } 187 188 191 public void setKeyType (int certusage, String keytype){ 192 List list = (List ) data.get(KEYTYPES); 193 list.set(certusage, keytype); 194 data.put(KEYTYPES, list); 195 } 196 197 201 public Collection getAllCertificateProfileIds(){ 202 return (Collection ) data.get(CERTIFICATEPROFILEID); 203 } 204 205 211 public Collection getAllCAIds(){ 212 Collection caids = (Collection ) data.get(CAID); 213 ArrayList retval = new ArrayList (); 214 Iterator iter = caids.iterator(); 215 while(iter.hasNext()){ 216 Integer value = (Integer ) iter.next(); 217 if(value.intValue() > CAInfo.SPECIALCAIDBORDER || value.intValue() < 0){ 218 retval.add(value); 219 } 220 } 221 222 return retval; 223 } 224 225 public abstract int[] getAvailableMinimumKeyLengths(); 226 227 public void upgrade(){ 228 super.upgrade(); 230 } 231 232 public boolean isTokenSupported(String [][] supportedcards, String tokenidentificationstring){ 234 boolean returnval = true; 235 Iterator iter = ((List ) data.get(MINIMUMKEYLENGTH)).iterator(); 236 int[] availablekeylengths = getAvailableMinimumKeyLengths(); 237 238 while(iter.hasNext()){ 239 int index = -1; 240 int keylength = ((Integer ) iter.next()).intValue(); 241 for(int i=0;i<availablekeylengths.length;i++){ 242 if(availablekeylengths[i] == keylength){ 243 index=i; 244 break; 245 } 246 } 247 returnval = returnval && super.isTokenSupported(supportedcards[index], tokenidentificationstring); 248 } 249 250 return returnval; 251 } 252 253 257 258 protected void clone(EIDProfile emptyclone){ 259 java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream (); 260 261 try{ 262 ObjectOutputStream oos = new ObjectOutputStream (baos); 263 oos.writeObject(this.saveData()); 264 oos.close(); 265 ObjectInputStream ois = new ObjectInputStream (new java.io.ByteArrayInputStream (baos.toByteArray())); 266 HashMap cloneddata = (HashMap ) ois.readObject(); 267 ois.close(); 268 emptyclone.loadData(cloneddata); 269 }catch(Exception e){ 270 throw new EJBException (e); 271 } 272 } 273 274 275 } 276 | Popular Tags |