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