forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix use of password protected PKCS#8 keys for SSL (elastic#55567)
PEMUtils would incorrectly fill the encryption password with zeros (the '\0' character) after decrypting a PKCS#8 key. Since PEMUtils did not take ownership of this password it should not zero it out because it does not know whether the caller will use that password array again. This is actually what PEMKeyConfig does - it uses the key encryption password as the password for the ephemeral keystore that it creates in order to build a KeyManager. Backport of: elastic#55457
- Loading branch information
Showing
7 changed files
with
143 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
libs/ssl-config/src/test/resources/certs/cert1/cert1-pkcs8.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCWz6ITDTlkTLue | ||
B30Jx0+7sWHdlM5ObZjWhMQ1eyJD0gYU/gkH2C88IN/PtSv04tzFS6PA4KPDLIya | ||
AhczPlGElSansiui//CpieCI4tt5c2BgVo3XdJaylYoW3CRILUrlSBOMUmJCQEok | ||
verxMrz8DeppNxRfj99pQkoxUkmFMZj/C7XNVYrTttdF1li5FUtWJxw234OUfum3 | ||
PQIzz6YTmoPtLrJ2fB8I4CH8R5hwGcryhBSAqq8pgy61aTPCgEBZ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Yi4yl6QkWum6viExkSP6M2P2qWccyUw/h5 | ||
+f42nJYd80sQvclQeN7UOL9L4+32A9kuptFMTNVcjCjxF8hqSG2Lqb1zXnROEFrM | ||
D8LY5agw1g7xoOIFuGJbDdfr9rw9op9ll9WhPCkCgYBIJPHnm5OGX2s35cMoVc3n | ||
TQriv5D04E4SR8O4NQRGkGiFR+jLx07l6JOYaKrHk/SGjEQLvS+fDl8nPhmlInst | ||
ykJ+rZN7OSck/cxkrBN0Ez+k4NI8xTlgJbhP2hwRC6Lk8o5MuVWjVAqsbzDp/9gx | ||
9m4Zr3M/8uZMtkRp2j2e6Q== | ||
-----END PRIVATE KEY----- |
29 changes: 29 additions & 0 deletions
29
libs/ssl-config/src/test/resources/certs/cert2/cert2-pkcs8.key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
-----BEGIN ENCRYPTED PRIVATE KEY----- | ||
MIIE6TAbBgkqhkiG9w0BBQMwDgQI3LMAczRe1pICAggABIIEyIfF+k/Z7mEPN+gu | ||
rrV4slxmFjnIzyjoOsWbFBN9j5W8kZGewzWvjnYAzVMVeMUXXW27EMOC818aF8Ry | ||
20BUVkmGNAUFVEslayeF0/S2sYR9xBPqYGLF0DI2VDTBIn8zrTdvQ0DYuuLf4g3W | ||
nY69paCGSVjP24xrnEck+X6PjwIQ89MsJlVLn2chPEetvgu2jB+OdRneSA+lqBSW | ||
2sDuKeXAmYdm3nCVz9do6T22OC9PUkzICGUvMyhYO4CD9dI3FFHa4ncKsr4+htfp | ||
p3eppDczSneDKTPmGJg41UrEVdfENvqYLbYrX2ZZRnWUeuLsGbZUsWyfMT5TT2yz | ||
sZXSS9+WRF8IDDhzKjsoSpsuNwMj8KMmc4oIrBNPysI+Bv0sQzPBlMJkHJ+Swb+W | ||
I2wWC7NS7cwGFEEzwXKYAYI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/S0TLcpHldoDJGdno7CytNGasrkFTaDLEhF68QI85zbMmyotKiZ | ||
FKooG78oyxWCYqqPJ9vVBGwsMNfDMJP56T9UNhL72FwNqzSCaEcAUlDm2zCiQWKd | ||
NpOfYzRx8uLp7UyzXbl959GjHWfTA74Yidug13eSHRgKwLXLuro05awG8yNXeDeL | ||
wDswgDyKmlV7JDJjQw== | ||
-----END ENCRYPTED PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ssl/PEMKeyConfigTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.ssl; | ||
|
||
import org.elasticsearch.common.settings.SecureString; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.env.Environment; | ||
import org.elasticsearch.env.TestEnvironment; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.hamcrest.Matchers; | ||
|
||
import javax.net.ssl.X509ExtendedKeyManager; | ||
|
||
import static org.hamcrest.Matchers.notNullValue; | ||
|
||
public class PEMKeyConfigTests extends ESTestCase { | ||
|
||
public static final SecureString NO_PASSWORD = new SecureString("".toCharArray()); | ||
public static final SecureString TESTNODE_PASSWORD = new SecureString("testnode".toCharArray()); | ||
|
||
public void testEncryptedPkcs8RsaKey() throws Exception { | ||
verifyKeyConfig("testnode.crt", "key_pkcs8_encrypted.pem", TESTNODE_PASSWORD); | ||
} | ||
|
||
public void testUnencryptedPkcs8RsaKey() throws Exception { | ||
verifyKeyConfig("testnode.crt", "rsa_key_pkcs8_plain.pem", NO_PASSWORD); | ||
} | ||
|
||
public void testUnencryptedPkcs8DsaKey() throws Exception { | ||
verifyKeyConfig("testnode.crt", "dsa_key_pkcs8_plain.pem", NO_PASSWORD); | ||
} | ||
|
||
public void testUnencryptedPkcs8EcKey() throws Exception { | ||
verifyKeyConfig("testnode.crt", "ec_key_pkcs8_plain.pem", NO_PASSWORD); | ||
} | ||
|
||
public void testEncryptedPkcs1RsaKey() throws Exception { | ||
verifyKeyConfig("testnode.crt", "testnode-aes" + randomFrom(128, 192, 256) + ".pem", TESTNODE_PASSWORD); | ||
} | ||
|
||
public void testUnencryptedPkcs1RsaKey() throws Exception { | ||
verifyKeyConfig("testnode.crt", "testnode-unprotected.pem", NO_PASSWORD); | ||
} | ||
|
||
private void verifyKeyConfig(String certName, String keyName, SecureString keyPassword) throws Exception { | ||
final Environment env = TestEnvironment.newEnvironment(buildEnvSettings(Settings.EMPTY)); | ||
PEMKeyConfig config = new PEMKeyConfig(getPath(keyName), keyPassword, getPath(certName)); | ||
assertThat(config.certificates(env), Matchers.iterableWithSize(1)); | ||
X509ExtendedKeyManager keyManager = config.createKeyManager(env); | ||
assertThat(keyManager, notNullValue()); | ||
assertThat(keyManager.getPrivateKey("key"), notNullValue()); | ||
} | ||
|
||
private String getPath(String fileName) { | ||
return getDataPath("/org/elasticsearch/xpack/security/transport/ssl/certs/simple/" + fileName) | ||
.toAbsolutePath().toString(); | ||
} | ||
|
||
} |