1# Fuzzers for libkeymaster4 2 3## Plugin Design Considerations 4The fuzzer plugins for libkeymaster4 are designed based on the understanding of the 5source code and try to achieve the following: 6 7##### Maximize code coverage 8The configuration parameters are not hardcoded, but instead selected based on 9incoming data. This ensures more code paths are reached by the fuzzers. 10 11libkeymaster4 supports the following parameters: 121. Security Level (parameter name: `securityLevel`) 132. Padding Mode (parameter name: `paddingMode`) 143. Digest (parameter name: `digest`) 154. Key Format (parameter name: `keyFormat`) 165. Key Purpose (parameter name: `keyPurpose`) 17 18| Parameter| Valid Values| Configured Value| 19|------------- |-------------| ----- | 20| `securityLevel` | 0.`SecurityLevel::SOFTWARE` 1.`SecurityLevel::TRUSTED_ENVIRONMENT` 2.`SecurityLevel::STRONGBOX`| Value obtained from FuzzedDataProvider| 21| `paddingMode` | 0.`PaddingMode::NONE` 1.`PaddingMode::RSA_OAEP` 2.`PaddingMode::RSA_PSS` 3. `PaddingMode::RSA_PKCS1_1_5_ENCRYPT` 4.`PaddingMode::RSA_PKCS1_1_5_SIGN` 5.`PaddingMode::PKCS7`| Value obtained from FuzzedDataProvider| 22| `digest` | 1. `Digest::NONE` 2.`Digest::MD5` 3.`Digest::SHA1` 4.`Digest::SHA_2_224` 5.`Digest::SHA_2_256` 6.`Digest::SHA_2_384` 7.`Digest::SHA_2_512`| Value obtained from FuzzedDataProvider| 23| `keyFormat` | 1. `KeyFormat::X509` 2.`KeyFormat::PKCS8` 3.`KeyFormat::RAW`| Value obtained from FuzzedDataProvider| 24| `keyPurpose` | 1. `KeyPurpose::ENCRYPT` 2.`KeyPurpose::DECRYPT` 3.`KeyPurpose::SIGN` 4. `KeyPurpose::VERIFY` 5. `KeyPurpose::WRAP_KEY`| Value obtained from FuzzedDataProvider| 25 26This also ensures that the plugins are always deterministic for any given input. 27 28##### Maximize utilization of input data 29The plugins feed the entire input data to the module. 30This ensures that the plugins tolerate any kind of input (empty, huge, 31malformed, etc) and dont `exit()` on any input and thereby increasing the 32chance of identifying vulnerabilities. 33 34## Build 35 36This describes steps to build k4_AndroidKeymaster4Device_fuzzer binary 37 38### Android 39 40#### Steps to build 41Build the fuzzer 42``` 43 $ mm k4_AndroidKeymaster4Device_fuzzer 44``` 45#### Steps to run 46To run on device 47``` 48 $ adb sync data 49 $ adb shell /data/fuzz/${TARGET_ARCH}/k4_AndroidKeymaster4Device_fuzzer/k4_AndroidKeymaster4Device_fuzzer 50``` 51 52## References: 53 * http://llvm.org/docs/LibFuzzer.html 54 * https://github.com/google/oss-fuzz 55