forked from opensearch-project/data-prepper
-
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.
MAINT: deprecate certificate_content with certificate_key (opensearch…
…-project#4434) * MAINT: deprecate certificate_content with certificate_key Signed-off-by: George Chen <[email protected]>
- Loading branch information
1 parent
df17cc5
commit 250531d
Showing
15 changed files
with
333 additions
and
30 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
...in/java/org/opensearch/dataprepper/plugins/certificate/validation/PemObjectValidator.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,16 @@ | ||
package org.opensearch.dataprepper.plugins.certificate.validation; | ||
|
||
import org.bouncycastle.util.io.pem.PemReader; | ||
|
||
import java.io.IOException; | ||
import java.io.StringReader; | ||
|
||
public class PemObjectValidator { | ||
public static boolean isPemObject(final String certificate) { | ||
try (PemReader reader = new PemReader(new StringReader(certificate))) { | ||
return reader.readPemObject() != null; | ||
} catch (IOException e) { | ||
return false; | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ava/org/opensearch/dataprepper/plugins/certificate/validation/PemObjectValidatorTest.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,42 @@ | ||
package org.opensearch.dataprepper.plugins.certificate.validation; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.UUID; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class PemObjectValidatorTest { | ||
private static final String TEST_CERTIFICATE = "-----BEGIN CERTIFICATE-----\n" + | ||
"MIIDYTCCAkmgAwIBAgIUFBUALAhfpezYbYw6AtH96tizP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2/2pucFJrML/Dtjv7SwrOXptWn+GCB+3bUpfNdg\n" + | ||
"sHeZEv9vpbQDzp1Lux7l3pMzwsi6HU4xTyHClBD7V8S2MUExMXDF+Cr4g7lmOb02\n" + | ||
"Bw0dTI7afBMI8n5YgTX78YMGqbO/WJ3bOc26P2i7RrRIhOXw69UZff2JwYAnX6Op\n" + | ||
"zHOodz4=\n" + | ||
"-----END CERTIFICATE-----"; | ||
|
||
@Test | ||
void testValidPemObject() { | ||
assertThat(PemObjectValidator.isPemObject(TEST_CERTIFICATE), is(true)); | ||
} | ||
|
||
@Test | ||
void testInValidPemObject() { | ||
assertThat(PemObjectValidator.isPemObject(UUID.randomUUID().toString()), is(false)); | ||
} | ||
} |
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
59 changes: 59 additions & 0 deletions
59
...est/java/org/opensearch/dataprepper/plugins/kafka/configuration/EncryptionConfigTest.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,59 @@ | ||
package org.opensearch.dataprepper.plugins.kafka.configuration; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
|
||
class EncryptionConfigTest { | ||
private static final String TEST_CERTIFICATE = "-----BEGIN CERTIFICATE-----\n" + | ||
"MIIDYTCCAkmgAwIBAgIUFBUALAhfpezYbYw6AtH96tizPTIwDQYJKoZIhvcNAQEL\n" + | ||
"BQAwWTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM\n" + | ||
"GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJMTI3LjAuMC4xMB4X\n" + | ||
"DTI0MDQxMTE3MzcyMloXDTM0MDQwOTE3MzcyMlowWTELMAkGA1UEBhMCQVUxEzAR\n" + | ||
"BgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoMGEludGVybmV0IFdpZGdpdHMgUHR5\n" + | ||
"IEx0ZDESMBAGA1UEAwwJMTI3LjAuMC4xMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A\n" + | ||
"MIIBCgKCAQEAuaS6lrpg38XT5wmukekr8NSXcO70yhMRLF29mAXasYeumtHVDR/p\n" + | ||
"f8vTE4l+b36kRuaew4htGRZQcWJBdPoCDkDHA3+5z5t9Fe3nR9FzIA+E/KjyMCEq\n" + | ||
"xNgc9OIN9UyBbbneMkR24W8LkAywxk3euXgj46+7SGFHAdNLqC72Yl3W1E32rQAR\n" + | ||
"c6zQIJ45uogqU19QJHCBBfJA+IFylwtNGWfNbvdvGCXx5FZnM3q4rCxNr9F+LBsS\n" + | ||
"xWFlXGMHXo2+bMBGIBXPGbGXpad/jVgxjM6zV5vnG1g8GDxaHaM+3LjJwa7eQYVA\n" + | ||
"ogetug9wqesxkf+Nic/rpB6J7zM2iwY0AQIDAQABoyEwHzAdBgNVHQ4EFgQUept4\n" + | ||
"OD2pNRYswtfrOqnOgx4QtjYwDQYJKoZIhvcNAQELBQADggEBACU+Qjmf35BOYjDj\n" + | ||
"TX1f6bhgwsHP/WHwWWKIhVSOB0CFHoizzQyLREgWWLkKs3Ye3q9DXku0saMfIerq\n" + | ||
"S7hqDA8hNVJVyllh2FuuNQVkmOKJFTwev2n3OvSyz4mxWW3UNJb/YTuK93nNHVVo\n" + | ||
"/3+lQg0sJRhSMs/GmR/Hn7/py2/2pucFJrML/Dtjv7SwrOXptWn+GCB+3bUpfNdg\n" + | ||
"sHeZEv9vpbQDzp1Lux7l3pMzwsi6HU4xTyHClBD7V8S2MUExMXDF+Cr4g7lmOb02\n" + | ||
"Bw0dTI7afBMI8n5YgTX78YMGqbO/WJ3bOc26P2i7RrRIhOXw69UZff2JwYAnX6Op\n" + | ||
"zHOodz4=\n" + | ||
"-----END CERTIFICATE-----"; | ||
private final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory().enable(YAMLGenerator.Feature.USE_PLATFORM_LINE_BREAKS)); | ||
|
||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
TEST_CERTIFICATE, | ||
"/some/file/path" | ||
}) | ||
void testIsCertificateValid_returns_true(final String certificate) throws JsonProcessingException { | ||
final String encryptionConfigYaml = String.format( | ||
" type: \"ssl\"\n" + | ||
" certificate: \"%s\"\n", certificate.replace("\n", "\\n")); | ||
final EncryptionConfig encryptionConfig = objectMapper.readValue(encryptionConfigYaml, EncryptionConfig.class); | ||
assertThat(encryptionConfig.isCertificateValid(), is(true)); | ||
} | ||
|
||
@Test | ||
void testIsCertificateValid_returns_false() throws JsonProcessingException { | ||
final String encryptionConfigYaml = | ||
" type: \"ssl\"\n" + | ||
" certificate: \"\\u0000\\u0081\"\n"; | ||
final EncryptionConfig encryptionConfig = objectMapper.readValue(encryptionConfigYaml, EncryptionConfig.class); | ||
assertThat(encryptionConfig.isCertificateValid(), is(false)); | ||
} | ||
} |
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
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
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
Oops, something went wrong.