UnsupportedDHKeys.java revision 14174:0bb2dfd0852c
11558Srgrimes/*
21558Srgrimes * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
31558Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41558Srgrimes *
51558Srgrimes * This code is free software; you can redistribute it and/or modify it
61558Srgrimes * under the terms of the GNU General Public License version 2 only, as
71558Srgrimes * published by the Free Software Foundation.
81558Srgrimes *
91558Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101558Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111558Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121558Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131558Srgrimes * accompanied this code).
141558Srgrimes *
151558Srgrimes * You should have received a copy of the GNU General Public License version
161558Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171558Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181558Srgrimes *
191558Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201558Srgrimes * or visit www.oracle.com if you need additional information or have any
211558Srgrimes * questions.
221558Srgrimes */
231558Srgrimes
241558Srgrimes/**
251558Srgrimes * @test
261558Srgrimes * @bug 8072452
271558Srgrimes * @summary Support DHE sizes up to 8192-bits and DSA sizes up to 3072-bits
281558Srgrimes */
291558Srgrimes
30114589Sobrienimport java.math.BigInteger;
311558Srgrimes
3223675Speterimport java.security.*;
33114589Sobrienimport javax.crypto.*;
3441477Sjulianimport javax.crypto.interfaces.*;
35114589Sobrienimport javax.crypto.spec.*;
36114589Sobrien
371558Srgrimespublic class UnsupportedDHKeys {
381558Srgrimes
3966861Sadrian    /*
4066861Sadrian     * Sizes and values for various lengths.
4123675Speter     */
421558Srgrimes    private enum UnsupportedKeySize {
431558Srgrimes        // not multiple of 64
441558Srgrimes        dhp513(513),    dhp769(769),    dhp895(895),
4523799Sbde        dhp1023(1023),  dhp1535(1535),  dhp2047(2047),
4623675Speter
4766861Sadrian        // unsupported
4823799Sbde        dhp2176(2176),  dhp3008(3008),  dhp4032(4032),
4966861Sadrian        dhp5120(5120),  dhp6400(6400),  dhp7680(7680),
5066861Sadrian        dhp8191(8191),  dhp8128(8128),  dhp8260(8260);
5175927Smckusick
5266861Sadrian        final int primeSize;
5366861Sadrian
5466861Sadrian        UnsupportedKeySize(int primeSize) {
5523675Speter            this.primeSize = primeSize;
561558Srgrimes        }
571558Srgrimes    }
581558Srgrimes
5966861Sadrian    public static void main(String[] args) throws Exception {
6092839Simp        for (UnsupportedKeySize keySize : UnsupportedKeySize.values()) {
6166861Sadrian            try {
6286514Siedowse                System.out.println("Checking " + keySize.primeSize + " ...");
6386514Siedowse                KeyPairGenerator kpg =
6466861Sadrian                        KeyPairGenerator.getInstance("DH", "SunJCE");
6566861Sadrian                kpg.initialize(keySize.primeSize);
6675927Smckusick
6766861Sadrian                throw new Exception("Should not support " + keySize.primeSize);
6866861Sadrian            } catch (InvalidParameterException ipe) {
6975927Smckusick                System.out.println("\tOk, unsupported");
7075927Smckusick            }
7175927Smckusick        }
7275927Smckusick    }
7375927Smckusick}
7475927Smckusick