apksigner with the Infisical PKCS#11 module. Since apksigner is a Java-based tool, it uses the same SunPKCS11 provider approach as jarsigner.
Prerequisites
- An Infisical project with a signer configured
- An active signing grant for the signer
- A machine identity with Universal Auth and
Signpermission on the signer - The Infisical PKCS#11 module installed and configured
- Android SDK Build Tools 30.0.0 or later (includes
apksigner)
Step 1: Create the SunPKCS11 Provider Configuration
Create a configuration file for Java’s SunPKCS11 provider. Save it asinfisical-pkcs11.cfg:
On macOS, use
.dylib. On Windows, use .dll. If you have multiple signers and need a specific one, add slot = 0 (replace with the correct slot index).Step 2: Sign an APK
Useapksigner with the PKCS#11 provider:
--ks NONE: Required when using PKCS#11 (no file-based keystore).--ks-type PKCS11: Tells apksigner to use the PKCS#11 provider.--ks-key-alias: The signer name (token label in PKCS#11).--out: Writes the signed APK to a new file. Without this flag,apksignermodifies the APK in place.
Signing an Android App Bundle (AAB)
For AAB files, usejarsigner instead of apksigner since AAB signing follows the JAR signing format:
Step 3: Verify the Signature
Verify the signed APK. If you signed in place (without--out), verify the same file. If you used --out, verify the output file:
CI/CD Integration
Example for a Gradle-based Android project in CI:Troubleshooting
For any issue, enable debug logging in your config file ("log_level": "debug", "log_file": "/tmp/infisical-pkcs11.log") to get detailed output.
Failed to load signer or key alias not found
Failed to load signer or key alias not found
Ensure the
--provider-class is sun.security.pkcs11.SunPKCS11, the --provider-arg points to a valid config file, and the --ks-key-alias matches your signer name exactly.APK signature scheme v2/v3 not applied
APK signature scheme v2/v3 not applied
Use
apksigner (not jarsigner) for APK signing. Only apksigner applies v2/v3 APK signature schemes.