jdk/test/sun/security/provider/X509Factory/BigCRL.java
author alanb
Tue, 02 Oct 2012 12:23:16 +0100
changeset 14017 9fa1edaf97a3
parent 10784 f800232d1474
child 14342 8435a30053c1
permissions -rw-r--r--
8000268: sun/security/provider/X509Factory/BigCRL.java failing on Linux 32-bit Reviewed-by: mullan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10784
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     1
/*
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     4
 *
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     8
 *
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    13
 * accompanied this code).
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    14
 *
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    18
 *
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    21
 * questions.
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    22
 */
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    23
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    24
/*
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    25
 * @test
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    26
 * @bug 7099399
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    27
 * @summary cannot deal with CRL file larger than 16MB
14017
9fa1edaf97a3 8000268: sun/security/provider/X509Factory/BigCRL.java failing on Linux 32-bit
alanb
parents: 10784
diff changeset
    28
 * @run main/othervm -Xshare:off -Xmx1024m BigCRL
10784
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    29
 */
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    30
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    31
import java.io.FileInputStream;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    32
import java.math.BigInteger;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    33
import java.security.KeyStore;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    34
import java.security.cert.Certificate;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    35
import java.security.PrivateKey;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    36
import java.security.cert.X509CRLEntry;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    37
import java.util.Arrays;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    38
import java.util.Date;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    39
import sun.security.x509.*;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    40
import java.security.cert.CertificateFactory;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    41
import java.io.ByteArrayInputStream;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    42
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    43
public class BigCRL {
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    44
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    45
    public static void main(String[] args) throws Exception {
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    46
        int n = 500000;
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    47
        String ks = System.getProperty("test.src", ".")
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    48
                + "/../../ssl/etc/keystore";
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    49
        String pass = "passphrase";
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    50
        String alias = "dummy";
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    51
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    52
        KeyStore keyStore = KeyStore.getInstance("JKS");
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    53
        keyStore.load(new FileInputStream(ks), pass.toCharArray());
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    54
        Certificate signerCert = keyStore.getCertificate(alias);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    55
        byte[] encoded = signerCert.getEncoded();
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    56
        X509CertImpl signerCertImpl = new X509CertImpl(encoded);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    57
        X509CertInfo signerCertInfo = (X509CertInfo)signerCertImpl.get(
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    58
                X509CertImpl.NAME + "." + X509CertImpl.INFO);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    59
        X500Name owner = (X500Name)signerCertInfo.get(X509CertInfo.SUBJECT + "."
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    60
                + CertificateSubjectName.DN_NAME);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    61
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    62
        Date date = new Date();
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    63
        PrivateKey privateKey = (PrivateKey)
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    64
                keyStore.getKey(alias, pass.toCharArray());
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    65
        String sigAlgName = signerCertImpl.getSigAlgOID();
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    66
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    67
        X509CRLEntry[] badCerts = new X509CRLEntry[n];
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    68
        CRLExtensions ext = new CRLExtensions();
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    69
        ext.set("Reason", new CRLReasonCodeExtension(1));
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    70
        for (int i = 0; i < n; i++) {
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    71
            badCerts[i] = new X509CRLEntryImpl(
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    72
                    BigInteger.valueOf(i), date, ext);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    73
        }
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    74
        X509CRLImpl crl = new X509CRLImpl(owner, date, date, badCerts);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    75
        crl.sign(privateKey, sigAlgName);
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    76
        byte[] data = crl.getEncodedInternal();
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    77
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    78
        // Make sure the CRL is big enough
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    79
        if ((data[1]&0xff) != 0x84) {
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    80
            throw new Exception("The file should be big enough?");
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    81
        }
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    82
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    83
        CertificateFactory cf = CertificateFactory.getInstance("X.509");
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    84
        cf.generateCRL(new ByteArrayInputStream(data));
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    85
    }
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    86
}
f800232d1474 7099399: cannot deal with CRL file larger than 16MB
weijun
parents:
diff changeset
    87