| 1 | /* KeyStoreSpi.java --- Key Store Service Provider Interface
|
|---|
| 2 | Copyright (C) 1999 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 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.
|
|---|
| 10 |
|
|---|
| 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.
|
|---|
| 15 |
|
|---|
| 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.
|
|---|
| 20 |
|
|---|
| 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.
|
|---|
| 25 |
|
|---|
| 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. */
|
|---|
| 37 |
|
|---|
| 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;
|
|---|
| 45 |
|
|---|
| 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.
|
|---|
| 51 |
|
|---|
| 52 | @since JDK 1.2
|
|---|
| 53 | @author Mark Benvenuto
|
|---|
| 54 | */
|
|---|
| 55 | public abstract class KeyStoreSpi
|
|---|
| 56 | {
|
|---|
| 57 | /**
|
|---|
| 58 | Constructs a new KeyStoreSpi
|
|---|
| 59 | */
|
|---|
| 60 | public KeyStoreSpi()
|
|---|
| 61 | {
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | /**
|
|---|
| 65 | Returns the key associated with given alias using the
|
|---|
| 66 | supplied password.
|
|---|
| 67 |
|
|---|
| 68 | @param alias an alias for the key to get
|
|---|
| 69 | @param password password to access key with
|
|---|
| 70 |
|
|---|
| 71 | @return the requested key, or null otherwise
|
|---|
| 72 |
|
|---|
| 73 | @throws NoSuchAlgorithmException if there is no algorithm
|
|---|
| 74 | for recovering the key
|
|---|
| 75 | @throws UnrecoverableKeyException key cannot be reocovered
|
|---|
| 76 | (wrong password).
|
|---|
| 77 | */
|
|---|
| 78 | public abstract Key engineGetKey(String alias, char[]password)
|
|---|
| 79 | throws NoSuchAlgorithmException, UnrecoverableKeyException;
|
|---|
| 80 |
|
|---|
| 81 | /**
|
|---|
| 82 | Gets a Certificate chain for the specified alias.
|
|---|
| 83 |
|
|---|
| 84 | @param alias the alias name
|
|---|
| 85 |
|
|---|
| 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).
|
|---|
| 91 | */
|
|---|
| 92 | public abstract java.security.cert.
|
|---|
| 93 | Certificate[] engineGetCertificateChain(String alias);
|
|---|
| 94 |
|
|---|
| 95 |
|
|---|
| 96 | /**
|
|---|
| 97 | Gets a Certificate for the specified alias.
|
|---|
| 98 |
|
|---|
| 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.
|
|---|
| 102 |
|
|---|
| 103 | @param alias the alias name
|
|---|
| 104 |
|
|---|
| 105 | @return a Certificate or null if the alias does not exist
|
|---|
| 106 | or there is no certificate for the alias
|
|---|
| 107 | */
|
|---|
| 108 | public abstract java.security.cert.
|
|---|
| 109 | Certificate engineGetCertificate(String alias);
|
|---|
| 110 |
|
|---|
| 111 | /**
|
|---|
| 112 | Gets entry creation date for the specified alias.
|
|---|
| 113 |
|
|---|
| 114 | @param alias the alias name
|
|---|
| 115 |
|
|---|
| 116 | @returns the entry creation date or null
|
|---|
| 117 | */
|
|---|
| 118 | public abstract Date engineGetCreationDate(String alias);
|
|---|
| 119 |
|
|---|
| 120 | /**
|
|---|
| 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.
|
|---|
| 125 |
|
|---|
| 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
|
|---|
| 131 |
|
|---|
| 132 | @throws KeyStoreException if it fails
|
|---|
| 133 | */
|
|---|
| 134 | public abstract void engineSetKeyEntry(String alias, Key key,
|
|---|
| 135 | char[]password,
|
|---|
| 136 | java.security.cert.
|
|---|
| 137 | Certificate[]chain) throws
|
|---|
| 138 | KeyStoreException;
|
|---|
| 139 |
|
|---|
| 140 | /**
|
|---|
| 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.
|
|---|
| 145 |
|
|---|
| 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
|
|---|
| 150 |
|
|---|
| 151 | @throws KeyStoreException if it fails
|
|---|
| 152 | */
|
|---|
| 153 | public abstract void engineSetKeyEntry(String alias, byte[]key,
|
|---|
| 154 | java.security.cert.
|
|---|
| 155 | Certificate[]chain) throws
|
|---|
| 156 | KeyStoreException;
|
|---|
| 157 |
|
|---|
| 158 |
|
|---|
| 159 | /**
|
|---|
| 160 | Assign the certificate to the alias in the keystore. It
|
|---|
| 161 | will overwrite an existing entry.
|
|---|
| 162 |
|
|---|
| 163 | @param alias the alias name
|
|---|
| 164 | @param cert the certificate to add
|
|---|
| 165 |
|
|---|
| 166 | @throws KeyStoreException if it fails
|
|---|
| 167 | */
|
|---|
| 168 | public abstract void engineSetCertificateEntry(String alias,
|
|---|
| 169 | java.security.cert.
|
|---|
| 170 | Certificate cert) throws
|
|---|
| 171 | KeyStoreException;
|
|---|
| 172 |
|
|---|
| 173 | /**
|
|---|
| 174 | Deletes the entry for the specified entry.
|
|---|
| 175 |
|
|---|
| 176 | @param alias the alias name
|
|---|
| 177 |
|
|---|
| 178 | @throws KeyStoreException if it fails
|
|---|
| 179 | */
|
|---|
| 180 | public abstract void engineDeleteEntry(String alias)
|
|---|
| 181 | throws KeyStoreException;
|
|---|
| 182 |
|
|---|
| 183 | /**
|
|---|
| 184 | Generates a list of all the aliases in the keystore.
|
|---|
| 185 |
|
|---|
| 186 | @return an Enumeration of the aliases
|
|---|
| 187 | */
|
|---|
| 188 | public abstract Enumeration engineAliases();
|
|---|
| 189 |
|
|---|
| 190 | /**
|
|---|
| 191 | Determines if the keystore contains the specified alias.
|
|---|
| 192 |
|
|---|
| 193 | @param alias the alias name
|
|---|
| 194 |
|
|---|
| 195 | @return true if it contains the alias, false otherwise
|
|---|
| 196 | */
|
|---|
| 197 | public abstract boolean engineContainsAlias(String alias);
|
|---|
| 198 |
|
|---|
| 199 | /**
|
|---|
| 200 | Returns the number of entries in the keystore.
|
|---|
| 201 |
|
|---|
| 202 | @returns the number of keystore entries.
|
|---|
| 203 | */
|
|---|
| 204 | public abstract int engineSize();
|
|---|
| 205 |
|
|---|
| 206 | /**
|
|---|
| 207 | Determines if the keystore contains a key entry for
|
|---|
| 208 | the specified alias.
|
|---|
| 209 |
|
|---|
| 210 | @param alias the alias name
|
|---|
| 211 |
|
|---|
| 212 | @return true if it is a key entry, false otherwise
|
|---|
| 213 | */
|
|---|
| 214 | public abstract boolean engineIsKeyEntry(String alias);
|
|---|
| 215 |
|
|---|
| 216 | /**
|
|---|
| 217 | Determines if the keystore contains a certificate entry for
|
|---|
| 218 | the specified alias.
|
|---|
| 219 |
|
|---|
| 220 | @param alias the alias name
|
|---|
| 221 |
|
|---|
| 222 | @return true if it is a certificate entry, false otherwise
|
|---|
| 223 | */
|
|---|
| 224 | public abstract boolean engineIsCertificateEntry(String alias);
|
|---|
| 225 |
|
|---|
| 226 | /**
|
|---|
| 227 | Determines if the keystore contains the specified certificate
|
|---|
| 228 | entry and returns the alias.
|
|---|
| 229 |
|
|---|
| 230 | It checks every entry and for a key entry checks only the
|
|---|
| 231 | first certificate in the chain.
|
|---|
| 232 |
|
|---|
| 233 | @param cert Certificate to look for
|
|---|
| 234 |
|
|---|
| 235 | @return alias of first matching certificate, null if it
|
|---|
| 236 | does not exist.
|
|---|
| 237 | */
|
|---|
| 238 | public abstract String engineGetCertificateAlias(java.security.cert.
|
|---|
| 239 | Certificate cert);
|
|---|
| 240 |
|
|---|
| 241 | /**
|
|---|
| 242 | Stores the keystore in the specified output stream and it
|
|---|
| 243 | uses the specified key it keep it secure.
|
|---|
| 244 |
|
|---|
| 245 | @param stream the output stream to save the keystore to
|
|---|
| 246 | @param password the password to protect the keystore integrity with
|
|---|
| 247 |
|
|---|
| 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.
|
|---|
| 253 | */
|
|---|
| 254 | public abstract void engineStore(OutputStream stream, char[]password)
|
|---|
| 255 | throws IOException, NoSuchAlgorithmException, CertificateException;
|
|---|
| 256 |
|
|---|
| 257 |
|
|---|
| 258 | /**
|
|---|
| 259 | Loads the keystore from the specified input stream and it
|
|---|
| 260 | uses the specified password to check for integrity if supplied.
|
|---|
| 261 |
|
|---|
| 262 | @param stream the input stream to load the keystore from
|
|---|
| 263 | @param password the password to check the keystore integrity with
|
|---|
| 264 |
|
|---|
| 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.
|
|---|
| 270 | */
|
|---|
| 271 | public abstract void engineLoad(InputStream stream, char[]password)
|
|---|
| 272 | throws IOException, NoSuchAlgorithmException, CertificateException;
|
|---|
| 273 | }
|
|---|