jdk/src/share/classes/java/security/cert/X509CRLSelector.java
author sherman
Tue, 30 Aug 2011 11:53:11 -0700
changeset 10419 12c063b39232
parent 10336 0bb1999251f8
child 18551 882a3948c6e6
permissions -rw-r--r--
7084245: Update usages of InternalError to use exception chaining Summary: to use new InternalError constructor with cause chainning Reviewed-by: alanb, ksrini, xuelei, neugens Contributed-by: sebastian.sickelmann@gmx.de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3314
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3314
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3314
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3314
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3314
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.security.auth.x500.X500Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.util.DerInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import sun.security.x509.CRLNumberExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.security.x509.X500Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * A <code>CRLSelector</code> that selects <code>X509CRLs</code> that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * match all specified criteria. This class is particularly useful when
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * selecting CRLs from a <code>CertStore</code> to check revocation status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * of a particular certificate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * When first constructed, an <code>X509CRLSelector</code> has no criteria
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * enabled and each of the <code>get</code> methods return a default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * value (<code>null</code>). Therefore, the {@link #match match} method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * would return <code>true</code> for any <code>X509CRL</code>. Typically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * several criteria are enabled (by calling {@link #setIssuers setIssuers}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * or {@link #setDateAndTime setDateAndTime}, for instance) and then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * <code>X509CRLSelector</code> is passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * {@link CertStore#getCRLs CertStore.getCRLs} or some similar
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Please refer to <a href="http://www.ietf.org/rfc/rfc3280.txt">RFC 3280:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * Internet X.509 Public Key Infrastructure Certificate and CRL Profile</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * for definitions of the X.509 CRL fields and extensions mentioned below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <b>Concurrent Access</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * Unless otherwise specified, the methods defined in this class are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * thread-safe. Multiple threads that need to access a single
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * object concurrently should synchronize amongst themselves and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * provide the necessary locking. Multiple threads each manipulating
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * separate objects need not synchronize.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @see CRLSelector
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @see X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * @author      Steve Hanna
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class X509CRLSelector implements CRLSelector {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
3314
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
    75
    static {
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
    76
        CertPathHelperImpl.initialize();
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
    77
    }
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
    78
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private HashSet<Object> issuerNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private HashSet<X500Principal> issuerX500Principals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private BigInteger minCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private BigInteger maxCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    private Date dateAndTime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private X509Certificate certChecking;
3314
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
    86
    private long skew = 0;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * Creates an <code>X509CRLSelector</code>. Initially, no criteria are set
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * so any <code>X509CRL</code> will match.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    public X509CRLSelector() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * Sets the issuerNames criterion. The issuer distinguished name in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * distinguished names. If <code>null</code>, any issuer distinguished name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * will do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * This method allows the caller to specify, with a single method call,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * the complete set of issuer names which <code>X509CRLs</code> may contain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * The specified value replaces the previous value for the issuerNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * criterion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * The <code>names</code> parameter (if not <code>null</code>) is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * <code>Collection</code> of <code>X500Principal</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * Note that the <code>names</code> parameter can contain duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * distinguished names, but they may be removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * <code>Collection</code> of names returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * {@link #getIssuers getIssuers} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Note that a copy is performed on the <code>Collection</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * protect against subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param issuers a <code>Collection</code> of X500Principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     *   (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     * @see #getIssuers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    public void setIssuers(Collection<X500Principal> issuers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if ((issuers == null) || issuers.isEmpty()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            issuerNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            issuerX500Principals = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            // clone
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            issuerX500Principals = new HashSet<X500Principal>(issuers);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            issuerNames = new HashSet<Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            for (X500Principal p : issuerX500Principals) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                issuerNames.add(p.getEncoded());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * <strong>Note:</strong> use {@linkplain #setIssuers(Collection)} instead
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * or only specify the byte array form of distinguished names when using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * this method. See {@link #addIssuerName(String)} for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Sets the issuerNames criterion. The issuer distinguished name in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * distinguished names. If <code>null</code>, any issuer distinguished name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * will do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * This method allows the caller to specify, with a single method call,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the complete set of issuer names which <code>X509CRLs</code> may contain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * The specified value replaces the previous value for the issuerNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * criterion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * The <code>names</code> parameter (if not <code>null</code>) is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <code>Collection</code> of names. Each name is a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * or a byte array representing a distinguished name (in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * <a href="http://www.ietf.org/rfc/rfc2253.txt">RFC 2253</a> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * ASN.1 DER encoded form, respectively). If <code>null</code> is supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * as the value for this argument, no issuerNames check will be performed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * Note that the <code>names</code> parameter can contain duplicate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * distinguished names, but they may be removed from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <code>Collection</code> of names returned by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * {@link #getIssuerNames getIssuerNames} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * If a name is specified as a byte array, it should contain a single DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * encoded distinguished name, as defined in X.501. The ASN.1 notation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * this structure is as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * <pre><code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * Name ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *   RDNSequence }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * RDNSequence ::= SEQUENCE OF RelativeDistinguishedName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * RelativeDistinguishedName ::=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *   SET SIZE (1 .. MAX) OF AttributeTypeAndValue
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * AttributeTypeAndValue ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *   type     AttributeType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *   value    AttributeValue }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * AttributeType ::= OBJECT IDENTIFIER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * AttributeValue ::= ANY DEFINED BY AttributeType
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * ....
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * DirectoryString ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *       teletexString           TeletexString (SIZE (1..MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     *       printableString         PrintableString (SIZE (1..MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *       universalString         UniversalString (SIZE (1..MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *       utf8String              UTF8String (SIZE (1.. MAX)),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     *       bmpString               BMPString (SIZE (1..MAX)) }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * </code></pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * Note that a deep copy is performed on the <code>Collection</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * protect against subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param names a <code>Collection</code> of names (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @throws IOException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @see #getIssuerNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    public void setIssuerNames(Collection<?> names) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        if (names == null || names.size() == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            issuerNames = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            issuerX500Principals = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            HashSet<Object> tempNames = cloneAndCheckIssuerNames(names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            // Ensure that we either set both of these or neither
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            issuerX500Principals = parseIssuerNames(tempNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            issuerNames = tempNames;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * Adds a name to the issuerNames criterion. The issuer distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * name in the <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * distinguished names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * This method allows the caller to add a name to the set of issuer names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * which <code>X509CRLs</code> may contain. The specified name is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * any previous value for the issuerNames criterion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * If the specified name is a duplicate, it may be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @param issuer the issuer as X500Principal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    public void addIssuer(X500Principal issuer) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        addIssuerNameInternal(issuer.getEncoded(), issuer);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * <strong>Denigrated</strong>, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * {@linkplain #addIssuer(X500Principal)} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * {@linkplain #addIssuerName(byte[])} instead. This method should not be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * relied on as it can fail to match some CRLs because of a loss of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * encoding information in the RFC 2253 String form of some distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * Adds a name to the issuerNames criterion. The issuer distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * name in the <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * distinguished names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * This method allows the caller to add a name to the set of issuer names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * which <code>X509CRLs</code> may contain. The specified name is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * any previous value for the issuerNames criterion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * If the specified name is a duplicate, it may be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @param name the name in RFC 2253 form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @throws IOException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void addIssuerName(String name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        addIssuerNameInternal(name, new X500Name(name).asX500Principal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Adds a name to the issuerNames criterion. The issuer distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * name in the <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * distinguished names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * This method allows the caller to add a name to the set of issuer names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * which <code>X509CRLs</code> may contain. The specified name is added to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * any previous value for the issuerNames criterion. If the specified name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * is a duplicate, it may be ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * If a name is specified as a byte array, it should contain a single DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * encoded distinguished name, as defined in X.501. The ASN.1 notation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * this structure is as follows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * The name is provided as a byte array. This byte array should contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * a single DER encoded distinguished name, as defined in X.501. The ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * notation for this structure appears in the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * {@link #setIssuerNames setIssuerNames(Collection names)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * Note that the byte array supplied here is cloned to protect against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @param name a byte array containing the name in ASN.1 DER encoded form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * @throws IOException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public void addIssuerName(byte[] name) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        // clone because byte arrays are modifiable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        addIssuerNameInternal(name.clone(), new X500Name(name).asX500Principal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * A private method that adds a name (String or byte array) to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * issuerNames criterion. The issuer distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * name in the <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * distinguished names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * @param name the name in string or byte array form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @param principal the name in X500Principal form
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * @throws IOException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    private void addIssuerNameInternal(Object name, X500Principal principal) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        if (issuerNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            issuerNames = new HashSet<Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        if (issuerX500Principals == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            issuerX500Principals = new HashSet<X500Principal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        issuerNames.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        issuerX500Principals.add(principal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Clone and check an argument of the form passed to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * setIssuerNames. Throw an IOException if the argument is malformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @param names a <code>Collection</code> of names. Each entry is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     *              String or a byte array (the name, in string or ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *              DER encoded form, respectively). <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *              not an acceptable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @return a deep copy of the specified <code>Collection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @throws IOException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    private static HashSet<Object> cloneAndCheckIssuerNames(Collection<?> names)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        HashSet<Object> namesCopy = new HashSet<Object>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        Iterator<?> i = names.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            Object nameObject = i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            if (!(nameObject instanceof byte []) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                !(nameObject instanceof String))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                throw new IOException("name not byte array or String");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            if (nameObject instanceof byte [])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                namesCopy.add(((byte []) nameObject).clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                namesCopy.add(nameObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        return(namesCopy);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Clone an argument of the form passed to setIssuerNames.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * Throw a RuntimeException if the argument is malformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * This method wraps cloneAndCheckIssuerNames, changing any IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * into a RuntimeException. This method should be used when the object being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * cloned has already been checked, so there should never be any exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @param names a <code>Collection</code> of names. Each entry is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *              String or a byte array (the name, in string or ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     *              DER encoded form, respectively). <code>null</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *              not an acceptable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @return a deep copy of the specified <code>Collection</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @throws RuntimeException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    private static HashSet<Object> cloneIssuerNames(Collection<Object> names) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            return cloneAndCheckIssuerNames(names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            throw new RuntimeException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Parse an argument of the form passed to setIssuerNames,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * returning a Collection of issuerX500Principals.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Throw an IOException if the argument is malformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * @param names a <code>Collection</code> of names. Each entry is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     *              String or a byte array (the name, in string or ASN.1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     *              DER encoded form, respectively). <Code>Null</Code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     *              not an acceptable value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * @return a HashSet of issuerX500Principals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @throws IOException if a parsing error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    private static HashSet<X500Principal> parseIssuerNames(Collection<Object> names)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        HashSet<X500Principal> x500Principals = new HashSet<X500Principal>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        for (Iterator<Object> t = names.iterator(); t.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            Object nameObject = t.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            if (nameObject instanceof String) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                x500Principals.add(new X500Name((String)nameObject).asX500Principal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    x500Principals.add(new X500Principal((byte[])nameObject));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    throw (IOException)new IOException("Invalid name").initCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        return x500Principals;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * Sets the minCRLNumber criterion. The <code>X509CRL</code> must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * CRL number extension whose value is greater than or equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * specified value. If <code>null</code>, no minCRLNumber check will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * @param minCRL the minimum CRL number accepted (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public void setMinCRLNumber(BigInteger minCRL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        this.minCRL = minCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * Sets the maxCRLNumber criterion. The <code>X509CRL</code> must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * CRL number extension whose value is less than or equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * specified value. If <code>null</code>, no maxCRLNumber check will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
     * @param maxCRL the maximum CRL number accepted (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    public void setMaxCRLNumber(BigInteger maxCRL) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        this.maxCRL = maxCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Sets the dateAndTime criterion. The specified date must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * equal to or later than the value of the thisUpdate component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * of the <code>X509CRL</code> and earlier than the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * nextUpdate component. There is no match if the <code>X509CRL</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * does not contain a nextUpdate component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * If <code>null</code>, no dateAndTime check will be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * Note that the <code>Date</code> supplied here is cloned to protect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * against subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @param dateAndTime the <code>Date</code> to match against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *                    (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @see #getDateAndTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void setDateAndTime(Date dateAndTime) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        if (dateAndTime == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            this.dateAndTime = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        else
3314
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   425
            this.dateAndTime = new Date(dateAndTime.getTime());
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   426
        this.skew = 0;
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   427
    }
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   428
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   429
    /**
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   430
     * Sets the dateAndTime criterion and allows for the specified clock skew
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   431
     * (in milliseconds) when checking against the validity period of the CRL.
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   432
     */
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   433
    void setDateAndTime(Date dateAndTime, long skew) {
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   434
        this.dateAndTime =
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   435
            (dateAndTime == null ? null : new Date(dateAndTime.getTime()));
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   436
        this.skew = skew;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * Sets the certificate being checked. This is not a criterion. Rather,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * it is optional information that may help a <code>CertStore</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * find CRLs that would be relevant when checking revocation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * specified certificate. If <code>null</code> is specified, then no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * such optional information is provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * @param cert the <code>X509Certificate</code> being checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     *             (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * @see #getCertificateChecking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    public void setCertificateChecking(X509Certificate cert) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        certChecking = cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * Returns the issuerNames criterion. The issuer distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * name in the <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * distinguished names. If the value returned is <code>null</code>, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * issuer distinguished name will do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * If the value returned is not <code>null</code>, it is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * unmodifiable <code>Collection</code> of <code>X500Principal</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * @return an unmodifiable <code>Collection</code> of names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *   (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @see #setIssuers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    public Collection<X500Principal> getIssuers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (issuerX500Principals == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        return Collections.unmodifiableCollection(issuerX500Principals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * Returns a copy of the issuerNames criterion. The issuer distinguished
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * name in the <code>X509CRL</code> must match at least one of the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * distinguished names. If the value returned is <code>null</code>, any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * issuer distinguished name will do.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
     * If the value returned is not <code>null</code>, it is a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * <code>Collection</code> of names. Each name is a <code>String</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * or a byte array representing a distinguished name (in RFC 2253 or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * ASN.1 DER encoded form, respectively).  Note that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <code>Collection</code> returned may contain duplicate names.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * If a name is specified as a byte array, it should contain a single DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * encoded distinguished name, as defined in X.501. The ASN.1 notation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * this structure is given in the documentation for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * {@link #setIssuerNames setIssuerNames(Collection names)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * Note that a deep copy is performed on the <code>Collection</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * protect against subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * @return a <code>Collection</code> of names (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * @see #setIssuerNames
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    public Collection<Object> getIssuerNames() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        if (issuerNames == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        return cloneIssuerNames(issuerNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * Returns the minCRLNumber criterion. The <code>X509CRL</code> must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * CRL number extension whose value is greater than or equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * specified value. If <code>null</code>, no minCRLNumber check will be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * @return the minimum CRL number accepted (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    public BigInteger getMinCRL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return minCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Returns the maxCRLNumber criterion. The <code>X509CRL</code> must have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * CRL number extension whose value is less than or equal to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     * specified value. If <code>null</code>, no maxCRLNumber check will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * @return the maximum CRL number accepted (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    public BigInteger getMaxCRL() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return maxCRL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * Returns the dateAndTime criterion. The specified date must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * equal to or later than the value of the thisUpdate component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * of the <code>X509CRL</code> and earlier than the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * nextUpdate component. There is no match if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * <code>X509CRL</code> does not contain a nextUpdate component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * If <code>null</code>, no dateAndTime check will be done.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * Note that the <code>Date</code> returned is cloned to protect against
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * subsequent modifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * @return the <code>Date</code> to match against (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * @see #setDateAndTime
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    public Date getDateAndTime() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (dateAndTime == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return (Date) dateAndTime.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * Returns the certificate being checked. This is not a criterion. Rather,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     * it is optional information that may help a <code>CertStore</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
     * find CRLs that would be relevant when checking revocation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * specified certificate. If the value returned is <code>null</code>, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * no such optional information is provided.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * @return the certificate being checked (or <code>null</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @see #setCertificateChecking
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    public X509Certificate getCertificateChecking() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        return certChecking;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * Returns a printable representation of the <code>X509CRLSelector</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
     * @return a <code>String</code> describing the contents of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     *         <code>X509CRLSelector</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        sb.append("X509CRLSelector: [\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        if (issuerNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
            sb.append("  IssuerNames:\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            Iterator<Object> i = issuerNames.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            while (i.hasNext())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                sb.append("    " + i.next() + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        if (minCRL != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            sb.append("  minCRLNumber: " + minCRL + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        if (maxCRL != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
            sb.append("  maxCRLNumber: " + maxCRL + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        if (dateAndTime != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            sb.append("  dateAndTime: " + dateAndTime + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        if (certChecking != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            sb.append("  Certificate being checked: " + certChecking + "\n");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
        sb.append("]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * Decides whether a <code>CRL</code> should be selected.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
     * @param crl the <code>CRL</code> to be checked
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
     * @return <code>true</code> if the <code>CRL</code> should be selected,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
     *         <code>false</code> otherwise
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public boolean match(CRL crl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        if (!(crl instanceof X509CRL)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        X509CRL xcrl = (X509CRL)crl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
        /* match on issuer name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
        if (issuerNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            X500Principal issuer = xcrl.getIssuerX500Principal();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
            Iterator<X500Principal> i = issuerX500Principals.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            boolean found = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            while (!found && i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                if (i.next().equals(issuer)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                    found = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                    debug.println("X509CRLSelector.match: issuer DNs "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
                        + "don't match");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
        if ((minCRL != null) || (maxCRL != null)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            /* Get CRL number extension from CRL */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            byte[] crlNumExtVal = xcrl.getExtensionValue("2.5.29.20");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            if (crlNumExtVal == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                    debug.println("X509CRLSelector.match: no CRLNumber");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            BigInteger crlNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                DerInputStream in = new DerInputStream(crlNumExtVal);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                byte[] encoded = in.getOctetString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                CRLNumberExtension crlNumExt =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    new CRLNumberExtension(Boolean.FALSE, encoded);
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   635
                crlNum = crlNumExt.get(CRLNumberExtension.NUMBER);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    debug.println("X509CRLSelector.match: exception in "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                        + "decoding CRL number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            /* match on minCRLNumber */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
            if (minCRL != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                if (crlNum.compareTo(minCRL) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                        debug.println("X509CRLSelector.match: CRLNumber too small");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            /* match on maxCRLNumber */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
            if (maxCRL != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                if (crlNum.compareTo(maxCRL) > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                    if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                        debug.println("X509CRLSelector.match: CRLNumber too large");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
        /* match on dateAndTime */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        if (dateAndTime != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
            Date crlThisUpdate = xcrl.getThisUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
            Date nextUpdate = xcrl.getNextUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
            if (nextUpdate == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
                    debug.println("X509CRLSelector.match: nextUpdate null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
            }
3314
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   676
            Date nowPlusSkew = dateAndTime;
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   677
            Date nowMinusSkew = dateAndTime;
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   678
            if (skew > 0) {
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   679
                nowPlusSkew = new Date(dateAndTime.getTime() + skew);
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   680
                nowMinusSkew = new Date(dateAndTime.getTime() - skew);
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   681
            }
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   682
            if (nowMinusSkew.after(nextUpdate)
1e9d33caef08 6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents: 2
diff changeset
   683
                || nowPlusSkew.before(crlThisUpdate)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
                    debug.println("X509CRLSelector.match: update out of range");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * Returns a copy of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * @return the copy
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
            X509CRLSelector copy = (X509CRLSelector)super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
            if (issuerNames != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
                copy.issuerNames =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
                        new HashSet<Object>(issuerNames);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
                copy.issuerX500Principals =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                        new HashSet<X500Principal>(issuerX500Principals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
            return copy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        } catch (CloneNotSupportedException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
            /* Cannot happen */
10419
12c063b39232 7084245: Update usages of InternalError to use exception chaining
sherman
parents: 10336
diff changeset
   711
            throw new InternalError(e.toString(), e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
}