1 13 14 package org.ejbca.core.model.ca.catoken; 15 16 import java.security.KeyStore ; 17 import java.security.KeyStoreException ; 18 import java.security.NoSuchAlgorithmException ; 19 import java.security.Provider ; 20 import java.security.PublicKey ; 21 import java.security.Security ; 22 import java.security.UnrecoverableKeyException ; 23 24 import org.apache.log4j.Logger; 25 26 33 public class EracomCAToken extends BaseCAToken implements IHardCAToken { 34 35 36 private static final Logger log = Logger.getLogger(EracomCAToken.class); 37 38 static final private String SLOT_LABEL_KEY = "slot"; 39 static final private String PROVIDER_CLASS = "au.com.eracom.crypto.provider.slot0.ERACOMProvider"; 40 41 45 public EracomCAToken() throws InstantiationException , IllegalAccessException { 46 super(PROVIDER_CLASS, null, SLOT_LABEL_KEY); 47 } 48 49 52 public void activate(String authCode) throws CATokenOfflineException, 53 CATokenAuthenticationFailedException { 54 try { 55 if ( Security.getProvider(getProvider())==null ) { 56 57 Class cl = Class.forName("au.com.eracom.crypto.provider.slot"+sSlotLabel+".ERACOMProvider"); 58 Provider prov = (Provider )cl.newInstance(); 59 Security.addProvider(prov); 60 } 61 if ( Security.getProvider(getProvider())==null ) 62 throw new CATokenOfflineException("not possible to install eracaom provider"); 63 KeyStore keyStore = KeyStore.getInstance("CRYPTOKI", "ERACOM."+sSlotLabel); 64 log.debug("Loading key from slot"+sSlotLabel+" using pin."); 65 keyStore.load(null, (authCode!=null && authCode.length()>0)? authCode.toCharArray():null); 66 setKeys(keyStore, authCode); 67 } 68 catch (Throwable t) { 69 log.error("Failed to initialize Eracom provider slot '"+sSlotLabel+"'.", t); 70 throw new CATokenAuthenticationFailedException("Failed to initialize Eracom provider keystore '"+sSlotLabel+"'."); 71 } 72 73 } 74 77 protected PublicKey readPublicKey(KeyStore keyStore, String alias) throws KeyStoreException , NoSuchAlgorithmException , UnrecoverableKeyException { 78 return (PublicKey )keyStore.getKey(alias+"_pub", null); 79 } 80 83 public String getProvider() { 84 log.debug("getProvider()"); 85 return "ERACOM."+sSlotLabel; 86 } 87 88 } 89 | Popular Tags |