1. /*
  2. * @(#)X509CRL.java 1.14 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.security.NoSuchAlgorithmException;
  9. import java.security.NoSuchProviderException;
  10. import java.security.InvalidKeyException;
  11. import java.security.SignatureException;
  12. import java.security.Principal;
  13. import java.security.PublicKey;
  14. import java.math.BigInteger;
  15. import java.util.Date;
  16. import java.util.Set;
  17. /**
  18. * <p>
  19. * Abstract class for an X.509 Certificate Revocation List (CRL).
  20. * A CRL is a time-stamped list identifying revoked certificates.
  21. * It is signed by a Certificate Authority (CA) and made freely
  22. * available in a public repository.
  23. *
  24. * <p>Each revoked certificate is
  25. * identified in a CRL by its certificate serial number. When a
  26. * certificate-using system uses a certificate (e.g., for verifying a
  27. * remote user's digital signature), that system not only checks the
  28. * certificate signature and validity but also acquires a suitably-
  29. * recent CRL and checks that the certificate serial number is not on
  30. * that CRL. The meaning of "suitably-recent" may vary with local
  31. * policy, but it usually means the most recently-issued CRL. A CA
  32. * issues a new CRL on a regular periodic basis (e.g., hourly, daily, or
  33. * weekly). Entries are added to CRLs as revocations occur, and an
  34. * entry may be removed when the certificate expiration date is reached.
  35. * <p>
  36. * The X.509 v2 CRL format is described below in ASN.1:
  37. * <pre>
  38. * CertificateList ::= SEQUENCE {
  39. * tbsCertList TBSCertList,
  40. * signatureAlgorithm AlgorithmIdentifier,
  41. * signature BIT STRING }
  42. * </pre>
  43. * <p>
  44. * A good decription and profiling is provided in the IETF PKIX WG
  45. * draft, Part I: X.509 Certificate and CRL Profile,
  46. * <draft-ietf-pkix-ipki-part1-07.txt>.
  47. * <p>
  48. * The ASN.1 definition of <code>tbsCertList</code> is:
  49. * <pre>
  50. * TBSCertList ::= SEQUENCE {
  51. * version Version OPTIONAL,
  52. * -- if present, must be v2
  53. * signature AlgorithmIdentifier,
  54. * issuer Name,
  55. * thisUpdate ChoiceOfTime,
  56. * nextUpdate ChoiceOfTime OPTIONAL,
  57. * revokedCertificates SEQUENCE OF SEQUENCE {
  58. * userCertificate CertificateSerialNumber,
  59. * revocationDate ChoiceOfTime,
  60. * crlEntryExtensions Extensions OPTIONAL
  61. * -- if present, must be v2
  62. * } OPTIONAL,
  63. * crlExtensions [0] EXPLICIT Extensions OPTIONAL
  64. * -- if present, must be v2
  65. * }
  66. * </pre>
  67. * <p>
  68. * CRLs are instantiated using a certificate factory. The following is an
  69. * example of how to instantiate an X.509 CRL:
  70. * <pre><code>
  71. * InputStream inStream = new FileInputStream("fileName-of-crl");
  72. * CertificateFactory cf = CertificateFactory.getInstance("X.509");
  73. * X509CRL crl = (X509CRL)cf.generateCRL(inStream);
  74. * inStream.close();
  75. * </code></pre>
  76. *
  77. * @author Hemma Prafullchandra
  78. *
  79. * @version 1.14
  80. *
  81. * @see CRL
  82. * @see CertificateFactory
  83. * @see X509Extension
  84. */
  85. public abstract class X509CRL extends CRL implements X509Extension {
  86. /**
  87. * Constructor for X.509 CRLs.
  88. */
  89. protected X509CRL() {
  90. super("X.509");
  91. }
  92. /**
  93. * Compares this CRL for equality with the given
  94. * object. If the <code>other</code> object is an
  95. * <code>instanceof</code> <code>X509CRL</code>, then
  96. * its encoded form is retrieved and compared with the
  97. * encoded form of this CRL.
  98. *
  99. * @param other the object to test for equality with this CRL.
  100. *
  101. * @return true iff the encoded forms of the two CRLs
  102. * match, false otherwise.
  103. */
  104. public boolean equals(Object other) {
  105. if (this == other)
  106. return true;
  107. if (!(other instanceof X509CRL))
  108. return false;
  109. try {
  110. byte[] thisCRL = this.getEncoded();
  111. byte[] otherCRL = ((X509CRL)other).getEncoded();
  112. if (thisCRL.length != otherCRL.length)
  113. return false;
  114. for (int i = 0; i < thisCRL.length; i++)
  115. if (thisCRL[i] != otherCRL[i])
  116. return false;
  117. return true;
  118. } catch (CRLException e) {
  119. return false;
  120. }
  121. }
  122. /**
  123. * Returns a hashcode value for this CRL from its
  124. * encoded form.
  125. *
  126. * @return the hashcode value.
  127. */
  128. public int hashCode() {
  129. int retval = 0;
  130. try {
  131. byte[] crlData = this.getEncoded();
  132. for (int i = 1; i < crlData.length; i++) {
  133. retval += crlData[i] * i;
  134. }
  135. return(retval);
  136. } catch (CRLException e) {
  137. return(retval);
  138. }
  139. }
  140. /**
  141. * Returns the ASN.1 DER-encoded form of this CRL.
  142. *
  143. * @exception CRLException if an encoding error occurs.
  144. */
  145. public abstract byte[] getEncoded()
  146. throws CRLException;
  147. /**
  148. * Verifies that this CRL was signed using the
  149. * private key that corresponds to the given public key.
  150. *
  151. * @param key the PublicKey used to carry out the verification.
  152. *
  153. * @exception NoSuchAlgorithmException on unsupported signature
  154. * algorithms.
  155. * @exception InvalidKeyException on incorrect key.
  156. * @exception NoSuchProviderException if there's no default provider.
  157. * @exception SignatureException on signature errors.
  158. * @exception CRLException on encoding errors.
  159. */
  160. public abstract void verify(PublicKey key)
  161. throws CRLException, NoSuchAlgorithmException,
  162. InvalidKeyException, NoSuchProviderException,
  163. SignatureException;
  164. /**
  165. * Verifies that this CRL was signed using the
  166. * private key that corresponds to the given public key.
  167. * This method uses the signature verification engine
  168. * supplied by the given provider.
  169. *
  170. * @param key the PublicKey used to carry out the verification.
  171. * @param sigProvider the name of the signature provider.
  172. *
  173. * @exception NoSuchAlgorithmException on unsupported signature
  174. * algorithms.
  175. * @exception InvalidKeyException on incorrect key.
  176. * @exception NoSuchProviderException on incorrect provider.
  177. * @exception SignatureException on signature errors.
  178. * @exception CRLException on encoding errors.
  179. */
  180. public abstract void verify(PublicKey key, String sigProvider)
  181. throws CRLException, NoSuchAlgorithmException,
  182. InvalidKeyException, NoSuchProviderException,
  183. SignatureException;
  184. /**
  185. * Gets the <code>version</code> (version number) value from the CRL.
  186. * The ASN.1 definition for this is:
  187. * <pre>
  188. * version Version OPTIONAL,
  189. * -- if present, must be v2<p>
  190. * Version ::= INTEGER { v1(0), v2(1), v3(2) }
  191. * -- v3 does not apply to CRLs but appears for consistency
  192. * -- with definition of Version for certs
  193. * </pre>
  194. *
  195. * @return the version number, i.e. 1 or 2.
  196. */
  197. public abstract int getVersion();
  198. /**
  199. * Gets the <code>issuer</code> (issuer distinguished name) value from
  200. * the CRL. The issuer name identifies the entity that signed (and
  201. * issued) the CRL.
  202. *
  203. * <p>The issuer name field contains an
  204. * X.500 distinguished name (DN).
  205. * The ASN.1 definition for this is:
  206. * <pre>
  207. * issuer Name
  208. *
  209. * Name ::= CHOICE { RDNSequence }
  210. * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
  211. * RelativeDistinguishedName ::=
  212. * SET OF AttributeValueAssertion
  213. *
  214. * AttributeValueAssertion ::= SEQUENCE {
  215. * AttributeType,
  216. * AttributeValue }
  217. * AttributeType ::= OBJECT IDENTIFIER
  218. * AttributeValue ::= ANY
  219. * </pre>
  220. * The <code>Name</code> describes a hierarchical name composed of
  221. * attributes,
  222. * such as country name, and corresponding values, such as US.
  223. * The type of the <code>AttributeValue</code> component is determined by
  224. * the <code>AttributeType</code> in general it will be a
  225. * <code>directoryString</code>. A <code>directoryString</code> is usually
  226. * one of <code>PrintableString</code>,
  227. * <code>TeletexString</code> or <code>UniversalString</code>.
  228. *
  229. * @return a Principal whose name is the issuer distinguished name.
  230. */
  231. public abstract Principal getIssuerDN();
  232. /**
  233. * Gets the <code>thisUpdate</code> date from the CRL.
  234. * The ASN.1 definition for this is:
  235. * <pre>
  236. * thisUpdate ChoiceOfTime
  237. * ChoiceOfTime ::= CHOICE {
  238. * utcTime UTCTime,
  239. * generalTime GeneralizedTime }
  240. * </pre>
  241. *
  242. * @return the <code>thisUpdate</code> date from the CRL.
  243. */
  244. public abstract Date getThisUpdate();
  245. /**
  246. * Gets the <code>nextUpdate</code> date from the CRL.
  247. *
  248. * @return the <code>nextUpdate</code> date from the CRL, or null if
  249. * not present.
  250. */
  251. public abstract Date getNextUpdate();
  252. /**
  253. * Gets the CRL entry with the given <code>serialNumber</code>
  254. * from this CRL.
  255. *
  256. * @return the entry with the given serial number, or null if no such entry
  257. * exists in this CRL.
  258. * @see X509CRLEntry
  259. */
  260. public abstract X509CRLEntry
  261. getRevokedCertificate(BigInteger serialNumber);
  262. /**
  263. * Gets all the entries from this CRL.
  264. * This returns a Set of X509CRLEntry objects.
  265. *
  266. * @return all the entries or null if there are none present.
  267. * @see X509CRLEntry
  268. */
  269. public abstract Set getRevokedCertificates();
  270. /**
  271. * Gets the DER-encoded CRL information, the
  272. * <code>tbsCertList</code> from this CRL.
  273. * This can be used to verify the signature independently.
  274. *
  275. * @return the DER-encoded CRL information.
  276. * @exception CRLException if an encoding error occurs.
  277. */
  278. public abstract byte[] getTBSCertList() throws CRLException;
  279. /**
  280. * Gets the <code>signature</code> value (the raw signature bits) from
  281. * the CRL.
  282. * The ASN.1 definition for this is:
  283. * <pre>
  284. * signature BIT STRING
  285. * </pre>
  286. *
  287. * @return the signature.
  288. */
  289. public abstract byte[] getSignature();
  290. /**
  291. * Gets the signature algorithm name for the CRL
  292. * signature algorithm. An example is the string "SHA-1/DSA".
  293. * The ASN.1 definition for this is:
  294. * <pre>
  295. * signatureAlgorithm AlgorithmIdentifier<p>
  296. * AlgorithmIdentifier ::= SEQUENCE {
  297. * algorithm OBJECT IDENTIFIER,
  298. * parameters ANY DEFINED BY algorithm OPTIONAL }
  299. * -- contains a value of the type
  300. * -- registered for use with the
  301. * -- algorithm object identifier value
  302. * </pre>
  303. *
  304. * <p>The algorithm name is determined from the <code>algorithm</code>
  305. * OID string.
  306. *
  307. * @return the signature algorithm name.
  308. */
  309. public abstract String getSigAlgName();
  310. /**
  311. * Gets the signature algorithm OID string from the CRL.
  312. * An OID is represented by a set of positive whole numbers separated
  313. * by periods.
  314. * For example, the string "1.2.840.10040.4.3" identifies the SHA-1
  315. * with DSA signature algorithm, as per the PKIX part I.
  316. *
  317. * <p>See {@link getSigAlgName()#getSigAlgName} for
  318. * relevant ASN.1 definitions.
  319. *
  320. * @return the signature algorithm OID string.
  321. */
  322. public abstract String getSigAlgOID();
  323. /**
  324. * Gets the DER-encoded signature algorithm parameters from this
  325. * CRL's signature algorithm. In most cases, the signature
  326. * algorithm parameters are null; the parameters are usually
  327. * supplied with the public key.
  328. * If access to individual parameter values is needed then use
  329. * {@link java.security.AlgorithmParameters AlgorithmParameters}
  330. * and instantiate with the name returned by
  331. * {@link getSigAlgName()#getSigAlgName}.
  332. *
  333. * <p>See {@link getSigAlgName()#getSigAlgName} for
  334. * relevant ASN.1 definitions.
  335. *
  336. * @return the DER-encoded signature algorithm parameters, or
  337. * null if no parameters are present.
  338. */
  339. public abstract byte[] getSigAlgParams();
  340. }