1 /*
2 * Copyright (c) 2020 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 "hal_token.h"
17 #include "ohos_errno.h"
18 #include <stdlib.h>
19 #include <sys/types.h>
20 #include <unistd.h>
21
OEMReadToken(char * token,unsigned int len)22 static int OEMReadToken(char *token, unsigned int len)
23 {
24 // OEM need add here, read token from device
25 return EC_SUCCESS;
26 }
27
OEMWriteToken(const char * token,unsigned int len)28 static int OEMWriteToken(const char *token, unsigned int len)
29 {
30 // OEM need add here, write token to device
31 return EC_SUCCESS;
32 }
33
OEMGetAcKey(char * acKey,unsigned int len)34 static int OEMGetAcKey(char *acKey, unsigned int len)
35 {
36 // OEM need add here, get AcKey
37 return EC_SUCCESS;
38 }
39
OEMGetProdId(char * productId,unsigned int len)40 static int OEMGetProdId(char *productId, unsigned int len)
41 {
42 // OEM need add here, get ProdId
43 return EC_SUCCESS;
44 }
45
OEMGetProdKey(char * productKey,unsigned int len)46 static int OEMGetProdKey(char *productKey, unsigned int len)
47 {
48 // OEM need add here, get ProdKey
49 return EC_SUCCESS;
50 }
51
UidVerify(void)52 static int UidVerify(void)
53 {
54 uid_t uid;
55
56 uid = getuid();
57 if (uid >= KIT_FRAMEWORK_UID_MAX) {
58 return EC_FAILURE;
59 }
60 return EC_SUCCESS;
61 }
62
HalReadToken(char * token,unsigned int len)63 int HalReadToken(char *token, unsigned int len)
64 {
65 if (token == NULL) {
66 return EC_FAILURE;
67 }
68
69 if (UidVerify()) {
70 return EC_FAILURE;
71 }
72
73 return OEMReadToken(token, len);
74 }
75
HalWriteToken(const char * token,unsigned int len)76 int HalWriteToken(const char *token, unsigned int len)
77 {
78 if (token == NULL) {
79 return EC_FAILURE;
80 }
81
82 if (UidVerify()) {
83 return EC_FAILURE;
84 }
85
86 return OEMWriteToken(token, len);
87 }
88
HalGetAcKey(char * acKey,unsigned int len)89 int HalGetAcKey(char *acKey, unsigned int len)
90 {
91 if (acKey == NULL) {
92 return EC_FAILURE;
93 }
94
95 if (UidVerify()) {
96 return EC_FAILURE;
97 }
98
99 return OEMGetAcKey(acKey, len);
100 }
101
HalGetProdId(char * productId,unsigned int len)102 int HalGetProdId(char *productId, unsigned int len)
103 {
104 if (productId == NULL) {
105 return EC_FAILURE;
106 }
107
108 return OEMGetProdId(productId, len);
109 }
110
HalGetProdKey(char * productKey,unsigned int len)111 int HalGetProdKey(char *productKey, unsigned int len)
112 {
113 if (productKey == NULL) {
114 return EC_FAILURE;
115 }
116
117 if (UidVerify()) {
118 return EC_FAILURE;
119 }
120
121 return OEMGetProdKey(productKey, len);
122 }