Skip to content

Commit 5acb7b3

Browse files
authored
Fix PemKeyConfigTests (#55577) (#55998)
We were creating PemKeyConfig objects using different private keys but always using testnode.crt certificate that uses the RSA public key. The PemKeyConfig was built but we would then later fail to handle SSL connections during the TLS handshake eitherway. This became obvious in FIPS tests where the consistency checks that FIPS 140 mandates kick in and failed early becausethe private key was of different type than the public key
1 parent 26438cb commit 5acb7b3

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

libs/ssl-config/src/test/java/org/elasticsearch/common/ssl/PemKeyConfigTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public void testBuildKeyConfigFromPkcs8PemFilesWithoutPassword() throws Exceptio
7070
}
7171

7272
public void testBuildKeyConfigFromPkcs8PemFilesWithPassword() throws Exception {
73+
assumeFalse("Can't run in a FIPS JVM, PBE KeySpec is not available", inFipsJvm());
7374
final Path cert = getDataPath("/certs/cert2/cert2.crt");
7475
final Path key = getDataPath("/certs/cert2/cert2-pkcs8.key");
7576
final PemKeyConfig keyConfig = new PemKeyConfig(cert, key, "c2-pass".toCharArray());

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/PEMKeyConfigTests.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class PEMKeyConfigTests extends ESTestCase {
2323
public static final SecureString TESTNODE_PASSWORD = new SecureString("testnode".toCharArray());
2424

2525
public void testEncryptedPkcs8RsaKey() throws Exception {
26+
assumeFalse("Can't run in a FIPS JVM, PBE KeySpec is not available", inFipsJvm());
2627
verifyKeyConfig("testnode.crt", "key_pkcs8_encrypted.pem", TESTNODE_PASSWORD);
2728
}
2829

@@ -31,11 +32,11 @@ public void testUnencryptedPkcs8RsaKey() throws Exception {
3132
}
3233

3334
public void testUnencryptedPkcs8DsaKey() throws Exception {
34-
verifyKeyConfig("testnode.crt", "dsa_key_pkcs8_plain.pem", NO_PASSWORD);
35+
verifyKeyConfig("testnode_dsa.crt", "dsa_key_pkcs8_plain.pem", NO_PASSWORD);
3536
}
3637

3738
public void testUnencryptedPkcs8EcKey() throws Exception {
38-
verifyKeyConfig("testnode.crt", "ec_key_pkcs8_plain.pem", NO_PASSWORD);
39+
verifyKeyConfig("testnode_ec.crt", "ec_key_pkcs8_plain.pem", NO_PASSWORD);
3940
}
4041

4142
public void testEncryptedPkcs1RsaKey() throws Exception {

x-pack/plugin/core/src/test/resources/org/elasticsearch/xpack/security/transport/ssl/certs/simple/README.asciidoc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ openssl pkcs12 -in dsa.p12 -nodes -nocerts | openssl pkcs8 -topk8 -nocrypt -outf
9191
----
9292
[source,shell]
9393
----
94+
openssl pkcs12 -in dsa.p12 -nodes -nokeys -cacerts -out testnode_dsa.crt
95+
----
96+
[source,shell]
97+
----
9498
keytool -importkeystore -srckeystore testnode.jks -destkeystore ec.p12 -deststoretype PKCS12 \
9599
-srcalias testnode_ec -deststorepass testnode -destkeypass testnode
96100
----
@@ -99,8 +103,10 @@ keytool -importkeystore -srckeystore testnode.jks -destkeystore ec.p12 -deststor
99103
openssl pkcs12 -in ec.p12 -nodes -nocerts | openssl pkcs8 -topk8 -nocrypt -outform pem \
100104
-out ec_key_pkcs8_plain.pem
101105
----
102-
103-
106+
[source,shell]
107+
----
108+
openssl pkcs12 -in ec.p12 -nodes -nokeys -cacerts -out testnode_ec.crt
109+
----
104110

105111
Create `PKCS#8` encrypted key from the encrypted `PKCS#1` encoded `testnode.pem`
106112
[source,shell]
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
Bag Attributes
2+
friendlyName: testnode_dsa
3+
localKeyID: 54 69 6D 65 20 31 35 38 37 35 35 38 39 34 34 36 39 38
4+
subject=CN = Elasticsearch Test Node
5+
6+
issuer=CN = Elasticsearch Test Node
7+
8+
-----BEGIN CERTIFICATE-----
9+
M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