|
| 1 | +name: Android FIPS Ready Gradle Build and Test |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ 'master', 'main', 'release/**' ] |
| 6 | + pull_request: |
| 7 | + branches: [ 'master' ] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: android-fips-${{ github.head_ref || github.ref }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + build_wolfcryptjni_fipsready: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + steps: |
| 17 | + - name: Clone wolfcrypt-jni |
| 18 | + uses: actions/checkout@v4 |
| 19 | + |
| 20 | + # Free up disk space to prevent emulator from failing |
| 21 | + - name: Free up disk space |
| 22 | + run: | |
| 23 | + sudo rm -rf /usr/share/dotnet |
| 24 | + sudo rm -rf /usr/local/lib/android/sdk/ndk |
| 25 | + sudo rm -rf /opt/ghc |
| 26 | + sudo rm -rf /opt/hostedtoolcache/CodeQL |
| 27 | + sudo docker image prune --all --force |
| 28 | + df -h |
| 29 | +
|
| 30 | + # Get latest stable wolfSSL version for FIPS Ready download |
| 31 | + - name: Get latest wolfSSL stable version |
| 32 | + id: wolfssl-version |
| 33 | + run: | |
| 34 | + LATEST=$(curl -s -H "Authorization: token ${{ github.token }}" \ |
| 35 | + "https://api.github.com/repos/wolfSSL/wolfssl/tags?per_page=100" | \ |
| 36 | + jq -r '.[].name | select(endswith("-stable"))' | \ |
| 37 | + sort -V | tail -1 | sed 's/^v//;s/-stable$//') |
| 38 | + if [ -z "$LATEST" ]; then |
| 39 | + echo "Failed to determine latest wolfSSL stable version" >&2 |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | + echo "version=$LATEST" >> $GITHUB_OUTPUT |
| 43 | + echo "wolfSSL stable version: $LATEST" |
| 44 | +
|
| 45 | + # Cache wolfSSL FIPS Ready archive |
| 46 | + - name: Cache wolfSSL FIPS Ready archive |
| 47 | + uses: actions/cache@v4 |
| 48 | + id: fips-cache |
| 49 | + with: |
| 50 | + path: wolfssl-fips-ready.zip |
| 51 | + key: wolfssl-fips-ready-${{ steps.wolfssl-version.outputs.version }} |
| 52 | + |
| 53 | + # Download wolfSSL FIPS Ready if not cached |
| 54 | + - name: Download wolfSSL FIPS Ready |
| 55 | + if: steps.fips-cache.outputs.cache-hit != 'true' |
| 56 | + run: | |
| 57 | + VERSION="${{ steps.wolfssl-version.outputs.version }}" |
| 58 | + URL="https://www.wolfssl.com/wolfssl-${VERSION}-gplv3-fips-ready.zip" |
| 59 | + echo "Downloading: $URL" |
| 60 | + wget -q "$URL" -O wolfssl-fips-ready.zip |
| 61 | +
|
| 62 | + # Extract wolfSSL FIPS Ready to expected location |
| 63 | + - name: Extract wolfSSL FIPS Ready |
| 64 | + run: | |
| 65 | + unzip -q wolfssl-fips-ready.zip -d /tmp/wolfssl-fips-extract |
| 66 | + EXTRACTED_DIR=$(find /tmp/wolfssl-fips-extract -mindepth 1 -maxdepth 1 -type d | head -1) |
| 67 | + echo "Extracted directory: $EXTRACTED_DIR" |
| 68 | + ls "$EXTRACTED_DIR/wolfcrypt/src/" | head -5 |
| 69 | + mv "$EXTRACTED_DIR" IDE/Android/app/src/main/cpp/wolfssl |
| 70 | +
|
| 71 | + # Configure CMakeLists.txt for FIPS Ready build |
| 72 | + - name: Configure for FIPS Ready |
| 73 | + run: | |
| 74 | + sed -i 's/set(WOLFSSL_PKG_TYPE "normal")/set(WOLFSSL_PKG_TYPE "fipsready")/' \ |
| 75 | + IDE/Android/app/src/main/cpp/CMakeLists.txt |
| 76 | + grep 'WOLFSSL_PKG_TYPE' IDE/Android/app/src/main/cpp/CMakeLists.txt |
| 77 | +
|
| 78 | + # Patch MainActivity to auto-trigger WolfCryptProvider on launch, |
| 79 | + # so FIPS error callback fires and prints the expected hash to logcat |
| 80 | + # without needing a button press. |
| 81 | + - name: Patch MainActivity for auto FIPS hash detection |
| 82 | + run: | |
| 83 | + sed -i 's/button.setOnClickListener(buttonListener);/button.setOnClickListener(buttonListener);\n\n try { testFindProvider(null); } catch (Exception e) { e.printStackTrace(); }/' \ |
| 84 | + IDE/Android/app/src/main/java/com/example/wolfssl/MainActivity.java |
| 85 | +
|
| 86 | + # Setup Java with Gradle caching |
| 87 | + - name: Setup java |
| 88 | + uses: actions/setup-java@v4 |
| 89 | + with: |
| 90 | + distribution: 'zulu' |
| 91 | + java-version: '21' |
| 92 | + cache: 'gradle' |
| 93 | + |
| 94 | + # Build all targets |
| 95 | + - name: Gradle Build (pass 1 - placeholder hash) |
| 96 | + run: cd IDE/Android && ./gradlew --build-cache assembleDebug assembleDebugUnitTest assembleDebugAndroidTest |
| 97 | + |
| 98 | + # Enable KVM for hardware acceleration |
| 99 | + - name: Enable KVM |
| 100 | + run: | |
| 101 | + echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules |
| 102 | + sudo udevadm control --reload-rules |
| 103 | + sudo udevadm trigger --name-match=kvm |
| 104 | +
|
| 105 | + # Cache AVD snapshot for faster emulator boot |
| 106 | + - name: AVD cache |
| 107 | + uses: actions/cache@v4 |
| 108 | + id: avd-cache |
| 109 | + with: |
| 110 | + path: | |
| 111 | + ~/.android/avd/* |
| 112 | + ~/.android/adb* |
| 113 | + key: avd-wolfcryptjni-fips-30-x86_64-google_apis-v1 |
| 114 | + |
| 115 | + # Create AVD and generate snapshot for caching |
| 116 | + - name: Create AVD and generate snapshot |
| 117 | + if: steps.avd-cache.outputs.cache-hit != 'true' |
| 118 | + uses: reactivecircus/android-emulator-runner@v2.37.0 |
| 119 | + with: |
| 120 | + api-level: 30 |
| 121 | + arch: x86_64 |
| 122 | + target: google_apis |
| 123 | + force-avd-creation: false |
| 124 | + emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 125 | + disable-animations: true |
| 126 | + script: echo "Generated AVD snapshot for caching" |
| 127 | + |
| 128 | + # Launch app briefly to capture FIPS in-core hash from logcat. |
| 129 | + # The FIPS error callback prints the expected verifyCore hash on |
| 130 | + # startup if there is a mismatch. |
| 131 | + - name: Capture FIPS in-core hash |
| 132 | + id: fips-hash |
| 133 | + uses: reactivecircus/android-emulator-runner@v2.37.0 |
| 134 | + timeout-minutes: 5 |
| 135 | + with: |
| 136 | + api-level: 30 |
| 137 | + arch: x86_64 |
| 138 | + target: google_apis |
| 139 | + force-avd-creation: false |
| 140 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 141 | + disable-animations: true |
| 142 | + script: | |
| 143 | + adb wait-for-device |
| 144 | + adb logcat -c |
| 145 | + cd IDE/Android && ./gradlew installDebug --no-daemon --no-watch-fs |
| 146 | + adb shell am start -W -n com.example.wolfssl/.MainActivity |
| 147 | + for i in 1 2 3 4 5 6; do sleep 5; adb logcat -d | grep -q 'hash = [A-Fa-f0-9]\{64\}' && break; echo "Waiting for FIPS hash ($i/6)..."; done |
| 148 | + adb logcat -d > /tmp/logcat_hash.txt 2>&1 |
| 149 | + HASH=$(grep -o 'hash = [A-Fa-f0-9]\{64\}' /tmp/logcat_hash.txt | head -1 | sed 's/hash = //'); if [ -n "$HASH" ]; then echo "Captured FIPS hash: $HASH"; echo "hash=$HASH" >> $GITHUB_OUTPUT; else echo "No FIPS hash found in logcat, assuming existing hash is correct"; echo "hash=" >> $GITHUB_OUTPUT; fi |
| 150 | +
|
| 151 | + # Update FIPS hash in CMakeLists.txt and rebuild if needed |
| 152 | + - name: Rebuild with correct FIPS hash |
| 153 | + if: steps.fips-hash.outputs.hash != '' |
| 154 | + run: | |
| 155 | + HASH="${{ steps.fips-hash.outputs.hash }}" |
| 156 | + echo "Updating FIPS hash to: $HASH" |
| 157 | + sed -i "s/WOLFCRYPT_FIPS_CORE_HASH_VALUE=[A-Fa-f0-9]*/WOLFCRYPT_FIPS_CORE_HASH_VALUE=$HASH/g" \ |
| 158 | + IDE/Android/app/src/main/cpp/CMakeLists.txt |
| 159 | + cd IDE/Android && ./gradlew --build-cache assembleDebug assembleDebugUnitTest assembleDebugAndroidTest |
| 160 | +
|
| 161 | + # Generate BKS KeyStore files for PKIX tests |
| 162 | + - name: Generate BKS KeyStore files |
| 163 | + run: | |
| 164 | + # Bouncy Castle version may need periodic updates |
| 165 | + BCPROV_JAR="bcprov-jdk18on-1.78.1.jar" |
| 166 | + BCPROV_URL="https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk18on/1.78.1/${BCPROV_JAR}" |
| 167 | + wget -q "$BCPROV_URL" -O "/tmp/${BCPROV_JAR}" |
| 168 | + wget -q "${BCPROV_URL}.sha256" -O "/tmp/${BCPROV_JAR}.sha256" |
| 169 | + (cd /tmp && echo "$(cat ${BCPROV_JAR}.sha256) ${BCPROV_JAR}" | sha256sum -c -) |
| 170 | + cd examples/certs && ./convert-to-bks.sh "/tmp/${BCPROV_JAR}" |
| 171 | +
|
| 172 | + # Run instrumented tests on Android emulator |
| 173 | + - name: Run Android Instrumented Tests |
| 174 | + uses: reactivecircus/android-emulator-runner@v2.37.0 |
| 175 | + timeout-minutes: 15 |
| 176 | + with: |
| 177 | + api-level: 30 |
| 178 | + arch: x86_64 |
| 179 | + target: google_apis |
| 180 | + force-avd-creation: false |
| 181 | + emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none |
| 182 | + disable-animations: true |
| 183 | + script: | |
| 184 | + adb wait-for-device |
| 185 | + adb shell mkdir -p /data/local/tmp/examples/certs/intermediate |
| 186 | + adb shell mkdir -p /data/local/tmp/examples/certs/rsapss |
| 187 | + adb shell mkdir -p /data/local/tmp/examples/certs/crl |
| 188 | + adb push ./examples/certs/ /data/local/tmp/examples/ |
| 189 | + adb logcat -c |
| 190 | + cd IDE/Android && ./gradlew connectedDebugAndroidTest --no-daemon --no-watch-fs || { adb logcat -d > /tmp/logcat.txt 2>&1; echo "=== LOGCAT (errors) ==="; grep -i "exception\|error\|fatal" /tmp/logcat.txt || true; exit 1; } |
| 191 | + adb logcat -d > /tmp/logcat.txt 2>&1 || true |
| 192 | + # Clean up emulator processes. Safe to kill -9 since |
| 193 | + # -no-snapshot-save is used (no snapshot to corrupt). |
| 194 | + pgrep -f '[q]emu-system' | xargs -r kill -9 2>/dev/null || true |
| 195 | + pgrep -f '[c]rashpad' | xargs -r kill -9 2>/dev/null || true |
| 196 | + sleep 2 |
| 197 | +
|
| 198 | + # Upload test reports even on failure |
| 199 | + - name: Upload Test Reports |
| 200 | + uses: actions/upload-artifact@v4 |
| 201 | + if: always() |
| 202 | + timeout-minutes: 5 |
| 203 | + with: |
| 204 | + name: android-fips-ready-test-reports |
| 205 | + path: | |
| 206 | + IDE/Android/app/build/reports/androidTests/ |
| 207 | + /tmp/logcat.txt |
| 208 | + /tmp/logcat_hash.txt |
| 209 | + retention-days: 14 |
0 commit comments