|
1 | 1 | package org.cloudfoundry.autoscaler.scheduler; |
2 | 2 |
|
| 3 | +import java.security.Security; |
| 4 | +import org.bouncycastle.crypto.fips.FipsStatus; |
| 5 | +import org.bouncycastle.jcajce.provider.BouncyCastleFipsProvider; |
3 | 6 | import org.cloudfoundry.autoscaler.scheduler.conf.MetricsConfig; |
4 | 7 | import org.slf4j.Logger; |
5 | 8 | import org.slf4j.LoggerFactory; |
|
41 | 44 | }) |
42 | 45 | public class SchedulerApplication { |
43 | 46 |
|
44 | | - private Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 47 | + private static final Logger logger = LoggerFactory.getLogger(SchedulerApplication.class); |
45 | 48 |
|
46 | 49 | @EventListener |
47 | 50 | public void onApplicationReady(ApplicationReadyEvent event) { |
48 | 51 | logger.info("Scheduler is ready to start"); |
49 | 52 | } |
50 | 53 |
|
| 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 | + |
51 | 87 | 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"); |
52 | 92 | SpringApplication.run(SchedulerApplication.class, args); |
53 | 93 | } |
54 | 94 | } |
0 commit comments