2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 2362N/A * published by the Free Software Foundation. Oracle designates this 0N/A * particular file as subject to the "Classpath" exception as provided 2362N/A * by Oracle in the LICENSE file that accompanied this code. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * Interface for an X.509 extension. 0N/A * <p>The extensions defined for X.509 v3 0N/A * {@link X509Certificate Certificates} and v2 0N/A * {@link X509CRL CRLs} (Certificate Revocation 0N/A * Lists) provide methods 0N/A * for associating additional attributes with users or public keys, 0N/A * for managing the certification hierarchy, and for managing CRL 0N/A * distribution. The X.509 extensions format also allows communities 0N/A * to define private extensions to carry information unique to those 0N/A * encounters a critical extension it does not recognize. A non-critical 0N/A * extension may be ignored if it is not recognized. 0N/A * The ASN.1 definition for this is: 0N/A * Extensions ::= SEQUENCE SIZE (1..MAX) OF Extension 0N/A * Extension ::= SEQUENCE { 0N/A * extnId OBJECT IDENTIFIER, 0N/A * critical BOOLEAN DEFAULT FALSE, 0N/A * extnValue OCTET STRING 0N/A * -- contains a DER encoding of a value 0N/A * -- of the type registered for use with 0N/A * -- the extnId object identifier value 0N/A * Since not all extensions are known, the <code>getExtensionValue</code> 0N/A * method returns the DER-encoded OCTET STRING of the 0N/A * extension value (i.e., the <code>extnValue</code>). This can then 0N/A * be handled by a <em>Class</em> that understands the extension. 0N/A * @author Hemma Prafullchandra 0N/A * Check if there is a critical extension that is not supported. 0N/A * @return <tt>true</tt> if a critical extension is found that is 0N/A * not supported, otherwise <tt>false</tt>. 0N/A * Gets a Set of the OID strings for the extension(s) marked 0N/A * implementing this interface. 0N/A * Here is sample code to get a Set of critical extensions from an 0N/A * X509Certificate and print the OIDs: 0N/A * InputStream inStrm = null; 0N/A * X509Certificate cert = null; 0N/A * inStrm = new FileInputStream("DER-encoded-Cert"); 0N/A * CertificateFactory cf = CertificateFactory.getInstance("X.509"); 0N/A * cert = (X509Certificate)cf.generateCertificate(inStrm); 0N/A * if (inStrm != null) { 0N/A * Set<String> critSet = cert.getCriticalExtensionOIDs(); 0N/A * if (critSet != null && !critSet.isEmpty()) { 0N/A * System.out.println("Set of critical extensions:"); 0N/A * for (String oid : critSet) { 0N/A * System.out.println(oid); 0N/A * @return a Set (or an empty Set if none are marked critical) of 0N/A * the extension OID strings for extensions that are marked critical. 0N/A * If there are no extensions present at all, then this method returns 0N/A * Gets a Set of the OID strings for the extension(s) marked 0N/A * implementing this interface. 0N/A * Here is sample code to get a Set of non-critical extensions from an 0N/A * X509CRL revoked certificate entry and print the OIDs: 0N/A * InputStream inStrm = null; 0N/A * CertificateFactory cf = null; 0N/A * X509CRL crl = null; 0N/A * inStrm = new FileInputStream("DER-encoded-CRL"); 0N/A * cf = CertificateFactory.getInstance("X.509"); 0N/A * crl = (X509CRL)cf.generateCRL(inStrm); 0N/A * if (inStrm != null) { 0N/A * byte[] certData = <DER-encoded certificate data> 0N/A * ByteArrayInputStream bais = new ByteArrayInputStream(certData); 0N/A * X509Certificate cert = (X509Certificate)cf.generateCertificate(bais); 0N/A * X509CRLEntry badCert = 0N/A * crl.getRevokedCertificate(cert.getSerialNumber());<p> 0N/A * if (badCert != null) { 0N/A * Set<String> nonCritSet = badCert.getNonCriticalExtensionOIDs();<p> 0N/A * if (nonCritSet != null) 0N/A * for (String oid : nonCritSet) { 0N/A * System.out.println(oid); 0N/A * @return a Set (or an empty Set if none are marked non-critical) of 0N/A * the extension OID strings for extensions that are marked non-critical. 0N/A * If there are no extensions present at all, then this method returns 0N/A * Gets the DER-encoded OCTET string for the extension value 0N/A * (<em>extnValue</em>) identified by the passed-in <code>oid</code> 0N/A * The <code>oid</code> string is 0N/A * represented by a set of nonnegative whole numbers separated 0N/A * <p>For example:<br> 0N/A * <table border=groove summary="Examples of OIDs and extension names"> 0N/A * <th>OID <em>(Object Identifier)</em></th> 0N/A * <th>Extension Name</th></tr> 0N/A * <tr><td>2.5.29.14</td> 0N/A * <td>SubjectKeyIdentifier</td></tr> 0N/A * <tr><td>2.5.29.15</td> 0N/A * <td>KeyUsage</td></tr> 0N/A * <tr><td>2.5.29.16</td> 0N/A * <td>PrivateKeyUsage</td></tr> 0N/A * <tr><td>2.5.29.17</td> 0N/A * <td>SubjectAlternativeName</td></tr> 0N/A * <tr><td>2.5.29.18</td> 0N/A * <td>IssuerAlternativeName</td></tr> 0N/A * <tr><td>2.5.29.19</td> 0N/A * <td>BasicConstraints</td></tr> 0N/A * <tr><td>2.5.29.30</td> 0N/A * <td>NameConstraints</td></tr> 0N/A * <tr><td>2.5.29.33</td> 0N/A * <td>PolicyMappings</td></tr> 0N/A * <tr><td>2.5.29.35</td> 0N/A * <td>AuthorityKeyIdentifier</td></tr> 0N/A * <tr><td>2.5.29.36</td> 0N/A * <td>PolicyConstraints</td></tr> 0N/A * @param oid the Object Identifier value for the extension. 0N/A * @return the DER-encoded octet string of the extension value or 0N/A * null if it is not present.