FSF GCC merge 02/23/03
[official-gcc.git] / libjava / java / security / KeyStoreSpi.java
blob70cb0c0dcd51f6fc5e7bd2b0e3ed4b3746efa4f5
1 /* KeyStoreSpi.java --- Key Store Service Provider Interface
2 Copyright (C) 1999 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 02111-1307 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package java.security;
39 import java.io.InputStream;
40 import java.io.IOException;
41 import java.io.OutputStream;
42 import java.security.cert.CertificateException;
43 import java.util.Date;
44 import java.util.Enumeration;
46 /**
47 KeyStoreSpi is the Service Provider Interface (SPI) for the
48 KeyStore class. This is the interface for providers to
49 supply to implement a keystore for a particular keystore
50 type.
52 @since JDK 1.2
53 @author Mark Benvenuto
55 public abstract class KeyStoreSpi
57 /**
58 Constructs a new KeyStoreSpi
60 public KeyStoreSpi()
64 /**
65 Returns the key associated with given alias using the
66 supplied password.
68 @param alias an alias for the key to get
69 @param password password to access key with
71 @return the requested key, or null otherwise
73 @throws NoSuchAlgorithmException if there is no algorithm
74 for recovering the key
75 @throws UnrecoverableKeyException key cannot be reocovered
76 (wrong password).
78 public abstract Key engineGetKey(String alias, char[]password)
79 throws NoSuchAlgorithmException, UnrecoverableKeyException;
81 /**
82 Gets a Certificate chain for the specified alias.
84 @param alias the alias name
86 @return a chain of Certificates ( ordered from the user's
87 certificate to the Certificate Authority's ) or
88 null if the alias does not exist or there is no
89 certificate chain for the alias ( the alias refers
90 to a trusted certificate entry or there is no entry).
92 public abstract java.security.cert.
93 Certificate[] engineGetCertificateChain(String alias);
96 /**
97 Gets a Certificate for the specified alias.
99 If there is a trusted certificate entry then that is returned.
100 it there is a key entry with a certificate chain then the
101 first certificate is return or else null.
103 @param alias the alias name
105 @return a Certificate or null if the alias does not exist
106 or there is no certificate for the alias
108 public abstract java.security.cert.
109 Certificate engineGetCertificate(String alias);
112 Gets entry creation date for the specified alias.
114 @param alias the alias name
116 @returns the entry creation date or null
118 public abstract Date engineGetCreationDate(String alias);
121 Assign the key to the alias in the keystore, protecting it
122 with the given password. It will overwrite an existing
123 entry and if the key is a PrivateKey, also add the
124 certificate chain representing the corresponding public key.
126 @param alias the alias name
127 @param key the key to add
128 @password the password to protect with
129 @param chain the certificate chain for the corresponding
130 public key
132 @throws KeyStoreException if it fails
134 public abstract void engineSetKeyEntry(String alias, Key key,
135 char[]password,
136 java.security.cert.
137 Certificate[]chain) throws
138 KeyStoreException;
141 Assign the key to the alias in the keystore. It will overwrite
142 an existing entry and if the key is a PrivateKey, also
143 add the certificate chain representing the corresponding
144 public key.
146 @param alias the alias name
147 @param key the key to add
148 @param chain the certificate chain for the corresponding
149 public key
151 @throws KeyStoreException if it fails
153 public abstract void engineSetKeyEntry(String alias, byte[]key,
154 java.security.cert.
155 Certificate[]chain) throws
156 KeyStoreException;
160 Assign the certificate to the alias in the keystore. It
161 will overwrite an existing entry.
163 @param alias the alias name
164 @param cert the certificate to add
166 @throws KeyStoreException if it fails
168 public abstract void engineSetCertificateEntry(String alias,
169 java.security.cert.
170 Certificate cert) throws
171 KeyStoreException;
174 Deletes the entry for the specified entry.
176 @param alias the alias name
178 @throws KeyStoreException if it fails
180 public abstract void engineDeleteEntry(String alias)
181 throws KeyStoreException;
184 Generates a list of all the aliases in the keystore.
186 @return an Enumeration of the aliases
188 public abstract Enumeration engineAliases();
191 Determines if the keystore contains the specified alias.
193 @param alias the alias name
195 @return true if it contains the alias, false otherwise
197 public abstract boolean engineContainsAlias(String alias);
200 Returns the number of entries in the keystore.
202 @returns the number of keystore entries.
204 public abstract int engineSize();
207 Determines if the keystore contains a key entry for
208 the specified alias.
210 @param alias the alias name
212 @return true if it is a key entry, false otherwise
214 public abstract boolean engineIsKeyEntry(String alias);
217 Determines if the keystore contains a certificate entry for
218 the specified alias.
220 @param alias the alias name
222 @return true if it is a certificate entry, false otherwise
224 public abstract boolean engineIsCertificateEntry(String alias);
227 Determines if the keystore contains the specified certificate
228 entry and returns the alias.
230 It checks every entry and for a key entry checks only the
231 first certificate in the chain.
233 @param cert Certificate to look for
235 @return alias of first matching certificate, null if it
236 does not exist.
238 public abstract String engineGetCertificateAlias(java.security.cert.
239 Certificate cert);
242 Stores the keystore in the specified output stream and it
243 uses the specified key it keep it secure.
245 @param stream the output stream to save the keystore to
246 @param password the password to protect the keystore integrity with
248 @throws IOException if an I/O error occurs.
249 @throws NoSuchAlgorithmException the data integrity algorithm
250 used cannot be found.
251 @throws CertificateException if any certificates could not be
252 stored in the output stream.
254 public abstract void engineStore(OutputStream stream, char[]password)
255 throws IOException, NoSuchAlgorithmException, CertificateException;
259 Loads the keystore from the specified input stream and it
260 uses the specified password to check for integrity if supplied.
262 @param stream the input stream to load the keystore from
263 @param password the password to check the keystore integrity with
265 @throws IOException if an I/O error occurs.
266 @throws NoSuchAlgorithmException the data integrity algorithm
267 used cannot be found.
268 @throws CertificateException if any certificates could not be
269 stored in the output stream.
271 public abstract void engineLoad(InputStream stream, char[]password)
272 throws IOException, NoSuchAlgorithmException, CertificateException;