Skip to content

Commit b5603dd

Browse files
PR 433 follow ups (#441)
1 parent f60a6e0 commit b5603dd

File tree

6 files changed

+50
-21
lines changed

6 files changed

+50
-21
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ ACCP did not track a FIPS branch/release version of AWS-LC until ACCP v2.3.0. Be
134134
| 2.4.0 | 1.30.1 | 2.0.13 |
135135
| 2.4.1 | 1.30.1 | 2.0.13 |
136136
| 2.5.0 | 1.47.0 | 3.0.0 |
137+
| 2.6.0 | 1.48.2 | 3.0.0 |
137138

138139
Notable differences between ACCP and ACCP-FIPS:
139140
* ACCP uses [the latest release of AWS-LC](https://github.com/aws/aws-lc/releases), whereas, ACCP-FIPS uses [the fips-2022-11-02 branch of AWS-LC](https://github.com/aws/aws-lc/tree/fips-2022-11-02).

aws-lc

build.gradle

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ plugins {
1414

1515
group = 'software.amazon.cryptools'
1616
version = '2.5.0'
17-
ext.awsLcMainTag = 'v1.47.0'
17+
ext.awsLcMainTag = 'v1.48.2'
1818
ext.awsLcFipsTag = 'AWS-LC-FIPS-3.0.0'
1919
ext.isExperimentalFips = Boolean.getBoolean('EXPERIMENTAL_FIPS')
2020
ext.isFips = ext.isExperimentalFips || Boolean.getBoolean('FIPS')
@@ -260,7 +260,7 @@ task buildAwsLc {
260260
args '-DCMAKE_BUILD_TYPE=RelWithDebInfo'
261261
args "-DCMAKE_INSTALL_PREFIX=${sharedObjectOutDir}"
262262
args "-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
263-
263+
def cmakeCFlags = ""
264264

265265
if (isFips) {
266266
println "Building AWS-LC in FIPS mode"
@@ -269,14 +269,18 @@ task buildAwsLc {
269269

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

275275
if (isFipsSelfTestFailureSkipAbort) {
276+
println "Building AWS-LC to enable CPU jitter sampling when seeding its DRBG"
277+
args '-DENABLE_FIPS_ENTROPY_CPU_JITTER=ON'
276278
println "Building AWS-LC to call callback instead of aborting on self-test failure"
277-
args '-DCMAKE_C_FLAGS="-DAWSLC_FIPS_FAILURE_CALLBACK"'
279+
cmakeCFlags += '-DAWSLC_FIPS_FAILURE_CALLBACK '
278280
}
279281

282+
args "-DCMAKE_C_FLAGS='${cmakeCFlags}'"
283+
280284
args '.'
281285
}
282286
}

csrc/fips_status.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
#include <openssl/crypto.h>
34
#include <cstdio>
45
#include <functional>
56
#include <jni.h>
@@ -66,10 +67,22 @@ Java_com_amazon_corretto_crypto_provider_AmazonCorrettoCryptoProvider_getFipsSel
6667
return arrayList;
6768
}
6869

69-
extern "C" JNIEXPORT int JNICALL
70-
Java_com_amazon_corretto_crypto_provider_AmazonCorrettoCryptoProvider_fipsStatusErrorCount(JNIEnv* env, jobject thisObj)
70+
extern "C" JNIEXPORT bool JNICALL
71+
Java_com_amazon_corretto_crypto_provider_AmazonCorrettoCryptoProvider_isFipsStatusOkInternal(
72+
JNIEnv* env, jobject thisObj)
7173
{
72-
return fipsStatusErrors.size();
74+
#if defined(EXPERIMENTAL_FIPS_BUILD)
75+
if (!FIPS_is_entropy_cpu_jitter()) {
76+
AWS_LC_fips_failure_callback("CPU Jitter is not enabled");
77+
return false;
78+
}
79+
#else
80+
// Below macro check can be removed once we consume an AWS-LC-FIPS verison with |FIPS_is_entropy_cpu_jitter|.
81+
// Until then, this function should never be called unless we're in EXPERIMENTAL_FIPS_BUILD, so abort below
82+
// to alert us when EXPERIMENTAL_FIPS_BUILD is dropped from FIPS_SELF_TEST_SKIP_ABORT in testing.
83+
abort();
84+
#endif
85+
return fipsStatusErrors.size() == 0;
7386
}
7487

7588
// TEST methods below

src/com/amazon/corretto/crypto/provider/AmazonCorrettoCryptoProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ public boolean isFips() {
652652
return Loader.FIPS_BUILD;
653653
}
654654

655-
private native int fipsStatusErrorCount();
655+
private native boolean isFipsStatusOkInternal();
656656

657657
/**
658658
* @return true if and only if the underlying libcrypto library's FIPS related checks pass
@@ -676,7 +676,7 @@ public boolean isFipsStatusOk() {
676676
}
677677
}
678678
}
679-
return fipsStatusErrorCount() == 0;
679+
return isFipsStatusOkInternal();
680680
}
681681

682682
private native List<String> getFipsSelfTestFailuresInternal();

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

+22-11
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
@ResourceLock(value = TestUtil.RESOURCE_GLOBAL, mode = ResourceAccessMode.READ_WRITE)
2929
public class FipsStatusTest {
3030

31-
private final AmazonCorrettoCryptoProvider provider = AmazonCorrettoCryptoProvider.INSTANCE;
31+
private static final AmazonCorrettoCryptoProvider provider =
32+
AmazonCorrettoCryptoProvider.INSTANCE;
3233
private static final String PWCT_BREAKAGE_ENV_VAR = "BORINGSSL_FIPS_BREAK_TEST";
3334

3435
@Test
@@ -55,18 +56,30 @@ public void givenAccpBuiltWithFips_whenAWS_LC_fips_failure_callback_expectExcept
5556
}
5657
}
5758

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 {
5976
NativeTestHooks.resetFipsStatus();
6077
final KeyPairGenerator kpg = KeyPairGenerator.getInstance(algo, provider);
6178
assertTrue(provider.isFipsStatusOk());
6279
// Set PWCT_BREAKAGE_ENV_VAR for desired keygen test to break it
6380
TestUtil.setEnv(PWCT_BREAKAGE_ENV_VAR, envVarValue);
6481
// 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());
7083
// Global FIPS status should not be OK, and we shouldn't be able to get more KPG instances
7184
assertTrue(provider.getFipsSelfTestFailures().size() > 0);
7285
assertFalse(provider.isFipsStatusOk());
@@ -86,12 +99,10 @@ private void testPwctBreakage(final String algo, String envVarValue) throws Exce
8699
public void testPwctBreakageSkipAbort() throws Exception {
87100
assumeTrue(provider.isFips());
88101
assumeTrue(provider.isFipsSelfTestFailureSkipAbort());
102+
assumeTrue(awsLcIsBuiltWitFipshBreakTest());
89103
testPwctBreakage("RSA", "RSA_PWCT");
90104
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");
95106
if (provider.isExperimentalFips()) { // can be removed when AWS-LC-FIPS supports ML-DSA
96107
testPwctBreakage("ML-DSA", "MLDSA_PWCT");
97108
}

0 commit comments

Comments
 (0)