1. /*
  2. * @(#)CertificateFactorySpi.java 1.5 01/11/29
  3. *
  4. * Copyright 2002 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.security.Provider;
  11. import java.security.NoSuchAlgorithmException;
  12. import java.security.NoSuchProviderException;
  13. /**
  14. * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>)
  15. * for the <code>CertificateFactory</code> class.
  16. * All the abstract methods in this class must be implemented by each
  17. * cryptographic service provider who wishes to supply the implementation
  18. * of a certificate factory for a particular certificate type, e.g., X.509.
  19. *
  20. * <p>Certificate factories are used to generate certificate and certificate
  21. * revocation list (CRL) objects from their encoding.
  22. *
  23. * <p>A certificate factory for X.509 must return certificates that are an
  24. * instance of <code>java.security.cert.X509Certificate</code>, and CRLs
  25. * that are an instance of <code>java.security.cert.X509CRL</code>.
  26. *
  27. * @author Hemma Prafullchandra
  28. * @author Jan Luehe
  29. *
  30. * @version 1.5
  31. *
  32. * @see CertificateFactory
  33. * @see Certificate
  34. * @see X509Certificate
  35. * @see CRL
  36. * @see X509CRL
  37. *
  38. * @since JDK1.2
  39. */
  40. public abstract class CertificateFactorySpi {
  41. /**
  42. * Generates a certificate object and initializes it with
  43. * the data read from the input stream <code>inStream</code>.
  44. *
  45. * <p>The given input stream <code>inStream</code> must contain a single
  46. * certificate.
  47. *
  48. * <p>In order to take advantage of the specialized certificate format
  49. * supported by this certificate factory,
  50. * the returned certificate object can be typecast to the corresponding
  51. * certificate class. For example, if this certificate
  52. * factory implements X.509 certificates, the returned certificate object
  53. * can be typecast to the <code>X509Certificate</code> class.
  54. *
  55. * <p>In the case of a certificate factory for X.509 certificates, the
  56. * certificate provided in <code>inStream</code> must be DER-encoded and
  57. * may be supplied in binary or printable (Base64) encoding. If the
  58. * certificate is provided in Base64 encoding, it must be bounded at
  59. * the beginning by -----BEGIN CERTIFICATE-----, and must be bounded at
  60. * the end by -----END CERTIFICATE-----.
  61. *
  62. * <p>Note that if the given input stream does not support
  63. * {@link java.io.InputStream#mark(int) mark} and
  64. * {@link java.io.InputStream#reset() reset}, this method will
  65. * consume the entire input stream.
  66. *
  67. * @param inStream an input stream with the certificate data.
  68. *
  69. * @return a certificate object initialized with the data
  70. * from the input stream.
  71. *
  72. * @exception CertificateException on parsing errors.
  73. */
  74. public abstract Certificate engineGenerateCertificate(InputStream inStream)
  75. throws CertificateException;
  76. /**
  77. * Returns a (possibly empty) collection view of the certificates read
  78. * from the given input stream <code>inStream</code>.
  79. *
  80. * <p>In order to take advantage of the specialized certificate format
  81. * supported by this certificate factory, each element in
  82. * the returned collection view can be typecast to the corresponding
  83. * certificate class. For example, if this certificate
  84. * factory implements X.509 certificates, the elements in the returned
  85. * collection can be typecast to the <code>X509Certificate</code> class.
  86. *
  87. * <p>In the case of a certificate factory for X.509 certificates,
  88. * <code>inStream</code> may contain a single DER-encoded certificate
  89. * in the formats described for
  90. * {@link #generateCertificate(java.io.InputStream) generateCertificate}.
  91. * In addition, <code>inStream</code> may contain a PKCS#7 certificate
  92. * chain. This is a PKCS#7 <i>SignedData</i> object, with the only
  93. * significant field being <i>certificates</i>. In particular, the
  94. * signature and the contents are ignored. This format allows multiple
  95. * certificates to be downloaded at once. If no certificates are present,
  96. * an empty collection is returned.
  97. *
  98. * <p>Note that if the given input stream does not support
  99. * {@link java.io.InputStream#mark(int) mark} and
  100. * {@link java.io.InputStream#reset() reset}, this method will
  101. * consume the entire input stream.
  102. *
  103. * @param inStream the input stream with the certificates.
  104. *
  105. * @return a (possibly empty) collection view of
  106. * java.security.cert.Certificate objects
  107. * initialized with the data from the input stream.
  108. *
  109. * @exception CertificateException on parsing errors.
  110. */
  111. public abstract Collection engineGenerateCertificates(InputStream inStream)
  112. throws CertificateException;
  113. /**
  114. * Generates a certificate revocation list (CRL) object and initializes it
  115. * with the data read from the input stream <code>inStream</code>.
  116. *
  117. * <p>In order to take advantage of the specialized CRL format
  118. * supported by this certificate factory,
  119. * the returned CRL object can be typecast to the corresponding
  120. * CRL class. For example, if this certificate
  121. * factory implements X.509 CRLs, the returned CRL object
  122. * can be typecast to the <code>X509CRL</code> class.
  123. *
  124. * <p>Note that if the given input stream does not support
  125. * {@link java.io.InputStream#mark(int) mark} and
  126. * {@link java.io.InputStream#reset() reset}, this method will
  127. * consume the entire input stream.
  128. *
  129. * @param inStream an input stream with the CRL data.
  130. *
  131. * @return a CRL object initialized with the data
  132. * from the input stream.
  133. *
  134. * @exception CRLException on parsing errors.
  135. */
  136. public abstract CRL engineGenerateCRL(InputStream inStream)
  137. throws CRLException;
  138. /**
  139. * Returns a (possibly empty) collection view of the CRLs read
  140. * from the given input stream <code>inStream</code>.
  141. *
  142. * <p>In order to take advantage of the specialized CRL format
  143. * supported by this certificate factory, each element in
  144. * the returned collection view can be typecast to the corresponding
  145. * CRL class. For example, if this certificate
  146. * factory implements X.509 CRLs, the elements in the returned
  147. * collection can be typecast to the <code>X509CRL</code> class.
  148. *
  149. * <p>In the case of a certificate factory for X.509 CRLs,
  150. * <code>inStream</code> may contain a single DER-encoded CRL.
  151. * In addition, <code>inStream</code> may contain a PKCS#7 CRL
  152. * set. This is a PKCS#7 <i>SignedData</i> object, with the only
  153. * significant field being <i>crls</i>. In particular, the
  154. * signature and the contents are ignored. This format allows multiple
  155. * CRLs to be downloaded at once. If no CRLs are present,
  156. * an empty collection is returned.
  157. *
  158. * <p>Note that if the given input stream does not support
  159. * {@link java.io.InputStream#mark(int) mark} and
  160. * {@link java.io.InputStream#reset() reset}, this method will
  161. * consume the entire input stream.
  162. *
  163. * @param inStream the input stream with the CRLs.
  164. *
  165. * @return a (possibly empty) collection view of
  166. * java.security.cert.CRL objects initialized with the data from the input
  167. * stream.
  168. *
  169. * @exception CRLException on parsing errors.
  170. */
  171. public abstract Collection engineGenerateCRLs(InputStream inStream)
  172. throws CRLException;
  173. }