001/*
002 * Copyright 2017-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2017-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2017-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.util.ssl.cert;
037
038
039
040import com.unboundid.util.NotMutable;
041import com.unboundid.util.OID;
042import com.unboundid.util.ThreadSafety;
043import com.unboundid.util.ThreadSafetyLevel;
044
045import static com.unboundid.util.ssl.cert.CertMessages.*;
046
047
048
049/**
050 * This class provides an implementation of the subject alternative name X.509
051 * certificate extension as described in
052 * <A HREF="https://www.ietf.org/rfc/rfc5280.txt">RFC 5280</A> section 4.2.1.6.
053 * It can provide additional information about the entity that is being
054 * certified, including alternate DNS hostnames or IP addresses that may be used
055 * to access the server, email addresses or DNs of end users, URIs of services,
056 * etc.  This information may be used in the course of determining whether to
057 * trust a peer certificate.
058 * <BR><BR>
059 * The OID for this extension is 2.5.29.17.  See the
060 * {@link GeneralAlternativeNameExtension} class for implementation details and
061 * the value encoding.
062 */
063@NotMutable()
064@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
065public final class SubjectAlternativeNameExtension
066       extends GeneralAlternativeNameExtension
067{
068  /**
069   * The OID (2.5.29.17) for subject alternative name extensions.
070   */
071  public static final OID SUBJECT_ALTERNATIVE_NAME_OID = new OID("2.5.29.17");
072
073
074
075  /**
076   * The serial version UID for this serializable class.
077   */
078  private static final long serialVersionUID = 4194307412985686108L;
079
080
081
082  /**
083   * Creates a new subject alternative name extension with the provided
084   * information.
085   *
086   * @param  isCritical    Indicates whether this extension should be considered
087   *                       critical.
088   * @param  generalNames  The set of names to include in this extension.  This
089   *                       must not be {@code null}.
090   *
091   * @throws  CertException  If a problem occurs while trying to encode the
092   *                         value.
093   */
094  SubjectAlternativeNameExtension(final boolean isCritical,
095                                  final GeneralNames generalNames)
096       throws CertException
097  {
098    super(SUBJECT_ALTERNATIVE_NAME_OID, isCritical, generalNames);
099  }
100
101
102
103  /**
104   * Creates a new subject alternative name extension from the provided generic
105   * extension.
106   *
107   * @param  extension  The extension to decode as a subject alternative name
108   *                    extension.
109   *
110   * @throws  CertException  If the provided extension cannot be decoded as a
111   *                         subject alternative name extension.
112   */
113  SubjectAlternativeNameExtension(final X509CertificateExtension extension)
114       throws CertException
115  {
116    super(extension);
117  }
118
119
120
121  /**
122   * {@inheritDoc}
123   */
124  @Override()
125  public String getExtensionName()
126  {
127    return INFO_SUBJECT_ALT_NAME_EXTENSION_NAME.get();
128  }
129
130
131
132  /**
133   * {@inheritDoc}
134   */
135  @Override()
136  public void toString(final StringBuilder buffer)
137  {
138    toString("SubjectAlternativeNameExtension", buffer);
139  }
140}