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 =
32
+ AmazonCorrettoCryptoProvider .INSTANCE ;
32
33
private static final String PWCT_BREAKAGE_ENV_VAR = "BORINGSSL_FIPS_BREAK_TEST" ;
33
34
34
35
@ Test
@@ -55,18 +56,30 @@ public void givenAccpBuiltWithFips_whenAWS_LC_fips_failure_callback_expectExcept
55
56
}
56
57
}
57
58
58
- private void testPwctBreakage (final String algo , String envVarValue ) throws Exception {
59
+ // Key generation should ~never fail under normal conditions, so consider a breakage to
60
+ // indicate that AWS-LC was built with the FIPS_BREAK_TEST build flag set.
61
+ private static boolean awsLcIsBuiltWitFipshBreakTest () throws Exception {
62
+ final String algorithm = "RSA" ;
63
+ KeyPairGenerator kpg = KeyPairGenerator .getInstance (algorithm , provider );
64
+ TestUtil .setEnv (PWCT_BREAKAGE_ENV_VAR , String .format ("%s_PWCT" , algorithm ));
65
+ try {
66
+ kpg .generateKeyPair ();
67
+ } catch (RuntimeCryptoException e ) {
68
+ return true ;
69
+ } finally {
70
+ TestUtil .setEnv (PWCT_BREAKAGE_ENV_VAR , null );
71
+ }
72
+ return false ;
73
+ }
74
+
75
+ private static void testPwctBreakage (final String algo , String envVarValue ) throws Exception {
59
76
NativeTestHooks .resetFipsStatus ();
60
77
final KeyPairGenerator kpg = KeyPairGenerator .getInstance (algo , provider );
61
78
assertTrue (provider .isFipsStatusOk ());
62
79
// Set PWCT_BREAKAGE_ENV_VAR for desired keygen test to break it
63
80
TestUtil .setEnv (PWCT_BREAKAGE_ENV_VAR , envVarValue );
64
81
// 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
- }
82
+ assertThrows (RuntimeCryptoException .class , () -> kpg .generateKeyPair ());
70
83
// Global FIPS status should not be OK, and we shouldn't be able to get more KPG instances
71
84
assertTrue (provider .getFipsSelfTestFailures ().size () > 0 );
72
85
assertFalse (provider .isFipsStatusOk ());
@@ -86,12 +99,10 @@ private void testPwctBreakage(final String algo, String envVarValue) throws Exce
86
99
public void testPwctBreakageSkipAbort () throws Exception {
87
100
assumeTrue (provider .isFips ());
88
101
assumeTrue (provider .isFipsSelfTestFailureSkipAbort ());
102
+ assumeTrue (awsLcIsBuiltWitFipshBreakTest ());
89
103
testPwctBreakage ("RSA" , "RSA_PWCT" );
90
104
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
- }
105
+ testPwctBreakage ("Ed25519" , "EDDSA_PWCT" );
95
106
if (provider .isExperimentalFips ()) { // can be removed when AWS-LC-FIPS supports ML-DSA
96
107
testPwctBreakage ("ML-DSA" , "MLDSA_PWCT" );
97
108
}
0 commit comments