1. /*
  2. * @(#)CertificateFactorySpi.java 1.19 04/05/05
  3. *
  4. * Copyright 2004 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.19, 05/05/04
  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. * <p> This method was added to version 1.4 of the Java 2 Platform
  90. * Standard Edition. In order to maintain backwards compatibility with
  91. * existing service providers, this method cannot be <code>abstract</code>
  92. * and by default throws an <code>UnsupportedOperationException</code>.
  93. *
  94. * @param inStream an <code>InputStream</code> containing the data
  95. * @return a <code>CertPath</code> initialized with the data from the
  96. * <code>InputStream</code>
  97. * @exception CertificateException if an exception occurs while decoding
  98. * @exception UnsupportedOperationException if the method is not supported
  99. * @since 1.4
  100. */
  101. public CertPath engineGenerateCertPath(InputStream inStream)
  102. throws CertificateException
  103. {
  104. throw new UnsupportedOperationException();
  105. }
  106. /**
  107. * Generates a <code>CertPath</code> object and initializes it with
  108. * the data read from the <code>InputStream</code> inStream. The data
  109. * is assumed to be in the specified encoding.
  110. *
  111. * <p> This method was added to version 1.4 of the Java 2 Platform
  112. * Standard Edition. In order to maintain backwards compatibility with
  113. * existing service providers, this method cannot be <code>abstract</code>
  114. * and by default throws an <code>UnsupportedOperationException</code>.
  115. *
  116. * @param inStream an <code>InputStream</code> containing the data
  117. * @param encoding the encoding used for the data
  118. * @return a <code>CertPath</code> initialized with the data from the
  119. * <code>InputStream</code>
  120. * @exception CertificateException if an exception occurs while decoding or
  121. * the encoding requested is not supported
  122. * @exception UnsupportedOperationException if the method is not supported
  123. * @since 1.4
  124. */
  125. public CertPath engineGenerateCertPath(InputStream inStream,
  126. String encoding) throws CertificateException
  127. {
  128. throw new UnsupportedOperationException();
  129. }
  130. /**
  131. * Generates a <code>CertPath</code> object and initializes it with
  132. * a <code>List</code> of <code>Certificate</code>s.
  133. * <p>
  134. * The certificates supplied must be of a type supported by the
  135. * <code>CertificateFactory</code>. They will be copied out of the supplied
  136. * <code>List</code> object.
  137. *
  138. * <p> This method was added to version 1.4 of the Java 2 Platform
  139. * Standard Edition. In order to maintain backwards compatibility with
  140. * existing service providers, this method cannot be <code>abstract</code>
  141. * and by default throws an <code>UnsupportedOperationException</code>.
  142. *
  143. * @param certificates a <code>List</code> of <code>Certificate</code>s
  144. * @return a <code>CertPath</code> initialized with the supplied list of
  145. * certificates
  146. * @exception CertificateException if an exception occurs
  147. * @exception UnsupportedOperationException if the method is not supported
  148. * @since 1.4
  149. */
  150. public CertPath
  151. engineGenerateCertPath(List<? extends Certificate> certificates)
  152. throws CertificateException
  153. {
  154. throw new UnsupportedOperationException();
  155. }
  156. /**
  157. * Returns an iteration of the <code>CertPath</code> encodings supported
  158. * by this certificate factory, with the default encoding first. See
  159. * Appendix A in the
  160. * <a href="../../../../guide/security/certpath/CertPathProgGuide.html#AppA">
  161. * Java Certification Path API Programmer's Guide</a>
  162. * for information about standard encoding names.
  163. * <p>
  164. * Attempts to modify the returned <code>Iterator</code> via its
  165. * <code>remove</code> method result in an
  166. * <code>UnsupportedOperationException</code>.
  167. *
  168. * <p> This method was added to version 1.4 of the Java 2 Platform
  169. * Standard Edition. In order to maintain backwards compatibility with
  170. * existing service providers, this method cannot be <code>abstract</code>
  171. * and by default throws an <code>UnsupportedOperationException</code>.
  172. *
  173. * @return an <code>Iterator</code> over the names of the supported
  174. * <code>CertPath</code> encodings (as <code>String</code>s)
  175. * @exception UnsupportedOperationException if the method is not supported
  176. * @since 1.4
  177. */
  178. public Iterator<String> engineGetCertPathEncodings() {
  179. throw new UnsupportedOperationException();
  180. }
  181. /**
  182. * Returns a (possibly empty) collection view of the certificates read
  183. * from the given input stream <code>inStream</code>.
  184. *
  185. * <p>In order to take advantage of the specialized certificate format
  186. * supported by this certificate factory, each element in
  187. * the returned collection view can be typecast to the corresponding
  188. * certificate class. For example, if this certificate
  189. * factory implements X.509 certificates, the elements in the returned
  190. * collection can be typecast to the <code>X509Certificate</code> class.
  191. *
  192. * <p>In the case of a certificate factory for X.509 certificates,
  193. * <code>inStream</code> may contain a single DER-encoded certificate
  194. * in the formats described for
  195. * {@link CertificateFactory#generateCertificate(java.io.InputStream)
  196. * generateCertificate}.
  197. * In addition, <code>inStream</code> may contain a PKCS#7 certificate
  198. * chain. This is a PKCS#7 <i>SignedData</i> object, with the only
  199. * significant field being <i>certificates</i>. In particular, the
  200. * signature and the contents are ignored. This format allows multiple
  201. * certificates to be downloaded at once. If no certificates are present,
  202. * an empty collection is returned.
  203. *
  204. * <p>Note that if the given input stream does not support
  205. * {@link java.io.InputStream#mark(int) mark} and
  206. * {@link java.io.InputStream#reset() reset}, this method will
  207. * consume the entire input stream.
  208. *
  209. * @param inStream the input stream with the certificates.
  210. *
  211. * @return a (possibly empty) collection view of
  212. * java.security.cert.Certificate objects
  213. * initialized with the data from the input stream.
  214. *
  215. * @exception CertificateException on parsing errors.
  216. */
  217. public abstract Collection<? extends Certificate>
  218. engineGenerateCertificates(InputStream inStream)
  219. throws CertificateException;
  220. /**
  221. * Generates a certificate revocation list (CRL) object and initializes it
  222. * with the data read from the input stream <code>inStream</code>.
  223. *
  224. * <p>In order to take advantage of the specialized CRL format
  225. * supported by this certificate factory,
  226. * the returned CRL object can be typecast to the corresponding
  227. * CRL class. For example, if this certificate
  228. * factory implements X.509 CRLs, the returned CRL object
  229. * can be typecast to the <code>X509CRL</code> class.
  230. *
  231. * <p>Note that if the given input stream does not support
  232. * {@link java.io.InputStream#mark(int) mark} and
  233. * {@link java.io.InputStream#reset() reset}, this method will
  234. * consume the entire input stream. Otherwise, each call to this
  235. * method consumes one CRL and the read position of the input stream
  236. * is positioned to the next available byte after the the inherent
  237. * end-of-CRL marker. If the data in the
  238. * input stream does not contain an inherent end-of-CRL marker (other
  239. * than EOF) and there is trailing data after the CRL is parsed, a
  240. * <code>CRLException</code> is thrown.
  241. *
  242. * @param inStream an input stream with the CRL data.
  243. *
  244. * @return a CRL object initialized with the data
  245. * from the input stream.
  246. *
  247. * @exception CRLException on parsing errors.
  248. */
  249. public abstract CRL engineGenerateCRL(InputStream inStream)
  250. throws CRLException;
  251. /**
  252. * Returns a (possibly empty) collection view of the CRLs read
  253. * from the given input stream <code>inStream</code>.
  254. *
  255. * <p>In order to take advantage of the specialized CRL format
  256. * supported by this certificate factory, each element in
  257. * the returned collection view can be typecast to the corresponding
  258. * CRL class. For example, if this certificate
  259. * factory implements X.509 CRLs, the elements in the returned
  260. * collection can be typecast to the <code>X509CRL</code> class.
  261. *
  262. * <p>In the case of a certificate factory for X.509 CRLs,
  263. * <code>inStream</code> may contain a single DER-encoded CRL.
  264. * In addition, <code>inStream</code> may contain a PKCS#7 CRL
  265. * set. This is a PKCS#7 <i>SignedData</i> object, with the only
  266. * significant field being <i>crls</i>. In particular, the
  267. * signature and the contents are ignored. This format allows multiple
  268. * CRLs to be downloaded at once. If no CRLs are present,
  269. * an empty collection is returned.
  270. *
  271. * <p>Note that if the given input stream does not support
  272. * {@link java.io.InputStream#mark(int) mark} and
  273. * {@link java.io.InputStream#reset() reset}, this method will
  274. * consume the entire input stream.
  275. *
  276. * @param inStream the input stream with the CRLs.
  277. *
  278. * @return a (possibly empty) collection view of
  279. * java.security.cert.CRL objects initialized with the data from the input
  280. * stream.
  281. *
  282. * @exception CRLException on parsing errors.
  283. */
  284. public abstract Collection<? extends CRL> engineGenerateCRLs
  285. (InputStream inStream) throws CRLException;
  286. }