1 18 19 package org.apache.jmeter.util.keystore; 20 21 import java.io.InputStream ; 22 import java.security.KeyStore ; 23 import java.security.PrivateKey ; 24 import java.security.cert.Certificate ; 25 import java.security.cert.X509Certificate ; 26 import java.util.Enumeration ; 27 28 34 public class DefaultKeyStore extends JmeterKeyStore 35 { 36 private X509Certificate [] certChain; 37 private PrivateKey key; 38 private String alias; 39 private final KeyStore store; 40 41 public DefaultKeyStore(String type) throws Exception 42 { 43 this.store = KeyStore.getInstance(type); 44 } 45 46 public void load(InputStream is, String pword) throws Exception 47 { 48 store.load(is, pword.toCharArray()); 49 PrivateKey key = null; 50 X509Certificate [] certChain = null; 51 52 Enumeration aliases = store.aliases(); 53 while (aliases.hasMoreElements()) 54 { 55 this.alias = (String ) aliases.nextElement(); 56 if (store.isKeyEntry(alias)) 57 { 58 key = (PrivateKey ) store.getKey(alias, pword.toCharArray()); 59 Certificate [] chain = store.getCertificateChain(alias); 60 certChain = new X509Certificate [chain.length]; 61 62 for (int i = 0; i < chain.length; i++) 63 { 64 certChain[i] = (X509Certificate ) chain[i]; 65 } 66 67 break; 68 } 69 } 70 71 if (null == key) 72 { 73 throw new Exception ("No key found"); 74 } 75 if (null == certChain) 76 { 77 throw new Exception ("No certificate chain found"); 78 } 79 80 this.key = key; 81 this.certChain = certChain; 82 } 83 84 public final X509Certificate [] getCertificateChain() 85 { 86 return this.certChain; 87 } 88 89 public final PrivateKey getPrivateKey() 90 { 91 return this.key; 92 } 93 94 public final String getAlias() 95 { 96 return this.alias; 97 } 98 } 99 | Popular Tags |