• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     /**  Window mode type is none interruption dialog box. */
78     NONE_INTERRUPTION_DIALOG_BOX = 4
79 };
80 
81 /**
82  * @brief The mode for reusing unlock authentication result.
83  */
84 enum ReuseMode : uint32_t {
85     /** Authentication type relevant.The unlock authentication result can be reused only when the result is within
86      * valid duration as well as it comes from one of specified UserAuthTypes of the AuthParam. */
87     AUTH_TYPE_RELEVANT = 1,
88     /** Authentication type irrelevant.The unlock authentication result can be reused as long as the result is within
89      * valid duration. */
90     AUTH_TYPE_IRRELEVANT = 2,
91     /** Caller irrelevant authentication type relevant.The unlock authentication result can be reused only when the
92      * result is within valid duration as well as it comes from one of specified UserAuthTypes of the AuthParam. */
93     CALLER_IRRELEVANT_AUTH_TYPE_RELEVANT = 3,
94     /** Caller irrelevant authentication type irrelevant.The unlock authentication result can be reused as long as the
95      * result is within valid duration. */
96     CALLER_IRRELEVANT_AUTH_TYPE_IRRELEVANT = 4,
97 };
98 
99 /**
100  * @brief Reuse unlock authentication result.
101  */
102 struct ReuseUnlockResult {
103     /** Whether to reuse unlock result, ReuseUnlockResult is valid only when isReuse is true.*/
104     bool isReuse {false};
105     /** The mode for reusing unlock authentication result. */
106     ReuseMode reuseMode {AUTH_TYPE_IRRELEVANT};
107     /** The allowable reuse duration.The value of duration should be between 0 and MAX_ALLOWABLE_REUSE_DURATION. */
108     uint64_t reuseDuration {0};
109 };
110 
111 /**
112  * @brief Auth widget parameter.
113  */
114 struct WidgetParam {
115     /** Title of widget. */
116     std::string title;
117     /** The description text of navigation button. */
118     std::string navigationButtonText;
119     /** Full screen or not. */
120     WindowModeType windowMode;
121 };
122 
123 /**
124  * @brief Auth widget parameter.
125  */
126 struct WidgetAuthParam {
127     /** user id */
128     int32_t userId;
129     /** challenge value */
130     std::vector<uint8_t> challenge;
131     /** Credential type for authentication. */
132     std::vector<AuthType> authTypes;
133     /** Trust level of authentication result. */
134     AuthTrustLevel authTrustLevel;
135     /** Reuse unlock authentication result. */
136     ReuseUnlockResult reuseUnlockResult;
137 };
138 
139 /**
140  * @brief Executor property needed to get.
141  */
142 struct GetPropertyRequest {
143     /** Auth type supported by executor. */
144     AuthType authType {0};
145     /** The keys of attribute needed to get. */
146     std::vector<Attributes::AttributeKey> keys {};
147 };
148 
149 /**
150  * @brief Executor property needed to set.
151  */
152 struct SetPropertyRequest {
153     /** Auth type supported by executor. */
154     AuthType authType {0};
155     /**  The executor's property mode. */
156     PropertyMode mode {0};
157     /** The attributes needed to set. */
158     Attributes attrs {};
159 };
160 
161 /**
162  * @brief Global config type.
163  */
164 enum GlobalConfigType : int32_t {
165     /** Pin expired period, valid only for pin. */
166     PIN_EXPIRED_PERIOD = 1,
167     /** Enable specified authType capability. */
168     ENABLE_STATUS = 2,
169 };
170 
171 /**
172  * @brief Global config value.
173  */
174 union GlobalConfigValue {
175     /** Global config value of pin expired period.It's value should between 0 and 2^50.
176       * When pinExpiredPeriod <= 0, userAuth won't check pin expired period. */
177     int64_t pinExpiredPeriod;
178     /** Enable specified authType capability. */
179     bool enableStatus;
180 };
181 
182 /**
183  * @brief Global config param.
184  */
185 struct GlobalConfigParam {
186     /** Global config type. */
187     GlobalConfigType type;
188     /** Global config value. */
189     GlobalConfigValue value;
190     /** Specified userIds. GlobalConfigParam will be effect for all userspaces when the array is empty. */
191     std::vector<int32_t> userIds;
192     /** Specified authTypes. Should not empty. */
193     std::vector<AuthType> authTypes;
194 };
195 } // namespace UserAuth
196 } // namespace UserIam
197 } // namespace OHOS
198 #endif // USER_AUTH_CLIENT_DEFINES_H