1 /* 2 * Copyright (c) 2022 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 16 #ifndef PINAUTH_CONTROLLER_H 17 #define PINAUTH_CONTROLLER_H 18 19 #include <cstdint> 20 #include <mutex> 21 #include <vector> 22 #include "auth_attributes.h" 23 #include "i_inputer_data_stub.h" 24 #include "iexecutor_messenger.h" 25 #include "if_system_ability_manager.h" 26 #include "nocopyable.h" 27 #include "pin_auth.h" 28 #include "pinauth_stub.h" 29 30 namespace OHOS { 31 namespace UserIAM { 32 namespace PinAuth { 33 const uint32_t DEVICE_UUID_LENGTH = 65; 34 const uint32_t SHA256_LENGTH = 256; 35 const uint32_t RANDOM_LENGTH = 32; 36 void NewSalt(std::vector<uint8_t> &saltV); 37 38 class PinAuthController : public IInputerDataStub { 39 public: 40 DISALLOW_COPY_AND_MOVE(PinAuthController); 41 PinAuthController(); 42 ~PinAuthController() override; 43 bool OnStart(std::vector<uint8_t> &salt); 44 void OnSetData(int32_t authSubType, std::vector<uint8_t> data) override; 45 void SaveParam(uint64_t scheduleId, std::shared_ptr<PinAuth> pin, 46 std::shared_ptr<AuthResPool::AuthAttributes> attributes); 47 void SetMessenger(const sptr<AuthResPool::IExecutorMessenger> &messenger); 48 void Cancel(); 49 50 private: 51 std::shared_ptr<PinAuth> pin_; 52 uint32_t command_ = 0; 53 uint64_t templateId_ = 0; 54 uint64_t scheduleId_ = 0; 55 std::vector<uint8_t> salt_; 56 std::shared_ptr<AuthResPool::AuthAttributes> attributes_; 57 sptr<AuthResPool::IExecutorMessenger> messenger_; 58 std::mutex mutex_; 59 bool canceled = false; 60 }; 61 } // namespace PinAuth 62 } // namespace UserIAM 63 } // namespace OHOS 64 65 #endif // PINAUTH_CONTROLLER_H 66