1. /*
  2. * @(#)CertificateFactorySpi.java 1.15 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.security.cert;
  8. import java.io.InputStream;
  9. import java.util.Collection;
  10. import java.util.Iterator;
  11. import java.util.List;
  12. import java.security.Provider;
  13. import java.security.NoSuchAlgorithmException;
  14. import java.security.NoSuchProviderException;
  15. /**
  16. * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
  17. * for the <code>CertificateFactory</code> class.
  18. * All the abstract methods in this class must be implemented by each
  19. * cryptographic service provider who wishes to supply the implementation
  20. * of a certificate factory for a particular certificate type, e.g., X.509.
  21. *
  22. * <p>Certificate factories are used to generate certificate, certification path
  23. * (<code>CertPath</code>) and certificate revocation list (CRL) objects from
  24. * their encodings.
  25. *
  26. * <p>A certificate factory for X.509 must return certificates that are an
  27. * instance of <code>java.security.cert.X509Certificate</code>, and CRLs
  28. * that are an instance of <code>java.security.cert.X509CRL</code>.
  29. *
  30. * @author Hemma Prafullchandra
  31. * @author Jan Luehe
  32. * @author Sean Mullan
  33. *
  34. * @version 1.15, 01/23/03
  35. *
  36. * @see CertificateFactory
  37. * @see Certificate
  38. * @see X509Certificate
  39. * @see CertPath
  40. * @see CRL
  41. * @see X509CRL
  42. *
  43. * @since 1.2
  44. */
  45. public abstract class CertificateFactorySpi {
  46. /**
  47. * Generates a certificate object and initializes it with
  48. * the data read from the input stream <code>inStream</code>.
  49. *
  50. * <p>In order to take advantage of the specialized certificate format
  51. * supported by this certificate factory,
  52. * the returned certificate object can be typecast to the corresponding
  53. * certificate class. For example, if this certificate
  54. * factory implements X.509 certificates, the returned certificate object
  55. * can be typecast to the <code>X509Certificate</code> class.
  56. *
  57. * <p>In the case of a certificate factory for X.509 certificates, the
  58. * certificate provided in <code>inStream</code> must be DER-encoded and
  59. * may be supplied in binary or printable (Base64) encoding. If the
  60. * certificate is provided in Base64 encoding, it must be bounded at
  61. * the beginning by -----BEGIN CERTIFICATE-----, and must be bounded at
  62. * the end by -----END CERTIFICATE-----.
  63. *
  64. * <p>Note that if the given input stream does not support
  65. * {@link java.io.InputStream#mark(int) mark} and
  66. * {@link java.io.InputStream#reset() reset}, this method will
  67. * consume the entire input stream. Otherwise, each call to this
  68. * method consumes one certificate and the read position of the input stream
  69. * is positioned to the next available byte after the the inherent
  70. * end-of-certificate marker. If the data in the
  71. * input stream does not contain an inherent end-of-certificate marker (other
  72. * than EOF) and there is trailing data after the certificate is parsed, a
  73. * <code>CertificateException</code> is thrown.
  74. *
  75. * @param inStream an input stream with the certificate data.
  76. *
  77. * @return a certificate object initialized with the data
  78. * from the input stream.
  79. *
  80. * @exception CertificateException on parsing errors.
  81. */
  82. public abstract Certificate engineGenerateCertificate(InputStream inStream)
  83. throws CertificateException;
  84. /**
  85. * Generates a <code>CertPath</code> object and initializes it with
  86. * the data read from the <code>InputStream</code> inStream. The data
  87. * is assumed to be in the default encoding.
  88. *
  89. * @param inStream an <code>InputStream</code> containing the data
  90. * @return a <code>CertPath</code> initialized with the data from the
  91. * <code>InputStream</code>
  92. * @exception CertificateException if an exception occurs while decoding
  93. * @since 1.4
  94. */
  95. public CertPath engineGenerateCertPath(InputStream inStream)
  96. throws CertificateException
  97. {
  98. throw new UnsupportedOperationException();
  99. }
  100. /**
  101. * Generates a <code>CertPath</code> object and initializes it with
  102. * the data read from the <code>InputStream</code> inStream. The data
  103. * is assumed to be in the specified encoding.
  104. *
  105. * <p> This method was added to version 1.4 of the Java 2 Platform
  106. * Standard Edition. In order to maintain backwards compatibility with
  107. * existing service providers, this method cannot be <code>abstract</code>
  108. * and by default throws an <code>UnsupportedOperationException</code>.
  109. *
  110. * @param inStream an <code>InputStream</code> containing the data
  111. * @param encoding the encoding used for the data
  112. * @return a <code>CertPath</code> initialized with the data from the
  113. * <code>InputStream</code>
  114. * @exception CertificateException if an exception occurs while decoding or
  115. * the encoding requested is not supported
  116. * @exception UnsupportedOperationException if the method is not supported
  117. * @since 1.4
  118. */
  119. public CertPath engineGenerateCertPath(InputStream inStream,
  120. String encoding) throws CertificateException
  121. {
  122. throw new UnsupportedOperationException();
  123. }
  124. /**
  125. * Generates a <code>CertPath</code> object and initializes it with
  126. * a <code>List</code> of <code>Certificate</code>s.
  127. * <p>
  128. * The certificates supplied must be of a type supported by the
  129. * <code>CertificateFactory</code>. They will be copied out of the supplied
  130. * <code>List</code> object.
  131. *
  132. * <p> This method was added to version 1.4 of the Java 2 Platform
  133. * Standard Edition. In order to maintain backwards compatibility with
  134. * existing service providers, this method cannot be <code>abstract</code>
  135. * and by default throws an <code>UnsupportedOperationException</code>.
  136. *
  137. * @param certificates a <code>List</code> of <code>Certificate</code>s
  138. * @return a <code>CertPath</code> initialized with the supplied list of
  139. * certificates
  140. * @exception CertificateException if an exception occurs
  141. * @exception UnsupportedOperationException if the method is not supported
  142. * @since 1.4
  143. */
  144. public CertPath engineGenerateCertPath(List certificates)
  145. throws CertificateException
  146. {
  147. throw new UnsupportedOperationException();
  148. }
  149. /**
  150. * Returns an iteration of the <code>CertPath</code> encodings supported
  151. * by this certificate factory, with the default encoding first. See
  152. * Appendix A in the
  153. * <a href="../../../../guide/security/certpath/CertPathProgGuide.html#AppA">
  154. * Java Certification Path API Programmer's Guide</a>
  155. * for information about standard encoding names.
  156. * <p>
  157. * Attempts to modify the returned <code>Iterator</code> via its
  158. * <code>remove</code> method result in an
  159. * <code>UnsupportedOperationException</code>.
  160. *
  161. * <p> This method was added to version 1.4 of the Java 2 Platform
  162. * Standard Edition. In order to maintain backwards compatibility with
  163. * existing service providers, this method cannot be <code>abstract</code>
  164. * and by default throws an <code>UnsupportedOperationException</code>.
  165. *
  166. * @return an <code>Iterator</code> over the names of the supported
  167. * <code>CertPath</code> encodings (as <code>String</code>s)
  168. * @exception UnsupportedOperationException if the method is not supported
  169. * @since 1.4
  170. */
  171. public Iterator engineGetCertPathEncodings() {
  172. throw new UnsupportedOperationException();
  173. }
  174. /**
  175. * Returns a (possibly empty) collection view of the certificates read
  176. * from the given input stream <code>inStream</code>.
  177. *
  178. * <p>In order to take advantage of the specialized certificate format
  179. * supported by this certificate factory, each element in
  180. * the returned collection view can be typecast to the corresponding
  181. * certificate class. For example, if this certificate
  182. * factory implements X.509 certificates, the elements in the returned
  183. * collection can be typecast to the <code>X509Certificate</code> class.
  184. *
  185. * <p>In the case of a certificate factory for X.509 certificates,
  186. * <code>inStream</code> may contain a single DER-encoded certificate
  187. * in the formats described for
  188. * {@link CertificateFactory#generateCertificate(java.io.InputStream)
  189. * generateCertificate}.
  190. * In addition, <code>inStream</code> may contain a PKCS#7 certificate
  191. * chain. This is a PKCS#7 <i>SignedData</i> object, with the only
  192. * significant field being <i>certificates</i>. In particular, the
  193. * signature and the contents are ignored. This format allows multiple
  194. * certificates to be downloaded at once. If no certificates are present,
  195. * an empty collection is returned.
  196. *
  197. * <p>Note that if the given input stream does not support
  198. * {@link java.io.InputStream#mark(int) mark} and
  199. * {@link java.io.InputStream#reset() reset}, this method will
  200. * consume the entire input stream.
  201. *
  202. * @param inStream the input stream with the certificates.
  203. *
  204. * @return a (possibly empty) collection view of
  205. * java.security.cert.Certificate objects
  206. * initialized with the data from the input stream.
  207. *
  208. * @exception CertificateException on parsing errors.
  209. */
  210. public abstract Collection engineGenerateCertificates(InputStream inStream)
  211. throws CertificateException;
  212. /**
  213. * Generates a certificate revocation list (CRL) object and initializes it
  214. * with the data read from the input stream <code>inStream</code>.
  215. *
  216. * <p>In order to take advantage of the specialized CRL format
  217. * supported by this certificate factory,
  218. * the returned CRL object can be typecast to the corresponding
  219. * CRL class. For example, if this certificate
  220. * factory implements X.509 CRLs, the returned CRL object
  221. * can be typecast to the <code>X509CRL</code> class.
  222. *
  223. * <p>Note that if the given input stream does not support
  224. * {@link java.io.InputStream#mark(int) mark} and
  225. * {@link java.io.InputStream#reset() reset}, this method will
  226. * consume the entire input stream. Otherwise, each call to this
  227. * method consumes one CRL and the read position of the input stream
  228. * is positioned to the next available byte after the the inherent
  229. * end-of-CRL marker. If the data in the
  230. * input stream does not contain an inherent end-of-CRL marker (other
  231. * than EOF) and there is trailing data after the CRL is parsed, a
  232. * <code>CRLException</code> is thrown.
  233. *
  234. * @param inStream an input stream with the CRL data.
  235. *
  236. * @return a CRL object initialized with the data
  237. * from the input stream.
  238. *
  239. * @exception CRLException on parsing errors.
  240. */
  241. public abstract CRL engineGenerateCRL(InputStream inStream)
  242. throws CRLException;
  243. /**
  244. * Returns a (possibly empty) collection view of the CRLs read
  245. * from the given input stream <code>inStream</code>.
  246. *
  247. * <p>In order to take advantage of the specialized CRL format
  248. * supported by this certificate factory, each element in
  249. * the returned collection view can be typecast to the corresponding
  250. * CRL class. For example, if this certificate
  251. * factory implements X.509 CRLs, the elements in the returned
  252. * collection can be typecast to the <code>X509CRL</code> class.
  253. *
  254. * <p>In the case of a certificate factory for X.509 CRLs,
  255. * <code>inStream</code> may contain a single DER-encoded CRL.
  256. * In addition, <code>inStream</code> may contain a PKCS#7 CRL
  257. * set. This is a PKCS#7 <i>SignedData</i> object, with the only
  258. * significant field being <i>crls</i>. In particular, the
  259. * signature and the contents are ignored. This format allows multiple
  260. * CRLs to be downloaded at once. If no CRLs are present,
  261. * an empty collection is returned.
  262. *
  263. * <p>Note that if the given input stream does not support
  264. * {@link java.io.InputStream#mark(int) mark} and
  265. * {@link java.io.InputStream#reset() reset}, this method will
  266. * consume the entire input stream.
  267. *
  268. * @param inStream the input stream with the CRLs.
  269. *
  270. * @return a (possibly empty) collection view of
  271. * java.security.cert.CRL objects initialized with the data from the input
  272. * stream.
  273. *
  274. * @exception CRLException on parsing errors.
  275. */
  276. public abstract Collection engineGenerateCRLs(InputStream inStream)
  277. throws CRLException;
  278. }