-
Notifications
You must be signed in to change notification settings - Fork 30
test: FIPS sample module #1196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
test: FIPS sample module #1196
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
34d02f9
Change KeyStore type
rpanackal 9d26587
Same as before.
rpanackal 2642905
Use standard notation X.509 instead of X509
rpanackal d35ed4c
Update test to show default keystore type used
rpanackal c8a0f3b
added a test profile
rpanackal 3ddc1ee
Merge branch 'main' into fips-compatibility
rpanackal 5ba452c
Cleanup
rpanackal d27cfca
Merge branch 'fips-keystore-change' into fips-compatibility
rpanackal 18a346a
Add test to confirm BCFIPS is working correctly
rpanackal 1658ad3
Move fips test into new test source root
rpanackal d3426cd
Merge branch 'fips-keystore-change' into fips-compatibility
rpanackal 27541c2
minor fix
rpanackal 72a1d73
Merge branch 'fips-keystore-change' into fips-compatibility
rpanackal cc4a5f0
Remove the profile and introduce a test module
rpanackal 043ee67
Update certs and add readme. Additonal test showcasing override
rpanackal aa63dfe
simplify
rpanackal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,144 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>com.sap.cloud.sdk.cloudplatform</groupId> | ||
| <artifactId>cloudplatform-parent</artifactId> | ||
| <version>5.31.0-SNAPSHOT</version> | ||
| </parent> | ||
| <artifactId>connectivity-fips-sample</artifactId> | ||
| <name>Connectivity - FIPS Sample</name> | ||
| <description>Non-released sample module that runs connectivity tests under the FIPS-approved Bouncy Castle provider.</description> | ||
| <url>https://sap.github.io/cloud-sdk/docs/java/getting-started</url> | ||
| <organization> | ||
| <name>SAP SE</name> | ||
| <url>https://www.sap.com</url> | ||
| </organization> | ||
| <licenses> | ||
| <license> | ||
| <name>The Apache Software License, Version 2.0</name> | ||
| <url>https://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
| </license> | ||
| </licenses> | ||
| <developers> | ||
| <developer> | ||
| <name>SAP</name> | ||
| <email>cloudsdk@sap.com</email> | ||
| <organization>SAP SE</organization> | ||
| <organizationUrl>https://www.sap.com</organizationUrl> | ||
| </developer> | ||
| </developers> | ||
| <properties> | ||
| <bc-fips.version>2.1.2</bc-fips.version> | ||
| <bcpkix-fips.version>2.1.9</bcpkix-fips.version> | ||
| </properties> | ||
| <dependencies> | ||
| <dependency> | ||
| <groupId>com.sap.cloud.sdk.cloudplatform</groupId> | ||
| <artifactId>cloudplatform-connectivity</artifactId> | ||
| <exclusions> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcprov-jdk18on</artifactId> | ||
| </exclusion> | ||
| <exclusion> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcpkix-jdk18on</artifactId> | ||
| </exclusion> | ||
| </exclusions> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bc-fips</artifactId> | ||
| <version>${bc-fips.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.bouncycastle</groupId> | ||
| <artifactId>bcpkix-fips</artifactId> | ||
| <version>${bcpkix-fips.version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.projectlombok</groupId> | ||
| <artifactId>lombok</artifactId> | ||
| <scope>provided</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-surefire-plugin</artifactId> | ||
| <configuration> | ||
| <argLine>${argLine} -Dorg.bouncycastle.fips.approved_only=true | ||
| </argLine> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-dependency-plugin</artifactId> | ||
| <configuration> | ||
| <ignoredUnusedDeclaredDependencies combine.children="append"> | ||
| <ignoredUnusedDeclaredDependency>org.bouncycastle:bc-fips</ignoredUnusedDeclaredDependency> | ||
| <ignoredUnusedDeclaredDependency>org.bouncycastle:bcpkix-fips</ignoredUnusedDeclaredDependency> | ||
| <ignoredUnusedDeclaredDependency>com.sap.cloud.sdk.cloudplatform:cloudplatform-connectivity</ignoredUnusedDeclaredDependency> | ||
| </ignoredUnusedDeclaredDependencies> | ||
| </configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-checkstyle-plugin</artifactId> | ||
| <configuration><skip>true</skip></configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-pmd-plugin</artifactId> | ||
| <configuration><skip>true</skip></configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-javadoc-plugin</artifactId> | ||
| <configuration><skip>true</skip></configuration> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.jacoco</groupId> | ||
| <artifactId>jacoco-maven-plugin</artifactId> | ||
| <configuration><skip>true</skip></configuration> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| <profiles> | ||
| <profile> | ||
| <id>release</id> | ||
| <activation> | ||
| <property><name>release</name></property> | ||
| </activation> | ||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.sonatype.central</groupId> | ||
| <artifactId>central-publishing-maven-plugin</artifactId> | ||
| <executions> | ||
| <execution> | ||
| <id>injected-central-publishing</id> | ||
| <phase /> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </profile> | ||
| </profiles> | ||
| </project> |
78 changes: 78 additions & 0 deletions
78
...s-sample/src/test/java/com/sap/cloud/sdk/cloudplatform/connectivity/FipsProviderTest.java
This file contains hidden or 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,78 @@ | ||
| package com.sap.cloud.sdk.cloudplatform.connectivity; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
|
||
| import java.io.FileReader; | ||
| import java.security.KeyStore; | ||
| import java.security.MessageDigest; | ||
| import java.security.NoSuchAlgorithmException; | ||
| import java.security.Security; | ||
|
|
||
| import org.bouncycastle.crypto.CryptoServicesRegistrar; | ||
| import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider; | ||
| import org.junit.jupiter.api.AfterAll; | ||
| import org.junit.jupiter.api.BeforeAll; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import lombok.SneakyThrows; | ||
|
|
||
| /** | ||
| * Tests the behavior of {@link KeyStoreReader} when operating in FIPS-approved mode with BouncyCastle FIPS provider. | ||
| */ | ||
| class FipsProviderTest | ||
| { | ||
| private static final String RES = "src/test/resources/certificates"; | ||
| private static final String CRT_PATH = RES + "/client-cert.crt"; | ||
| private static final String KEY_PATH = RES + "/client-cert.key"; | ||
| private static final String ALIAS = "client-cert"; | ||
| private static final char[] EMPTY_PASSWORD = new char[0]; | ||
|
|
||
| @AfterAll | ||
| static void removeBouncyCastleFips() | ||
| { | ||
| Security.removeProvider("BCFIPS"); | ||
| } | ||
|
|
||
| @BeforeAll | ||
| static void registerBouncyCastleFips() | ||
| { | ||
| Security.insertProviderAt(new BouncyCastleFipsProvider(), 1); | ||
|
|
||
| assertThat(Security.getProvider("BCFIPS")) | ||
| .describedAs("BC FIPS provider must be registered as a JCA provider") | ||
| .isNotNull(); | ||
|
|
||
| assertThat(CryptoServicesRegistrar.isInApprovedOnlyMode()) | ||
| .describedAs("BC FIPS must be in approved-only mode. ") | ||
| .isTrue(); | ||
| } | ||
|
|
||
| @Test | ||
| @SneakyThrows | ||
| void testDefaultKeystoreTypeIsP12() | ||
| { | ||
| final KeyStore keyStore = | ||
| KeyStoreReader.createKeyStore(ALIAS, EMPTY_PASSWORD, new FileReader(CRT_PATH), new FileReader(KEY_PATH)); | ||
|
|
||
| assertThat(keyStore.getType()).isEqualToIgnoringCase("PKCS12"); | ||
| } | ||
|
|
||
| @Test | ||
| @SneakyThrows | ||
| void testKeystoreTypeOverrideToBCFKS() | ||
| { | ||
| Security.setProperty("keystore.type", "BCFKS"); | ||
|
|
||
| final KeyStore keyStore = KeyStore.getInstance("BCFKS"); | ||
| assertThat(keyStore.getType()).isEqualTo("BCFKS"); | ||
| } | ||
|
|
||
| @Test | ||
| void testMD5IsRejectedInApprovedOnlyMode() | ||
| { | ||
| assertThatThrownBy(() -> MessageDigest.getInstance("MD5", "BCFIPS")) | ||
| .isInstanceOf(NoSuchAlgorithmException.class); | ||
|
|
||
| } | ||
| } | ||
18 changes: 18 additions & 0 deletions
18
cloudplatform/connectivity-fips-sample/src/test/resources/README.md
This file contains hidden or 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,18 @@ | ||
| # Credentials | ||
|
|
||
| The credential files are required for running the FIPS provider tests. | ||
|
|
||
| ## Generate Client Credentials | ||
|
|
||
| Run the following commands from `cloudplatform/connectivity-fips-sample/src/test/resources/`: | ||
|
|
||
| ```bash | ||
| # Create the directory | ||
| mkdir -p certificates | ||
|
|
||
| # Generate the key and certificate using Docker (alpine/openssl) | ||
| docker run --rm -v "$(pwd)/certificates:/certs" alpine/openssl \ | ||
| req -x509 -newkey rsa:2048 -nodes \ | ||
| -keyout /certs/client-cert.key \ | ||
| -out /certs/client-cert.crt \ | ||
| -days 3650 -subj "/CN=localhost" |
19 changes: 19 additions & 0 deletions
19
cloudplatform/connectivity-fips-sample/src/test/resources/certificates/client-cert.crt
This file contains hidden or 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,19 @@ | ||
| -----BEGIN CERTIFICATE----- | ||
| MIIDCTCCAfGgAwIBAgIUBERZ7w9qG2je5O6o+Nn+ssaZYOQwDQYJKoZIhvcNAQEL | ||
| BQAwFDESMBAGA1UEAwwJbG9jYWxob3N0MB4XDTI2MDYwODEzMjQzNVoXDTM2MDYw | ||
| NTEzMjQzNVowFDESMBAGA1UEAwwJbG9jYWxob3N0MIIBIjANBgkqhkiG9w0BAQEF | ||
| AAOCAQ8AMIIBCgKCAQEAsXImnalCNo7Jk4EyD1aqWJgrzVXYALVKm8kq5E+azFpv | ||
| 3XB8QQBUXfJJNdkY1uNni6cd+twTzAhdBK+ygTsBkDbMz/r0oniLlLmGTG7L5aCW | ||
| asYVa+HTesi0EunlGDzFbRSuwy/IdfvK2uaU0VeGoyt7Zr0OWg72mPwGPQRvPcEI | ||
| ZljEkgajhiHeEGM9hlCTZnpx9Aye3C/4yek4734QK+ZYqvW/1mYJ08EwDudQUy8n | ||
| rrXhAg7/ppS9v2480fAGI7WonRt4y+sAlaET8YkxNXCRPygwTDaGfQ/yjvXfK37B | ||
| yiEl8qDMFU/WVjEBlet8wLT2/A7qxzjow0UWtsPWWQIDAQABo1MwUTAdBgNVHQ4E | ||
| FgQUEfT0MvVXq56A21bschMDKdUqg7UwHwYDVR0jBBgwFoAUEfT0MvVXq56A21bs | ||
| chMDKdUqg7UwDwYDVR0TAQH/BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAQI0R | ||
| I+x9f2zfQThxkRsF5NoQCqgtaGckcsqk1ADcDLqQWck/j9CE3xMLPYcDKgwURG5s | ||
| /yHUJhv+9/S2uQ/0Xl32GF8fl45av3yUz1aPW6T1JsHWD6/thUtoxvuZr5W1rn/1 | ||
| UdYvVnNutLGp1PQWbjxmdH2sZwmDZ/2ovKNCEwnmzOi3Jft7xnu94SyTZqVYnJt0 | ||
| rQw5NwrjxspPsJQx/2Rd7EEeg4b/LQEQrEIhchNPzGyLK14mF4nk/ImZ5unkNePt | ||
| kgy6ysoQWHBf+N+184c9B3+qFZAItWOGvBx9z0jS9eQELWT7MBsJ4s2Lufku73kn | ||
| V2gbQ/izbQlQpKduuw== | ||
| -----END CERTIFICATE----- |
28 changes: 28 additions & 0 deletions
28
cloudplatform/connectivity-fips-sample/src/test/resources/certificates/client-cert.key
This file contains hidden or 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----- | ||
| MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCxciadqUI2jsmT | ||
| gTIPVqpYmCvNVdgAtUqbySrkT5rMWm/dcHxBAFRd8kk12RjW42eLpx363BPMCF0E | ||
| r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LCLdN6Q3LWLk/XF62NRgxGSOgFmjNHY9Hd/gR4XFc | ||
| dmtBpUZGVmZPbPudHi077d11Gr36boHiGfFx83pGFZ4II2TvbIBn1q777BrK/CT0 | ||
| Bs+x+TV73aYMY8RnvHygv8TwQ1qV1sxLJJatfsBMFZgzvBQ68FcUJWasnwKBgQCk | ||
| An2lfu+dnvoxdw7CTKQzrfyKY8dRymBnqjPjuoPVOU/T/yXcxQ4J8pTiroLTPgcG | ||
| IiGgXDZaw49VmgILVnXli6UtpwFxAwQVzA/XoqUGZAjsaF6EazWWMDRK56BJIpBE | ||
| PuoKB+VWaa9A/MG4wB10i/AXGg7FffQUpMFi2Pw2YwKBgHRt+tnkw3gvUSWQ4E/z | ||
| /g525QMFP3xTadIT7qzif+LSMqtip3vVbC+sBAJQ+GChNq8MFnr72H/siOwmODS2 | ||
| hWaN/7EQCuxo6bzs9QYIgMa5qkBaQIO5RQWsbj8jcUGKXuGTxbWNkR2+tHzLYxeG | ||
| p/Hb2ZSw9PU5Q7fHpaU9wjEo | ||
| -----END PRIVATE KEY----- | ||
|
rpanackal marked this conversation as resolved.
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added an additional test showcasing, how to override the return of
KeyStore.getDefaultType(), enabling users to override the keystore type on fips environment where there is stricter requirements.