Add C++11 header <cuchar>.
[official-gcc.git] / libjava / classpath / java / security / KeyStoreSpi.java
blobb44bd84a84f2506d554008584c72dd064df2c09b
1 /* KeyStoreSpi.java --- Key Store Service Provider Interface
2 Copyright (C) 1999, 2004 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., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 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. */
39 package java.security;
41 import java.io.IOException;
42 import java.io.InputStream;
43 import java.io.OutputStream;
44 import java.security.cert.CertificateException;
45 import java.util.Date;
46 import java.util.Enumeration;
48 /**
49 * KeyStoreSpi is the Service Provider Interface (SPI) for the
50 * KeyStore class. This is the interface for providers to
51 * supply to implement a keystore for a particular keystore
52 * type.
54 * @since 1.2
55 * @author Mark Benvenuto
57 public abstract class KeyStoreSpi
59 /**
60 * Constructs a new KeyStoreSpi
62 public KeyStoreSpi()
66 /**
67 * Returns the key associated with given alias using the
68 * supplied password.
70 * @param alias an alias for the key to get
71 * @param password password to access key with
73 * @return the requested key, or null otherwise
75 * @throws NoSuchAlgorithmException if there is no algorithm
76 * for recovering the key
77 * @throws UnrecoverableKeyException key cannot be reocovered
78 * (wrong password).
80 public abstract Key engineGetKey(String alias, char[]password)
81 throws NoSuchAlgorithmException, UnrecoverableKeyException;
83 /**
84 * Gets a Certificate chain for the specified alias.
86 * @param alias the alias name
88 * @return a chain of Certificates ( ordered from the user's
89 * certificate to the Certificate Authority's ) or
90 * null if the alias does not exist or there is no
91 * certificate chain for the alias ( the alias refers
92 * to a trusted certificate entry or there is no entry).
94 public abstract java.security.cert.
95 Certificate[] engineGetCertificateChain(String alias);
98 /**
99 * Gets a Certificate for the specified alias.
101 * If there is a trusted certificate entry then that is returned.
102 * it there is a key entry with a certificate chain then the
103 * first certificate is return or else null.
105 * @param alias the alias name
107 * @return a Certificate or null if the alias does not exist
108 * or there is no certificate for the alias
110 public abstract java.security.cert.
111 Certificate engineGetCertificate(String alias);
114 * Gets entry creation date for the specified alias.
116 * @param alias the alias name
118 * @returns the entry creation date or null
120 public abstract Date engineGetCreationDate(String alias);
123 * Assign the key to the alias in the keystore, protecting it
124 * with the given password. It will overwrite an existing
125 * entry and if the key is a PrivateKey, also add the
126 * certificate chain representing the corresponding public key.
128 * @param alias the alias name
129 * @param key the key to add
130 * @password the password to protect with
131 * @param chain the certificate chain for the corresponding
132 * public key
134 * @throws KeyStoreException if it fails
136 public abstract void engineSetKeyEntry(String alias, Key key,
137 char[]password,
138 java.security.cert.
139 Certificate[]chain) throws
140 KeyStoreException;
143 * Assign the key to the alias in the keystore. It will overwrite
144 * an existing entry and if the key is a PrivateKey, also
145 * add the certificate chain representing the corresponding
146 * public key.
148 * @param alias the alias name
149 * @param key the key to add
150 * @param chain the certificate chain for the corresponding
151 * public key
153 * @throws KeyStoreException if it fails
155 public abstract void engineSetKeyEntry(String alias, byte[]key,
156 java.security.cert.
157 Certificate[]chain) throws
158 KeyStoreException;
162 * Assign the certificate to the alias in the keystore. It
163 * will overwrite an existing entry.
165 * @param alias the alias name
166 * @param cert the certificate to add
168 * @throws KeyStoreException if it fails
170 public abstract void engineSetCertificateEntry(String alias,
171 java.security.cert.
172 Certificate cert) throws
173 KeyStoreException;
176 * Deletes the entry for the specified entry.
178 * @param alias the alias name
180 * @throws KeyStoreException if it fails
182 public abstract void engineDeleteEntry(String alias)
183 throws KeyStoreException;
186 * Generates a list of all the aliases in the keystore.
188 * @return an Enumeration of the aliases
190 public abstract Enumeration<String> engineAliases();
193 * Determines if the keystore contains the specified alias.
195 * @param alias the alias name
197 * @return true if it contains the alias, false otherwise
199 public abstract boolean engineContainsAlias(String alias);
202 * Returns the number of entries in the keystore.
204 * @returns the number of keystore entries.
206 public abstract int engineSize();
209 * Determines if the keystore contains a key entry for
210 * the specified alias.
212 * @param alias the alias name
214 * @return true if it is a key entry, false otherwise
216 public abstract boolean engineIsKeyEntry(String alias);
219 * Determines if the keystore contains a certificate entry for
220 * the specified alias.
222 * @param alias the alias name
224 * @return true if it is a certificate entry, false otherwise
226 public abstract boolean engineIsCertificateEntry(String alias);
229 * Determines if the keystore contains the specified certificate
230 * entry and returns the alias.
232 * It checks every entry and for a key entry checks only the
233 * first certificate in the chain.
235 * @param cert Certificate to look for
237 * @return alias of first matching certificate, null if it
238 * does not exist.
240 public abstract String engineGetCertificateAlias(java.security.cert.
241 Certificate cert);
244 * Stores the keystore in the specified output stream and it
245 * uses the specified key it keep it secure.
247 * @param stream the output stream to save the keystore to
248 * @param password the password to protect the keystore integrity with
250 * @throws IOException if an I/O error occurs.
251 * @throws NoSuchAlgorithmException the data integrity algorithm
252 * used cannot be found.
253 * @throws CertificateException if any certificates could not be
254 * stored in the output stream.
256 public abstract void engineStore(OutputStream stream, char[]password)
257 throws IOException, NoSuchAlgorithmException, CertificateException;
261 * Loads the keystore from the specified input stream and it
262 * uses the specified password to check for integrity if supplied.
264 * @param stream the input stream to load the keystore from
265 * @param password the password to check the keystore integrity with
267 * @throws IOException if an I/O error occurs.
268 * @throws NoSuchAlgorithmException the data integrity algorithm
269 * used cannot be found.
270 * @throws CertificateException if any certificates could not be
271 * stored in the output stream.
273 public abstract void engineLoad(InputStream stream, char[]password)
274 throws IOException, NoSuchAlgorithmException, CertificateException;