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 /** 17 * @file co_auth_client_defines.h 18 * 19 * @brief Type definitions used by user auth client. 20 * @since 3.1 21 * @version 3.2 22 */ 23 24 #ifndef USER_AUTH_CLIENT_DEFINES_H 25 #define USER_AUTH_CLIENT_DEFINES_H 26 27 #include <vector> 28 29 #include "attributes.h" 30 #include "iam_common_defines.h" 31 32 namespace OHOS { 33 namespace UserIam { 34 namespace UserAuth { 35 const uint64_t MAX_ALLOWABLE_REUSE_DURATION = 5 * 60 * 1000; 36 37 /** 38 * @brief Remote auth parameter. 39 */ 40 struct RemoteAuthParam { 41 /** verifier network id */ 42 std::optional<std::string> verifierNetworkId; 43 /** collector network id */ 44 std::optional<std::string> collectorNetworkId; 45 /** collector token id */ 46 std::optional<uint32_t> collectorTokenId; 47 }; 48 49 /** 50 * @brief Auth parameter. 51 */ 52 struct AuthParam { 53 /** user id */ 54 int32_t userId; 55 /** challenge value */ 56 std::vector<uint8_t> challenge; 57 /** Credential type for authentication. */ 58 AuthType authType; 59 /** Trust level of authentication result. */ 60 AuthTrustLevel authTrustLevel; 61 /** Auth intention. */ 62 AuthIntent authIntent; 63 /** Remote auth parameter. */ 64 std::optional<RemoteAuthParam> remoteAuthParam; 65 }; 66 67 /** 68 * @brief Window mode type for user authentication widget. 69 */ 70 enum WindowModeType : int32_t { 71 /** Window mode type is dialog box. */ 72 DIALOG_BOX = 1, 73 /** Window mode type is full screen. */ 74 FULLSCREEN = 2, 75 /** Window mode type is not set */ 76 UNKNOWN_WINDOW_MODE = 3, 77 }; 78 79 /** 80 * @brief The mode for reusing unlock authentication result. 81 */ 82 enum ReuseMode : uint32_t { 83 /** Authentication type relevant.The unlock authentication result can be reused only when the result is within 84 * valid duration as well as it comes from one of specified UserAuthTypes of the AuthParam. */ 85 AUTH_TYPE_RELEVANT = 1, 86 /** Authentication type irrelevant.The unlock authentication result can be reused as long as the result is within 87 * valid duration. */ 88 AUTH_TYPE_IRRELEVANT = 2, 89 }; 90 91 /** 92 * @brief Reuse unlock authentication result. 93 */ 94 struct ReuseUnlockResult { 95 /** Whether to reuse unlock result, ReuseUnlockResult is valid only when isReuse is true.*/ 96 bool isReuse {false}; 97 /** The mode for reusing unlock authentication result. */ 98 ReuseMode reuseMode {AUTH_TYPE_IRRELEVANT}; 99 /** The allowable reuse duration.The value of duration should be between 0 and MAX_ALLOWABLE_REUSE_DURATION. */ 100 uint64_t reuseDuration {0}; 101 }; 102 103 /** 104 * @brief Auth widget parameter. 105 */ 106 struct WidgetParam { 107 /** Title of widget. */ 108 std::string title; 109 /** The description text of navigation button. */ 110 std::string navigationButtonText; 111 /** Full screen or not. */ 112 WindowModeType windowMode; 113 }; 114 115 /** 116 * @brief Auth widget parameter. 117 */ 118 struct WidgetAuthParam { 119 /** user id */ 120 int32_t userId; 121 /** challenge value */ 122 std::vector<uint8_t> challenge; 123 /** Credential type for authentication. */ 124 std::vector<AuthType> authTypes; 125 /** Trust level of authentication result. */ 126 AuthTrustLevel authTrustLevel; 127 /** Reuse unlock authentication result. */ 128 ReuseUnlockResult reuseUnlockResult; 129 }; 130 131 /** 132 * @brief Executor property needed to get. 133 */ 134 struct GetPropertyRequest { 135 /** Auth type supported by executor. */ 136 AuthType authType {0}; 137 /** The keys of attribute needed to get. */ 138 std::vector<Attributes::AttributeKey> keys {}; 139 }; 140 141 /** 142 * @brief Executor property needed to set. 143 */ 144 struct SetPropertyRequest { 145 /** Auth type supported by executor. */ 146 AuthType authType {0}; 147 /** The executor's property mode. */ 148 PropertyMode mode {0}; 149 /** The attributes needed to set. */ 150 Attributes attrs {}; 151 }; 152 153 /** 154 * @brief Global config type. 155 */ 156 enum GlobalConfigType : int32_t { 157 /** Pin expired period */ 158 PIN_EXPIRED_PERIOD = 1, 159 }; 160 161 /** 162 * @brief Global config value. 163 */ 164 union GlobalConfigValue { 165 /** Global config value of pin expired period.It's value should between 0 and 2^50. 166 * When pinExpiredPeriod <= 0, userAuth won't check pin expired period */ 167 int64_t pinExpiredPeriod; 168 }; 169 170 /** 171 * @brief Global config param. 172 */ 173 struct GlobalConfigParam { 174 /** Global config type. */ 175 GlobalConfigType type; 176 /** Global config value. */ 177 GlobalConfigValue value; 178 }; 179 } // namespace UserAuth 180 } // namespace UserIam 181 } // namespace OHOS 182 #endif // USER_AUTH_CLIENT_DEFINES_H