8260693: Provide the support for specifying a signer in keytool -genkeypair

Reviewed-by: weijun
This commit is contained in:
Hai-May Chao 2021-04-09 01:59:59 +00:00
parent 77b16739ab
commit 719f95e504
6 changed files with 484 additions and 42 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,7 +34,9 @@ import java.security.interfaces.EdECPublicKey;
import java.security.interfaces.RSAKey;
import java.security.interfaces.DSAKey;
import java.security.interfaces.DSAParams;
import java.security.interfaces.XECKey;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import java.security.spec.ECParameterSpec;
import java.security.spec.InvalidParameterSpecException;
@ -97,6 +99,21 @@ public final class KeyUtil {
} else if (key instanceof DHKey) {
DHKey pubk = (DHKey)key;
size = pubk.getParams().getP().bitLength();
} else if (key instanceof XECKey) {
XECKey pubk = (XECKey)key;
AlgorithmParameterSpec params = pubk.getParams();
if (params instanceof NamedParameterSpec) {
String name = ((NamedParameterSpec) params).getName();
if (name.equalsIgnoreCase(NamedParameterSpec.X25519.getName())) {
size = 255;
} else if (name.equalsIgnoreCase(NamedParameterSpec.X448.getName())) {
size = 448;
} else {
size = -1;
}
} else {
size = -1;
}
} else if (key instanceof EdECKey) {
String nc = ((EdECKey) key).getParams().getName();
if (nc.equalsIgnoreCase(NamedParameterSpec.ED25519.getName())) {

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -111,6 +111,7 @@ public final class SecurityProviderConstants {
public static final int DEF_DH_KEY_SIZE;
public static final int DEF_EC_KEY_SIZE;
public static final int DEF_ED_KEY_SIZE;
public static final int DEF_XEC_KEY_SIZE;
private static final String KEY_LENGTH_PROP =
"jdk.security.defaultKeySize";
@ -124,6 +125,7 @@ public final class SecurityProviderConstants {
int dhKeySize = 2048;
int ecKeySize = 256;
int edKeySize = 255;
int xecKeySize = 255;
if (keyLengthStr != null) {
try {
@ -162,6 +164,8 @@ public final class SecurityProviderConstants {
ecKeySize = value;
} else if (algoName.equalsIgnoreCase("EdDSA")) {
edKeySize = value;
} else if (algoName.equals("XDH")) {
xecKeySize = value;
} else {
if (debug != null) {
debug.println("Ignoring unsupported algo in " +
@ -189,6 +193,7 @@ public final class SecurityProviderConstants {
DEF_DH_KEY_SIZE = dhKeySize;
DEF_EC_KEY_SIZE = ecKeySize;
DEF_ED_KEY_SIZE = edKeySize;
DEF_XEC_KEY_SIZE = xecKeySize;
// Set up aliases with default mappings
// This is needed when the mapping contains non-oid