1 17 package org.apache.servicemix.soap.handlers.security; 18 19 import java.security.KeyStoreException ; 20 import java.security.PrivateKey ; 21 import java.security.cert.Certificate ; 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.List ; 25 26 import org.apache.servicemix.jbi.security.keystore.KeystoreInstance; 27 import org.apache.servicemix.jbi.security.keystore.KeystoreManager; 28 29 public class KeystoreInstanceCrypto extends BaseCrypto { 30 31 private KeystoreInstance keystore; 32 33 public KeystoreInstanceCrypto() { 34 } 35 36 public KeystoreInstanceCrypto(KeystoreInstance keystore) { 37 this.keystore = keystore; 38 } 39 40 public KeystoreInstanceCrypto(KeystoreManager keystoreManager, String keystore) { 41 this.keystore = keystoreManager.getKeystore(keystore); 42 } 43 44 47 public KeystoreInstance getKeystore() { 48 return keystore; 49 } 50 51 54 public void setKeystore(KeystoreInstance keystore) { 55 this.keystore = keystore; 56 } 57 58 protected String [] getAliases() throws KeyStoreException { 59 String [] pks = keystore.listPrivateKeys(); 60 String [] tcs = keystore.listTrustCertificates(); 61 List aliases = new ArrayList (); 62 aliases.addAll(Arrays.asList(pks)); 63 aliases.addAll(Arrays.asList(tcs)); 64 return (String []) aliases.toArray(new String [aliases.size()]); 65 } 66 67 protected Certificate getCertificate(String alias) throws KeyStoreException { 68 return keystore.getCertificate(alias); 69 } 70 71 protected String getCertificateAlias(Certificate cert) throws KeyStoreException { 72 return keystore.getCertificateAlias(cert); 73 } 74 75 protected Certificate [] getCertificateChain(String alias) throws KeyStoreException { 76 return keystore.getCertificateChain(alias); 77 } 78 79 public PrivateKey getPrivateKey(String alias, String password) throws Exception { 80 return keystore.getPrivateKey(alias); 81 } 82 83 protected String [] getTrustCertificates() throws KeyStoreException { 84 return keystore.listTrustCertificates(); 85 } 86 87 } 88 | Popular Tags |