mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 22:34:27 +02:00
8215694: keytool cannot generate RSASSA-PSS certificates
Reviewed-by: xuelei
This commit is contained in:
parent
7a046a24ea
commit
1d014da14b
8 changed files with 355 additions and 114 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2019, 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
|
||||
|
@ -52,6 +52,7 @@ import java.security.cert.URICertStoreParameters;
|
|||
|
||||
|
||||
import java.security.interfaces.ECKey;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.ECParameterSpec;
|
||||
import java.text.Collator;
|
||||
import java.text.MessageFormat;
|
||||
|
@ -1431,14 +1432,16 @@ public final class Main {
|
|||
signature.initSign(privateKey);
|
||||
|
||||
X509CertInfo info = new X509CertInfo();
|
||||
AlgorithmParameterSpec params = AlgorithmId
|
||||
.getDefaultAlgorithmParameterSpec(sigAlgName, privateKey);
|
||||
AlgorithmId algID = AlgorithmId.getWithParameterSpec(sigAlgName, params);
|
||||
info.set(X509CertInfo.VALIDITY, interval);
|
||||
info.set(X509CertInfo.SERIAL_NUMBER, new CertificateSerialNumber(
|
||||
new java.util.Random().nextInt() & 0x7fffffff));
|
||||
info.set(X509CertInfo.VERSION,
|
||||
new CertificateVersion(CertificateVersion.V3));
|
||||
info.set(X509CertInfo.ALGORITHM_ID,
|
||||
new CertificateAlgorithmId(
|
||||
AlgorithmId.get(sigAlgName)));
|
||||
new CertificateAlgorithmId(algID));
|
||||
info.set(X509CertInfo.ISSUER, issuer);
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
|
||||
|
@ -1482,7 +1485,7 @@ public final class Main {
|
|||
signerCert.getPublicKey());
|
||||
info.set(X509CertInfo.EXTENSIONS, ext);
|
||||
X509CertImpl cert = new X509CertImpl(info);
|
||||
cert.sign(privateKey, sigAlgName);
|
||||
cert.sign(privateKey, params, sigAlgName, null);
|
||||
dumpCert(cert, out);
|
||||
for (Certificate ca: keyStore.getCertificateChain(alias)) {
|
||||
if (ca instanceof X509Certificate) {
|
||||
|
@ -1585,6 +1588,12 @@ public final class Main {
|
|||
|
||||
Signature signature = Signature.getInstance(sigAlgName);
|
||||
signature.initSign(privKey);
|
||||
AlgorithmParameterSpec params = AlgorithmId
|
||||
.getDefaultAlgorithmParameterSpec(sigAlgName, privKey);
|
||||
if (params != null) {
|
||||
signature.setParameter(params);
|
||||
}
|
||||
|
||||
X500Name subject = dname == null?
|
||||
new X500Name(((X509Certificate)cert).getSubjectDN().toString()):
|
||||
new X500Name(dname);
|
||||
|
@ -2962,7 +2971,9 @@ public final class Main {
|
|||
// other solution: We first sign the cert, then retrieve the
|
||||
// outer sigalg and use it to set the inner sigalg
|
||||
X509CertImpl newCert = new X509CertImpl(certInfo);
|
||||
newCert.sign(privKey, sigAlgName);
|
||||
AlgorithmParameterSpec params = AlgorithmId
|
||||
.getDefaultAlgorithmParameterSpec(sigAlgName, privKey);
|
||||
newCert.sign(privKey, params, sigAlgName, null);
|
||||
AlgorithmId sigAlgid = (AlgorithmId)newCert.get(X509CertImpl.SIG_ALG);
|
||||
certInfo.set(CertificateAlgorithmId.NAME + "." +
|
||||
CertificateAlgorithmId.ALGORITHM, sigAlgid);
|
||||
|
@ -2979,7 +2990,7 @@ public final class Main {
|
|||
certInfo.set(X509CertInfo.EXTENSIONS, ext);
|
||||
// Sign the new certificate
|
||||
newCert = new X509CertImpl(certInfo);
|
||||
newCert.sign(privKey, sigAlgName);
|
||||
newCert.sign(privKey, params, sigAlgName, null);
|
||||
|
||||
// Store the new certificate as a single-element certificate chain
|
||||
keyStore.setKeyEntry(alias, privKey,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue