jdk/test/sun/security/pkcs11/Cipher/JNICheck.java
author darcy
Wed, 29 Apr 2015 10:25:53 -0700
changeset 30046 cf2c86e1819e
parent 27487 106d0156648d
permissions -rw-r--r--
8078334: Mark regression tests using randomness Reviewed-by: xuelei, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27487
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     1
/*
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     4
 *
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     7
 * published by the Free Software Foundation.
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     8
 *
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    13
 * accompanied this code).
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    14
 *
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    18
 *
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    21
 * questions.
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    22
 */
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    23
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    24
/*
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    25
 * @test
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    26
 * @bug 8063700
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    27
 * @run main/othervm -Xcheck:jni JNICheck
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    28
 */
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    29
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    30
import javax.crypto.Cipher;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    31
import javax.crypto.SealedObject;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    32
import javax.crypto.SecretKey;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    33
import javax.crypto.KeyGenerator;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    34
import java.security.NoSuchProviderException;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    35
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    36
public class JNICheck {
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    37
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    38
    /* This test is similar to the JCK test that found 8063700. */
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    39
    static class SealedObjectTest {
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    40
        Cipher c;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    41
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    42
        SealedObjectTest() throws Exception {
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    43
            try {
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    44
                c = Cipher.getInstance("AES", "SunPKCS11-Solaris");
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    45
            } catch (NoSuchProviderException nspe) {
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    46
                System.out.println("No SunPKCS11-Solaris provider.  Test skipped");
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    47
                return;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    48
            }
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    49
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    50
            String s = "Test string";
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    51
            SealedObject so;
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    52
            SecretKey key = KeyGenerator.getInstance("AES").generateKey();
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    53
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    54
            c.init(Cipher.ENCRYPT_MODE, key);
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    55
            so = new SealedObject(s, c);
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    56
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    57
            so.getObject(key, "SunPKCS11-Solaris");
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    58
        }
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    59
    }
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    60
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    61
    public static void main(String args[]) throws Exception {
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    62
        new SealedObjectTest();
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    63
    }
106d0156648d 8063700: -Xcheck:jni changes cause many JCK failures in api/javax_crypto tests in SunPKCS11
ascarpino
parents:
diff changeset
    64
}