• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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 #ifndef ATTEST_CHANNEL_H
16 #define ATTEST_CHANNEL_H
17 
18 #include <stdint.h>
19 #include <stdlib.h>
20 #include <stdbool.h>
21 
22 #include "mbedtls/ctr_drbg.h"
23 #include "mbedtls/debug.h"
24 #include "mbedtls/entropy.h"
25 #include "mbedtls/error.h"
26 #include "mbedtls/net_sockets.h"
27 #include "mbedtls/ssl.h"
28 #include "mbedtls/timing.h"
29 #include "mbedtls/x509.h"
30 #include "mbedtls/x509_crt.h"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #define MAX_HOST_NAME_LEN       64
37 #define MAX_PORT_LEN            5
38 #define MAX_SEED_LEN            16
39 
40 typedef struct {
41     mbedtls_entropy_context   entropyCtx;
42     mbedtls_ctr_drbg_context  ctrDrbgCtx;
43     mbedtls_net_context       netCtx;
44     mbedtls_ssl_context       sslCtx;
45     mbedtls_ssl_config        sslConf;
46     mbedtls_x509_crt          caCert;
47 } TLSConfig;
48 
49 typedef struct {
50     char        hostName[MAX_HOST_NAME_LEN + 1];
51     char        port[MAX_PORT_LEN + 1];
52 } ServerInfo;
53 
54 typedef struct {
55     TLSConfig   tlsConfig;                   // TLSConfig配置
56     ServerInfo  serverInfo;                  // 服务器信息
57     char        entropySeed[MAX_SEED_LEN];   // mbedtls熵源seed, 可用CERTMGR_ID作为seed值
58 } TLSSession;
59 
60 int32_t TLSConnect(TLSSession* session);
61 
62 int32_t TLSWrite(const TLSSession* session, const uint8_t* buf, size_t len);
63 
64 int32_t TLSRead(const TLSSession* session, uint8_t* buf, size_t len);
65 
66 int32_t TLSClose(TLSSession* session);
67 
68 #ifdef __cplusplus
69 }
70 #endif
71 #endif
72