From 83e1781bf08fdfa843249604d4fb83cc1ce66a3f Mon Sep 17 00:00:00 2001 From: Bret Ambrose Date: Tue, 11 Jul 2023 14:06:48 -0700 Subject: [PATCH] Musl testing (#544) Co-authored-by: Michael Graeb Co-authored-by: Waqar Ahmed Khan --- .builder/actions/aws_crt_java_test.py | 39 +++++------ .builder/actions/build-classifier.py | 15 +++++ .github/workflows/ci.yml | 42 +++++++++++- CMakeLists.txt | 5 +- README.md | 9 ++- builder.json | 22 +++++++ codebuild/cd/deploy-platform-specific-jars.sh | 2 +- codebuild/cd/musl-arm64-build.yml | 22 +++++++ codebuild/cd/musl-armv7-build.yml | 23 +++++++ codebuild/cd/musl-linux-build.sh | 29 ++++++++ codebuild/cd/musl-x64-build.yml | 22 +++++++ .../cd/test-platform-specific-jar-snapshot.sh | 2 +- codebuild/macos_compatibility_check.py | 4 +- crt/aws-c-io | 2 +- crt/aws-c-s3 | 2 +- .../java/software/amazon/awssdk/crt/CRT.java | 66 ++++++++++++++++++- .../DefaultChainCredentialsProvider.java | 2 +- .../awssdk/crt/test/Mqtt5ClientTest.java | 3 +- .../test/MqttClientConnectionMethodTest.java | 3 +- .../amazon/awssdk/crt/test/Pkcs11LibTest.java | 4 +- .../awssdk/crt/test/ServerListenerTest.java | 1 - .../crt/test/TlsContextOptionsTest.java | 3 +- 22 files changed, 282 insertions(+), 40 deletions(-) create mode 100644 .builder/actions/build-classifier.py create mode 100644 codebuild/cd/musl-arm64-build.yml create mode 100644 codebuild/cd/musl-armv7-build.yml create mode 100755 codebuild/cd/musl-linux-build.sh create mode 100644 codebuild/cd/musl-x64-build.yml diff --git a/.builder/actions/aws_crt_java_test.py b/.builder/actions/aws_crt_java_test.py index a52cf91f5..1e9b044f4 100644 --- a/.builder/actions/aws_crt_java_test.py +++ b/.builder/actions/aws_crt_java_test.py @@ -6,10 +6,25 @@ class AWSCrtJavaTest(Builder.Action): - def _run_java_tests(self, *cmd_args): + def _run_java_tests(self, *extra_args): if os.path.exists('log.txt'): os.remove('log.txt') + profiles = 'continuous-integration' + + cmd_args = [ + "mvn", "-B", + "-P", profiles, + "-DredirectTestOutputToFile=true", + "-DreuseForks=false", + "-Daws.crt.memory.tracing=2", + "-Daws.crt.debugnative=true", + "-Daws.crt.aws_trace_log_per_test", + "-Daws.crt.ci=true", + ] + cmd_args.extend(extra_args) + cmd_args.append("test") + result = self.env.shell.exec(*cmd_args, check=False) if result.returncode: if os.path.exists('log.txt'): @@ -23,29 +38,11 @@ def start_maven_tests(self, env): # tests must run with leak detection turned on env.shell.setenv('AWS_CRT_MEMORY_TRACING', '2') - self._run_java_tests( - "mvn", "-P", "continuous-integration", "-B", "test", - "-DredirectTestOutputToFile=true", - "-DreuseForks=false", - "-DrerunFailingTestsCount=5", - "-Daws.crt.memory.tracing=2", - "-Daws.crt.debugnative=true", - "-Daws.crt.aws_trace_log_per_test", - "-Daws.crt.ci=true", - ) + self._run_java_tests("-DrerunFailingTestsCount=5") # run the ShutdownTest by itself env.shell.setenv('AWS_CRT_SHUTDOWN_TESTING', '1') - self._run_java_tests( - "mvn", "-P", "continuous-integration", "-B", "test", - "-DredirectTestOutputToFile=true", - "-DreuseForks=false", - "-Daws.crt.memory.tracing=2", - "-Daws.crt.debugnative=true", - "-Daws.crt.aws_trace_log_per_test", - "-Daws.crt.ci=true", - "-Dtest=ShutdownTest", - ) + self._run_java_tests("-Dtest=ShutdownTest") # run the elasticurl integration tests python = sys.executable diff --git a/.builder/actions/build-classifier.py b/.builder/actions/build-classifier.py new file mode 100644 index 000000000..55836d0be --- /dev/null +++ b/.builder/actions/build-classifier.py @@ -0,0 +1,15 @@ + +import Builder +import sys +import os +import tempfile +from builder.core.host import current_host + +# This action is used by the musl-linux-build.sh script to build the binaries for release. +class BuildClassifier(Builder.Action): + + + def run(self, env): + crt_classifier = os.getenv("CRT_CLASSIFIER") + if crt_classifier is not None: + env.shell.exec("mvn", "-B", "install", "-DskipTests", "-Dshared-lib.skip=true", f"-Dcrt.classifier={crt_classifier}", check=True) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f8e73629d..db7d2b2fa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,7 +7,7 @@ on: - 'docs' env: - BUILDER_VERSION: v0.9.45 + BUILDER_VERSION: v0.9.46 BUILDER_SOURCE: releases BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net PACKAGE_NAME: aws-crt-java @@ -79,6 +79,46 @@ jobs: python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')" chmod a+x builder ./builder build -p ${{ env.PACKAGE_NAME }} --target=linux-${{ matrix.arch }} --spec=downstream + + linux-musl: + runs-on: ubuntu-22.04 # latest + strategy: + matrix: + image: + - alpine-3.16-x64 + - alpine-3.16-arm64 + - openwrt-x64-openjdk8 + steps: + - name: Install qemu/docker + run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - name: Checkout Sources + uses: actions/checkout@v2 + with: + submodules: true + - name: Build ${{ env.PACKAGE_NAME }} + run: | + aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh + ./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-${{ matrix.image }} build -p ${{ env.PACKAGE_NAME }} + + # armv7 needs its own action due to inability to differentiate at runtime armv6 vs armv7 in the jvm: + # + # At build time we can properly figure out that we're targeting armv7. + # At run time we have to force armv7 (via environment variable) in order to achieve proper resource path + # resolution. + linux-musl-armv7: + runs-on: ubuntu-20.04 # latest + steps: + - name: Install qemu/docker + run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + - name: Checkout Sources + uses: actions/checkout@v2 + with: + submodules: true + - name: Build ${{ env.PACKAGE_NAME }} + run: | + export AWS_CRT_ARCH=armv7 + aws s3 cp s3://aws-crt-test-stuff/ci/${{ env.BUILDER_VERSION }}/linux-container-ci.sh ./linux-container-ci.sh && chmod a+x ./linux-container-ci.sh + ./linux-container-ci.sh ${{ env.BUILDER_VERSION }} aws-crt-alpine-3.16-armv7 build -p ${{ env.PACKAGE_NAME }} raspberry: runs-on: ubuntu-22.04 # latest diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b7aac4ed..082668493 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -105,6 +105,9 @@ endif() include(UseJava) include(AwsPlatformDetect) include(AwsSharedLibSetup) +include(AwsCRuntime) + +aws_determine_local_c_runtime(AWS_C_RUNTIME) file(GLOB AWS_CRT_JAVA_HEADERS "include/aws/jni/*.h" @@ -156,7 +159,7 @@ file(GLOB CRT_JAVA_SRC # figure out the target platform info and output the lib there aws_detect_target_platform(TARGET_OS TARGET_ARCH) message(STATUS "Compiling for ${TARGET_OS}-${TARGET_ARCH}") -set(TARGET_LIB_DIR "${AWS_LIBRARY_OUTPUT_DIR}/${TARGET_OS}/${TARGET_ARCH}") +set(TARGET_LIB_DIR "${AWS_LIBRARY_OUTPUT_DIR}/${TARGET_OS}/${TARGET_ARCH}/${AWS_C_RUNTIME}") # shared lib that contains the CRT and JNI bindings, to be loaded by java add_library(${PROJECT_NAME} SHARED ${CRT_JAVA_HEADERS} ${CRT_JAVA_SRC}) diff --git a/README.md b/README.md index 5d2acbaf8..daeeece08 100644 --- a/README.md +++ b/README.md @@ -82,11 +82,14 @@ The `aws-crt` JAR in Maven Central is a large "uber" jar that contains compiled ### Available platform classifiers -- linux-armv6 -- linux-armv7 +- linux-armv6 (no auto-detect) +- linux-armv7 (no auto-detect) - linux-aarch_64 - linux-x86_32 - linux-x86_64 +- linux-x86_64-musl (no auto-detect) +- linux-armv7-musl (no auto-detect) +- linux-aarch_64-musl (no auto-detect) - osx-aarch_64 - osx-x86_64 - windows-x86_32 @@ -97,6 +100,8 @@ The `aws-crt` JAR in Maven Central is a large "uber" jar that contains compiled The [os-maven-plugin](https://github.com/trustin/os-maven-plugin) can automatically detect your platform's classifier at build time. **NOTES**: The auto-detected `linux-arm_32` platform classifier is not supported, you must specify `linux-armv6` or `linux-armv7`. +Additionally, musl vs glibc detection is not supported either. If you are deploying to a musl-based system and wish to use +a classifier-based jar, you must specify the classifier name yourself. ``` xml diff --git a/builder.json b/builder.json index 12fae410b..94586bcfc 100644 --- a/builder.json +++ b/builder.json @@ -78,6 +78,28 @@ "-DBUILD_TESTING=OFF" ] } + }, + "hosts": { + "_comment": "Reset the overrides from targets/linux/architectures/arm* for Alpine", + "alpine": { + "!packages": [ + "maven", + "openjdk8" + ], + "!build_steps": [ + "mvn -P continuous-integration -B compile", + "build-classifier" + ], + "!test_steps": [ + "aws-crt-java-test" + ] + }, + "openwrt": { + "!packages": [], + "!build_steps": [ + "mvn -P continuous-integration -B compile" + ] + } } }, "android": { diff --git a/codebuild/cd/deploy-platform-specific-jars.sh b/codebuild/cd/deploy-platform-specific-jars.sh index 12a613d06..d8fefba88 100755 --- a/codebuild/cd/deploy-platform-specific-jars.sh +++ b/codebuild/cd/deploy-platform-specific-jars.sh @@ -13,7 +13,7 @@ else DEPLOY_REPOSITORY_URL=https://aws.oss.sonatype.org:443/service/local/staging/deployByRepositoryId/${STAGING_REPO_ID} fi -CLASSIFIERS_ARRAY=("linux-armv6" "linux-armv7" "linux-aarch_64" "linux-x86_32" "linux-x86_64" "osx-aarch_64" "osx-x86_64" "windows-x86_32" "windows-x86_64") +CLASSIFIERS_ARRAY=("linux-armv6" "linux-armv7" "linux-aarch_64" "linux-x86_32" "linux-x86_64" "osx-aarch_64" "osx-x86_64" "windows-x86_32" "windows-x86_64" "linux-x86_64-musl" "linux-armv7-musl" "linux-aarch_64-musl") for str in ${CLASSIFIERS_ARRAY[@]}; do FILES="${FILES}target/aws-crt-1.0.0-SNAPSHOT-$str.jar," diff --git a/codebuild/cd/musl-arm64-build.yml b/codebuild/cd/musl-arm64-build.yml new file mode 100644 index 000000000..a8a05264d --- /dev/null +++ b/codebuild/cd/musl-arm64-build.yml @@ -0,0 +1,22 @@ +version: 0.2 +phases: + install: + commands: + pre_build: + commands: + - export CC=gcc + build: + commands: + - cd aws-crt-java + - ./codebuild/cd/musl-linux-build.sh aws-crt-alpine-3.16-arm64 linux-aarch_64-musl + + post_build: + commands: + +artifacts: + files: + - 'dist/**/*' + +cache: + paths: + - '/root/.m2/**/*' diff --git a/codebuild/cd/musl-armv7-build.yml b/codebuild/cd/musl-armv7-build.yml new file mode 100644 index 000000000..626ac7b94 --- /dev/null +++ b/codebuild/cd/musl-armv7-build.yml @@ -0,0 +1,23 @@ +version: 0.2 +phases: + install: + commands: + pre_build: + commands: + - export CC=gcc + build: + commands: + - cd aws-crt-java + - export AWS_CRT_ARCH=armv7 + - ./codebuild/cd/musl-linux-build.sh aws-crt-alpine-3.16-armv7 linux-armv7-musl + + post_build: + commands: + +artifacts: + files: + - 'dist/**/*' + +cache: + paths: + - '/root/.m2/**/*' diff --git a/codebuild/cd/musl-linux-build.sh b/codebuild/cd/musl-linux-build.sh new file mode 100755 index 000000000..1117bb124 --- /dev/null +++ b/codebuild/cd/musl-linux-build.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -ex + +IMAGE_NAME=$1 +shift +CLASSIFIER=$1 +shift + +# Pry the builder version this CRT is using out of ci.yml +BUILDER_VERSION=$(cat .github/workflows/ci.yml | grep 'BUILDER_VERSION:' | sed 's/\s*BUILDER_VERSION:\s*\(.*\)/\1/') +echo "Using builder version ${BUILDER_VERSION}" + +aws ecr get-login-password | docker login 123124136734.dkr.ecr.us-east-1.amazonaws.com -u AWS --password-stdin +export DOCKER_IMAGE=123124136734.dkr.ecr.us-east-1.amazonaws.com/${IMAGE_NAME}:${BUILDER_VERSION} +export QEMU_IMAGE=123124136734.dkr.ecr.us-east-1.amazonaws.com/multiarch-qemu-user-static:latest +docker run --rm --privileged ${QEMU_IMAGE} --reset -p yes + + +export CRT_CLASSIFIER=${CLASSIFIER} +export BRANCH_TAG=$(git describe --tags) +docker run --mount type=bind,src=$(pwd),dst=/root/aws-crt-java --env AWS_ACCESS_KEY_ID --env AWS_SECRET_ACCESS_KEY --env AWS_DEFAULT_REGION --env CXXFLAGS --env AWS_CRT_ARCH --env CRT_CLASSIFIER $DOCKER_IMAGE --version=${BUILDER_VERSION} build -p aws-crt-java --branch ${BRANCH_TAG} run_tests=false +docker container prune -f + +# Upload the artifacts to S3 +export GIT_TAG=$(git describe --tags) + +aws s3 cp --recursive --include "*.so" target/cmake-build/lib s3://aws-crt-java-pipeline/${GIT_TAG}/lib +aws s3 cp target/ s3://aws-crt-java-pipeline/${GIT_TAG}/jar/ --recursive --exclude "*" --include "aws-crt*.jar" diff --git a/codebuild/cd/musl-x64-build.yml b/codebuild/cd/musl-x64-build.yml new file mode 100644 index 000000000..b252c335c --- /dev/null +++ b/codebuild/cd/musl-x64-build.yml @@ -0,0 +1,22 @@ +version: 0.2 +phases: + install: + commands: + pre_build: + commands: + - export CC=gcc + build: + commands: + - cd aws-crt-java + - ./codebuild/cd/musl-linux-build.sh aws-crt-alpine-3.16-x64 linux-x86_64-musl + + post_build: + commands: + +artifacts: + files: + - 'dist/**/*' + +cache: + paths: + - '/root/.m2/**/*' diff --git a/codebuild/cd/test-platform-specific-jar-snapshot.sh b/codebuild/cd/test-platform-specific-jar-snapshot.sh index 189a21243..96fdee3b9 100644 --- a/codebuild/cd/test-platform-specific-jar-snapshot.sh +++ b/codebuild/cd/test-platform-specific-jar-snapshot.sh @@ -2,7 +2,7 @@ set -ex -PLATFORM_ARRAY=("linux-armv6" "linux-armv7" "linux-aarch_64" "linux-x86_32" "linux-x86_64" "osx-aarch_64" "osx-x86_64" "windows-x86_32" "windows-x86_64") +PLATFORM_ARRAY=("linux-armv6" "linux-armv7" "linux-aarch_64" "linux-x86_32" "linux-x86_64" "osx-aarch_64" "osx-x86_64" "windows-x86_32" "windows-x86_64" "linux-x86_64-musl" "linux-armv7-musl" "linux-aarch_64-musl") # test uber jar mvn -B dependency:get -DrepoUrl=https://aws.oss.sonatype.org/content/repositories/snapshots -Dartifact=software.amazon.awssdk.crt:aws-crt:${CRT_VERSION}-SNAPSHOT -Dtransitive=false diff --git a/codebuild/macos_compatibility_check.py b/codebuild/macos_compatibility_check.py index 946dadbc1..8aabd0969 100644 --- a/codebuild/macos_compatibility_check.py +++ b/codebuild/macos_compatibility_check.py @@ -25,7 +25,7 @@ def main(): # version 10.9 # sdk 12.1 # Load command 9 - otool_cmd = "otool -l target/cmake-build/lib/osx/{}/libaws-crt-jni.dylib | grep -A3 \'LC_VERSION_MIN_MACOSX\' | grep -E version | tr -s ' ' | cut -f3 -d' ' | tr -d '[:space:]'".format(arch) + otool_cmd = "otool -l target/cmake-build/lib/osx/{}/cruntime/libaws-crt-jni.dylib | grep -A3 \'LC_VERSION_MIN_MACOSX\' | grep -E version | tr -s ' ' | cut -f3 -d' ' | tr -d '[:space:]'".format(arch) if len(sys.argv) > 1: # Parsing the macos archtecture @@ -39,7 +39,7 @@ def main(): arch = "armv8" # The oldest version we can target on arm64 is 11.0 supported_version = "11.0" - otool_cmd = "otool -l target/cmake-build/lib/osx/{}/libaws-crt-jni.dylib | grep -E minos | tr -s ' ' | cut -f3 -d' ' | tr -d ' ' | tr -d '[:space:]'".format(arch) + otool_cmd = "otool -l target/cmake-build/lib/osx/{}/cruntime/libaws-crt-jni.dylib | grep -E minos | tr -s ' ' | cut -f3 -d' ' | tr -d ' ' | tr -d '[:space:]'".format(arch) print("Start to validate the build binary for MacOS with architecture {}, expected min os version: {}".format(arch,supported_version)) result = subprocess.check_output(otool_cmd, shell=True).decode("utf-8") diff --git a/crt/aws-c-io b/crt/aws-c-io index 1f9a08502..e87baa29f 160000 --- a/crt/aws-c-io +++ b/crt/aws-c-io @@ -1 +1 @@ -Subproject commit 1f9a085027c5e0f3e0c0e2a9fbe685f12af8105d +Subproject commit e87baa29fb621c8b42146c0206867f012f1acf23 diff --git a/crt/aws-c-s3 b/crt/aws-c-s3 index 28f7b8738..61c5282da 160000 --- a/crt/aws-c-s3 +++ b/crt/aws-c-s3 @@ -1 +1 @@ -Subproject commit 28f7b87386242a68e51c50944917c6ac0f771cc8 +Subproject commit 61c5282da191ccdb7f6460800c7bfc4d013ca8b4 diff --git a/src/main/java/software/amazon/awssdk/crt/CRT.java b/src/main/java/software/amazon/awssdk/crt/CRT.java index 0b99c0a4d..6052e4d12 100644 --- a/src/main/java/software/amazon/awssdk/crt/CRT.java +++ b/src/main/java/software/amazon/awssdk/crt/CRT.java @@ -4,11 +4,13 @@ */ package software.amazon.awssdk.crt; +import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.lang.reflect.InvocationTargetException; import java.util.*; @@ -19,6 +21,9 @@ * load the shared lib */ public final class CRT { + private static final String CRT_ARCH_OVERRIDE_SYSTEM_PROPERTY = "aws.crt.arch"; + private static final String CRT_ARCH_OVERRIDE_ENVIRONMENT_VARIABLE = "AWS_CRT_ARCH"; + private static final String CRT_LIB_NAME = "aws-crt-jni"; public static final int AWS_CRT_SUCCESS = 0; private static final CrtPlatform s_platform; @@ -104,6 +109,16 @@ public static String getOSIdentifier() throws UnknownPlatformException { * @return a string describing the detected architecture the CRT is executing on */ public static String getArchIdentifier() throws UnknownPlatformException { + String systemPropertyOverride = System.getProperty(CRT_ARCH_OVERRIDE_SYSTEM_PROPERTY); + if (systemPropertyOverride != null && systemPropertyOverride.length() > 0) { + return systemPropertyOverride; + } + + String environmentOverride = System.getenv(CRT_ARCH_OVERRIDE_ENVIRONMENT_VARIABLE); + if (environmentOverride != null && environmentOverride.length() > 0) { + return environmentOverride; + } + CrtPlatform platform = getPlatformImpl(); String arch = normalize(platform != null ? platform.getArchIdentifier() : System.getProperty("os.arch")); @@ -119,15 +134,60 @@ public static String getArchIdentifier() throws UnknownPlatformException { } } else if (arch.startsWith("arm64") || arch.startsWith("aarch64")) { return "armv8"; - } else if (arch.equals("arm")) { - return "armv6"; } else if (arch.equals("armv7l")) { return "armv7"; + } else if (arch.startsWith("arm")) { + return "armv6"; } throw new UnknownPlatformException("AWS CRT: architecture not supported: " + arch); } + private static final String NON_LINUX_RUNTIME_TAG = "cruntime"; + private static final String MUSL_RUNTIME_TAG = "musl"; + private static final String GLIBC_RUNTIME_TAG = "glibc"; + + public static String getCRuntime(String osIdentifier) { + if (!osIdentifier.equals("linux")) { + return NON_LINUX_RUNTIME_TAG; + } + + Runtime rt = Runtime.getRuntime(); + String[] commands = {"ldd", "--version"}; + try { + java.lang.Process proc = rt.exec(commands); + + // the "normal" input stream of the proc is the stdout of the invoked command + BufferedReader stdOutput = new BufferedReader(new + InputStreamReader(proc.getInputStream())); + + // sometimes, ldd's output goes to stderr, so capture that too + BufferedReader stdError = new BufferedReader(new + InputStreamReader(proc.getErrorStream())); + + String line; + StringBuilder outputBuilder = new StringBuilder(); + while ((line = stdOutput.readLine()) != null) { + outputBuilder.append(line); + } + + StringBuilder errorBuilder = new StringBuilder(); + while ((line = stdError.readLine()) != null) { + errorBuilder.append(line); + } + + String lddOutput = outputBuilder.toString(); + String lddError = errorBuilder.toString(); + if (lddOutput.contains("musl") || lddError.contains("musl")) { + return MUSL_RUNTIME_TAG; + } else { + return GLIBC_RUNTIME_TAG; + } + } catch (IOException io) { + return GLIBC_RUNTIME_TAG; + } + } + private static void extractAndLoadLibrary(String path) { try { // Check java.io.tmpdir @@ -187,7 +247,7 @@ private static void extractAndLoadLibrary(String path) { } // open a stream to read the shared lib contents from this JAR - String libResourcePath = "/" + os + "/" + getArchIdentifier() + "/" + libraryName; + String libResourcePath = "/" + os + "/" + getArchIdentifier() + "/" + getCRuntime(os) + "/" + libraryName; try (InputStream in = CRT.class.getResourceAsStream(libResourcePath)) { if (in == null) { throw new IOException("Unable to open library in jar for AWS CRT: " + libResourcePath); diff --git a/src/main/java/software/amazon/awssdk/crt/auth/credentials/DefaultChainCredentialsProvider.java b/src/main/java/software/amazon/awssdk/crt/auth/credentials/DefaultChainCredentialsProvider.java index d2c816561..e114e1ea8 100644 --- a/src/main/java/software/amazon/awssdk/crt/auth/credentials/DefaultChainCredentialsProvider.java +++ b/src/main/java/software/amazon/awssdk/crt/auth/credentials/DefaultChainCredentialsProvider.java @@ -50,7 +50,7 @@ private DefaultChainCredentialsProvider(DefaultChainCredentialsProviderBuilder b super(); ClientBootstrap clientBootstrap = builder.getClientBootstrap(); if (clientBootstrap == null) { - throw new IllegalArgumentException("DefaultChainCredentialsProvider: clientBootstrap must be non-null"); + clientBootstrap = ClientBootstrap.getOrCreateStaticDefault(); } long nativeHandle = defaultChainCredentialsProviderNew(this, clientBootstrap.getNativeHandle()); diff --git a/src/test/java/software/amazon/awssdk/crt/test/Mqtt5ClientTest.java b/src/test/java/software/amazon/awssdk/crt/test/Mqtt5ClientTest.java index 112eda72a..ba9ca10f6 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/Mqtt5ClientTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/Mqtt5ClientTest.java @@ -3126,8 +3126,9 @@ public void ConnDC_Cred_UC4() { AWS_TEST_MQTT5_IOT_CORE_HOST, AWS_TEST_MQTT5_IOT_CORE_PKCS11_LIB, AWS_TEST_MQTT5_IOT_CORE_PKCS11_TOKEN_LABEL, AWS_TEST_MQTT5_IOT_CORE_PKCS11_PIN, AWS_TEST_MQTT5_IOT_CORE_PKCS11_PKEY_LABEL, AWS_TEST_MQTT5_IOT_CORE_PKCS11_CERT_FILE); + // The published Softhsm package on muslc (Alpine) crashes if we don't call C_Finalize at the end. try ( - Pkcs11Lib pkcs11Lib = new Pkcs11Lib(AWS_TEST_MQTT5_IOT_CORE_PKCS11_LIB); + Pkcs11Lib pkcs11Lib = new Pkcs11Lib(AWS_TEST_MQTT5_IOT_CORE_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.STRICT); TlsContextPkcs11Options pkcs11Options = new TlsContextPkcs11Options(pkcs11Lib);) { pkcs11Options.withTokenLabel(AWS_TEST_MQTT5_IOT_CORE_PKCS11_TOKEN_LABEL); pkcs11Options.withUserPin(AWS_TEST_MQTT5_IOT_CORE_PKCS11_PIN); diff --git a/src/test/java/software/amazon/awssdk/crt/test/MqttClientConnectionMethodTest.java b/src/test/java/software/amazon/awssdk/crt/test/MqttClientConnectionMethodTest.java index b688002e1..8e67465ec 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/MqttClientConnectionMethodTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/MqttClientConnectionMethodTest.java @@ -135,8 +135,9 @@ public void ConnDC_Cred_UC4() AWS_TEST_MQTT311_IOT_CORE_HOST, AWS_TEST_MQTT311_IOT_CORE_PKCS11_LIB, AWS_TEST_MQTT311_IOT_CORE_PKCS11_TOKEN_LABEL, AWS_TEST_MQTT311_IOT_CORE_PKCS11_PIN, AWS_TEST_MQTT311_IOT_CORE_PKCS11_PKEY_LABEL, AWS_TEST_MQTT311_IOT_CORE_PKCS11_CERT_FILE); + // The published Softhsm package on muslc (Alpine) crashes if we don't call C_Finalize at the end. try ( - Pkcs11Lib pkcs11Lib = new Pkcs11Lib(AWS_TEST_MQTT311_IOT_CORE_PKCS11_LIB); + Pkcs11Lib pkcs11Lib = new Pkcs11Lib(AWS_TEST_MQTT311_IOT_CORE_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.STRICT); TlsContextPkcs11Options pkcs11Options = new TlsContextPkcs11Options(pkcs11Lib); ) { diff --git a/src/test/java/software/amazon/awssdk/crt/test/Pkcs11LibTest.java b/src/test/java/software/amazon/awssdk/crt/test/Pkcs11LibTest.java index 2f3cbf86b..bec538dee 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/Pkcs11LibTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/Pkcs11LibTest.java @@ -37,7 +37,8 @@ public Pkcs11LibTest() { public void testPkcs11Lib() { assumeEnvironmentSetUpForPkcs11Tests(); - try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(TEST_PKCS11_LIB)) { + // The published Softhsm package on muslc (Alpine) crashes if we don't call C_Finalize at the end. + try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(TEST_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.STRICT)) { } } @@ -67,4 +68,5 @@ public void testPkcs11LibInitializeFinalizeBehavior() { assertTrue(crtException.errorName.contains("CKR_CRYPTOKI_NOT_INITIALIZED")); } + } diff --git a/src/test/java/software/amazon/awssdk/crt/test/ServerListenerTest.java b/src/test/java/software/amazon/awssdk/crt/test/ServerListenerTest.java index b21e31488..857642f7f 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/ServerListenerTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/ServerListenerTest.java @@ -111,7 +111,6 @@ public void onConnectionShutdown(ServerConnection serverConnection, int errorCod } }); } catch (CrtRuntimeException ex) { - assertTrue(ex.getMessage().contains("AWS_IO_SOCKET_ADDRESS_IN_USE(1054), Socket address already in use.")); exceptionThrown = true; } assertTrue(exceptionThrown); diff --git a/src/test/java/software/amazon/awssdk/crt/test/TlsContextOptionsTest.java b/src/test/java/software/amazon/awssdk/crt/test/TlsContextOptionsTest.java index 3278e4d32..9d9942868 100644 --- a/src/test/java/software/amazon/awssdk/crt/test/TlsContextOptionsTest.java +++ b/src/test/java/software/amazon/awssdk/crt/test/TlsContextOptionsTest.java @@ -224,7 +224,8 @@ public void testMtlsPkcs11() { skipIfNetworkUnavailable(); Pkcs11LibTest.assumeEnvironmentSetUpForPkcs11Tests(); - try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(Pkcs11LibTest.TEST_PKCS11_LIB); + // The published Softhsm package on muslc (Alpine) crashes if we don't call C_Finalize at the end. + try (Pkcs11Lib pkcs11Lib = new Pkcs11Lib(Pkcs11LibTest.TEST_PKCS11_LIB, Pkcs11Lib.InitializeFinalizeBehavior.STRICT); TlsContextPkcs11Options pkcs11Options = new TlsContextPkcs11Options(pkcs11Lib) .withUserPin(Pkcs11LibTest.TEST_PKCS11_PIN) .withTokenLabel(Pkcs11LibTest.TEST_PKCS11_TOKEN_LABEL)