Path: blob/master/test/jdk/sun/security/tools/keytool/NewSize7.java
41152 views
/*1* Copyright (c) 2009, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 656112626* @summary keytool should use larger default keysize for keypairs27* @modules java.base/sun.security.tools.keytool28* @compile -XDignore.symbol.file NewSize7.java29* @run main NewSize730*/3132import java.io.File;33import java.io.FileInputStream;34import java.nio.file.Files;35import java.nio.file.Paths;36import java.security.KeyStore;37import java.security.cert.X509Certificate;38import java.security.interfaces.RSAPublicKey;3940public class NewSize7 {41public static void main(String[] args) throws Exception {42String FILE = "newsize7-ks";43new File(FILE).delete();44sun.security.tools.keytool.Main.main(("-debug -genkeypair -keystore " +45FILE +46" -alias a -dname cn=c -storepass changeit" +47" -keypass changeit -keyalg rsa").split(" "));48KeyStore ks = KeyStore.getInstance("JKS");49try (FileInputStream fin = new FileInputStream(FILE)) {50ks.load(fin, "changeit".toCharArray());51}52Files.delete(Paths.get(FILE));53RSAPublicKey r = (RSAPublicKey)ks.getCertificate("a").getPublicKey();54if (r.getModulus().bitLength() != 2048) {55throw new Exception("Bad keysize");56}57X509Certificate x = (X509Certificate)ks.getCertificate("a");58if (!x.getSigAlgName().equals("SHA256withRSA")) {59throw new Exception("Bad sigalg");60}61}62}636465