117fd14ceSopenharmony_ci/* 217fd14ceSopenharmony_ci * Copyright (C) 2023 Huawei Device Co., Ltd. 317fd14ceSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 417fd14ceSopenharmony_ci * you may not use this file except in compliance with the License. 517fd14ceSopenharmony_ci * You may obtain a copy of the License at 617fd14ceSopenharmony_ci * 717fd14ceSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 817fd14ceSopenharmony_ci * 917fd14ceSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1017fd14ceSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1117fd14ceSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1217fd14ceSopenharmony_ci * See the License for the specific language governing permissions and 1317fd14ceSopenharmony_ci * limitations under the License. 1417fd14ceSopenharmony_ci */ 1517fd14ceSopenharmony_ci 1617fd14ceSopenharmony_ci#include "identity_manager.h" 1717fd14ceSopenharmony_ci 1817fd14ceSopenharmony_ci#include "hc_log.h" 1917fd14ceSopenharmony_ci 2017fd14ceSopenharmony_ci/* in order to expand to uint16_t */ 2117fd14ceSopenharmony_cistatic const uint8_t KEY_TYPE_PAIRS[KEY_ALIAS_TYPE_END][KEY_TYPE_PAIR_LEN] = { 2217fd14ceSopenharmony_ci { 0x00, 0x00 }, /* ACCESSOR_PK */ 2317fd14ceSopenharmony_ci { 0x00, 0x01 }, /* CONTROLLER_PK */ 2417fd14ceSopenharmony_ci { 0x00, 0x02 }, /* ed25519 KEYPAIR */ 2517fd14ceSopenharmony_ci { 0x00, 0x03 }, /* KEK, key encryption key, used only by DeviceAuthService */ 2617fd14ceSopenharmony_ci { 0x00, 0x04 }, /* DEK, data encryption key, used only by upper apps */ 2717fd14ceSopenharmony_ci { 0x00, 0x05 }, /* key tmp */ 2817fd14ceSopenharmony_ci { 0x00, 0x06 }, /* PSK, preshared key index */ 2917fd14ceSopenharmony_ci { 0x00, 0x07 }, /* AUTHTOKEN */ 3017fd14ceSopenharmony_ci { 0x00, 0x08 } /* P2P_AUTH */ 3117fd14ceSopenharmony_ci}; 3217fd14ceSopenharmony_ci 3317fd14ceSopenharmony_ciuint8_t *GetKeyTypePair(KeyAliasType keyAliasType) 3417fd14ceSopenharmony_ci{ 3517fd14ceSopenharmony_ci return (uint8_t *)KEY_TYPE_PAIRS[keyAliasType]; 3617fd14ceSopenharmony_ci} 3717fd14ceSopenharmony_ci 3817fd14ceSopenharmony_ciconst AuthIdentity *GetAuthIdentityByType(AuthIdentityType type) 3917fd14ceSopenharmony_ci{ 4017fd14ceSopenharmony_ci switch (type) { 4117fd14ceSopenharmony_ci case AUTH_IDENTITY_TYPE_GROUP: 4217fd14ceSopenharmony_ci return GetGroupAuthIdentity(); 4317fd14ceSopenharmony_ci case AUTH_IDENTITY_TYPE_PIN: 4417fd14ceSopenharmony_ci return GetPinAuthIdentity(); 4517fd14ceSopenharmony_ci case AUTH_IDENTITY_TYPE_P2P: 4617fd14ceSopenharmony_ci return GetP2pAuthIdentity(); 4717fd14ceSopenharmony_ci default: 4817fd14ceSopenharmony_ci LOGE("unknow AuthIdentityType: %d", type); 4917fd14ceSopenharmony_ci return NULL; 5017fd14ceSopenharmony_ci } 5117fd14ceSopenharmony_ci} 5217fd14ceSopenharmony_ci 5317fd14ceSopenharmony_cistatic const AuthIdentityManager g_identityManager = { 5417fd14ceSopenharmony_ci .getAuthIdentityByType = GetAuthIdentityByType, 5517fd14ceSopenharmony_ci .getCredentialOperator = GetCredentialOperator, 5617fd14ceSopenharmony_ci}; 5717fd14ceSopenharmony_ci 5817fd14ceSopenharmony_ciconst AuthIdentityManager *GetAuthIdentityManager(void) 5917fd14ceSopenharmony_ci{ 6017fd14ceSopenharmony_ci return &g_identityManager; 6117fd14ceSopenharmony_ci} 62