Path: blob/master/test/jdk/sun/security/pkcs11/KeyAgreement/UnsupportedDHKeys.java
41155 views
/*1* Copyright (c) 2016, 2018, 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 807245226* @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits27* @library /test/lib ..28* @modules jdk.crypto.cryptoki29* @run main/othervm UnsupportedDHKeys30* @run main/othervm -Djava.security.manager=allow UnsupportedDHKeys sm31*/3233import java.security.InvalidParameterException;34import java.security.KeyPairGenerator;35import java.security.Provider;3637public class UnsupportedDHKeys extends PKCS11Test {3839/*40* Sizes and values for various lengths.41*/42private enum UnsupportedKeySize {43// not multiple of 6444dhp513(513), dhp769(769), dhp895(895),45dhp1023(1023), dhp1535(1535), dhp2047(2047),4647// unsupported48dhp2176(2176), dhp3008(3008), dhp4032(4032),49dhp5120(5120), dhp6400(6400), dhp7680(7680),50dhp8191(8191), dhp8128(8128), dhp8260(8260);5152final int primeSize;5354UnsupportedKeySize(int primeSize) {55this.primeSize = primeSize;56}57}5859@Override60public void main(Provider provider) throws Exception {61if (provider.getService("KeyPairGenerator", "DiffieHellman") == null) {62System.out.println("No supported of DH KeyPairGenerator, skipping");63return;64}6566for (UnsupportedKeySize keySize : UnsupportedKeySize.values()) {67try {68System.out.println("Checking " + keySize.primeSize + " ...");69KeyPairGenerator kpg =70KeyPairGenerator.getInstance("DiffieHellman", provider);71kpg.initialize(keySize.primeSize);7273throw new Exception("Should not support " + keySize.primeSize);74} catch (InvalidParameterException ipe) {75System.out.println("\tOk, unsupported");76}77}78}7980public static void main(String[] args) throws Exception {81main(new UnsupportedDHKeys(), args);82}83}848586