Path: blob/master/test/jdk/sun/security/ec/ed/EdCRLSign.java
41152 views
/*1* Copyright (c) 2020, 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*/2223import java.security.KeyPair;24import java.security.KeyPairGenerator;25import java.security.SecureRandom;26import java.security.spec.NamedParameterSpec;27import java.util.Date;28import sun.security.x509.X500Name;29import sun.security.x509.X509CRLImpl;3031/*32* @test33* @bug 820963234* @summary CRL Sign35* @modules java.base/sun.security.x50936* @run main EdCRLSign37*/38public class EdCRLSign {3940private static final String ED25519 = "Ed25519";41private static final String ED448 = "Ed448";42private static final String OIDN25519 = "1.3.101.112";43private static final String OID25519 = "OID.1.3.101.112";44private static final String OIDN448 = "1.3.101.113";45private static final String OID448 = "OID.1.3.101.113";46private static final String PROVIDER = "SunEC";47private static final SecureRandom S_RND = new SecureRandom(new byte[]{0x1});4849public static void main(String[] args) throws Exception {5051for (boolean initWithRandom : new boolean[]{true, false}) {52// Default Parameter53test(PROVIDER, ED25519, null, initWithRandom);54test(PROVIDER, ED448, null, initWithRandom);5556// With named parameter57test(PROVIDER, ED25519, ED25519, initWithRandom);58test(PROVIDER, OIDN25519, ED25519, initWithRandom);59test(PROVIDER, OID25519, ED25519, initWithRandom);60test(PROVIDER, ED448, ED448, initWithRandom);61test(PROVIDER, OIDN448, ED448, initWithRandom);62test(PROVIDER, OID448, ED448, initWithRandom);6364// With size parameter65test(PROVIDER, ED25519, 255, initWithRandom);66test(PROVIDER, OIDN25519, 255, initWithRandom);67test(PROVIDER, OID25519, 255, initWithRandom);68test(PROVIDER, ED448, 448, initWithRandom);69test(PROVIDER, OIDN448, 448, initWithRandom);70test(PROVIDER, OID448, 448, initWithRandom);71}72}7374// Test CRL signature using a KeyPair.75private static void test(String provider, String name, Object param,76boolean initWithRandom) throws Exception {7778System.out.printf("Case Algo:%s, Param:%s, Intitiate with random:%s%n",79name, param, initWithRandom);80KeyPair kp = genKeyPair(provider, name, param, initWithRandom);81X509CRLImpl crl = new X509CRLImpl(82new X500Name("CN=Issuer"), new Date(), new Date());83crl.sign(kp.getPrivate(), name);84crl.verify(kp.getPublic());85System.out.println("Passed.");86}8788private static KeyPair genKeyPair(String provider, String name,89Object param, boolean initWithRandom) throws Exception {9091KeyPairGenerator kpg = KeyPairGenerator.getInstance(name, provider);92if (initWithRandom) {93if (param instanceof Integer) {94kpg.initialize((Integer) param, S_RND);95} else if (param instanceof String) {96kpg.initialize(new NamedParameterSpec((String) param), S_RND);97}98} else {99if (param instanceof Integer) {100kpg.initialize((Integer) param);101} else if (param instanceof String) {102kpg.initialize(new NamedParameterSpec((String) param));103}104}105return kpg.generateKeyPair();106}107108}109110111