Skip to content

Commit a4e24ee

Browse files
committed
feat(fips): Add Bouncy Castle FIPS dependencies and initialize FIPS mode in SchedulerApplication
1 parent dd69e1e commit a4e24ee

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

src/autoscaler/scheduler/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,17 @@
134134
<artifactId>assertj-core</artifactId>
135135
<scope>test</scope>
136136
</dependency>
137+
<!-- Bouncy Castle FIPS for FIPS 140-2 compliance -->
138+
<dependency>
139+
<groupId>org.bouncycastle</groupId>
140+
<artifactId>bc-fips</artifactId>
141+
<version>1.0.2.5</version>
142+
</dependency>
143+
<dependency>
144+
<groupId>org.bouncycastle</groupId>
145+
<artifactId>bctls-fips</artifactId>
146+
<version>1.0.19</version>
147+
</dependency>
137148
</dependencies>
138149
<build>
139150
<plugins>

src/autoscaler/scheduler/src/main/java/org/cloudfoundry/autoscaler/scheduler/SchedulerApplication.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.cloudfoundry.autoscaler.scheduler;
22

3+
import java.security.Security;
4+
import org.bouncycastle.crypto.fips.FipsStatus;
5+
import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider;
36
import org.cloudfoundry.autoscaler.scheduler.conf.MetricsConfig;
47
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
@@ -41,14 +44,51 @@
4144
})
4245
public class SchedulerApplication {
4346

44-
private Logger logger = LoggerFactory.getLogger(this.getClass());
47+
private static final Logger logger = LoggerFactory.getLogger(SchedulerApplication.class);
4548

4649
@EventListener
4750
public void onApplicationReady(ApplicationReadyEvent event) {
4851
logger.info("Scheduler is ready to start");
4952
}
5053

54+
/**
55+
* Initializes and validates FIPS mode for the application.
56+
* Exits with error code 140 if FIPS mode is not enabled or cannot be initialized.
57+
*/
58+
private static void initializeAndValidateFipsMode() {
59+
try {
60+
// Register Bouncy Castle FIPS provider as the primary security provider
61+
Security.insertProviderAt(new BouncyCastleFipsProvider(), 1);
62+
63+
// Check if Bouncy Castle FIPS is ready and in approved mode
64+
if (!FipsStatus.isReady()) {
65+
logger.error("FIPS mode is not ready. Application requires FIPS 140-2 compliance.");
66+
System.err.println("ERROR: FIPS mode is not ready. Application requires FIPS 140-2 compliance.");
67+
System.exit(140);
68+
}
69+
70+
// Verify that BC-FIPS provider is now installed and available
71+
if (Security.getProvider("BCFIPS") == null) {
72+
logger.error("Bouncy Castle FIPS provider (BCFIPS) failed to register.");
73+
System.err.println("ERROR: Bouncy Castle FIPS provider (BCFIPS) failed to register.");
74+
System.exit(140);
75+
}
76+
77+
logger.info("FIPS mode initialization successful - running in FIPS 140-2 compliant mode");
78+
logger.info("Active security providers: {}", java.util.Arrays.toString(Security.getProviders()));
79+
80+
} catch (Exception e) {
81+
logger.error("Failed to initialize FIPS mode: {}", e.getMessage(), e);
82+
System.err.println("ERROR: Failed to initialize FIPS mode: " + e.getMessage());
83+
System.exit(140);
84+
}
85+
}
86+
5187
public static void main(String[] args) {
88+
// Initialize and validate FIPS mode before starting the application
89+
initializeAndValidateFipsMode();
90+
91+
logger.info("Starting Scheduler application with FIPS 140-2 compliance");
5292
SpringApplication.run(SchedulerApplication.class, args);
5393
}
5494
}

0 commit comments

Comments
 (0)