Skip to content

Commit ab6b7ef

Browse files
committed
8296901: Do not create unsigned certificate and CRL
Reviewed-by: mullan
1 parent 7b3984c commit ab6b7ef

File tree

11 files changed

+395
-414
lines changed

11 files changed

+395
-414
lines changed

src/java.base/share/classes/sun/security/tools/keytool/CertAndKeyGen.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,12 +335,11 @@ public X509Certificate getSelfCertificate (X500Name myname, Date firstDate,
335335
}
336336
if (ext != null) info.setExtensions(ext);
337337

338-
cert = new X509CertImpl(info);
339338
if (signerFlag) {
340339
// use signer's private key to sign
341-
cert.sign(signerPrivateKey, sigAlg);
340+
cert = X509CertImpl.newSigned(info, signerPrivateKey, sigAlg);
342341
} else {
343-
cert.sign(privateKey, sigAlg);
342+
cert = X509CertImpl.newSigned(info, privateKey, sigAlg);
344343
}
345344

346345
return cert;

src/java.base/share/classes/sun/security/tools/keytool/Main.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1536,8 +1536,8 @@ private void doGenCert(String alias, String sigAlgName, InputStream in, PrintStr
15361536
subjectPubKey,
15371537
signerSubjectKeyId);
15381538
info.setExtensions(ext);
1539-
X509CertImpl cert = new X509CertImpl(info);
1540-
cert.sign(privateKey, sigAlgName);
1539+
X509CertImpl cert = X509CertImpl
1540+
.newSigned(info, privateKey, sigAlgName);
15411541
dumpCert(cert, out);
15421542
for (Certificate ca: keyStore.getCertificateChain(alias)) {
15431543
if (ca instanceof X509Certificate xca) {
@@ -1589,8 +1589,9 @@ private void doGenCRL(PrintStream out)
15891589
badCerts[i] = new X509CRLEntryImpl(new BigInteger(ids.get(i)), firstDate);
15901590
}
15911591
}
1592-
X509CRLImpl crl = new X509CRLImpl(owner, firstDate, lastDate, badCerts);
1593-
crl.sign(privateKey, sigAlgName);
1592+
X509CRLImpl crl = X509CRLImpl.newSigned(
1593+
new X509CRLImpl.TBSCertList(owner, firstDate, lastDate, badCerts),
1594+
privateKey, sigAlgName);
15941595
if (rfc) {
15951596
out.println("-----BEGIN X509 CRL-----");
15961597
out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(crl.getEncodedInternal()));
@@ -3228,8 +3229,8 @@ private void doSelfCert(String alias, String dname, String sigAlgName)
32283229
null);
32293230
certInfo.setExtensions(ext);
32303231
// Sign the new certificate
3231-
X509CertImpl newCert = new X509CertImpl(certInfo);
3232-
newCert.sign(privKey, sigAlgName);
3232+
X509CertImpl newCert = X509CertImpl.newSigned(
3233+
certInfo, privKey, sigAlgName);
32333234

32343235
// Store the new certificate as a single-element certificate chain
32353236
keyStore.setKeyEntry(alias, privKey,

0 commit comments

Comments
 (0)