You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/05/26 07:18:22 UTC
[tomcat] branch 9.0.x updated: Fix regression that broke support for unencrypted PKCS#1 keys
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new d2c5f957cf Fix regression that broke support for unencrypted PKCS#1 keys
d2c5f957cf is described below
commit d2c5f957cfa80a3c84b938756c0fd1050043ea27
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu May 26 08:18:01 2022 +0100
Fix regression that broke support for unencrypted PKCS#1 keys
---
java/org/apache/tomcat/util/net/jsse/PEMFile.java | 8 +++++++-
test/org/apache/tomcat/util/net/jsse/TestPEMFile.java | 6 ++++++
webapps/docs/changelog.xml | 5 +++++
3 files changed, 18 insertions(+), 1 deletion(-)
diff --git a/java/org/apache/tomcat/util/net/jsse/PEMFile.java b/java/org/apache/tomcat/util/net/jsse/PEMFile.java
index 80c585d3b8..03abf596d7 100644
--- a/java/org/apache/tomcat/util/net/jsse/PEMFile.java
+++ b/java/org/apache/tomcat/util/net/jsse/PEMFile.java
@@ -143,7 +143,13 @@ public class PEMFile {
privateKey = part.toPrivateKey(password, keyAlgorithm, Format.PKCS8);
break;
case Part.RSA_PRIVATE_KEY:
- privateKey = part.toPrivateKey(password, keyAlgorithm, Format.PKCS1);
+ if (part.algorithm == null) {
+ // If no encryption algorithm was detected, ignore any
+ // (probably default) key password provided.
+ privateKey = part.toPrivateKey(null, keyAlgorithm, Format.PKCS1);
+ } else {
+ privateKey = part.toPrivateKey(password, keyAlgorithm, Format.PKCS1);
+ }
break;
case Part.CERTIFICATE:
case Part.X509_CERTIFICATE:
diff --git a/test/org/apache/tomcat/util/net/jsse/TestPEMFile.java b/test/org/apache/tomcat/util/net/jsse/TestPEMFile.java
index 7adba1d6ab..2ee54e26e1 100644
--- a/test/org/apache/tomcat/util/net/jsse/TestPEMFile.java
+++ b/test/org/apache/tomcat/util/net/jsse/TestPEMFile.java
@@ -40,6 +40,12 @@ public class TestPEMFile {
}
+ @Test
+ public void testKeyPkcs1WithUnnecessaryPassword() throws Exception {
+ testKey(KEY_PKCS1, "ignore-me");
+ }
+
+
@Test
public void testKeyEncryptedPkcs1DesEde3Cbc() throws Exception {
testKeyEncrypted(KEY_ENCRYPTED_PKCS1_DES_EDE3_CBC);
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 504a56ad06..8d150c2a5e 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -137,6 +137,11 @@
<bug>66084</bug>: Correctly calculate bytes written to a response. Pull
request <pr>516</pr> provided by aooohan HanLi. (markt)
</fix>
+ <add>
+ Correct a regression in the support added for encrypted PKCS#1 formatted
+ private keys in the previous release that broke support for unencrypted
+ PKCS#1 formatted private keys. (jfclere/markt)
+ </add>
</changelog>
</subsection>
<subsection name="Jasper">
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org