1 /*
2 * Copyright (C) 2023 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 #include "identity_manager.h"
17
18 #include "hc_log.h"
19
20 /* in order to expand to uint16_t */
21 static const uint8_t KEY_TYPE_PAIRS[KEY_ALIAS_TYPE_END][KEY_TYPE_PAIR_LEN] = {
22 { 0x00, 0x00 }, /* ACCESSOR_PK */
23 { 0x00, 0x01 }, /* CONTROLLER_PK */
24 { 0x00, 0x02 }, /* ed25519 KEYPAIR */
25 { 0x00, 0x03 }, /* KEK, key encryption key, used only by DeviceAuthService */
26 { 0x00, 0x04 }, /* DEK, data encryption key, used only by upper apps */
27 { 0x00, 0x05 }, /* key tmp */
28 { 0x00, 0x06 }, /* PSK, preshared key index */
29 { 0x00, 0x07 }, /* AUTHTOKEN */
30 { 0x00, 0x08 } /* P2P_AUTH */
31 };
32
GetKeyTypePair(KeyAliasType keyAliasType)33 uint8_t *GetKeyTypePair(KeyAliasType keyAliasType)
34 {
35 return (uint8_t *)KEY_TYPE_PAIRS[keyAliasType];
36 }
37
GetAuthIdentityByType(AuthIdentityType type)38 const AuthIdentity *GetAuthIdentityByType(AuthIdentityType type)
39 {
40 switch (type) {
41 case AUTH_IDENTITY_TYPE_GROUP:
42 return GetGroupAuthIdentity();
43 case AUTH_IDENTITY_TYPE_PIN:
44 return GetPinAuthIdentity();
45 case AUTH_IDENTITY_TYPE_P2P:
46 return GetP2pAuthIdentity();
47 default:
48 LOGE("unknow AuthIdentityType: %d", type);
49 return NULL;
50 }
51 }
52
53 static const AuthIdentityManager g_identityManager = {
54 .getAuthIdentityByType = GetAuthIdentityByType,
55 .getCredentialOperator = GetCredentialOperator,
56 };
57
GetAuthIdentityManager(void)58 const AuthIdentityManager *GetAuthIdentityManager(void)
59 {
60 return &g_identityManager;
61 }
62