Source for java.security.KeyStoreSpi

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