• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _TC_NS_CLIENT_DRIVER_SUB_H_
33 #define _TC_NS_CLIENT_DRIVER_SUB_H_
34 #include <securec.h>
35 #include "tc_ns_client.h"
36 #include "teek_ns_client.h"
37 
38 #define CHECK_PATH_HASH_FAIL   0xff01
39 #define CHECK_SECLABEL_FAIL    0xff02
40 #define CHECK_CODE_HASH_FAIL   0xff03
41 #define ENTER_BYPASS_CHANNEL   0xff04
42 #define BUF_MAX_SIZE           1024
43 #define MAX_PATH_SIZE          512
44 #define SHA256_DIGEST_LENTH    32
45 
46 char *GetProcessPath(LosTaskCB *task, char *tpath, int pathLen);
47 int CalcProcessPathHash(const unsigned char *data,
48     unsigned long dataLen, unsigned char *digest, unsigned int digLen);
49 int PackCaCert(char *caCert, const char *path,
50     LosTaskCB *caTask, int uid);
51 TcNsService *TcFindServiceInDev(TcNsDevFile *dev,
52     const unsigned char *uuid, int uuidSize);
53 TcNsService *TcRefServiceInDev(TcNsDevFile *dev, const unsigned char *uuid,
54     int uuidSize, bool *isFull);
55 TcNsService *TcFindServiceFromAll(const unsigned char *uuid, uint32_t uuidLen);
56 int AddServiceToDev(TcNsDevFile *dev, TcNsService *service);
57 void DelServiceFromDev(TcNsDevFile *dev, TcNsService *service);
58 TcNsSession *TcFindSessionWithOwner(struct list_head *sessionList,
59     unsigned int sessionId, TcNsDevFile *devFile);
60 void DumpServicesStatus(const char *param);
61 errno_t InitContext(TcNsClientContext *context,
62     const unsigned char *uuid, const unsigned int uuidLen);
63 #ifdef SECURITY_AUTH_ENHANCE
64 int GenerateRandomData(uint8_t *data, uint32_t size);
65 bool IsValidEncryptionHead(const struct EncryptionHead *head, const uint8_t *data, uint32_t len);
66 int GenerateChallengeWord(uint8_t *challengeWord, uint32_t size);
67 int SetEncryptionHead(struct EncryptionHead *head, uint32_t len);
68 TcNsSession *TcFindSession2(unsigned int devFileId, const TcNsSmcCmd *cmd);
69 void CleanSessionSecureInformation(TcNsSession *session);
70 int GetSessionSecureParams(TcNsDevFile *devFile, TcNsClientContext *context, TcNsSession *session);
71 #endif
72 int CloseSession(TcNsDevFile *dev, TcNsSession *session, const unsigned char *uuid,
73     unsigned int uuidLen, unsigned int sessionId);
74 void KillSession(TcNsDevFile *dev, const unsigned char *uuid,
75     unsigned int uuidLen, unsigned int sessionId);
76 int TcNsServiceInit(const unsigned char *uuid, uint32_t uuidLen, TcNsService **newService);
77 uint32_t TcNsGetUid(void);
78 int GetPackNameLen(TcNsDevFile *devFile, const uint8_t *certBuffer,
79     unsigned int certBufferSize);
80 int GetPublicKeyLen(TcNsDevFile *devFile, const uint8_t *certBuffer,
81     unsigned int certBufferSize);
82 bool IsValidTaSize(const char *fileBuffer, unsigned int fileSize);
83 int TcNsNeedLoadImage(unsigned int fileId, const unsigned char *uuid,
84     unsigned int uuidLen);
85 int LoadTaImage(TcNsDevFile *devFile, TcNsClientContext *context);
86 void ReleaseFreeSession(TcNsDevFile *devFile, TcNsClientContext *context, TcNsSession *session);
87 void CloseSessionInServiceList(TcNsDevFile *dev, TcNsService *service, uint32_t i);
88 void CloseUnclosedSession(TcNsDevFile *dev, uint32_t i);
89 void DelDevNode(TcNsDevFile *dev);
90 int NsClientCloseTeecdNotAgent(TcNsDevFile *dev);
91 int TcNsLoadSecfile(TcNsDevFile *devFile, const void __user *argp);
92 #endif
93