• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "keystoreCommon.h"
17 #include <keystore/Signature.h>
18 
19 class KeystoreSignatureFuzzer {
20   public:
21     void process(const uint8_t* data, size_t size);
~KeystoreSignatureFuzzer()22     ~KeystoreSignatureFuzzer() {}
23 
24   private:
25     void invokeSignature();
26     std::unique_ptr<FuzzedDataProvider> mFdp;
27 };
28 
invokeSignature()29 void KeystoreSignatureFuzzer::invokeSignature() {
30     std::optional<Signature> signature;
31     bool shouldUseParameterizedConstructor = mFdp->ConsumeBool();
32     if (shouldUseParameterizedConstructor) {
33         std::vector<uint8_t> signatureData = initSignatureData(mFdp.get());
34         signature = Signature(signatureData);
35     } else {
36         signature = Signature();
37     }
38     invokeReadWriteParcel(&signature.value());
39 }
40 
process(const uint8_t * data,size_t size)41 void KeystoreSignatureFuzzer::process(const uint8_t* data, size_t size) {
42     mFdp = std::make_unique<FuzzedDataProvider>(data, size);
43     invokeSignature();
44 }
45 
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)46 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
47     KeystoreSignatureFuzzer keystoreSignatureFuzzer;
48     keystoreSignatureFuzzer.process(data, size);
49     return 0;
50 }
51