Skip to content

Commit f3c1fd5

Browse files
Disable EdDSA PWCT, block until self-tests finish
1 parent 4caf24b commit f3c1fd5

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ task buildAwsLc {
269269

270270
if (allowFipsTestBreak) {
271271
println "Building AWS-LC with hooks to break FIPS tests"
272-
args '-DFIPS_BREAK_TEST='
272+
args '-DFIPS_BREAK_TEST=TESTS'
273273
}
274274

275275
if (isFipsSelfTestFailureSkipAbort) {

csrc/auto_free.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
void releaseOwnership() { PTR_NAME(name) = NULL; } \
8080
void clear() \
8181
{ \
82-
CONCAT2(name, _free)(PTR_NAME(name)); \
82+
CONCAT2(name, _free)(PTR_NAME(name)); \
8383
PTR_NAME(name) = NULL; \
8484
} \
8585
name* operator->() { return *this; } \

csrc/ed_gen.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
using namespace AmazonCorrettoCryptoProvider;
99

10-
void generateEdKey(EVP_PKEY_auto& key)
10+
static void generateEdKey(EVP_PKEY_auto& key)
1111
{
1212
EVP_PKEY_CTX_auto ctx = EVP_PKEY_CTX_auto::from(EVP_PKEY_CTX_new_id(EVP_PKEY_ED25519, nullptr));
1313
CHECK_OPENSSL(ctx.isInitialized());
1414
CHECK_OPENSSL(EVP_PKEY_keygen_init(ctx) == 1);
15-
CHECK_OPENSSL(EVP_PKEY_keygen(ctx, key.getAddressOfPtr()));
15+
CHECK_OPENSSL(EVP_PKEY_keygen(ctx, key.getAddressOfPtr()) == 1);
1616
}
1717

1818
JNIEXPORT jlong JNICALL Java_com_amazon_corretto_crypto_provider_EdGen_generateEvpEdKey(JNIEnv* pEnv, jclass)

csrc/fips_status.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include <cstdio>
44
#include <functional>
55
#include <jni.h>
6+
#include <string.h>
67
#include <vector>
78

89
#include "string_vector.h"

tst/com/amazon/corretto/crypto/provider/test/FipsStatusTest.java

+22-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.amazon.corretto.crypto.provider.AmazonCorrettoCryptoProvider;
1313
import com.amazon.corretto.crypto.provider.FipsStatusException;
1414
import com.amazon.corretto.crypto.provider.RuntimeCryptoException;
15+
import com.amazon.corretto.crypto.provider.SelfTestStatus;
1516
import java.security.KeyPairGenerator;
1617
import javax.crypto.KeyGenerator;
1718
import org.junit.jupiter.api.Test;
@@ -35,6 +36,7 @@ public class FipsStatusTest {
3536
public void givenAccpBuiltWithFips_whenAWS_LC_fips_failure_callback_expectException()
3637
throws Exception {
3738
if (provider.isFips() && provider.isFipsSelfTestFailureSkipAbort()) {
39+
blockUntilSelfTestsRun();
3840
assertTrue(provider.isFipsStatusOk());
3941
assertEquals(0, provider.getFipsSelfTestFailures().size());
4042
assertNotNull(KeyGenerator.getInstance("AES", provider));
@@ -48,6 +50,7 @@ public void givenAccpBuiltWithFips_whenAWS_LC_fips_failure_callback_expectExcept
4850
// we need to flip the status back to OK so the rest of tests would work. In practice, once
4951
// the flag is set to false, it remains false.
5052
NativeTestHooks.resetFipsStatus();
53+
assertTrue(provider.isFipsStatusOk());
5154
} else {
5255
assertThrows(UnsupportedOperationException.class, () -> provider.isFipsStatusOk());
5356
assertThrows(UnsupportedOperationException.class, () -> provider.getFipsSelfTestFailures());
@@ -72,21 +75,37 @@ private void testPwctBreakage(final String algo, String envVarValue) throws Exce
7275
}
7376
// Be sure to reset provider-global state!
7477
TestUtil.setEnv(PWCT_BREAKAGE_ENV_VAR, null);
78+
assertNotNull(kpg.generateKeyPair());
7579
NativeTestHooks.resetFipsStatus();
7680
assertTrue(provider.isFipsStatusOk());
7781
}
7882

7983
@Test
8084
public void testPwctBreakageSkipAbort() throws Exception {
85+
blockUntilSelfTestsRun();
8186
assumeTrue(provider.isFips());
8287
assumeTrue(provider.isFipsSelfTestFailureSkipAbort());
8388
testPwctBreakage("RSA", "RSA_PWCT");
8489
testPwctBreakage("EC", "ECDSA_PWCT");
85-
if (TestUtil.getJavaVersion() >= 15) {
86-
testPwctBreakage("EdDSA", "EDDSA_PWCT");
87-
}
90+
// TODO: Re-enable this test when AWS-LC's EdDSA can fail keygen
91+
// https://github.com/aws/aws-lc/pull/2256
92+
// testPwctBreakage("EdDSA", "EDDSA_PWCT");
8893
if (provider.isExperimentalFips()) { // can be removed when AWS-LC-FIPS supports ML-DSA
8994
testPwctBreakage("ML-DSA", "MLDSA_PWCT");
9095
}
9196
}
97+
98+
// FIPS status won't be OK until the power-on self tests have run and passed, so provide a method
99+
// that blocks until the tests have completed. Set a deadline to make terminal hang impossible.
100+
private void blockUntilSelfTestsRun() throws Exception {
101+
assertTrue(provider.isFips());
102+
long timeout = 5 * 1000;
103+
long deadline = System.currentTimeMillis() + timeout;
104+
while (provider.getSelfTestStatus() == SelfTestStatus.NOT_RUN) {
105+
Thread.sleep(100);
106+
if (System.currentTimeMillis() > deadline) {
107+
throw new RuntimeException("FIPS self tests timed out");
108+
}
109+
}
110+
}
92111
}

0 commit comments

Comments
 (0)