changeset 39508:b0c063e32440

8144559: sun/security/mscapi/SignUsingNONEwithRSA.sh failed intermittently Reviewed-by: vinnie
author rhalade
date Fri, 08 Jul 2016 10:15:38 -0700
parents e65f112c7ee9
children 0bd60e219fd0
files jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh
diffstat 2 files changed, 43 insertions(+), 101 deletions(-) [+]
line wrap: on
line diff
--- a/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java	Fri Jul 08 19:38:17 2016 +0300
+++ b/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.java	Fri Jul 08 10:15:38 2016 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -21,12 +21,21 @@
  * questions.
  */
 
-/**
- * @see SignUsingNONEwithRSA.sh
+ /*
+ * @test
+ * @bug 6578658
+ * @modules java.base/sun.security.x509
+ *          java.base/sun.security.tools.keytool
+ * @requires os.family == "windows"
+ * @summary Sign using the NONEwithRSA signature algorithm from SunMSCAPI
  */
 
 import java.security.*;
+import java.security.cert.X509Certificate;
+import java.security.interfaces.RSAPrivateCrtKey;
 import java.util.*;
+import sun.security.tools.keytool.CertAndKeyGen;
+import sun.security.x509.X500Name;
 
 public class SignUsingNONEwithRSA {
 
@@ -92,24 +101,42 @@
                 System.out.println("    " + provider.getName());
             }
         }
-        System.out.println("-------------------------------------------------");
+        System.out.println(
+                "Creating a temporary RSA keypair in the Windows-My store");
+        KeyStore ks = KeyStore.getInstance("Windows-MY");
+        ks.load(null, null);
+        CertAndKeyGen ckg = new CertAndKeyGen("RSA", "SHA1withRSA");
+        ckg.generate(1024);
+        RSAPrivateCrtKey k = (RSAPrivateCrtKey) ckg.getPrivateKey();
+        ks.setKeyEntry("6578658", k, null, new X509Certificate[]{
+                    ckg.getSelfCertificate(new X500Name("cn=6578658,c=US"), 1000)
+                });
+        ks.store(null, null);
 
-        KeyPair keys = getKeysFromKeyStore();
-        signAllUsing("SunMSCAPI", keys.getPrivate());
-        System.out.println("-------------------------------------------------");
+        System.out.println("---------------------------------------------");
 
-        verifyAllUsing("SunMSCAPI", keys.getPublic());
-        System.out.println("-------------------------------------------------");
+        try {
+            KeyPair keys = getKeysFromKeyStore();
+            signAllUsing("SunMSCAPI", keys.getPrivate());
+            System.out.println("---------------------------------------------");
 
-        verifyAllUsing("SunJCE", keys.getPublic());
-        System.out.println("-------------------------------------------------");
+            verifyAllUsing("SunMSCAPI", keys.getPublic());
+            System.out.println("---------------------------------------------");
 
-        keys = generateKeys();
-        signAllUsing("SunJCE", keys.getPrivate());
-        System.out.println("-------------------------------------------------");
+            verifyAllUsing("SunJCE", keys.getPublic());
+            System.out.println("---------------------------------------------");
 
-        verifyAllUsing("SunMSCAPI", keys.getPublic());
-        System.out.println("-------------------------------------------------");
+            keys = generateKeys();
+            signAllUsing("SunJCE", keys.getPrivate());
+            System.out.println("---------------------------------------------");
+
+            verifyAllUsing("SunMSCAPI", keys.getPublic());
+            System.out.println("---------------------------------------------");
+        } finally {
+            System.out.println(
+                    "Deleting temporary RSA keypair from Windows-My store");
+            ks.deleteEntry("6578658");
+        }
 
     }
 
--- a/jdk/test/sun/security/mscapi/SignUsingNONEwithRSA.sh	Fri Jul 08 19:38:17 2016 +0300
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,85 +0,0 @@
-#!/bin/sh
-
-#
-# Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
-# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-#
-# This code is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 only, as
-# published by the Free Software Foundation.
-#
-# This code is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# version 2 for more details (a copy is included in the LICENSE file that
-# accompanied this code).
-#
-# You should have received a copy of the GNU General Public License version
-# 2 along with this work; if not, write to the Free Software Foundation,
-# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-# or visit www.oracle.com if you need additional information or have any
-# questions.
-#
-
-
-# @test
-# @bug 6578658
-# @requires os.family == "windows"
-# @run shell SignUsingNONEwithRSA.sh
-# @summary Sign using the NONEwithRSA signature algorithm from SunMSCAPI
-# @key intermittent
-
-# set a few environment variables so that the shell-script can run stand-alone
-# in the source directory
-if [ "${TESTSRC}" = "" ] ; then
-   TESTSRC="."
-fi
-
-if [ "${TESTCLASSES}" = "" ] ; then
-   TESTCLASSES="."
-fi
-
-if [ "${TESTJAVA}" = "" ] ; then
-   echo "TESTJAVA not set.  Test cannot execute."
-   echo "FAILED!!!"
-   exit 1
-fi
-
-OS=`uname -s`
-case "$OS" in
-    Windows* | CYGWIN* )
-
-        echo "Creating a temporary RSA keypair in the Windows-My store..."
-        ${TESTJAVA}/bin/keytool ${TESTTOOLVMOPTS} \
-	    -genkeypair \
-	    -storetype Windows-My \
-	    -keyalg RSA \
-	    -alias 6578658 \
-	    -dname "cn=6578658,c=US" \
-	    -noprompt
-
-        echo
-	echo "Running the test..."
-        ${TESTJAVA}/bin/javac ${TESTTOOLVMOPTS} ${TESTJAVACOPTS} -d . ${TESTSRC}\\SignUsingNONEwithRSA.java
-        ${TESTJAVA}/bin/java ${TESTVMOPTS} SignUsingNONEwithRSA
-
-        rc=$?
-
-        echo
-        echo "Removing the temporary RSA keypair from the Windows-My store..."
-        ${TESTJAVA}/bin/keytool ${TESTTOOLVMOPTS} \
-	    -delete \
-	    -storetype Windows-My \
-	    -alias 6578658
-
-	echo done.
-        exit $rc
-        ;;
-
-    * )
-        echo "This test is not intended for '$OS' - passing test"
-        exit 0
-        ;;
-esac