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 17 #pragma once 18 19 #include <android-base/logging.h> 20 #include <random> 21 22 namespace aidl::android::hardware::biometrics::fingerprint { 23 24 class FakeFingerprintEngine { 25 public: FakeFingerprintEngine()26 FakeFingerprintEngine() : mRandom(std::mt19937::default_seed) {} 27 generateChallengeImpl(ISessionCallback * cb)28 void generateChallengeImpl(ISessionCallback* cb) { 29 LOG(INFO) << "generateChallengeImpl"; 30 std::uniform_int_distribution<int64_t> dist; 31 auto challenge = dist(mRandom); 32 cb->onChallengeGenerated(challenge); 33 } 34 revokeChallengeImpl(ISessionCallback * cb,int64_t challenge)35 void revokeChallengeImpl(ISessionCallback* cb, int64_t challenge) { 36 LOG(INFO) << "revokeChallengeImpl"; 37 cb->onChallengeRevoked(challenge); 38 } 39 enrollImpl(ISessionCallback * cb,const keymaster::HardwareAuthToken & hat)40 void enrollImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& hat) { 41 LOG(INFO) << "enrollImpl"; 42 // Do proper HAT verification in the real implementation. 43 if (hat.mac.empty()) { 44 cb->onError(Error::UNABLE_TO_PROCESS, 0 /* vendorError */); 45 return; 46 } 47 cb->onEnrollmentProgress(0 /* enrollmentId */, 0 /* remaining */); 48 } 49 authenticateImpl(ISessionCallback * cb,int64_t)50 void authenticateImpl(ISessionCallback* cb, int64_t /* operationId */) { 51 LOG(INFO) << "authenticateImpl"; 52 cb->onAuthenticationSucceeded(0 /* enrollmentId */, {} /* hat */); 53 } 54 detectInteractionImpl(ISessionCallback * cb)55 void detectInteractionImpl(ISessionCallback* cb) { 56 LOG(INFO) << "detectInteractionImpl"; 57 cb->onInteractionDetected(); 58 } 59 enumerateEnrollmentsImpl(ISessionCallback * cb)60 void enumerateEnrollmentsImpl(ISessionCallback* cb) { 61 LOG(INFO) << "enumerateEnrollmentsImpl"; 62 cb->onEnrollmentsEnumerated({} /* enrollmentIds */); 63 } 64 removeEnrollmentsImpl(ISessionCallback * cb,const std::vector<int32_t> & enrollmentIds)65 void removeEnrollmentsImpl(ISessionCallback* cb, const std::vector<int32_t>& enrollmentIds) { 66 LOG(INFO) << "removeEnrollmentsImpl"; 67 cb->onEnrollmentsRemoved(enrollmentIds); 68 } 69 getAuthenticatorIdImpl(ISessionCallback * cb)70 void getAuthenticatorIdImpl(ISessionCallback* cb) { 71 LOG(INFO) << "getAuthenticatorIdImpl"; 72 cb->onAuthenticatorIdRetrieved(0 /* authenticatorId */); 73 } 74 invalidateAuthenticatorIdImpl(ISessionCallback * cb)75 void invalidateAuthenticatorIdImpl(ISessionCallback* cb) { 76 LOG(INFO) << "invalidateAuthenticatorIdImpl"; 77 cb->onAuthenticatorIdInvalidated(0 /* newAuthenticatorId */); 78 } 79 resetLockoutImpl(ISessionCallback * cb,const keymaster::HardwareAuthToken &)80 void resetLockoutImpl(ISessionCallback* cb, const keymaster::HardwareAuthToken& /*hat*/) { 81 LOG(INFO) << "resetLockoutImpl"; 82 cb->onLockoutCleared(); 83 } 84 85 std::mt19937 mRandom; 86 }; 87 88 } // namespace aidl::android::hardware::biometrics::fingerprint 89