KeyStoreSpi.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* KeyStoreSpi.java --- Key Store Service Provider Interface
  2. Copyright (C) 1999 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.security;
  32. import java.io.InputStream;
  33. import java.io.IOException;
  34. import java.io.OutputStream;
  35. import java.security.cert.CertificateException;
  36. import java.util.Date;
  37. import java.util.Enumeration;
  38. /**
  39. KeyStoreSpi is the Service Provider Interface (SPI) for the
  40. KeyStore class. This is the interface for providers to
  41. supply to implement a keystore for a particular keystore
  42. type.
  43. @since JDK 1.2
  44. @author Mark Benvenuto
  45. */
  46. public abstract class KeyStoreSpi
  47. {
  48. /**
  49. Constructs a new KeyStoreSpi
  50. */
  51. public KeyStoreSpi()
  52. {
  53. }
  54. /**
  55. Returns the key associated with given alias using the
  56. supplied password.
  57. @param alias an alias for the key to get
  58. @param password password to access key with
  59. @return the requested key, or null otherwise
  60. @throws NoSuchAlgorithmException if there is no algorithm
  61. for recovering the key
  62. @throws UnrecoverableKeyException key cannot be reocovered
  63. (wrong password).
  64. */
  65. public abstract Key engineGetKey(String alias, char[]password)
  66. throws NoSuchAlgorithmException, UnrecoverableKeyException;
  67. /**
  68. Gets a Certificate chain for the specified alias.
  69. @param alias the alias name
  70. @return a chain of Certificates ( ordered from the user's
  71. certificate to the Certificate Authority's ) or
  72. null if the alias does not exist or there is no
  73. certificate chain for the alias ( the alias refers
  74. to a trusted certificate entry or there is no entry).
  75. */
  76. public abstract java.security.cert.
  77. Certificate[] engineGetCertificateChain(String alias);
  78. /**
  79. Gets a Certificate for the specified alias.
  80. If there is a trusted certificate entry then that is returned.
  81. it there is a key entry with a certificate chain then the
  82. first certificate is return or else null.
  83. @param alias the alias name
  84. @return a Certificate or null if the alias does not exist
  85. or there is no certificate for the alias
  86. */
  87. public abstract java.security.cert.
  88. Certificate engineGetCertificate(String alias);
  89. /**
  90. Gets entry creation date for the specified alias.
  91. @param alias the alias name
  92. @returns the entry creation date or null
  93. */
  94. public abstract Date engineGetCreationDate(String alias);
  95. /**
  96. Assign the key to the alias in the keystore, protecting it
  97. with the given password. It will overwrite an existing
  98. entry and if the key is a PrivateKey, also add the
  99. certificate chain representing the corresponding public key.
  100. @param alias the alias name
  101. @param key the key to add
  102. @password the password to protect with
  103. @param chain the certificate chain for the corresponding
  104. public key
  105. @throws KeyStoreException if it fails
  106. */
  107. public abstract void engineSetKeyEntry(String alias, Key key,
  108. char[]password,
  109. java.security.cert.
  110. Certificate[]chain) throws
  111. KeyStoreException;
  112. /**
  113. Assign the key to the alias in the keystore. It will overwrite
  114. an existing entry and if the key is a PrivateKey, also
  115. add the certificate chain representing the corresponding
  116. public key.
  117. @param alias the alias name
  118. @param key the key to add
  119. @param chain the certificate chain for the corresponding
  120. public key
  121. @throws KeyStoreException if it fails
  122. */
  123. public abstract void engineSetKeyEntry(String alias, byte[]key,
  124. java.security.cert.
  125. Certificate[]chain) throws
  126. KeyStoreException;
  127. /**
  128. Assign the certificate to the alias in the keystore. It
  129. will overwrite an existing entry.
  130. @param alias the alias name
  131. @param cert the certificate to add
  132. @throws KeyStoreException if it fails
  133. */
  134. public abstract void engineSetCertificateEntry(String alias,
  135. java.security.cert.
  136. Certificate cert) throws
  137. KeyStoreException;
  138. /**
  139. Deletes the entry for the specified entry.
  140. @param alias the alias name
  141. @throws KeyStoreException if it fails
  142. */
  143. public abstract void engineDeleteEntry(String alias)
  144. throws KeyStoreException;
  145. /**
  146. Generates a list of all the aliases in the keystore.
  147. @return an Enumeration of the aliases
  148. */
  149. public abstract Enumeration engineAliases();
  150. /**
  151. Determines if the keystore contains the specified alias.
  152. @param alias the alias name
  153. @return true if it contains the alias, false otherwise
  154. */
  155. public abstract boolean engineContainsAlias(String alias);
  156. /**
  157. Returns the number of entries in the keystore.
  158. @returns the number of keystore entries.
  159. */
  160. public abstract int engineSize();
  161. /**
  162. Determines if the keystore contains a key entry for
  163. the specified alias.
  164. @param alias the alias name
  165. @return true if it is a key entry, false otherwise
  166. */
  167. public abstract boolean engineIsKeyEntry(String alias);
  168. /**
  169. Determines if the keystore contains a certificate entry for
  170. the specified alias.
  171. @param alias the alias name
  172. @return true if it is a certificate entry, false otherwise
  173. */
  174. public abstract boolean engineIsCertificateEntry(String alias);
  175. /**
  176. Determines if the keystore contains the specified certificate
  177. entry and returns the alias.
  178. It checks every entry and for a key entry checks only the
  179. first certificate in the chain.
  180. @param cert Certificate to look for
  181. @return alias of first matching certificate, null if it
  182. does not exist.
  183. */
  184. public abstract String engineGetCertificateAlias(java.security.cert.
  185. Certificate cert);
  186. /**
  187. Stores the keystore in the specified output stream and it
  188. uses the specified key it keep it secure.
  189. @param stream the output stream to save the keystore to
  190. @param password the password to protect the keystore integrity with
  191. @throws IOException if an I/O error occurs.
  192. @throws NoSuchAlgorithmException the data integrity algorithm
  193. used cannot be found.
  194. @throws CertificateException if any certificates could not be
  195. stored in the output stream.
  196. */
  197. public abstract void engineStore(OutputStream stream, char[]password)
  198. throws IOException, NoSuchAlgorithmException, CertificateException;
  199. /**
  200. Loads the keystore from the specified input stream and it
  201. uses the specified password to check for integrity if supplied.
  202. @param stream the input stream to load the keystore from
  203. @param password the password to check the keystore integrity with
  204. @throws IOException if an I/O error occurs.
  205. @throws NoSuchAlgorithmException the data integrity algorithm
  206. used cannot be found.
  207. @throws CertificateException if any certificates could not be
  208. stored in the output stream.
  209. */
  210. public abstract void engineLoad(InputStream stream, char[]password)
  211. throws IOException, NoSuchAlgorithmException, CertificateException;
  212. }