1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef STORAGE_DAEMON_FBEX_MOCK_H 16 #define STORAGE_DAEMON_FBEX_MOCK_H 17 18 #include <gmock/gmock.h> 19 #include <memory> 20 21 #include "fbex.h" 22 23 namespace OHOS { 24 namespace StorageDaemon { 25 class IFbexMoc { 26 public: 27 virtual ~IFbexMoc() = default; 28 public: 29 virtual bool IsFBEXSupported() = 0; 30 virtual int InstallKeyToKernel(uint32_t userId, uint32_t type, KeyBlob &iv, 31 uint8_t flag, const KeyBlob &authToken) = 0; 32 virtual int UninstallOrLockUserKeyToKernel(uint32_t, uint32_t, uint8_t *, uint32_t, bool) = 0; 33 virtual int InstallDoubleDeKeyToKernel(UserIdToFbeStr &userIdToFbe, KeyBlob &iv, 34 uint8_t flag, const KeyBlob &authToken) = 0; 35 virtual int LockScreenToKernel(uint32_t userId) = 0; 36 virtual int UnlockScreenToKernel(uint32_t userId, uint32_t type, 37 uint8_t *iv, uint32_t size, const KeyBlob &authToken) = 0; 38 virtual int ReadESecretToKernel(UserIdToFbeStr &, uint32_t, KeyBlob &, const KeyBlob &, bool &) = 0; 39 virtual int WriteESecretToKernel(UserIdToFbeStr &, uint32_t, uint8_t *, uint32_t length) = 0; 40 virtual bool IsMspReady() = 0; 41 virtual int GetStatus() = 0; 42 virtual int InstallEL5KeyToKernel(uint32_t, uint32_t, uint8_t, bool &, bool &) = 0; 43 virtual int DeleteClassEPinCode(uint32_t userIdSingle, uint32_t userIdDouble) = 0; 44 virtual int ChangePinCodeClassE(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport) = 0; 45 virtual int UpdateClassEBackUp(uint32_t userIdSingle, uint32_t userIdDouble) = 0; 46 virtual int GenerateAppkey(UserIdToFbeStr &, uint32_t, std::unique_ptr<uint8_t[]> &, uint32_t) = 0; 47 virtual int LockUece(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport) = 0; 48 public: 49 static inline std::shared_ptr<IFbexMoc> fbexMoc = nullptr; 50 }; 51 52 class FbexMoc : public IFbexMoc { 53 public: 54 MOCK_METHOD0(IsFBEXSupported, bool()); 55 MOCK_METHOD5(InstallKeyToKernel, int(uint32_t userId, uint32_t type, KeyBlob &iv, 56 uint8_t flag, const KeyBlob &authToken)); 57 MOCK_METHOD5(UninstallOrLockUserKeyToKernel, int(uint32_t, uint32_t, uint8_t *, uint32_t, bool)); 58 MOCK_METHOD4(InstallDoubleDeKeyToKernel, int(UserIdToFbeStr &, KeyBlob &iv, 59 uint8_t flag, const KeyBlob &authToken)); 60 MOCK_METHOD1(LockScreenToKernel, int(uint32_t userId)); 61 MOCK_METHOD5(UnlockScreenToKernel, int(uint32_t userId, uint32_t type, 62 uint8_t *iv, uint32_t size, const KeyBlob &authToken)); 63 MOCK_METHOD5(ReadESecretToKernel, int(UserIdToFbeStr &, uint32_t, KeyBlob &, const KeyBlob &, bool &)); 64 MOCK_METHOD4(WriteESecretToKernel, int(UserIdToFbeStr &, uint32_t, uint8_t *, uint32_t length)); 65 MOCK_METHOD0(IsMspReady, bool()); 66 MOCK_METHOD0(GetStatus, int()); 67 MOCK_METHOD5(InstallEL5KeyToKernel, int(uint32_t, uint32_t, uint8_t, bool &, bool &)); 68 MOCK_METHOD2(DeleteClassEPinCode, int(uint32_t userIdSingle, uint32_t userIdDouble)); 69 MOCK_METHOD3(ChangePinCodeClassE, int(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport)); 70 MOCK_METHOD2(UpdateClassEBackUp, int(uint32_t userIdSingle, uint32_t userIdDouble)); 71 MOCK_METHOD4(GenerateAppkey, int(UserIdToFbeStr &, uint32_t, std::unique_ptr<uint8_t[]> &, uint32_t)); 72 MOCK_METHOD3(LockUece, int(uint32_t userIdSingle, uint32_t userIdDouble, bool &isFbeSupport)); 73 }; 74 } 75 } 76 #endif