Skip to content

Commit

Permalink
Merge branch 'develop' into evp_factory
Browse files Browse the repository at this point in the history
* develop:
  Add property to skip bundled lib and improve docs. (corretto#168)
  Update openssl to 1.1.1m
  Add TLS1.3 to local integ tests. (corretto#169)
  Improve consistency checks in rsa key generation unit test (corretto#163)
  Improve zeroization of DRBG output (corretto#162)
  Add more debug logic (corretto#167)
  • Loading branch information
SalusaSecondus committed Jan 11, 2022
2 parents 90c24bc + 80b3fa9 commit de38de3
Show file tree
Hide file tree
Showing 19 changed files with 312 additions and 102 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@

### Patches
* Correctly reject non-empty `PSource.PSpecified` values for RSA-OAEP.
## 1.7.0 (Unreleased)
### Improvements
* Now uses [OpenSSL 1.1.1m](https://www.openssl.org/source/openssl-1.1.1m.tar.gz). [PR #173](https://github.com/corretto/amazon-corretto-crypto-provider/pull/173)
* Add "help" value to two of our properties which outputs (to STDERR) valid values.
* `com.amazon.corretto.crypto.provider.extrachecks`
* `com.amazon.corretto.crypto.provider.debug`
* Add new `com.amazon.corretto.crypto.provider.debug` property to gate possibly expensive debug logic.
Current values are:
* `FreeTrace` - Enables tracking of allocation and freeing of native objects from java for more detailed exceptions.
* `VerboseLogging` - Enables more detailed logging.
* `ALL` - Enables all of the above
(May still require changes to your logging configuration to see the new logs.)
* Enables skipping the bundled lib by setting the system property `com.amazon.corretto.crypto.provider.useExternalLib` [PR #168](https://github.com/corretto/amazon-corretto-crypto-provider/pull/168)

### Patches
* Improve zeroization of DRBG output. [PR #162](https://github.com/corretto/amazon-corretto-crypto-provider/pull/162)

## 1.6.1
### Patches
* Fix an issue where a race condition can cause ACCP's MessageDigest hashing algorithms to return the same value for different inputs [PR #157](https://github.com/corretto/amazon-corretto-crypto-provider/pull/157)
Expand Down
30 changes: 28 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ set(ACCP_SRC
src/com/amazon/corretto/crypto/provider/AesCtrDrbg.java
src/com/amazon/corretto/crypto/provider/AesGcmSpi.java
src/com/amazon/corretto/crypto/provider/ConstantTime.java
src/com/amazon/corretto/crypto/provider/DebugFlag.java
src/com/amazon/corretto/crypto/provider/EcGen.java
src/com/amazon/corretto/crypto/provider/EvpKeyAgreement.java
src/com/amazon/corretto/crypto/provider/EvpKey.java
Expand Down Expand Up @@ -620,8 +621,12 @@ if (TEST_JAVA_MAJOR_VERSION VERSION_GREATER_EQUAL 17)
)
endif()

set(TEST_RUNNER_ARGUMENTS
set(COVERAGE_ARGUMENTS
-javaagent:${JACOCO_AGENT_JAR}=destfile=coverage/jacoco.exec,classdumpdir=coverage/classes
)

set(TEST_RUNNER_ARGUMENTS
${COVERAGE_ARGUMENTS}
${TEST_ADD_OPENS}
-Djava.library.path=$<TARGET_FILE_DIR:amazonCorrettoCryptoProvider>
-Dcom.amazon.corretto.crypto.provider.inTestSuite=hunter2
Expand Down Expand Up @@ -674,6 +679,7 @@ add_custom_target(check-junit-SecurityManager
add_custom_target(check-junit-extra-checks
COMMAND ${TEST_JAVA_EXECUTABLE}
-Dcom.amazon.corretto.crypto.provider.extrachecks=ALL
-Dcom.amazon.corretto.crypto.provider.debug=ALL
${TEST_RUNNER_ARGUMENTS}
--select-package=com.amazon.corretto.crypto.provider.test
--exclude-package=com.amazon.corretto.crypto.provider.test.integration
Expand All @@ -683,6 +689,7 @@ add_custom_target(check-junit-extra-checks

add_custom_target(check-recursive-init
COMMAND ${TEST_JAVA_EXECUTABLE}
${COVERAGE_ARGUMENTS}
-cp $<TARGET_PROPERTY:accp-jar,JAR_FILE>:$<TARGET_PROPERTY:tests-jar,JAR_FILE>:${TEST_CLASSPATH}
-Djava.library.path=$<TARGET_FILE_DIR:amazonCorrettoCryptoProvider>
-Dcom.amazon.corretto.crypto.provider.inTestSuite=hunter2
Expand All @@ -694,8 +701,25 @@ add_custom_target(check-recursive-init

add_custom_target(check-install-via-properties
COMMAND ${TEST_JAVA_EXECUTABLE}
${COVERAGE_ARGUMENTS}
-cp $<TARGET_PROPERTY:accp-jar,JAR_FILE>:$<TARGET_PROPERTY:tests-jar,JAR_FILE>:${TEST_CLASSPATH}
-Djava.library.path=$<TARGET_FILE_DIR:amazonCorrettoCryptoProvider>
-Dcom.amazon.corretto.crypto.provider.inTestSuite=hunter2
-Dtest.data.dir=${TEST_DATA_DIR}
-Djava.security.properties=${ORIG_SRCROOT}/etc/amazon-corretto-crypto-provider.security
${TEST_JAVA_ARGS}
com.amazon.corretto.crypto.provider.test.SecurityPropertyTester

DEPENDS accp-jar tests-jar)

add_custom_target(check-external-lib
# Unfortunately we do not have a way to know where the library is loaded from.
# So this test just proves that requesting the external lib does not break things
COMMAND ${TEST_JAVA_EXECUTABLE}
${COVERAGE_ARGUMENTS}
-cp $<TARGET_PROPERTY:accp-jar,JAR_FILE>:$<TARGET_PROPERTY:tests-jar,JAR_FILE>:${TEST_CLASSPATH}
-Djava.library.path=$<TARGET_FILE_DIR:amazonCorrettoCryptoProvider>
-Dcom.amazon.corretto.crypto.provider.useExternalLib=true
-Dcom.amazon.corretto.crypto.provider.inTestSuite=hunter2
-Dtest.data.dir=${TEST_DATA_DIR}
-Djava.security.properties=${ORIG_SRCROOT}/etc/amazon-corretto-crypto-provider.security
Expand All @@ -706,6 +730,7 @@ add_custom_target(check-install-via-properties

add_custom_target(check-install-via-properties-recursive
COMMAND ${TEST_JAVA_EXECUTABLE}
${COVERAGE_ARGUMENTS}
-cp $<TARGET_PROPERTY:accp-jar,JAR_FILE>:$<TARGET_PROPERTY:tests-jar,JAR_FILE>:${TEST_CLASSPATH}
-Djava.library.path=$<TARGET_FILE_DIR:amazonCorrettoCryptoProvider>
-Dcom.amazon.corretto.crypto.provider.inTestSuite=hunter2
Expand All @@ -718,6 +743,7 @@ add_custom_target(check-install-via-properties-recursive

add_custom_target(check-install-via-properties-with-debug
COMMAND ${TEST_JAVA_EXECUTABLE}
${COVERAGE_ARGUMENTS}
-cp $<TARGET_PROPERTY:accp-jar,JAR_FILE>:$<TARGET_PROPERTY:tests-jar,JAR_FILE>:${TEST_CLASSPATH}
-Djava.library.path=$<TARGET_FILE_DIR:amazonCorrettoCryptoProvider>
-Dcom.amazon.corretto.crypto.provider.inTestSuite=hunter2
Expand All @@ -730,7 +756,7 @@ add_custom_target(check-install-via-properties-with-debug
DEPENDS accp-jar tests-jar)

add_custom_target(check
DEPENDS check-recursive-init check-install-via-properties check-install-via-properties-with-debug check-junit check-junit-SecurityManager)
DEPENDS check-recursive-init check-install-via-properties check-install-via-properties-with-debug check-junit check-junit-SecurityManager check-external-lib)

if(ENABLE_NATIVE_TEST_HOOKS)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
Expand Down
31 changes: 29 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
The Amazon Corretto Crypto Provider (ACCP) is a collection of high-performance cryptographic implementations exposed via the standard [JCA/JCE](https://docs.oracle.com/en/java/javase/11/security/java-cryptography-architecture-jca-reference-guide.html) interfaces.
This means that it can be used as a drop in replacement for many different Java applications.
(Differences from the default OpenJDK implementations are [documented here](./DIFFERENCES.md).)
Currently algorithms are primarily backed by OpenSSL's implementations (1.1.1j as of ACCP 1.6.0) but this may change in the future.
Currently algorithms are primarily backed by OpenSSL's implementations (1.1.1m as of ACCP 1.7.0) but this may change in the future.

[Security issue notifications](./CONTRIBUTING.md#security-issue-notifications)

Expand Down Expand Up @@ -125,7 +125,7 @@ For more information, please see [VERSIONING.rst](https://github.com/corretto/am
### Gradle
Add the following to your `build.gradle` file. If you already have a
`dependencies` block in your `build.gradle`, you can add the ACCP line to your
existing block.
existing block.
This will instruct it to use the most recent 1.x version of ACCP.
For more information, please see [VERSIONING.rst](https://github.com/corretto/amazon-corretto-crypto-provider/blob/develop/VERSIONING.rst).

Expand Down Expand Up @@ -210,6 +210,33 @@ We generally do not recommend this solution as we believe that gracefully fallin
AmazonCorrettoCryptoProvider.INSTANCE.assertHealthy();
```

### Other system properties
ACCP can be configured via several system properties.
None of these should be needed for standard deployments and we recommend not touching them.
They are of most use to developers needing to test ACCP or experiment with benchmarking.
These are all read early in the load process and may be cached so any changes to them made from within Java may not be respected.
Thus, these should all be set on the JVM command line using `-D`.

* `com.amazon.corretto.crypto.provider.extrachecks`
Adds exta cryptographic consistency checks which are not necessary on standard systems.
These checks may be computationally expensive and are not normally relevant.
See `ExtraCheck.java` for values and more information.
(Also accepts "ALL" as a value to enable all flags and "help" to print out all flags to STDERR.)
* `com.amazon.corretto.crypto.provider.debug`
Enables extra debugging behavior.
These behaviors may be computationally expensive, produce additional output, or otherwise change the behavior of ACCP.
No values here will lower the security of ACCP or cause it to give incorrect results.
See `DebugFlag.java` for values and more information.
(Also accepts "ALL" as a value to enable all flags and "help" to print out all flags to STDERR.)
* `com.amazon.corretto.crypto.provider.useExternalLib`
Takes in `true` or `false` (defaults to `false`).
If `true` then ACCP skips trying to load the native library bundled within its JAR and goes directly to the system library path.
* `com.amazon.corretto.crypto.provider.janitor.stripes`
Takes *positive integer value* which is the requested minimum number of "stripes" used by the `Janitor` for dividing cleaning tasks (messes) among its workers.
(Current behavior is to default this value to 4 times the CPU core count and then round the value up to the nearest power of two.)
See `Janitor.java` for for more information.


# License
This library is licensed under the Apache 2.0 license although portions of this product include software licensed under the
[dual OpenSSL and SSLeay license](https://www.openssl.org/source/license.html).
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ plugins {
group = 'software.amazon.cryptools'
version = '2.0.0'

def openssl_version = '1.1.1j'
def openssl_version = '1.1.1m'
def opensslSrcPath = "${buildDir}/openssl/openssl-${openssl_version}"

configurations {
Expand Down
2 changes: 1 addition & 1 deletion csrc/rdrand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ bool rd_into_buf(bool (*rng)(uint64_t *), unsigned char *buf, int len) {
}

memcpy(buf, &remain, len);
secureZero(&remain, 0);
secureZero(&remain, sizeof(remain));
}
#else
goto fail;
Expand Down
2 changes: 1 addition & 1 deletion openssl.sha256
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aaf2fcb575cdf6491b98ab4829abf78a3dec8402b8b81efc8f23c00d443981bf openssl-1.1.1j.tar.gz
f89199be8b23ca45fc7cb9f1d8d3ee67312318286ad030f5316aca6462db6c96 openssl-1.1.1m.tar.gz
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class AmazonCorrettoCryptoProvider extends java.security.Provider {
private transient SelfTestSuite selfTestSuite = new SelfTestSuite();

static {
if (!Loader.IS_AVAILABLE) {
if (!Loader.IS_AVAILABLE && DebugFlag.VERBOSELOGS.isEnabled()) {
getLogger("AmazonCorrettoCryptoProvider").fine("Native JCE libraries are unavailable - disabling");
rdRandSupported_ = false;
} else {
Expand Down Expand Up @@ -220,7 +220,7 @@ private void checkTests() throws NoSuchAlgorithmException {
* end up falling back.
*/
if (!getType().equals("SecureRandom")) {
throw new NoSuchAlgorithmException("Can't use AACP before JAR validation completes");
throw new NoSuchAlgorithmException("Can't use ACCP before JAR validation completes");
}
}

Expand Down Expand Up @@ -276,23 +276,9 @@ private void resetAllSelfTests() {
public AmazonCorrettoCryptoProvider() {
super("AmazonCorrettoCryptoProvider", PROVIDER_VERSION, "");

final String[] extraCheckOptions = Loader.getProperty("extrachecks", "").split(",");
for (final String check : extraCheckOptions) {
if (check.equalsIgnoreCase("all")) {
extraChecks.addAll(EnumSet.allOf(ExtraCheck.class));
break;
}
try {
final ExtraCheck value = ExtraCheck.valueOf(check.toUpperCase());
if (value != null) {
extraChecks.add(value);
}
} catch (Exception ex) {
// Ignore
}
}
Utils.optionsFromProperty(ExtraCheck.class, extraChecks, "extrachecks");

if (!Loader.IS_AVAILABLE) {
if (!Loader.IS_AVAILABLE && DebugFlag.VERBOSELOGS.isEnabled()) {
getLogger("AmazonCorrettoCryptoProvider").fine("Native JCE libraries are unavailable - disabling");

// Don't implement anything
Expand Down Expand Up @@ -347,7 +333,7 @@ public static boolean isRdRandSupported() {
* {@link SelfTestStatus#NOT_RUN} will be returned if any tests have not be run.
* {@link SelfTestStatus#PASSED} will only be returned if all tests have been run and have
* all passed.
*
*
* <p>Algorithms currently run by this method:
* <ul>
* <li>NIST800-90A/AES-CTR-256
Expand All @@ -357,7 +343,7 @@ public static boolean isRdRandSupported() {
* <li>HMacSHA1
* <li>HMacMD5
* </ul>
*
*
* @see #runSelfTests()
*/
public SelfTestStatus getSelfTestStatus() {
Expand All @@ -369,7 +355,7 @@ public SelfTestStatus getSelfTestStatus() {
* Please see {@link #getSelfTestStatus()} for the algorithms tested and
* the possible return values. (though this method will never return
* {@link SelfTestStatus#NOT_RUN}).
*
*
* @see #getSelfTestStatus()
*/
public SelfTestStatus runSelfTests() {
Expand All @@ -387,7 +373,7 @@ public Throwable getLoadingError() {
/**
* <p>Throws an instance of {@link RuntimeCryptoException} if this library is not currently
* functional. Otherwise does nothing.
*
*
* <p>This library is considered healthy if {@link #getLoadingError()} returns {@code null}
* and {@link #runSelfTests()} returns {@link SelfTestStatus#PASSED}.
*/
Expand Down
41 changes: 41 additions & 0 deletions src/com/amazon/corretto/crypto/provider/DebugFlag.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

package com.amazon.corretto.crypto.provider;

import java.util.EnumSet;

/**
* Indicates whether a given debug mode is enabled for ACCP. None of these modes
* may compromise the security of ACCP but they are permitted to have
* significant performance costs.
*
* These are used by passing them by name (case-insensitive) to the
* {@code com.amazon.corretto.crypto.provider.debug} system property. Example:
* {@code -Dcom.amazon.corretto.crypto.provider.debug=FreeTrace}.
*
* Alternatively you can enable all debug flags with the magic value of "ALL".
*/
enum DebugFlag {
/** Trace when native values are created and freed. */
FREETRACE,
/**
* Increases the verbosity of logs.
* May still need to be combined with increasing the log level of your configured logger.
*/
VERBOSELOGS;

private static final EnumSet<DebugFlag> ENABLED_FLAGS = EnumSet.noneOf(DebugFlag.class);

static {
Utils.optionsFromProperty(DebugFlag.class, ENABLED_FLAGS, "debug");
}

static boolean isEnabled(final DebugFlag flag) {
return ENABLED_FLAGS.contains(flag);
}

boolean isEnabled() {
return isEnabled(this);
}
}
Loading

0 comments on commit de38de3

Please sign in to comment.