-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Iwan Igonin <[email protected]>
- Loading branch information
Showing
18 changed files
with
268 additions
and
18 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
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,58 @@ | ||
# Security Properties for JDK 11 and higher, with BouncyCastle FIPS provider and BouncyCastleJSSEProvider in non-approved mode | ||
|
||
security.provider.1=org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider | ||
security.provider.2=org.bouncycastle.jsse.provider.BouncyCastleJsseProvider | ||
security.provider.3=SUN | ||
security.provider.4=SunJGSS | ||
|
||
securerandom.source=file:/dev/urandom | ||
securerandom.strongAlgorithms=NativePRNGBlocking:SUN,DRBG:SUN | ||
securerandom.drbg.config= | ||
|
||
login.configuration.provider=sun.security.provider.ConfigFile | ||
policy.provider=sun.security.provider.PolicyFile | ||
policy.expandProperties=true | ||
policy.allowSystemProperty=true | ||
policy.ignoreIdentityScope=false | ||
keystore.type.compat=true | ||
|
||
package.access=sun.misc.,\ | ||
sun.reflect. | ||
package.definition=sun.misc.,\ | ||
sun.reflect. | ||
|
||
security.overridePropertiesFile=true | ||
|
||
ssl.KeyManagerFactory.algorithm=PKIX | ||
ssl.TrustManagerFactory.algorithm=PKIX | ||
|
||
networkaddress.cache.negative.ttl=10 | ||
krb5.kdc.bad.policy = tryLast | ||
|
||
jdk.certpath.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, DSA keySize < 1024 | ||
jdk.jar.disabledAlgorithms=MD2, MD5, RSA keySize < 1024, DSA keySize < 1024 | ||
jdk.tls.disabledAlgorithms=SSLv3, RC4, MD5withRSA, DH keySize < 1024, DES40_CBC, RC4_40 | ||
jdk.tls.legacyAlgorithms= \ | ||
K_NULL, C_NULL, M_NULL, \ | ||
DH_anon, ECDH_anon, \ | ||
RC4_128, RC4_40, DES_CBC, DES40_CBC, \ | ||
3DES_EDE_CBC | ||
jdk.tls.keyLimits=AES/GCM/NoPadding KeyUpdate 2^37 | ||
|
||
crypto.policy=unlimited | ||
|
||
jdk.xml.dsig.secureValidationPolicy=\ | ||
disallowAlg http://www.w3.org/2001/04/xmldsig-more#rsa-md5,\ | ||
disallowAlg http://www.w3.org/2001/04/xmldsig-more#hmac-md5,\ | ||
disallowAlg http://www.w3.org/2001/04/xmldsig-more#md5,\ | ||
maxTransforms 5,\ | ||
maxReferences 30,\ | ||
disallowReferenceUriSchemes file http https,\ | ||
minKeySize RSA 1024,\ | ||
minKeySize DSA 1024,\ | ||
minKeySize EC 224,\ | ||
noDuplicateIds,\ | ||
noRetrievalMethodLoops | ||
|
||
jceks.key.serialFilter = java.base/java.lang.Enum;java.base/java.security.KeyRep;\ | ||
java.base/java.security.KeyRep$Type;java.base/javax.crypto.spec.SecretKeySpec;!* |
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
77 changes: 77 additions & 0 deletions
77
libs/common/src/test/java/org/opensearch/common/crypto/KeyStoreFactoryTests.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,77 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.common.crypto; | ||
|
||
import com.carrotsearch.randomizedtesting.generators.RandomStrings; | ||
|
||
import org.opensearch.test.OpenSearchTestCase; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
public class KeyStoreFactoryTests extends OpenSearchTestCase { | ||
|
||
public void testPKCS12KeyStore() { | ||
assumeFalse("Can't run in a FIPS JVM as PBE is not available", inFipsJvm()); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.PKCS_12).getType(), equalTo("PKCS12")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.PKCS_12).getProvider().getName(), equalTo("BCFIPS")); | ||
|
||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.PKCS_12, "BCFIPS").getType(), equalTo("PKCS12")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.PKCS_12, "BCFIPS").getProvider().getName(), equalTo("BCFIPS")); | ||
|
||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.PKCS_12, "SUN").getType(), equalTo("PKCS12")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.PKCS_12, "SUN").getProvider().getName(), equalTo("SUN")); | ||
|
||
KeyStoreType.TYPE_TO_EXTENSION_MAP.get(KeyStoreType.PKCS_12).forEach(extension -> { | ||
var keyStore = KeyStoreFactory.getInstanceBasedOnFileExtension(createRandomFileName(extension)); | ||
assertThat(keyStore.getType(), equalTo(KeyStoreType.PKCS_12.getJcaName())); | ||
}); | ||
} | ||
|
||
public void testJKSKeyStore() { | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.JKS).getType(), equalTo("JKS")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.JKS).getProvider().getName(), equalTo("SUN")); | ||
|
||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.JKS, "SUN").getType(), equalTo("JKS")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.JKS, "SUN").getProvider().getName(), equalTo("SUN")); | ||
|
||
assertThrows("BCFKS not found", SecurityException.class, () -> KeyStoreFactory.getInstance(KeyStoreType.JKS, "BCFIPS")); | ||
|
||
KeyStoreType.TYPE_TO_EXTENSION_MAP.get(KeyStoreType.JKS).forEach(extension -> { | ||
var keyStore = KeyStoreFactory.getInstanceBasedOnFileExtension(createRandomFileName(extension)); | ||
assertThat(keyStore.getType(), equalTo(KeyStoreType.JKS.getJcaName())); | ||
}); | ||
} | ||
|
||
public void testBCFIPSKeyStore() { | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.BCFKS).getType(), equalTo("BCFKS")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.BCFKS).getProvider().getName(), equalTo("BCFIPS")); | ||
|
||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.BCFKS, "BCFIPS").getType(), equalTo("BCFKS")); | ||
assertThat(KeyStoreFactory.getInstance(KeyStoreType.BCFKS, "BCFIPS").getProvider().getName(), equalTo("BCFIPS")); | ||
|
||
assertThrows("BCFKS not found", SecurityException.class, () -> KeyStoreFactory.getInstance(KeyStoreType.BCFKS, "SUN")); | ||
|
||
KeyStoreType.TYPE_TO_EXTENSION_MAP.get(KeyStoreType.BCFKS).forEach(extension -> { | ||
var keyStore = KeyStoreFactory.getInstanceBasedOnFileExtension(createRandomFileName(extension)); | ||
assertThat(keyStore.getType(), equalTo(KeyStoreType.BCFKS.getJcaName())); | ||
}); | ||
} | ||
|
||
public void testUnknownKeyStoreType() { | ||
assertThrows( | ||
"Unknown keystore type for file path: keystore.unknown", | ||
IllegalArgumentException.class, | ||
() -> KeyStoreFactory.getInstanceBasedOnFileExtension(createRandomFileName("unknown")) | ||
); | ||
} | ||
|
||
private String createRandomFileName(String extension) { | ||
return RandomStrings.randomAsciiAlphanumOfLengthBetween(random(), 0, 10) + "." + extension; | ||
} | ||
} |
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.