e.g. Calendar Search Help
You must enter a value before pressing Search
jmeter

Class: org.apache.jmeter.util.keystore.DefaultKeyStore   ©

 OK to copy?
01 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/util/keystore/DefaultKeyStore.java,v 1.5 2004/02/13 02:21:38 sebb Exp $
02 /*
03  * Copyright 2001-2004 The Apache Software Foundation.
04  *
05  * Licensed under the Apache License, Version 2.0 (the "License");
06  * you may not use this file except in compliance with the License.
07  * You may obtain a copy of the License at
08  *
09  *   http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  * 
17 */
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 /**
29  * Use this Keystore to wrap the normal KeyStore implementation.
30  *
31  * @author <a href="bloritsch@apache.org">Berin Loritsch</a>
32  * @version CVS $Revision: 1.5 $ $Date: 2004/02/13 02:21:38 $
33  */
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     {
Rate48         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             {
Rate58                 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 }

            
All Examples in File:
Example
Line
Rating (found
useful by...)
48 0% of 0
58 0% of 0