28
28
@ ResourceLock (value = TestUtil .RESOURCE_GLOBAL , mode = ResourceAccessMode .READ_WRITE )
29
29
public class FipsStatusTest {
30
30
31
- private final AmazonCorrettoCryptoProvider provider = AmazonCorrettoCryptoProvider .INSTANCE ;
31
+ private static final AmazonCorrettoCryptoProvider provider = AmazonCorrettoCryptoProvider .INSTANCE ;
32
32
private static final String PWCT_BREAKAGE_ENV_VAR = "BORINGSSL_FIPS_BREAK_TEST" ;
33
33
34
34
@ Test
@@ -55,18 +55,30 @@ public void givenAccpBuiltWithFips_whenAWS_LC_fips_failure_callback_expectExcept
55
55
}
56
56
}
57
57
58
- private void testPwctBreakage (final String algo , String envVarValue ) throws Exception {
58
+ // Key generation should ~never fail under normal conditions, so consider a breakage to
59
+ // indicate that AWS-LC was built with the FIPS_BREAK_TEST build flag set.
60
+ private static boolean awsLcIsBuiltWitFipshBreakTest () throws Exception {
61
+ final String algorithm = "RSA" ;
62
+ KeyPairGenerator kpg = KeyPairGenerator .getInstance (algorithm , provider );
63
+ TestUtil .setEnv (PWCT_BREAKAGE_ENV_VAR , String .format ("%s_PWCT" , algorithm ));
64
+ try {
65
+ kpg .generateKeyPair ();
66
+ } catch (RuntimeCryptoException e ) {
67
+ return true ;
68
+ } finally {
69
+ TestUtil .setEnv (PWCT_BREAKAGE_ENV_VAR , null );
70
+ }
71
+ return false ;
72
+ }
73
+
74
+ private static void testPwctBreakage (final String algo , String envVarValue ) throws Exception {
59
75
NativeTestHooks .resetFipsStatus ();
60
76
final KeyPairGenerator kpg = KeyPairGenerator .getInstance (algo , provider );
61
77
assertTrue (provider .isFipsStatusOk ());
62
78
// Set PWCT_BREAKAGE_ENV_VAR for desired keygen test to break it
63
79
TestUtil .setEnv (PWCT_BREAKAGE_ENV_VAR , envVarValue );
64
80
// Key generation should now fail
65
- if ("Ed25519" .equals (algo )) { // TODO: Remove after https://github.com/aws/aws-lc/pull/2256
66
- assertNotNull (kpg .generateKeyPair ());
67
- } else {
68
- assertThrows (RuntimeCryptoException .class , () -> kpg .generateKeyPair ());
69
- }
81
+ assertThrows (RuntimeCryptoException .class , () -> kpg .generateKeyPair ());
70
82
// Global FIPS status should not be OK, and we shouldn't be able to get more KPG instances
71
83
assertTrue (provider .getFipsSelfTestFailures ().size () > 0 );
72
84
assertFalse (provider .isFipsStatusOk ());
@@ -86,12 +98,10 @@ private void testPwctBreakage(final String algo, String envVarValue) throws Exce
86
98
public void testPwctBreakageSkipAbort () throws Exception {
87
99
assumeTrue (provider .isFips ());
88
100
assumeTrue (provider .isFipsSelfTestFailureSkipAbort ());
101
+ assumeTrue (awsLcIsBuiltWitFipshBreakTest ());
89
102
testPwctBreakage ("RSA" , "RSA_PWCT" );
90
103
testPwctBreakage ("EC" , "ECDSA_PWCT" );
91
- // TODO: remove check after https://github.com/corretto/amazon-corretto-crypto-provider/pull/438
92
- if (TestUtil .getJavaVersion () >= 15 ) {
93
- testPwctBreakage ("Ed25519" , "EDDSA_PWCT" );
94
- }
104
+ testPwctBreakage ("Ed25519" , "EDDSA_PWCT" );
95
105
if (provider .isExperimentalFips ()) { // can be removed when AWS-LC-FIPS supports ML-DSA
96
106
testPwctBreakage ("ML-DSA" , "MLDSA_PWCT" );
97
107
}
0 commit comments