J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | package java.security.cert; |
| 27 | |
| 28 | import java.math.BigInteger; |
| 29 | import java.security.Principal; |
| 30 | import java.security.PublicKey; |
| 31 | import java.util.Collection; |
| 32 | import java.util.Date; |
| 33 | import java.util.List; |
| 34 | import javax.security.auth.x500.X500Principal; |
| 35 | |
| 36 | import sun.security.x509.X509CertImpl; |
| 37 | |
| 38 | /** |
| 39 | * <p> |
| 40 | * Abstract class for X.509 certificates. This provides a standard |
| 41 | * way to access all the attributes of an X.509 certificate. |
| 42 | * <p> |
| 43 | * In June of 1996, the basic X.509 v3 format was completed by |
| 44 | * ISO/IEC and ANSI X9, which is described below in ASN.1: |
| 45 | * <pre> |
| 46 | * Certificate ::= SEQUENCE { |
| 47 | * tbsCertificate TBSCertificate, |
| 48 | * signatureAlgorithm AlgorithmIdentifier, |
| 49 | * signature BIT STRING } |
| 50 | * </pre> |
| 51 | * <p> |
| 52 | * These certificates are widely used to support authentication and |
| 53 | * other functionality in Internet security systems. Common applications |
| 54 | * include Privacy Enhanced Mail (PEM), Transport Layer Security (SSL), |
| 55 | * code signing for trusted software distribution, and Secure Electronic |
| 56 | * Transactions (SET). |
| 57 | * <p> |
| 58 | * These certificates are managed and vouched for by <em>Certificate |
| 59 | * Authorities</em> (CAs). CAs are services which create certificates by |
| 60 | * placing data in the X.509 standard format and then digitally signing |
| 61 | * that data. CAs act as trusted third parties, making introductions |
| 62 | * between principals who have no direct knowledge of each other. |
| 63 | * CA certificates are either signed by themselves, or by some other |
| 64 | * CA such as a "root" CA. |
| 65 | * <p> |
| 66 | * More information can be found in |
| 67 | * <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509 |
| 68 | * Public Key Infrastructure Certificate and CRL Profile</a>. |
| 69 | * <p> |
| 70 | * The ASN.1 definition of <code>tbsCertificate</code> is: |
| 71 | * <pre> |
| 72 | * TBSCertificate ::= SEQUENCE { |
| 73 | * version [0] EXPLICIT Version DEFAULT v1, |
| 74 | * serialNumber CertificateSerialNumber, |
| 75 | * signature AlgorithmIdentifier, |
| 76 | * issuer Name, |
| 77 | * validity Validity, |
| 78 | * subject Name, |
| 79 | * subjectPublicKeyInfo SubjectPublicKeyInfo, |
| 80 | * issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL, |
| 81 | * -- If present, version must be v2 or v3 |
| 82 | * subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL, |
| 83 | * -- If present, version must be v2 or v3 |
| 84 | * extensions [3] EXPLICIT Extensions OPTIONAL |
| 85 | * -- If present, version must be v3 |
| 86 | * } |
| 87 | * </pre> |
| 88 | * <p> |
| 89 | * Certificates are instantiated using a certificate factory. The following is |
| 90 | * an example of how to instantiate an X.509 certificate: |
| 91 | * <pre> |
| 92 | * InputStream inStream = null; |
| 93 | * try { |
| 94 | * inStream = new FileInputStream("fileName-of-cert"); |
| 95 | * CertificateFactory cf = CertificateFactory.getInstance("X.509"); |
| 96 | * X509Certificate cert = (X509Certificate)cf.generateCertificate(inStream); |
| 97 | * } finally { |
| 98 | * if (inStream != null) { |
| 99 | * inStream.close(); |
| 100 | * } |
| 101 | * } |
| 102 | * </pre> |
| 103 | * |
| 104 | * @author Hemma Prafullchandra |
| 105 | * |
| 106 | * |
| 107 | * @see Certificate |
| 108 | * @see CertificateFactory |
| 109 | * @see X509Extension |
| 110 | */ |
| 111 | |
| 112 | public abstract class X509Certificate extends Certificate |
| 113 | implements X509Extension { |
| 114 | |
| 115 | private static final long serialVersionUID = -2491127588187038216L; |
| 116 | |
| 117 | private transient X500Principal subjectX500Principal, issuerX500Principal; |
| 118 | |
| 119 | /** |
| 120 | * Constructor for X.509 certificates. |
| 121 | */ |
| 122 | protected X509Certificate() { |
| 123 | super("X.509"); |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | * Checks that the certificate is currently valid. It is if |
| 128 | * the current date and time are within the validity period given in the |
| 129 | * certificate. |
| 130 | * <p> |
| 131 | * The validity period consists of two date/time values: |
| 132 | * the first and last dates (and times) on which the certificate |
| 133 | * is valid. It is defined in |
| 134 | * ASN.1 as: |
| 135 | * <pre> |
| 136 | * validity Validity<p> |
| 137 | * Validity ::= SEQUENCE { |
| 138 | * notBefore CertificateValidityDate, |
| 139 | * notAfter CertificateValidityDate }<p> |
| 140 | * CertificateValidityDate ::= CHOICE { |
| 141 | * utcTime UTCTime, |
| 142 | * generalTime GeneralizedTime } |
| 143 | * </pre> |
| 144 | * |
| 145 | * @exception CertificateExpiredException if the certificate has expired. |
| 146 | * @exception CertificateNotYetValidException if the certificate is not |
| 147 | * yet valid. |
| 148 | */ |
| 149 | public abstract void checkValidity() |
| 150 | throws CertificateExpiredException, CertificateNotYetValidException; |
| 151 | |
| 152 | /** |
| 153 | * Checks that the given date is within the certificate's |
| 154 | * validity period. In other words, this determines whether the |
| 155 | * certificate would be valid at the given date/time. |
| 156 | * |
| 157 | * @param date the Date to check against to see if this certificate |
| 158 | * is valid at that date/time. |
| 159 | * |
| 160 | * @exception CertificateExpiredException if the certificate has expired |
| 161 | * with respect to the <code>date</code> supplied. |
| 162 | * @exception CertificateNotYetValidException if the certificate is not |
| 163 | * yet valid with respect to the <code>date</code> supplied. |
| 164 | * |
| 165 | * @see #checkValidity() |
| 166 | */ |
| 167 | public abstract void checkValidity(Date date) |
| 168 | throws CertificateExpiredException, CertificateNotYetValidException; |
| 169 | |
| 170 | /** |
| 171 | * Gets the <code>version</code> (version number) value from the |
| 172 | * certificate. |
| 173 | * The ASN.1 definition for this is: |
| 174 | * <pre> |
| 175 | * version [0] EXPLICIT Version DEFAULT v1<p> |
| 176 | * Version ::= INTEGER { v1(0), v2(1), v3(2) } |
| 177 | * </pre> |
| 178 | * @return the version number, i.e. 1, 2 or 3. |
| 179 | */ |
| 180 | public abstract int getVersion(); |
| 181 | |
| 182 | /** |
| 183 | * Gets the <code>serialNumber</code> value from the certificate. |
| 184 | * The serial number is an integer assigned by the certification |
| 185 | * authority to each certificate. It must be unique for each |
| 186 | * certificate issued by a given CA (i.e., the issuer name and |
| 187 | * serial number identify a unique certificate). |
| 188 | * The ASN.1 definition for this is: |
| 189 | * <pre> |
| 190 | * serialNumber CertificateSerialNumber<p> |
| 191 | * |
| 192 | * CertificateSerialNumber ::= INTEGER |
| 193 | * </pre> |
| 194 | * |
| 195 | * @return the serial number. |
| 196 | */ |
| 197 | public abstract BigInteger getSerialNumber(); |
| 198 | |
| 199 | /** |
| 200 | * <strong>Denigrated</strong>, replaced by {@linkplain |
| 201 | * #getIssuerX500Principal()}. This method returns the <code>issuer</code> |
| 202 | * as an implementation specific Principal object, which should not be |
| 203 | * relied upon by portable code. |
| 204 | * |
| 205 | * <p> |
| 206 | * Gets the <code>issuer</code> (issuer distinguished name) value from |
| 207 | * the certificate. The issuer name identifies the entity that signed (and |
| 208 | * issued) the certificate. |
| 209 | * |
| 210 | * <p>The issuer name field contains an |
| 211 | * X.500 distinguished name (DN). |
| 212 | * The ASN.1 definition for this is: |
| 213 | * <pre> |
| 214 | * issuer Name<p> |
| 215 | * |
| 216 | * Name ::= CHOICE { RDNSequence } |
| 217 | * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName |
| 218 | * RelativeDistinguishedName ::= |
| 219 | * SET OF AttributeValueAssertion |
| 220 | * |
| 221 | * AttributeValueAssertion ::= SEQUENCE { |
| 222 | * AttributeType, |
| 223 | * AttributeValue } |
| 224 | * AttributeType ::= OBJECT IDENTIFIER |
| 225 | * AttributeValue ::= ANY |
| 226 | * </pre> |
| 227 | * The <code>Name</code> describes a hierarchical name composed of |
| 228 | * attributes, |
| 229 | * such as country name, and corresponding values, such as US. |
| 230 | * The type of the <code>AttributeValue</code> component is determined by |
| 231 | * the <code>AttributeType</code>; in general it will be a |
| 232 | * <code>directoryString</code>. A <code>directoryString</code> is usually |
| 233 | * one of <code>PrintableString</code>, |
| 234 | * <code>TeletexString</code> or <code>UniversalString</code>. |
| 235 | * |
| 236 | * @return a Principal whose name is the issuer distinguished name. |
| 237 | */ |
| 238 | public abstract Principal getIssuerDN(); |
| 239 | |
| 240 | /** |
| 241 | * Returns the issuer (issuer distinguished name) value from the |
| 242 | * certificate as an <code>X500Principal</code>. |
| 243 | * <p> |
| 244 | * It is recommended that subclasses override this method. |
| 245 | * |
| 246 | * @return an <code>X500Principal</code> representing the issuer |
| 247 | * distinguished name |
| 248 | * @since 1.4 |
| 249 | */ |
| 250 | public X500Principal getIssuerX500Principal() { |
| 251 | if (issuerX500Principal == null) { |
| 252 | issuerX500Principal = X509CertImpl.getIssuerX500Principal(this); |
| 253 | } |
| 254 | return issuerX500Principal; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * <strong>Denigrated</strong>, replaced by {@linkplain |
| 259 | * #getSubjectX500Principal()}. This method returns the <code>subject</code> |
| 260 | * as an implementation specific Principal object, which should not be |
| 261 | * relied upon by portable code. |
| 262 | * |
| 263 | * <p> |
| 264 | * Gets the <code>subject</code> (subject distinguished name) value |
| 265 | * from the certificate. If the <code>subject</code> value is empty, |
| 266 | * then the <code>getName()</code> method of the returned |
| 267 | * <code>Principal</code> object returns an empty string (""). |
| 268 | * |
| 269 | * <p> The ASN.1 definition for this is: |
| 270 | * <pre> |
| 271 | * subject Name |
| 272 | * </pre> |
| 273 | * |
| 274 | * <p>See {@link #getIssuerDN() getIssuerDN} for <code>Name</code> |
| 275 | * and other relevant definitions. |
| 276 | * |
| 277 | * @return a Principal whose name is the subject name. |
| 278 | */ |
| 279 | public abstract Principal getSubjectDN(); |
| 280 | |
| 281 | /** |
| 282 | * Returns the subject (subject distinguished name) value from the |
| 283 | * certificate as an <code>X500Principal</code>. If the subject value |
| 284 | * is empty, then the <code>getName()</code> method of the returned |
| 285 | * <code>X500Principal</code> object returns an empty string (""). |
| 286 | * <p> |
| 287 | * It is recommended that subclasses override this method. |
| 288 | * |
| 289 | * @return an <code>X500Principal</code> representing the subject |
| 290 | * distinguished name |
| 291 | * @since 1.4 |
| 292 | */ |
| 293 | public X500Principal getSubjectX500Principal() { |
| 294 | if (subjectX500Principal == null) { |
| 295 | subjectX500Principal = X509CertImpl.getSubjectX500Principal(this); |
| 296 | } |
| 297 | return subjectX500Principal; |
| 298 | } |
| 299 | |
| 300 | /** |
| 301 | * Gets the <code>notBefore</code> date from the validity period of |
| 302 | * the certificate. |
| 303 | * The relevant ASN.1 definitions are: |
| 304 | * <pre> |
| 305 | * validity Validity<p> |
| 306 | * |
| 307 | * Validity ::= SEQUENCE { |
| 308 | * notBefore CertificateValidityDate, |
| 309 | * notAfter CertificateValidityDate }<p> |
| 310 | * CertificateValidityDate ::= CHOICE { |
| 311 | * utcTime UTCTime, |
| 312 | * generalTime GeneralizedTime } |
| 313 | * </pre> |
| 314 | * |
| 315 | * @return the start date of the validity period. |
| 316 | * @see #checkValidity |
| 317 | */ |
| 318 | public abstract Date getNotBefore(); |
| 319 | |
| 320 | /** |
| 321 | * Gets the <code>notAfter</code> date from the validity period of |
| 322 | * the certificate. See {@link #getNotBefore() getNotBefore} |
| 323 | * for relevant ASN.1 definitions. |
| 324 | * |
| 325 | * @return the end date of the validity period. |
| 326 | * @see #checkValidity |
| 327 | */ |
| 328 | public abstract Date getNotAfter(); |
| 329 | |
| 330 | /** |
| 331 | * Gets the DER-encoded certificate information, the |
| 332 | * <code>tbsCertificate</code> from this certificate. |
| 333 | * This can be used to verify the signature independently. |
| 334 | * |
| 335 | * @return the DER-encoded certificate information. |
| 336 | * @exception CertificateEncodingException if an encoding error occurs. |
| 337 | */ |
| 338 | public abstract byte[] getTBSCertificate() |
| 339 | throws CertificateEncodingException; |
| 340 | |
| 341 | /** |
| 342 | * Gets the <code>signature</code> value (the raw signature bits) from |
| 343 | * the certificate. |
| 344 | * The ASN.1 definition for this is: |
| 345 | * <pre> |
| 346 | * signature BIT STRING |
| 347 | * </pre> |
| 348 | * |
| 349 | * @return the signature. |
| 350 | */ |
| 351 | public abstract byte[] getSignature(); |
| 352 | |
| 353 | /** |
| 354 | * Gets the signature algorithm name for the certificate |
| 355 | * signature algorithm. An example is the string "SHA-1/DSA". |
| 356 | * The ASN.1 definition for this is: |
| 357 | * <pre> |
| 358 | * signatureAlgorithm AlgorithmIdentifier<p> |
| 359 | * AlgorithmIdentifier ::= SEQUENCE { |
| 360 | * algorithm OBJECT IDENTIFIER, |
| 361 | * parameters ANY DEFINED BY algorithm OPTIONAL } |
| 362 | * -- contains a value of the type |
| 363 | * -- registered for use with the |
| 364 | * -- algorithm object identifier value |
| 365 | * </pre> |
| 366 | * |
| 367 | * <p>The algorithm name is determined from the <code>algorithm</code> |
| 368 | * OID string. |
| 369 | * |
| 370 | * @return the signature algorithm name. |
| 371 | */ |
| 372 | public abstract String getSigAlgName(); |
| 373 | |
| 374 | /** |
| 375 | * Gets the signature algorithm OID string from the certificate. |
| 376 | * An OID is represented by a set of nonnegative whole numbers separated |
| 377 | * by periods. |
| 378 | * For example, the string "1.2.840.10040.4.3" identifies the SHA-1 |
| 379 | * with DSA signature algorithm defined in |
| 380 | * <a href="http://www.ietf.org/rfc/rfc3279.txt">RFC 3279: Algorithms and |
| 381 | * Identifiers for the Internet X.509 Public Key Infrastructure Certificate |
| 382 | * and CRL Profile</a>. |
| 383 | * |
| 384 | * <p>See {@link #getSigAlgName() getSigAlgName} for |
| 385 | * relevant ASN.1 definitions. |
| 386 | * |
| 387 | * @return the signature algorithm OID string. |
| 388 | */ |
| 389 | public abstract String getSigAlgOID(); |
| 390 | |
| 391 | /** |
| 392 | * Gets the DER-encoded signature algorithm parameters from this |
| 393 | * certificate's signature algorithm. In most cases, the signature |
| 394 | * algorithm parameters are null; the parameters are usually |
| 395 | * supplied with the certificate's public key. |
| 396 | * If access to individual parameter values is needed then use |
| 397 | * {@link java.security.AlgorithmParameters AlgorithmParameters} |
| 398 | * and instantiate with the name returned by |
| 399 | * {@link #getSigAlgName() getSigAlgName}. |
| 400 | * |
| 401 | * <p>See {@link #getSigAlgName() getSigAlgName} for |
| 402 | * relevant ASN.1 definitions. |
| 403 | * |
| 404 | * @return the DER-encoded signature algorithm parameters, or |
| 405 | * null if no parameters are present. |
| 406 | */ |
| 407 | public abstract byte[] getSigAlgParams(); |
| 408 | |
| 409 | /** |
| 410 | * Gets the <code>issuerUniqueID</code> value from the certificate. |
| 411 | * The issuer unique identifier is present in the certificate |
| 412 | * to handle the possibility of reuse of issuer names over time. |
| 413 | * RFC 3280 recommends that names not be reused and that |
| 414 | * conforming certificates not make use of unique identifiers. |
| 415 | * Applications conforming to that profile should be capable of |
| 416 | * parsing unique identifiers and making comparisons. |
| 417 | * |
| 418 | * <p>The ASN.1 definition for this is: |
| 419 | * <pre> |
| 420 | * issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL<p> |
| 421 | * UniqueIdentifier ::= BIT STRING |
| 422 | * </pre> |
| 423 | * |
| 424 | * @return the issuer unique identifier or null if it is not |
| 425 | * present in the certificate. |
| 426 | */ |
| 427 | public abstract boolean[] getIssuerUniqueID(); |
| 428 | |
| 429 | /** |
| 430 | * Gets the <code>subjectUniqueID</code> value from the certificate. |
| 431 | * |
| 432 | * <p>The ASN.1 definition for this is: |
| 433 | * <pre> |
| 434 | * subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL<p> |
| 435 | * UniqueIdentifier ::= BIT STRING |
| 436 | * </pre> |
| 437 | * |
| 438 | * @return the subject unique identifier or null if it is not |
| 439 | * present in the certificate. |
| 440 | */ |
| 441 | public abstract boolean[] getSubjectUniqueID(); |
| 442 | |
| 443 | /** |
| 444 | * Gets a boolean array representing bits of |
| 445 | * the <code>KeyUsage</code> extension, (OID = 2.5.29.15). |
| 446 | * The key usage extension defines the purpose (e.g., encipherment, |
| 447 | * signature, certificate signing) of the key contained in the |
| 448 | * certificate. |
| 449 | * The ASN.1 definition for this is: |
| 450 | * <pre> |
| 451 | * KeyUsage ::= BIT STRING { |
| 452 | * digitalSignature (0), |
| 453 | * nonRepudiation (1), |
| 454 | * keyEncipherment (2), |
| 455 | * dataEncipherment (3), |
| 456 | * keyAgreement (4), |
| 457 | * keyCertSign (5), |
| 458 | * cRLSign (6), |
| 459 | * encipherOnly (7), |
| 460 | * decipherOnly (8) } |
| 461 | * </pre> |
| 462 | * RFC 3280 recommends that when used, this be marked |
| 463 | * as a critical extension. |
| 464 | * |
| 465 | * @return the KeyUsage extension of this certificate, represented as |
| 466 | * an array of booleans. The order of KeyUsage values in the array is |
| 467 | * the same as in the above ASN.1 definition. The array will contain a |
| 468 | * value for each KeyUsage defined above. If the KeyUsage list encoded |
| 469 | * in the certificate is longer than the above list, it will not be |
| 470 | * truncated. Returns null if this certificate does not |
| 471 | * contain a KeyUsage extension. |
| 472 | */ |
| 473 | public abstract boolean[] getKeyUsage(); |
| 474 | |
| 475 | /** |
| 476 | * Gets an unmodifiable list of Strings representing the OBJECT |
| 477 | * IDENTIFIERs of the <code>ExtKeyUsageSyntax</code> field of the |
| 478 | * extended key usage extension, (OID = 2.5.29.37). It indicates |
| 479 | * one or more purposes for which the certified public key may be |
| 480 | * used, in addition to or in place of the basic purposes |
| 481 | * indicated in the key usage extension field. The ASN.1 |
| 482 | * definition for this is: |
| 483 | * <pre> |
| 484 | * ExtKeyUsageSyntax ::= SEQUENCE SIZE (1..MAX) OF KeyPurposeId<p> |
| 485 | * |
| 486 | * KeyPurposeId ::= OBJECT IDENTIFIER<p> |
| 487 | * </pre> |
| 488 | * |
| 489 | * Key purposes may be defined by any organization with a |
| 490 | * need. Object identifiers used to identify key purposes shall be |
| 491 | * assigned in accordance with IANA or ITU-T Rec. X.660 | |
| 492 | * ISO/IEC/ITU 9834-1. |
| 493 | * <p> |
| 494 | * This method was added to version 1.4 of the Java 2 Platform Standard |
| 495 | * Edition. In order to maintain backwards compatibility with existing |
| 496 | * service providers, this method is not <code>abstract</code> |
| 497 | * and it provides a default implementation. Subclasses |
| 498 | * should override this method with a correct implementation. |
| 499 | * |
| 500 | * @return the ExtendedKeyUsage extension of this certificate, |
| 501 | * as an unmodifiable list of object identifiers represented |
| 502 | * as Strings. Returns null if this certificate does not |
| 503 | * contain an ExtendedKeyUsage extension. |
| 504 | * @throws CertificateParsingException if the extension cannot be decoded |
| 505 | * @since 1.4 |
| 506 | */ |
| 507 | public List<String> getExtendedKeyUsage() throws CertificateParsingException { |
| 508 | return X509CertImpl.getExtendedKeyUsage(this); |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Gets the certificate constraints path length from the |
| 513 | * critical <code>BasicConstraints</code> extension, (OID = 2.5.29.19). |
| 514 | * <p> |
| 515 | * The basic constraints extension identifies whether the subject |
| 516 | * of the certificate is a Certificate Authority (CA) and |
| 517 | * how deep a certification path may exist through that CA. The |
| 518 | * <code>pathLenConstraint</code> field (see below) is meaningful |
| 519 | * only if <code>cA</code> is set to TRUE. In this case, it gives the |
| 520 | * maximum number of CA certificates that may follow this certificate in a |
| 521 | * certification path. A value of zero indicates that only an end-entity |
| 522 | * certificate may follow in the path. |
| 523 | * <p> |
| 524 | * The ASN.1 definition for this is: |
| 525 | * <pre> |
| 526 | * BasicConstraints ::= SEQUENCE { |
| 527 | * cA BOOLEAN DEFAULT FALSE, |
| 528 | * pathLenConstraint INTEGER (0..MAX) OPTIONAL } |
| 529 | * </pre> |
| 530 | * |
| 531 | * @return the value of <code>pathLenConstraint</code> if the |
| 532 | * BasicConstraints extension is present in the certificate and the |
| 533 | * subject of the certificate is a CA, otherwise -1. |
| 534 | * If the subject of the certificate is a CA and |
| 535 | * <code>pathLenConstraint</code> does not appear, |
| 536 | * <code>Integer.MAX_VALUE</code> is returned to indicate that there is no |
| 537 | * limit to the allowed length of the certification path. |
| 538 | */ |
| 539 | public abstract int getBasicConstraints(); |
| 540 | |
| 541 | /** |
| 542 | * Gets an immutable collection of subject alternative names from the |
| 543 | * <code>SubjectAltName</code> extension, (OID = 2.5.29.17). |
| 544 | * <p> |
| 545 | * The ASN.1 definition of the <code>SubjectAltName</code> extension is: |
| 546 | * <pre> |
| 547 | * SubjectAltName ::= GeneralNames |
| 548 | * |
| 549 | * GeneralNames :: = SEQUENCE SIZE (1..MAX) OF GeneralName |
| 550 | * |
| 551 | * GeneralName ::= CHOICE { |
| 552 | * otherName [0] OtherName, |
| 553 | * rfc822Name [1] IA5String, |
| 554 | * dNSName [2] IA5String, |
| 555 | * x400Address [3] ORAddress, |
| 556 | * directoryName [4] Name, |
| 557 | * ediPartyName [5] EDIPartyName, |
| 558 | * uniformResourceIdentifier [6] IA5String, |
| 559 | * iPAddress [7] OCTET STRING, |
| 560 | * registeredID [8] OBJECT IDENTIFIER} |
| 561 | * </pre> |
| 562 | * <p> |
| 563 | * If this certificate does not contain a <code>SubjectAltName</code> |
| 564 | * extension, <code>null</code> is returned. Otherwise, a |
| 565 | * <code>Collection</code> is returned with an entry representing each |
| 566 | * <code>GeneralName</code> included in the extension. Each entry is a |
| 567 | * <code>List</code> whose first entry is an <code>Integer</code> |
| 568 | * (the name type, 0-8) and whose second entry is a <code>String</code> |
| 569 | * or a byte array (the name, in string or ASN.1 DER encoded form, |
| 570 | * respectively). |
| 571 | * <p> |
| 572 | * <a href="http://www.ietf.org/rfc/rfc822.txt">RFC 822</a>, DNS, and URI |
| 573 | * names are returned as <code>String</code>s, |
| 574 | * using the well-established string formats for those types (subject to |
| 575 | * the restrictions included in RFC 3280). IPv4 address names are |
| 576 | * returned using dotted quad notation. IPv6 address names are returned |
| 577 | * in the form "a1:a2:...:a8", where a1-a8 are hexadecimal values |
| 578 | * representing the eight 16-bit pieces of the address. OID names are |
| 579 | * returned as <code>String</code>s represented as a series of nonnegative |
| 580 | * integers separated by periods. And directory names (distinguished names) |
| 581 | * are returned in <a href="http://www.ietf.org/rfc/rfc2253.txt"> |
| 582 | * RFC 2253</a> string format. No standard string format is |
| 583 | * defined for otherNames, X.400 names, EDI party names, or any |
| 584 | * other type of names. They are returned as byte arrays |
| 585 | * containing the ASN.1 DER encoded form of the name. |
| 586 | * <p> |
| 587 | * Note that the <code>Collection</code> returned may contain more |
| 588 | * than one name of the same type. Also, note that the returned |
| 589 | * <code>Collection</code> is immutable and any entries containing byte |
| 590 | * arrays are cloned to protect against subsequent modifications. |
| 591 | * <p> |
| 592 | * This method was added to version 1.4 of the Java 2 Platform Standard |
| 593 | * Edition. In order to maintain backwards compatibility with existing |
| 594 | * service providers, this method is not <code>abstract</code> |
| 595 | * and it provides a default implementation. Subclasses |
| 596 | * should override this method with a correct implementation. |
| 597 | * |
| 598 | * @return an immutable <code>Collection</code> of subject alternative |
| 599 | * names (or <code>null</code>) |
| 600 | * @throws CertificateParsingException if the extension cannot be decoded |
| 601 | * @since 1.4 |
| 602 | */ |
| 603 | public Collection<List<?>> getSubjectAlternativeNames() |
| 604 | throws CertificateParsingException { |
| 605 | return X509CertImpl.getSubjectAlternativeNames(this); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Gets an immutable collection of issuer alternative names from the |
| 610 | * <code>IssuerAltName</code> extension, (OID = 2.5.29.18). |
| 611 | * <p> |
| 612 | * The ASN.1 definition of the <code>IssuerAltName</code> extension is: |
| 613 | * <pre> |
| 614 | * IssuerAltName ::= GeneralNames |
| 615 | * </pre> |
| 616 | * The ASN.1 definition of <code>GeneralNames</code> is defined |
| 617 | * in {@link #getSubjectAlternativeNames getSubjectAlternativeNames}. |
| 618 | * <p> |
| 619 | * If this certificate does not contain an <code>IssuerAltName</code> |
| 620 | * extension, <code>null</code> is returned. Otherwise, a |
| 621 | * <code>Collection</code> is returned with an entry representing each |
| 622 | * <code>GeneralName</code> included in the extension. Each entry is a |
| 623 | * <code>List</code> whose first entry is an <code>Integer</code> |
| 624 | * (the name type, 0-8) and whose second entry is a <code>String</code> |
| 625 | * or a byte array (the name, in string or ASN.1 DER encoded form, |
| 626 | * respectively). For more details about the formats used for each |
| 627 | * name type, see the <code>getSubjectAlternativeNames</code> method. |
| 628 | * <p> |
| 629 | * Note that the <code>Collection</code> returned may contain more |
| 630 | * than one name of the same type. Also, note that the returned |
| 631 | * <code>Collection</code> is immutable and any entries containing byte |
| 632 | * arrays are cloned to protect against subsequent modifications. |
| 633 | * <p> |
| 634 | * This method was added to version 1.4 of the Java 2 Platform Standard |
| 635 | * Edition. In order to maintain backwards compatibility with existing |
| 636 | * service providers, this method is not <code>abstract</code> |
| 637 | * and it provides a default implementation. Subclasses |
| 638 | * should override this method with a correct implementation. |
| 639 | * |
| 640 | * @return an immutable <code>Collection</code> of issuer alternative |
| 641 | * names (or <code>null</code>) |
| 642 | * @throws CertificateParsingException if the extension cannot be decoded |
| 643 | * @since 1.4 |
| 644 | */ |
| 645 | public Collection<List<?>> getIssuerAlternativeNames() |
| 646 | throws CertificateParsingException { |
| 647 | return X509CertImpl.getIssuerAlternativeNames(this); |
| 648 | } |
| 649 | } |