0N/A/*
2362N/A * Copyright (c) 2002, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
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 *
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 *
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.
0N/A *
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
2362N/A * questions.
0N/A */
0N/A
0N/Apackage sun.security.x509;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.io.OutputStream;
0N/A
0N/Aimport java.util.*;
0N/A
0N/Aimport sun.security.util.DerOutputStream;
0N/Aimport sun.security.util.DerValue;
0N/Aimport sun.security.util.ObjectIdentifier;
0N/A
0N/A/**
0N/A * Represent the CRL Distribution Points Extension (OID = 2.5.29.31).
0N/A * <p>
0N/A * The CRL distribution points extension identifies how CRL information
0N/A * is obtained. The extension SHOULD be non-critical, but the PKIX profile
0N/A * recommends support for this extension by CAs and applications.
0N/A * <p>
0N/A * For PKIX, if the cRLDistributionPoints extension contains a
0N/A * DistributionPointName of type URI, the following semantics MUST be
0N/A * assumed: the URI is a pointer to the current CRL for the associated
0N/A * reasons and will be issued by the associated cRLIssuer. The
0N/A * expected values for the URI conform to the following rules. The
0N/A * name MUST be a non-relative URL, and MUST follow the URL syntax and
0N/A * encoding rules specified in [RFC 1738]. The name must include both
0N/A * a scheme (e.g., "http" or "ftp") and a scheme-specific-part. The
0N/A * scheme- specific-part must include a fully qualified domain name or
0N/A * IP address as the host. As specified in [RFC 1738], the scheme
0N/A * name is not case-sensitive (e.g., "http" is equivalent to "HTTP").
0N/A * The host part is also not case-sensitive, but other components of
0N/A * the scheme-specific-part may be case-sensitive. When comparing
0N/A * URIs, conforming implementations MUST compare the scheme and host
0N/A * without regard to case, but assume the remainder of the
0N/A * scheme-specific-part is case sensitive. Processing rules for other
0N/A * values are not defined by this specification. If the
0N/A * distributionPoint omits reasons, the CRL MUST include revocations
0N/A * for all reasons. If the distributionPoint omits cRLIssuer, the CRL
0N/A * MUST be issued by the CA that issued the certificate.
0N/A * <p>
0N/A * The ASN.1 definition for this is:
0N/A * <pre>
0N/A * id-ce-cRLDistributionPoints OBJECT IDENTIFIER ::= { id-ce 31 }
0N/A *
0N/A * cRLDistributionPoints ::= {
0N/A * CRLDistPointsSyntax }
0N/A *
0N/A * CRLDistPointsSyntax ::= SEQUENCE SIZE (1..MAX) OF DistributionPoint
0N/A * </pre>
0N/A * <p>
0N/A * @author Anne Anderson
0N/A * @author Andreas Sterbenz
0N/A * @since 1.4.2
0N/A * @see DistributionPoint
0N/A * @see Extension
0N/A * @see CertAttrSet
0N/A */
0N/Apublic class CRLDistributionPointsExtension extends Extension
0N/A implements CertAttrSet<String> {
0N/A
0N/A /**
0N/A * Identifier for this attribute, to be used with the
0N/A * get, set, delete methods of Certificate, x509 type.
0N/A */
0N/A public static final String IDENT =
0N/A "x509.info.extensions.CRLDistributionPoints";
0N/A
0N/A /**
0N/A * Attribute name.
0N/A */
0N/A public static final String NAME = "CRLDistributionPoints";
0N/A public static final String POINTS = "points";
0N/A
0N/A /**
0N/A * The List of DistributionPoint objects.
0N/A */
0N/A private List<DistributionPoint> distributionPoints;
0N/A
0N/A private String extensionName;
0N/A
0N/A /**
0N/A * Create a CRLDistributionPointsExtension from a List of
0N/A * DistributionPoint; the criticality is set to false.
0N/A *
0N/A * @param distributionPoints the list of distribution points
0N/A * @throws IOException on error
0N/A */
0N/A public CRLDistributionPointsExtension(
0N/A List<DistributionPoint> distributionPoints) throws IOException {
0N/A
0N/A this(false, distributionPoints);
0N/A }
0N/A
0N/A /**
0N/A * Create a CRLDistributionPointsExtension from a List of
0N/A * DistributionPoint.
0N/A *
0N/A * @param isCritical the criticality setting.
0N/A * @param distributionPoints the list of distribution points
0N/A * @throws IOException on error
0N/A */
0N/A public CRLDistributionPointsExtension(boolean isCritical,
0N/A List<DistributionPoint> distributionPoints) throws IOException {
0N/A
0N/A this(PKIXExtensions.CRLDistributionPoints_Id, isCritical,
0N/A distributionPoints, NAME);
0N/A }
0N/A
0N/A /**
0N/A * Creates the extension (also called by the subclass).
0N/A */
0N/A protected CRLDistributionPointsExtension(ObjectIdentifier extensionId,
0N/A boolean isCritical, List<DistributionPoint> distributionPoints,
0N/A String extensionName) throws IOException {
0N/A
0N/A this.extensionId = extensionId;
0N/A this.critical = isCritical;
0N/A this.distributionPoints = distributionPoints;
0N/A encodeThis();
0N/A this.extensionName = extensionName;
0N/A }
0N/A
0N/A /**
0N/A * Create the extension from the passed DER encoded value of the same.
0N/A *
0N/A * @param critical true if the extension is to be treated as critical.
0N/A * @param value Array of DER encoded bytes of the actual value.
0N/A * @exception IOException on error.
0N/A */
0N/A public CRLDistributionPointsExtension(Boolean critical, Object value)
0N/A throws IOException {
0N/A this(PKIXExtensions.CRLDistributionPoints_Id, critical, value, NAME);
0N/A }
0N/A
0N/A /**
0N/A * Creates the extension (also called by the subclass).
0N/A */
0N/A protected CRLDistributionPointsExtension(ObjectIdentifier extensionId,
0N/A Boolean critical, Object value, String extensionName)
0N/A throws IOException {
0N/A
0N/A this.extensionId = extensionId;
0N/A this.critical = critical.booleanValue();
0N/A
0N/A if (!(value instanceof byte[])) {
0N/A throw new IOException("Illegal argument type");
0N/A }
0N/A
0N/A extensionValue = (byte[])value;
0N/A DerValue val = new DerValue(extensionValue);
0N/A if (val.tag != DerValue.tag_Sequence) {
0N/A throw new IOException("Invalid encoding for " + extensionName +
0N/A " extension.");
0N/A }
0N/A distributionPoints = new ArrayList<DistributionPoint>();
0N/A while (val.data.available() != 0) {
0N/A DerValue seq = val.data.getDerValue();
0N/A DistributionPoint point = new DistributionPoint(seq);
0N/A distributionPoints.add(point);
0N/A }
0N/A this.extensionName = extensionName;
0N/A }
0N/A
0N/A /**
0N/A * Return the name of this attribute.
0N/A */
0N/A public String getName() {
0N/A return extensionName;
0N/A }
0N/A
0N/A /**
0N/A * Write the extension to the DerOutputStream.
0N/A *
0N/A * @param out the DerOutputStream to write the extension to.
0N/A * @exception IOException on encoding errors.
0N/A */
0N/A public void encode(OutputStream out) throws IOException {
0N/A encode(out, PKIXExtensions.CRLDistributionPoints_Id, false);
0N/A }
0N/A
0N/A /**
0N/A * Write the extension to the DerOutputStream.
0N/A * (Also called by the subclass)
0N/A */
0N/A protected void encode(OutputStream out, ObjectIdentifier extensionId,
0N/A boolean isCritical) throws IOException {
0N/A
0N/A DerOutputStream tmp = new DerOutputStream();
0N/A if (this.extensionValue == null) {
0N/A this.extensionId = extensionId;
0N/A this.critical = isCritical;
0N/A encodeThis();
0N/A }
0N/A super.encode(tmp);
0N/A out.write(tmp.toByteArray());
0N/A }
0N/A
0N/A /**
0N/A * Set the attribute value.
0N/A */
0N/A public void set(String name, Object obj) throws IOException {
0N/A if (name.equalsIgnoreCase(POINTS)) {
0N/A if (!(obj instanceof List)) {
0N/A throw new IOException("Attribute value should be of type List.");
0N/A }
0N/A distributionPoints = (List<DistributionPoint>)obj;
0N/A } else {
0N/A throw new IOException("Attribute name [" + name +
0N/A "] not recognized by " +
0N/A "CertAttrSet:" + extensionName + ".");
0N/A }
0N/A encodeThis();
0N/A }
0N/A
0N/A /**
0N/A * Get the attribute value.
0N/A */
0N/A public Object get(String name) throws IOException {
0N/A if (name.equalsIgnoreCase(POINTS)) {
0N/A return distributionPoints;
0N/A } else {
0N/A throw new IOException("Attribute name [" + name +
0N/A "] not recognized by " +
0N/A "CertAttrSet:" + extensionName + ".");
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Delete the attribute value.
0N/A */
0N/A public void delete(String name) throws IOException {
0N/A if (name.equalsIgnoreCase(POINTS)) {
0N/A distributionPoints = new ArrayList<DistributionPoint>();
0N/A } else {
0N/A throw new IOException("Attribute name [" + name +
0N/A "] not recognized by " +
0N/A "CertAttrSet:" + extensionName + ".");
0N/A }
0N/A encodeThis();
0N/A }
0N/A
0N/A /**
0N/A * Return an enumeration of names of attributes existing within this
0N/A * attribute.
0N/A */
0N/A public Enumeration<String> getElements() {
0N/A AttributeNameEnumeration elements = new AttributeNameEnumeration();
0N/A elements.addElement(POINTS);
0N/A return elements.elements();
0N/A }
0N/A
0N/A // Encode this extension value
0N/A private void encodeThis() throws IOException {
0N/A if (distributionPoints.isEmpty()) {
0N/A this.extensionValue = null;
0N/A } else {
0N/A DerOutputStream pnts = new DerOutputStream();
0N/A for (DistributionPoint point : distributionPoints) {
0N/A point.encode(pnts);
0N/A }
0N/A DerOutputStream seq = new DerOutputStream();
0N/A seq.write(DerValue.tag_Sequence, pnts);
0N/A this.extensionValue = seq.toByteArray();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return the extension as user readable string.
0N/A */
0N/A public String toString() {
0N/A return super.toString() + extensionName + " [\n "
0N/A + distributionPoints + "]\n";
0N/A }
0N/A
0N/A}