⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 x509certselector.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* X509CertSelector.java -- selects X.509 certificates by criteria.   Copyright (C) 2004, 2005 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package java.security.cert;import gnu.classpath.SystemProperties;import gnu.java.security.OID;import java.io.IOException;import java.math.BigInteger;import java.security.KeyFactory;import java.security.PublicKey;import java.security.spec.X509EncodedKeySpec;import java.util.ArrayList;import java.util.Arrays;import java.util.Collection;import java.util.Collections;import java.util.Date;import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Set;import javax.security.auth.x500.X500Principal;/** * A concrete implementation of {@link CertSelector} for X.509 certificates, * which allows a number of criteria to be set when accepting certificates, * from validity dates, to issuer and subject distinguished names, to some * of the various X.509 extensions. * * <p>Use of this class requires extensive knowledge of the Internet * Engineering Task Force's Public Key Infrastructure (X.509). The primary * document describing this standard is <a * href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280: Internet X.509 * Public Key Infrastructure Certificate and Certificate Revocation List * (CRL) Profile</a>. * * <p>Note that this class is not thread-safe. If multiple threads will * use or modify this class then they need to synchronize on the object. * * @author Casey Marshall (csm@gnu.org) */public class X509CertSelector implements CertSelector, Cloneable{  // Constants and fields.  // -------------------------------------------------------------------------  private static final String AUTH_KEY_ID = "2.5.29.35";  private static final String SUBJECT_KEY_ID = "2.5.29.14";  private static final String NAME_CONSTRAINTS_ID = "2.5.29.30";  private int basicConstraints;  private X509Certificate cert;  private BigInteger serialNo;  private X500Principal issuer;  private X500Principal subject;  private byte[] subjectKeyId;  private byte[] authKeyId;  private boolean[] keyUsage;  private Date certValid;  private OID sigId;  private PublicKey subjectKey;  private X509EncodedKeySpec subjectKeySpec;  private Set keyPurposeSet;  private List altNames;  private boolean matchAllNames;  private byte[] nameConstraints;  private Set policy;  // Constructors.  // ------------------------------------------------------------------------  /**   * Creates a new X.509 certificate selector. The new selector will be   * empty, and will accept any certificate (provided that it is an   * {@link X509Certificate}).   */  public X509CertSelector()  {    basicConstraints = -1;  }  // Instance methods.  // ------------------------------------------------------------------------  /**   * Returns the certificate criterion, or <code>null</code> if this value   * was not set.   *   * @return The certificate.   */  public X509Certificate getCertificate()  {    return cert;  }  /**   * Sets the certificate criterion. If set, only certificates that are   * equal to the certificate passed here will be accepted.   *   * @param cert The certificate.   */  public void setCertificate(X509Certificate cert)  {    this.cert = cert;  }  /**   * Returns the serial number criterion, or <code>null</code> if this   * value was not set.   *   * @return The serial number.   */  public BigInteger getSerialNumber()  {    return serialNo;  }  /**   * Sets the serial number of the desired certificate. Only certificates that   * contain this serial number are accepted.   *   * @param serialNo The serial number.   */  public void setSerialNumber(BigInteger serialNo)  {    this.serialNo = serialNo;  }  /**   * Returns the issuer criterion as a string, or <code>null</code> if this   * value was not set.   *   * @return The issuer.   */  public String getIssuerAsString()  {    if (issuer != null)      return issuer.getName();    else      return null;  }  /**   * Returns the issuer criterion as a sequence of DER bytes, or   * <code>null</code> if this value was not set.   *   * @return The issuer.   */  public byte[] getIssuerAsBytes() throws IOException  {    if (issuer != null)      return issuer.getEncoded();    else      return null;  }  /**   * Sets the issuer, specified as a string representation of the issuer's   * distinguished name. Only certificates issued by this issuer will   * be accepted.   *   * @param name The string representation of the issuer's distinguished name.   * @throws IOException If the given name is incorrectly formatted.   */  public void setIssuer(String name) throws IOException  {    if (name != null)      {        try          {            issuer = new X500Principal(name);          }        catch (IllegalArgumentException iae)          {            throw new IOException(iae.getMessage());          }      }    else      issuer = null;  }  /**   * Sets the issuer, specified as the DER encoding of the issuer's   * distinguished name. Only certificates issued by this issuer will   * be accepted.   *   * @param name The DER encoding of the issuer's distinguished name.   * @throws IOException If the given name is incorrectly formatted.   */  public void setIssuer(byte[] name) throws IOException  {    if (name != null)      {        try          {            issuer = new X500Principal(name);          }        catch (IllegalArgumentException iae)          {            throw new IOException(iae.getMessage());          }      }    else      issuer = null;  }  /**   * Returns the subject criterion as a string, of <code>null</code> if   * this value was not set.   *   * @return The subject.   */  public String getSubjectAsString()  {    if (subject != null)      return subject.getName();    else      return null;  }  /**   * Returns the subject criterion as a sequence of DER bytes, or   * <code>null</code> if this value is not set.   *   * @return The subject.   */  public byte[] getSubjectAsBytes() throws IOException  {    if (subject != null)      return subject.getEncoded();    else      return null;  }  /**   * Sets the subject, specified as a string representation of the   * subject's distinguished name. Only certificates with the given   * subject will be accepted.   *   * @param name The string representation of the subject's distinguished name.   * @throws IOException If the given name is incorrectly formatted.   */  public void setSubject(String name) throws IOException  {    if (name != null)      {        try          {            subject = new X500Principal(name);          }        catch (IllegalArgumentException iae)          {            throw new IOException(iae.getMessage());          }      }    else      subject = null;  }  /**   * Sets the subject, specified as the DER encoding of the subject's   * distinguished name. Only certificates with the given subject will   * be accepted.   *   * @param name The DER encoding of the subject's distinguished name.   * @throws IOException If the given name is incorrectly formatted.   */  public void setSubject(byte[] name) throws IOException  {    if (name != null)      {        try          {            subject = new X500Principal(name);          }        catch (IllegalArgumentException iae)          {            throw new IOException(iae.getMessage());          }      }    else      subject = null;  }  /**   * Returns the subject key identifier criterion, or <code>null</code> if   * this value was not set. Note that the byte array is cloned to prevent   * modification.   *   * @return The subject key identifier.   */  public byte[] getSubjectKeyIdentifier()  {    if (subjectKeyId != null)      return (byte[]) subjectKeyId.clone();    else      return null;  }  /**   * Sets the subject key identifier criterion, or <code>null</code> to clear   * this criterion. Note that the byte array is cloned to prevent modification.   *   * @param subjectKeyId The subject key identifier.   */  public void setSubjectKeyIdentifier(byte[] subjectKeyId)  {    this.subjectKeyId = subjectKeyId != null ? (byte[]) subjectKeyId.clone() :      null;  }  /**   * Returns the authority key identifier criterion, or <code>null</code> if   * this value was not set. Note that the byte array is cloned to prevent   * modification.   *   * @return The authority key identifier.   */  public byte[] getAuthorityKeyIdentifier()  {    if (authKeyId != null)      return (byte[]) authKeyId.clone();    else      return null;  }  /**   * Sets the authority key identifier criterion, or <code>null</code> to clear   * this criterion. Note that the byte array is cloned to prevent modification.   *

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -