1 |
/* KeyStoreSpi.java --- Key Store Service Provider Interface |
/* KeyStoreSpi.java --- Key Store Service Provider Interface |
2 |
Copyright (C) 1999 Free Software Foundation, Inc. |
Copyright (C) 1999, 2004 Free Software Foundation, Inc. |
3 |
|
|
4 |
This file is part of GNU Classpath. |
This file is part of GNU Classpath. |
5 |
|
|
35 |
obligated to do so. If you do not wish to do so, delete this |
obligated to do so. If you do not wish to do so, delete this |
36 |
exception statement from your version. */ |
exception statement from your version. */ |
37 |
|
|
38 |
|
|
39 |
package java.security; |
package java.security; |
40 |
import java.io.InputStream; |
|
41 |
import java.io.IOException; |
import java.io.IOException; |
42 |
|
import java.io.InputStream; |
43 |
import java.io.OutputStream; |
import java.io.OutputStream; |
44 |
import java.security.cert.CertificateException; |
import java.security.cert.CertificateException; |
45 |
import java.util.Date; |
import java.util.Date; |
46 |
import java.util.Enumeration; |
import java.util.Enumeration; |
47 |
|
|
48 |
/** |
/** |
49 |
KeyStoreSpi is the Service Provider Interface (SPI) for the |
* KeyStoreSpi is the Service Provider Interface (SPI) for the |
50 |
KeyStore class. This is the interface for providers to |
* KeyStore class. This is the interface for providers to |
51 |
supply to implement a keystore for a particular keystore |
* supply to implement a keystore for a particular keystore |
52 |
type. |
* type. |
53 |
|
* |
54 |
@since JDK 1.2 |
* @since 1.2 |
55 |
@author Mark Benvenuto |
* @author Mark Benvenuto |
56 |
*/ |
*/ |
57 |
public abstract class KeyStoreSpi |
public abstract class KeyStoreSpi |
58 |
{ |
{ |
59 |
/** |
/** |
60 |
Constructs a new KeyStoreSpi |
* Constructs a new KeyStoreSpi |
61 |
*/ |
*/ |
62 |
public KeyStoreSpi() |
public KeyStoreSpi() |
63 |
{ |
{ |
64 |
} |
} |
65 |
|
|
66 |
/** |
/** |
67 |
Returns the key associated with given alias using the |
* Returns the key associated with given alias using the |
68 |
supplied password. |
* supplied password. |
69 |
|
* |
70 |
@param alias an alias for the key to get |
* @param alias an alias for the key to get |
71 |
@param password password to access key with |
* @param password password to access key with |
72 |
|
* |
73 |
@return the requested key, or null otherwise |
* @return the requested key, or null otherwise |
74 |
|
* |
75 |
@throws NoSuchAlgorithmException if there is no algorithm |
* @throws NoSuchAlgorithmException if there is no algorithm |
76 |
for recovering the key |
* for recovering the key |
77 |
@throws UnrecoverableKeyException key cannot be reocovered |
* @throws UnrecoverableKeyException key cannot be reocovered |
78 |
(wrong password). |
* (wrong password). |
79 |
*/ |
*/ |
80 |
public abstract Key engineGetKey(String alias, char[]password) |
public abstract Key engineGetKey(String alias, char[]password) |
81 |
throws NoSuchAlgorithmException, UnrecoverableKeyException; |
throws NoSuchAlgorithmException, UnrecoverableKeyException; |
82 |
|
|
83 |
/** |
/** |
84 |
Gets a Certificate chain for the specified alias. |
* Gets a Certificate chain for the specified alias. |
85 |
|
* |
86 |
@param alias the alias name |
* @param alias the alias name |
87 |
|
* |
88 |
@return a chain of Certificates ( ordered from the user's |
* @return a chain of Certificates ( ordered from the user's |
89 |
certificate to the Certificate Authority's ) or |
* certificate to the Certificate Authority's ) or |
90 |
null if the alias does not exist or there is no |
* null if the alias does not exist or there is no |
91 |
certificate chain for the alias ( the alias refers |
* certificate chain for the alias ( the alias refers |
92 |
to a trusted certificate entry or there is no entry). |
* to a trusted certificate entry or there is no entry). |
93 |
*/ |
*/ |
94 |
public abstract java.security.cert. |
public abstract java.security.cert. |
95 |
Certificate[] engineGetCertificateChain(String alias); |
Certificate[] engineGetCertificateChain(String alias); |
96 |
|
|
97 |
|
|
98 |
/** |
/** |
99 |
Gets a Certificate for the specified alias. |
* Gets a Certificate for the specified alias. |
100 |
|
* |
101 |
If there is a trusted certificate entry then that is returned. |
* If there is a trusted certificate entry then that is returned. |
102 |
it there is a key entry with a certificate chain then the |
* it there is a key entry with a certificate chain then the |
103 |
first certificate is return or else null. |
* first certificate is return or else null. |
104 |
|
* |
105 |
@param alias the alias name |
* @param alias the alias name |
106 |
|
* |
107 |
@return a Certificate or null if the alias does not exist |
* @return a Certificate or null if the alias does not exist |
108 |
or there is no certificate for the alias |
* or there is no certificate for the alias |
109 |
*/ |
*/ |
110 |
public abstract java.security.cert. |
public abstract java.security.cert. |
111 |
Certificate engineGetCertificate(String alias); |
Certificate engineGetCertificate(String alias); |
112 |
|
|
113 |
/** |
/** |
114 |
Gets entry creation date for the specified alias. |
* Gets entry creation date for the specified alias. |
115 |
|
* |
116 |
@param alias the alias name |
* @param alias the alias name |
117 |
|
* |
118 |
@returns the entry creation date or null |
* @returns the entry creation date or null |
119 |
*/ |
*/ |
120 |
public abstract Date engineGetCreationDate(String alias); |
public abstract Date engineGetCreationDate(String alias); |
121 |
|
|
122 |
/** |
/** |
123 |
Assign the key to the alias in the keystore, protecting it |
* Assign the key to the alias in the keystore, protecting it |
124 |
with the given password. It will overwrite an existing |
* with the given password. It will overwrite an existing |
125 |
entry and if the key is a PrivateKey, also add the |
* entry and if the key is a PrivateKey, also add the |
126 |
certificate chain representing the corresponding public key. |
* certificate chain representing the corresponding public key. |
127 |
|
* |
128 |
@param alias the alias name |
* @param alias the alias name |
129 |
@param key the key to add |
* @param key the key to add |
130 |
@password the password to protect with |
* @password the password to protect with |
131 |
@param chain the certificate chain for the corresponding |
* @param chain the certificate chain for the corresponding |
132 |
public key |
* public key |
133 |
|
* |
134 |
@throws KeyStoreException if it fails |
* @throws KeyStoreException if it fails |
135 |
*/ |
*/ |
136 |
public abstract void engineSetKeyEntry(String alias, Key key, |
public abstract void engineSetKeyEntry(String alias, Key key, |
137 |
char[]password, |
char[]password, |
140 |
KeyStoreException; |
KeyStoreException; |
141 |
|
|
142 |
/** |
/** |
143 |
Assign the key to the alias in the keystore. It will overwrite |
* Assign the key to the alias in the keystore. It will overwrite |
144 |
an existing entry and if the key is a PrivateKey, also |
* an existing entry and if the key is a PrivateKey, also |
145 |
add the certificate chain representing the corresponding |
* add the certificate chain representing the corresponding |
146 |
public key. |
* public key. |
147 |
|
* |
148 |
@param alias the alias name |
* @param alias the alias name |
149 |
@param key the key to add |
* @param key the key to add |
150 |
@param chain the certificate chain for the corresponding |
* @param chain the certificate chain for the corresponding |
151 |
public key |
* public key |
152 |
|
* |
153 |
@throws KeyStoreException if it fails |
* @throws KeyStoreException if it fails |
154 |
*/ |
*/ |
155 |
public abstract void engineSetKeyEntry(String alias, byte[]key, |
public abstract void engineSetKeyEntry(String alias, byte[]key, |
156 |
java.security.cert. |
java.security.cert. |
159 |
|
|
160 |
|
|
161 |
/** |
/** |
162 |
Assign the certificate to the alias in the keystore. It |
* Assign the certificate to the alias in the keystore. It |
163 |
will overwrite an existing entry. |
* will overwrite an existing entry. |
164 |
|
* |
165 |
@param alias the alias name |
* @param alias the alias name |
166 |
@param cert the certificate to add |
* @param cert the certificate to add |
167 |
|
* |
168 |
@throws KeyStoreException if it fails |
* @throws KeyStoreException if it fails |
169 |
*/ |
*/ |
170 |
public abstract void engineSetCertificateEntry(String alias, |
public abstract void engineSetCertificateEntry(String alias, |
171 |
java.security.cert. |
java.security.cert. |
173 |
KeyStoreException; |
KeyStoreException; |
174 |
|
|
175 |
/** |
/** |
176 |
Deletes the entry for the specified entry. |
* Deletes the entry for the specified entry. |
177 |
|
* |
178 |
@param alias the alias name |
* @param alias the alias name |
179 |
|
* |
180 |
@throws KeyStoreException if it fails |
* @throws KeyStoreException if it fails |
181 |
*/ |
*/ |
182 |
public abstract void engineDeleteEntry(String alias) |
public abstract void engineDeleteEntry(String alias) |
183 |
throws KeyStoreException; |
throws KeyStoreException; |
184 |
|
|
185 |
/** |
/** |
186 |
Generates a list of all the aliases in the keystore. |
* Generates a list of all the aliases in the keystore. |
187 |
|
* |
188 |
@return an Enumeration of the aliases |
* @return an Enumeration of the aliases |
189 |
*/ |
*/ |
190 |
public abstract Enumeration engineAliases(); |
public abstract Enumeration engineAliases(); |
191 |
|
|
192 |
/** |
/** |
193 |
Determines if the keystore contains the specified alias. |
* Determines if the keystore contains the specified alias. |
194 |
|
* |
195 |
@param alias the alias name |
* @param alias the alias name |
196 |
|
* |
197 |
@return true if it contains the alias, false otherwise |
* @return true if it contains the alias, false otherwise |
198 |
*/ |
*/ |
199 |
public abstract boolean engineContainsAlias(String alias); |
public abstract boolean engineContainsAlias(String alias); |
200 |
|
|
201 |
/** |
/** |
202 |
Returns the number of entries in the keystore. |
* Returns the number of entries in the keystore. |
203 |
|
* |
204 |
@returns the number of keystore entries. |
* @returns the number of keystore entries. |
205 |
*/ |
*/ |
206 |
public abstract int engineSize(); |
public abstract int engineSize(); |
207 |
|
|
208 |
/** |
/** |
209 |
Determines if the keystore contains a key entry for |
* Determines if the keystore contains a key entry for |
210 |
the specified alias. |
* the specified alias. |
211 |
|
* |
212 |
@param alias the alias name |
* @param alias the alias name |
213 |
|
* |
214 |
@return true if it is a key entry, false otherwise |
* @return true if it is a key entry, false otherwise |
215 |
*/ |
*/ |
216 |
public abstract boolean engineIsKeyEntry(String alias); |
public abstract boolean engineIsKeyEntry(String alias); |
217 |
|
|
218 |
/** |
/** |
219 |
Determines if the keystore contains a certificate entry for |
* Determines if the keystore contains a certificate entry for |
220 |
the specified alias. |
* the specified alias. |
221 |
|
* |
222 |
@param alias the alias name |
* @param alias the alias name |
223 |
|
* |
224 |
@return true if it is a certificate entry, false otherwise |
* @return true if it is a certificate entry, false otherwise |
225 |
*/ |
*/ |
226 |
public abstract boolean engineIsCertificateEntry(String alias); |
public abstract boolean engineIsCertificateEntry(String alias); |
227 |
|
|
228 |
/** |
/** |
229 |
Determines if the keystore contains the specified certificate |
* Determines if the keystore contains the specified certificate |
230 |
entry and returns the alias. |
* entry and returns the alias. |
231 |
|
* |
232 |
It checks every entry and for a key entry checks only the |
* It checks every entry and for a key entry checks only the |
233 |
first certificate in the chain. |
* first certificate in the chain. |
234 |
|
* |
235 |
@param cert Certificate to look for |
* @param cert Certificate to look for |
236 |
|
* |
237 |
@return alias of first matching certificate, null if it |
* @return alias of first matching certificate, null if it |
238 |
does not exist. |
* does not exist. |
239 |
*/ |
*/ |
240 |
public abstract String engineGetCertificateAlias(java.security.cert. |
public abstract String engineGetCertificateAlias(java.security.cert. |
241 |
Certificate cert); |
Certificate cert); |
242 |
|
|
243 |
/** |
/** |
244 |
Stores the keystore in the specified output stream and it |
* Stores the keystore in the specified output stream and it |
245 |
uses the specified key it keep it secure. |
* uses the specified key it keep it secure. |
246 |
|
* |
247 |
@param stream the output stream to save the keystore to |
* @param stream the output stream to save the keystore to |
248 |
@param password the password to protect the keystore integrity with |
* @param password the password to protect the keystore integrity with |
249 |
|
* |
250 |
@throws IOException if an I/O error occurs. |
* @throws IOException if an I/O error occurs. |
251 |
@throws NoSuchAlgorithmException the data integrity algorithm |
* @throws NoSuchAlgorithmException the data integrity algorithm |
252 |
used cannot be found. |
* used cannot be found. |
253 |
@throws CertificateException if any certificates could not be |
* @throws CertificateException if any certificates could not be |
254 |
stored in the output stream. |
* stored in the output stream. |
255 |
*/ |
*/ |
256 |
public abstract void engineStore(OutputStream stream, char[]password) |
public abstract void engineStore(OutputStream stream, char[]password) |
257 |
throws IOException, NoSuchAlgorithmException, CertificateException; |
throws IOException, NoSuchAlgorithmException, CertificateException; |
258 |
|
|
259 |
|
|
260 |
/** |
/** |
261 |
Loads the keystore from the specified input stream and it |
* Loads the keystore from the specified input stream and it |
262 |
uses the specified password to check for integrity if supplied. |
* uses the specified password to check for integrity if supplied. |
263 |
|
* |
264 |
@param stream the input stream to load the keystore from |
* @param stream the input stream to load the keystore from |
265 |
@param password the password to check the keystore integrity with |
* @param password the password to check the keystore integrity with |
266 |
|
* |
267 |
@throws IOException if an I/O error occurs. |
* @throws IOException if an I/O error occurs. |
268 |
@throws NoSuchAlgorithmException the data integrity algorithm |
* @throws NoSuchAlgorithmException the data integrity algorithm |
269 |
used cannot be found. |
* used cannot be found. |
270 |
@throws CertificateException if any certificates could not be |
* @throws CertificateException if any certificates could not be |
271 |
stored in the output stream. |
* stored in the output stream. |
272 |
*/ |
*/ |
273 |
public abstract void engineLoad(InputStream stream, char[]password) |
public abstract void engineLoad(InputStream stream, char[]password) |
274 |
throws IOException, NoSuchAlgorithmException, CertificateException; |
throws IOException, NoSuchAlgorithmException, CertificateException; |