jdk/test/sun/security/mscapi/SmallPrimeExponentP.java
author erikj
Fri, 01 Apr 2016 17:08:43 +0200
changeset 36725 f458544b0d76
parent 36627 fc9279e35b31
child 37360 ca6e631dfa5a
permissions -rw-r--r--
8153261: Clean up fix for JDK-8153217 Reviewed-by: tbell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31264
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     1
/*
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     4
 *
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     8
 *
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    13
 * accompanied this code).
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    14
 *
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    18
 *
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    21
 * questions.
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    22
 */
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    23
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    24
import sun.security.tools.keytool.CertAndKeyGen;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    25
import sun.security.x509.X500Name;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    26
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    27
import java.security.KeyStore;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    28
import java.security.SecureRandom;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    29
import java.security.cert.X509Certificate;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    30
import java.security.interfaces.RSAPrivateCrtKey;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    31
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    32
/*
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    33
 * @test
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    34
 * @bug 8023546
36627
fc9279e35b31 8151835: Mark SmallPrimeExponentP.java as intermittently failing
darcy
parents: 33868
diff changeset
    35
 * @key intermittent
31264
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    36
 * @modules java.base/sun.security.x509
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    37
 *          java.base/sun.security.tools.keytool
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    38
 * @summary sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
33868
9c1bde39fe18 8139436: sun.security.mscapi.KeyStore might load incomplete data
clanger
parents: 31264
diff changeset
    39
 * @requires os.family == "windows"
31264
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    40
 */
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    41
public class SmallPrimeExponentP {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    42
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    43
    public static void main(String argv[]) throws Exception {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    44
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    45
        String osName = System.getProperty("os.name");
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    46
        if (!osName.startsWith("Windows")) {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    47
            System.out.println("Not windows");
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    48
            return;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    49
        }
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    50
        KeyStore ks = KeyStore.getInstance("Windows-MY");
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    51
        ks.load(null, null);
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    52
        CertAndKeyGen ckg = new CertAndKeyGen("RSA", "SHA1withRSA");
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    53
        ckg.setRandom(new SecureRandom());
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    54
        boolean see63 = false, see65 = false;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    55
        while (!see63 || !see65) {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    56
            ckg.generate(1024);
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    57
            RSAPrivateCrtKey k = (RSAPrivateCrtKey) ckg.getPrivateKey();
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    58
            int len = k.getPrimeExponentP().toByteArray().length;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    59
            if (len == 63 || len == 65) {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    60
                if (len == 63) {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    61
                    if (see63) continue;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    62
                    else see63 = true;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    63
                }
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    64
                if (len == 65) {
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    65
                    if (see65) continue;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    66
                    else see65 = true;
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    67
                }
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    68
                System.err.print(len);
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    69
                ks.setKeyEntry("anything", k, null, new X509Certificate[]{
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    70
                        ckg.getSelfCertificate(new X500Name("CN=Me"), 1000)
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    71
                });
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    72
            }
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    73
            System.err.print('.');
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    74
        }
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    75
        ks.store(null, null);
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    76
    }
896105040033 8023546: sun/security/mscapi/ShortRSAKey1024.sh fails intermittently
weijun
parents:
diff changeset
    77
}