< prev index next >

test/sun/security/mscapi/SignUsingNONEwithRSA.java

Print this page
rev 11258 : 8139436: sun.security.mscapi.KeyStore might load incomplete data
Reviewed-by: vinnie, weijun
   1 /*
   2  * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 101         verifyAllUsing("SunMSCAPI", keys.getPublic());
 102         System.out.println("-------------------------------------------------");
 103 
 104         verifyAllUsing("SunJCE", keys.getPublic());
 105         System.out.println("-------------------------------------------------");
 106 
 107         keys = generateKeys();
 108         signAllUsing("SunJCE", keys.getPrivate());
 109         System.out.println("-------------------------------------------------");
 110 
 111         verifyAllUsing("SunMSCAPI", keys.getPublic());
 112         System.out.println("-------------------------------------------------");
 113 
 114     }
 115 
 116     private static KeyPair getKeysFromKeyStore() throws Exception {
 117         KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
 118         ks.load(null, null);
 119         System.out.println("Loaded keystore: Windows-MY");
 120 
 121         Enumeration e = ks.aliases();
 122         PrivateKey privateKey = null;
 123         PublicKey publicKey = null;
 124 
 125         while (e.hasMoreElements()) {
 126             String alias = (String) e.nextElement();
 127             if (alias.equals("6578658")) {
 128                 System.out.println("Loaded entry: " + alias);
 129                 privateKey = (PrivateKey) ks.getKey(alias, null);
 130                 publicKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
 131             }
 132         }
 133         if (privateKey == null || publicKey == null) {
 134             throw new Exception("Cannot load the keys need to run this test");
 135         }
 136 
 137         return new KeyPair(publicKey, privateKey);
 138     }
 139 
 140 
 141     private static KeyPair generateKeys() throws Exception {
 142         KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
 143         keyGen.initialize(1024, null);
 144         KeyPair pair = keyGen.generateKeyPair();
 145         PrivateKey privateKey = pair.getPrivate();
 146         PublicKey publicKey = pair.getPublic();


   1 /*
   2  * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */


 101         verifyAllUsing("SunMSCAPI", keys.getPublic());
 102         System.out.println("-------------------------------------------------");
 103 
 104         verifyAllUsing("SunJCE", keys.getPublic());
 105         System.out.println("-------------------------------------------------");
 106 
 107         keys = generateKeys();
 108         signAllUsing("SunJCE", keys.getPrivate());
 109         System.out.println("-------------------------------------------------");
 110 
 111         verifyAllUsing("SunMSCAPI", keys.getPublic());
 112         System.out.println("-------------------------------------------------");
 113 
 114     }
 115 
 116     private static KeyPair getKeysFromKeyStore() throws Exception {
 117         KeyStore ks = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
 118         ks.load(null, null);
 119         System.out.println("Loaded keystore: Windows-MY");
 120 
 121         Enumeration<String> e = ks.aliases();
 122         PrivateKey privateKey = null;
 123         PublicKey publicKey = null;
 124 
 125         while (e.hasMoreElements()) {
 126             String alias = e.nextElement();
 127             if (alias.equals("6578658")) {
 128                 System.out.println("Loaded entry: " + alias);
 129                 privateKey = (PrivateKey) ks.getKey(alias, null);
 130                 publicKey = (PublicKey) ks.getCertificate(alias).getPublicKey();
 131             }
 132         }
 133         if (privateKey == null || publicKey == null) {
 134             throw new Exception("Cannot load the keys need to run this test");
 135         }
 136 
 137         return new KeyPair(publicKey, privateKey);
 138     }
 139 
 140 
 141     private static KeyPair generateKeys() throws Exception {
 142         KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
 143         keyGen.initialize(1024, null);
 144         KeyPair pair = keyGen.generateKeyPair();
 145         PrivateKey privateKey = pair.getPrivate();
 146         PublicKey publicKey = pair.getPublic();


< prev index next >