1 /* 2 * Copyright (c) 2022-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 16 /** 17 * @file attributes.h 18 * 19 * @brief Attributes enum define. 20 * @since 3.1 21 * @version 3.2 22 */ 23 24 #ifndef IAM_ATTRIBUTES_H 25 #define IAM_ATTRIBUTES_H 26 27 #include <memory> 28 #include <string> 29 #include <vector> 30 31 namespace OHOS { 32 namespace UserIam { 33 namespace UserAuth { 34 class Attributes final { 35 public: 36 /** 37 * @brief The key to set attribute. 38 */ 39 enum AttributeKey : uint32_t { 40 /** Root tag, the value type is std::vector<uint8_t>. */ 41 ATTR_ROOT = 100000, 42 /** Result code, the value type is int32_t. */ 43 ATTR_RESULT_CODE = 100001, 44 /** Signature, the value type is std::vector<uint8_t>. */ 45 ATTR_SIGNATURE = 100004, 46 /** Identify mode, the value type is uint32_t. */ 47 ATTR_IDENTIFY_MODE = 100005, 48 /** Template ID, the value type is uint64_t. */ 49 ATTR_TEMPLATE_ID = 100006, 50 /** Template ID list, the value type is std::vector<uint64_t>. */ 51 ATTR_TEMPLATE_ID_LIST = 100007, 52 /** Attribute error count, the value type is int32_t. */ 53 ATTR_ERROR_COUNT = 100008, 54 /** Remain time, the value type is int32_t. */ 55 ATTR_REMAIN_TIMES = 100009, 56 ATTR_REMAIN_ATTEMPTS = ATTR_REMAIN_TIMES, 57 /** Freezing time, the value type is int32_t. */ 58 ATTR_FREEZING_TIME = 100010, 59 ATTR_LOCKOUT_DURATION = ATTR_FREEZING_TIME, 60 /** Session ID, the value type is uint64_t. */ 61 ATTR_SESSION_ID = 100014, 62 /** Caller package name, the value type is string. */ 63 ATTR_CALLER_NAME = 100015, 64 /** Schedule version, the value type is uint32_t. */ 65 ATTR_SCHEDULE_VERSION = 100016, 66 /** Schedule ID, the value type is uint64_t. */ 67 ATTR_SCHEDULE_ID = 100017, 68 /** Locked templates, the value type is std::vector<uint64_t>. */ 69 ATTR_LOCKED_TEMPLATES = 100018, 70 /** Unlocked templates, the value type is std::vector<uint64_t>. */ 71 ATTR_UNLOCKED_TEMPLATES = 100019, 72 /** Data, the value type is std::vector<uint8_t>. */ 73 ATTR_DATA = 100020, 74 /** Pin subtype, the value type is int32_t. */ 75 ATTR_PIN_SUB_TYPE = 100021, 76 /** Schedule mode, the value type is int32_t. */ 77 ATTR_SCHEDULE_MODE = 100022, 78 /** Property mode, the value type is uint32_t. */ 79 ATTR_PROPERTY_MODE = 100023, 80 /** Authenticate type, the value type is int32_t. */ 81 ATTR_AUTH_TYPE = 100024, 82 /** Credential ID, the value type is uint64_t. */ 83 ATTR_CREDENTIAL_ID = 100025, 84 /** Caller UID, the value type is uint64_t. */ 85 ATTR_CALLER_UID = 100027, 86 /** Tag of result, the value type is std::vector<uint8_t>. */ 87 ATTR_RESULT = 100028, 88 /** Capability level, the value type is uint64_t. */ 89 ATTR_CAPABILITY_LEVEL = 100029, 90 /** Algorithm information, the value type is uint64_t. */ 91 ATTR_ALGORITHM_INFO = 100030, 92 /** Timer stamp, the value type is uint64_t. */ 93 ATTR_TIME_STAMP = 100031, 94 /** Root secret, the value type is std::vector<uint8_t>. */ 95 ATTR_ROOT_SECRET = 100032, 96 /** Auth token, the value type is std::vector<uint8_t>. */ 97 ATTR_AUTH_TOKEN = 100033, 98 /** Security user ID return when add pin credential, the value type is uint64_t. */ 99 ATTR_SEC_USER_ID = 100034, 100 /** Enroll progress, the value type is string. */ 101 ATTR_ENROLL_PROGRESS = 100035, 102 /** Sensor info, the value type is string. */ 103 ATTR_SENSOR_INFO = 100036, 104 /** Key list, the value type is std::vector<uint32_t>. */ 105 ATTR_KEY_LIST = 100037, 106 /** End after first fail, the value type is boolean. */ 107 ATTR_END_AFTER_FIRST_FAIL = 100038, 108 /** Tip info, the value type is int32_t. */ 109 ATTR_TIP_INFO = 100039, 110 /** Old root secret, the value type is std::vector<uint8_t>. */ 111 ATTR_OLD_ROOT_SECRET = 100040, 112 /** Old credential ID, the value type is uint64_t. */ 113 ATTR_OLD_CREDENTIAL_ID = 100041, 114 /** Source role, the value type is int32_t. */ 115 ATTR_SRC_ROLE = 100042, 116 /** User ID, the value type is int32_t. */ 117 ATTR_USER_ID = 100043, 118 /** Extra information, the value type is std::vector<uint8_t>. */ 119 ATTR_EXTRA_INFO = 100044, 120 /** Executor ID, the value type is uint64_t. */ 121 ATTR_EXECUTOR_INDEX = 100045, 122 /** Executor sensor hint, the value type is uint32_t. */ 123 ATTR_EXECUTOR_SENSOR_HINT = 100046, 124 /** Executor matcher, the value type is uint32_t. */ 125 ATTR_EXECUTOR_MATCHER = 100047, 126 /** Access token ID, the value type is uint32_t. */ 127 ATTR_ACCESS_TOKEN_ID = 100048, 128 /** Template change reason, the value type is string. */ 129 ATTR_TEMPLATE_CHANGE_REASON = 100049, 130 /** Credential digest, the value type is uint16_t. */ 131 ATTR_CREDENTIAL_DIGEST = 100050, 132 /** Credential count, the value type is uint16_t. */ 133 ATTR_CREDENTIAL_COUNT = 100051, 134 /** Message sequence number, the value type is uint32_t. */ 135 ATTR_MSG_SEQ_NUM = 100052, 136 /** Reply message, the value type is bool. */ 137 ATTR_MSG_ACK = 100053, 138 /** Message source UDID, the value type is string. */ 139 ATTR_MSG_SRC_UDID = 100054, 140 /** Source of message, the value type is string. */ 141 ATTR_MSG_SRC_END_POINT = 100055, 142 /** Destination of message, the value type is string. */ 143 ATTR_MSG_DEST_END_POINT = 100056, 144 /** Connection name, the value type is string. */ 145 ATTR_CONNECTION_NAME = 100057, 146 /** Message version, the value type is uint32_t. */ 147 ATTR_MSG_VERSION = 100058, 148 /** Message type, the value type is int32_t. */ 149 ATTR_MSG_TYPE = 100059, 150 /** Message reply sequence number, the value type is uint32_t. */ 151 ATTR_MSG_REPLY_SEQ_NUM = 100060, 152 /** Context ID, the value type is uint64_t. */ 153 ATTR_CONTEXT_ID = 100061, 154 /** Collector info, the value type is std::vector<uint8_t>. */ 155 ATTR_COLLECTOR_INFO = 100062, 156 /** Executor role, the value type is int32_t. */ 157 ATTR_EXECUTOR_ROLE = 100063, 158 /** Schedule data, the value type is std::vector<uint8_t>. */ 159 ATTR_SCHEDULE_DATA = 100064, 160 /** Signed authentication result, the value type is std::vector<uint8_t>. */ 161 ATTR_SIGNED_AUTH_RESULT = 100065, 162 /** Destination role, the value type is int32_t. */ 163 ATTR_DEST_ROLE = 100066, 164 /** Local UDID, the value type is string. */ 165 ATTR_LOCAL_UDID = 100067, 166 /** Peer UDID, the value type is string. */ 167 ATTR_PEER_UDID = 100068, 168 /** Public key, the value type is std::vector<uint8_t>. */ 169 ATTR_PUBLIC_KEY = 100069, 170 /** Executor info list, the value type is std::vector<uint8_t>. */ 171 ATTR_EXECUTOR_REGISTER_INFO_LIST = 100070, 172 /** Executor secure level, the value type is int32_t. */ 173 ATTR_ESL = 100071, 174 /** Challenge, the value type is std::vector<uint8_t>. */ 175 ATTR_CHALLENGE = 100072, 176 /** Remote executor info, the value type is std::vector<uint8_t>. */ 177 ATTR_REMOTE_EXECUTOR_INFO = 100073, 178 /** Authentication types, the value type is std::vector<int32_t>. */ 179 ATTR_AUTH_TYPES = 100074, 180 /** Authentication trust level, the value type is int32_t. */ 181 ATTR_AUTH_TRUST_LEVEL = 100075, 182 /** Device UDID, the value type is string. */ 183 ATTR_DEVICE_UDID = 100080, 184 /** Collector network id. */ 185 ATTR_COLLECTOR_NETWORK_ID = 100081, 186 /** Collector token id. */ 187 ATTR_COLLECTOR_TOKEN_ID = 100082, 188 /** Pin expired info, the value type is int64_t and it's max value is 2^50. */ 189 ATTR_PIN_EXPIRED_INFO = 100083, 190 /** next fail lockout duration, the value type is int32_t. */ 191 ATTR_NEXT_FAIL_LOCKOUT_DURATION = 100084, 192 /** caller type, the value type is int32_t. */ 193 ATTR_CALLER_TYPE = 100085, 194 }; 195 196 /** 197 * @brief Default constructor. 198 */ 199 Attributes(); 200 201 /** 202 * @brief Overload constructor. 203 * 204 * This constructor prohibits implicit type conversion of input parameters. 205 * 206 * @param raw The value to be passed in when defining Attribute. 207 */ 208 explicit Attributes(const std::vector<uint8_t> &raw); 209 210 /** 211 * @brief Overload constructor. 212 * 213 * This constructor is used to define constant Attribute type. 214 * 215 * @param other The value to be passed in when defining Attribute. 216 */ 217 Attributes(const Attributes &other) = delete; 218 219 /** 220 * @brief Overload operator. 221 * 222 * @param other The value to be compared. 223 */ 224 Attributes &operator=(const Attributes &other) = delete; 225 226 /** 227 * @brief Overload constructor. 228 * 229 * @param other The value to be passed in when defining Attribute. 230 */ 231 Attributes(Attributes &&other) noexcept; 232 233 /** 234 * @brief Overload operator. 235 * 236 * @param other The value to be compared. 237 */ 238 Attributes &operator=(Attributes &&other) noexcept; 239 240 /** 241 * @brief Deconstructor. 242 */ 243 virtual ~Attributes(); 244 245 /** 246 * @brief Set bool value. 247 * 248 * @param key The attribute key. 249 * @param value The bool value. 250 * @return Return success or not(true:success; false:failed). 251 */ 252 bool SetBoolValue(AttributeKey key, bool value); 253 254 /** 255 * @brief Set uint64 value. 256 * 257 * @param key The attribute key. 258 * @param value The uint64_t value. 259 * @return Return success or not(true:success; false:failed). 260 */ 261 bool SetUint64Value(AttributeKey key, uint64_t value); 262 263 /** 264 * @brief Set uint32_t value. 265 * 266 * @param key The attribute key. 267 * @param value The uint32_t value. 268 * @return Return success or not(true:success; false:failed). 269 */ 270 bool SetUint32Value(AttributeKey key, uint32_t value); 271 272 /** 273 * @brief Set uint16_t value. 274 * 275 * @param key The attribute key. 276 * @param value The uint16_t value. 277 * @return Return success or not(true:success; false:failed). 278 */ 279 bool SetUint16Value(AttributeKey key, uint16_t value); 280 281 /** 282 * @brief Set uint8_t value. 283 * 284 * @param key The attribute key. 285 * @param value The uint8_t value. 286 * @return Return success or not(true:success; false:failed). 287 */ 288 bool SetUint8Value(AttributeKey key, uint8_t value); 289 290 /** 291 * @brief Set int32_t value. 292 * 293 * @param key The attribute key. 294 * @param value The int32_t value. 295 * @return Return success or not(true:success; false:failed). 296 */ 297 bool SetInt32Value(AttributeKey key, int32_t value); 298 299 /** 300 * @brief Set int64_t value. 301 * 302 * @param key The attribute key. 303 * @param value The int64_t value. 304 * @return Return success or not(true:success; false:failed). 305 */ 306 bool SetInt64Value(AttributeKey key, int64_t value); 307 308 /** 309 * @brief Set string value. 310 * 311 * @param key The attribute key. 312 * @param value The string. 313 * @return Return success or not(true:success; false:failed). 314 */ 315 bool SetStringValue(AttributeKey key, const std::string &value); 316 317 /** 318 * @brief Set Attributes value. 319 * 320 * @param key The attribute key. 321 * @param value The attributes type value. 322 * @return Return success or not(true:success; false:failed). 323 */ 324 bool SetAttributesValue(AttributeKey key, const Attributes &value); 325 bool SetAttributesArrayValue(AttributeKey key, const std::vector<Attributes> &array); 326 327 /** 328 * @brief Set vector<uint64_t> value. 329 * 330 * @param key The attribute key. 331 * @param value The vector<uint64_t> value. 332 * @return Return success or not(true:success; false:failed). 333 */ 334 bool SetUint64ArrayValue(AttributeKey key, const std::vector<uint64_t> &value); 335 336 /** 337 * @brief Set vector<uint32_t> value. 338 * 339 * @param key The attribute key. 340 * @param value The vector<uint32_t> value. 341 * @return Return success or not(true:success; false:failed). 342 */ 343 bool SetUint32ArrayValue(AttributeKey key, const std::vector<uint32_t> &value); 344 345 /** 346 * @brief Set vector<uint32_t> value. 347 * 348 * @param key The attribute key. 349 * @param value The vector<uint32_t> value. 350 * @return Return success or not(true:success; false:failed). 351 */ 352 bool SetInt32ArrayValue(AttributeKey key, const std::vector<int32_t> &value); 353 354 /** 355 * @brief Set vector<uint16_t> value. 356 * 357 * @param key The attribute key. 358 * @param value The vector<uint16_t> value. 359 * @return Return success or not(true:success; false:failed). 360 */ 361 bool SetUint16ArrayValue(AttributeKey key, const std::vector<uint16_t> &value); 362 363 /** 364 * @brief Set vector<uint8_t> value. 365 * 366 * @param key The attribute key. 367 * @param value The vector<uint8_t> value. 368 * @return Return success or not(true:success; false:failed). 369 */ 370 bool SetUint8ArrayValue(AttributeKey key, const std::vector<uint8_t> &value); 371 372 /** 373 * @brief Get bool value. 374 * 375 * @param key The attribute key. 376 * @param value Return bool value corresponding to key. 377 * @return Return success or not(true:success; false:failed). 378 */ 379 bool GetBoolValue(AttributeKey key, bool &value) const; 380 381 /** 382 * @brief Get uint64_t value. 383 * 384 * @param key The attribute key. 385 * @param value Return uint64_t value corresponding to key. 386 * @return Return success or not(true:success; false:failed). 387 */ 388 bool GetUint64Value(AttributeKey key, uint64_t &value) const; 389 390 /** 391 * @brief Get uint32_t value. 392 * 393 * @param key The attribute key. 394 * @param value Return uint32_t value corresponding to key. 395 * @return Return success or not(true:success; false:failed). 396 */ 397 bool GetUint32Value(AttributeKey key, uint32_t &value) const; 398 399 /** 400 * @brief Get uint16_t value. 401 * 402 * @param key The attribute key. 403 * @param value Return uint16_t value corresponding to key. 404 * @return Return success or not(true:success; false:failed). 405 */ 406 bool GetUint16Value(AttributeKey key, uint16_t &value) const; 407 408 /** 409 * @brief Get uint8_t value. 410 * 411 * @param key The attribute key. 412 * @param value Return uint8_t value corresponding to key. 413 * @return Return success or not(true:success; false:failed). 414 */ 415 bool GetUint8Value(AttributeKey key, uint8_t &value) const; 416 417 /** 418 * @brief Get int32_t value. 419 * 420 * @param key The attribute key. 421 * @param value Return int32_t value corresponding to key. 422 * @return Return success or not(true:success; false:failed). 423 */ 424 bool GetInt32Value(AttributeKey key, int32_t &value) const; 425 426 /** 427 * @brief Get int64_t value. 428 * 429 * @param key The attribute key. 430 * @param value Return int64_t value corresponding to key. 431 * @return Return success or not(true:success; false:failed). 432 */ 433 bool GetInt64Value(AttributeKey key, int64_t &value) const; 434 435 /** 436 * @brief Get string value. 437 * 438 * @param key The attribute key. 439 * @param value Return string corresponding to key. 440 * @return Return success or not(true:success; false:failed). 441 */ 442 bool GetStringValue(AttributeKey key, std::string &value) const; 443 444 /** 445 * @brief Get vector<uint64_t> value. 446 * 447 * @param key The attribute key. 448 * @param value Return vector<uint64_t> value corresponding to key. 449 * @return Return success or not(true:success; false:failed). 450 */ 451 bool GetUint64ArrayValue(AttributeKey key, std::vector<uint64_t> &value) const; 452 453 /** 454 * @brief Get vector<uint32_t> value. 455 * 456 * @param key The attribute key. 457 * @param value Return vector<uint32_t> value corresponding to key. 458 * @return Return success or not(true:success; false:failed). 459 */ 460 bool GetUint32ArrayValue(AttributeKey key, std::vector<uint32_t> &value) const; 461 462 /** 463 * @brief Get vector<uint32_t> value. 464 * 465 * @param key The attribute key. 466 * @param value Return vector<uint32_t> value corresponding to key. 467 * @return Return success or not(true:success; false:failed). 468 */ 469 bool GetInt32ArrayValue(AttributeKey key, std::vector<int32_t> &value) const; 470 471 /** 472 * @brief Get vector<uint16_t> value. 473 * 474 * @param key The attribute key. 475 * @param value Return vector<uint16_t> value corresponding to key. 476 * @return Return success or not(true:success; false:failed). 477 */ 478 bool GetUint16ArrayValue(AttributeKey key, std::vector<uint16_t> &value) const; 479 480 /** 481 * @brief Get vector<uint8_t> value. 482 * 483 * @param key The attribute key. 484 * @param value Return vector<uint8_t> value corresponding to key. 485 * @return Return success or not(true:success; false:failed). 486 */ 487 bool GetUint8ArrayValue(AttributeKey key, std::vector<uint8_t> &value) const; 488 489 /** 490 * @brief Get Attributes value. 491 * 492 * @param key The attribute key. 493 * @param value Return Attributes value corresponding to key. 494 * @return Return success or not(true:success; false:failed). 495 */ 496 bool GetAttributesValue(AttributeKey key, Attributes &value) const; 497 498 bool GetAttributesArrayValue(AttributeKey key, std::vector<Attributes> &array) const; 499 500 /** 501 * @brief Serialize the Attribute object. 502 * 503 * @return Return serialized Attribute object. 504 */ 505 std::vector<uint8_t> Serialize() const; 506 507 /** 508 * @brief Get all keys of Attribute. 509 * 510 * @return Return all keys of Attribute. 511 */ 512 std::vector<AttributeKey> GetKeys() const; 513 514 private: 515 class Impl; 516 std::unique_ptr<Impl> impl_; 517 }; 518 } // namespace UserAuth 519 } // namespace UserIam 520 } // namespace OHOS 521 522 #endif // IAM_ATTRIBUTES_H 523