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
16#ifndef COMMUNICATION_NETSTACK_TLS_H
17#define COMMUNICATION_NETSTACK_TLS_H
18
19#include <string>
20
21#include "net_address.h"
22#include "secure_data.h"
23
24namespace OHOS {
25namespace NetStack {
26namespace TlsSocket {
27using Handle = void *;
28constexpr const char *PROTOCOL_TLS_V12 = "TLSv1.2";
29constexpr const char *PROTOCOL_TLS_V13 = "TLSv1.3";
30constexpr const char *CERT_PATH = "/system/lib";
31constexpr int CERT_PATH_LEN = 11;
32
33struct CipherSuite {
34    uint64_t cipherId_;
35    std::string cipherName_;
36};
37
38enum EncodingFormat { DER, PEM };
39
40struct X509CertRawData {
41    SecureData data;
42    EncodingFormat encodingFormat;
43};
44
45enum TlsMode { UNENCRYPTED_MODE, SSL_CLIENT_MODE, SSL_SERVER_MODE };
46
47enum PeerVerifyMode { VERIFY_NONE, QUERY_PEER, VERIFY_PEER, AUTO_VERIFY_PEER };
48
49enum KeyType { PRIVATE_KEY, PUBLIC_KEY };
50
51enum CertType { CA_CERT, LOCAL_CERT };
52
53enum KeyAlgorithm { OPAQUE, ALGORITHM_RSA, ALGORITHM_DSA, ALGORITHM_EC, ALGORITHM_DH };
54
55enum AlternativeNameEntryType { EMAIL_ENTRY, DNS_ENTRY, IPADDRESS_ENTRY };
56
57enum OpenMode {
58    NOT_OPEN,
59    READ_ONLY,
60    WRITE_ONLY,
61    READ_WRITE = READ_ONLY | WRITE_ONLY,
62    APPEND,
63    TRUNCATE,
64    TEXT,
65    UNBUFFERED,
66    NEW_ONLY,
67    EXISTION_ONLY
68};
69
70enum NetworkLayerProtocol { IPV4_PROTOCOL, IPV6_PROTOCOL, ANY_IP_PROTOCOL, UNKNOW_NETWORK_LAYER_PROTOCOL = -1 };
71
72enum class ImplementedClass { KEY, CERTIFICATE, SOCKET, DIFFIE_HELLMAN, ELLIPTIC_CURVE };
73
74enum class SupportedFeature {
75    CERTIFICATE_VERIFICATION,
76    CLIENT_SIDE_ALPN,
77    SERVER_SIDE_ALPN,
78    OCSP,
79    PSK,
80    SESSION_TICKET,
81    ALERTS
82};
83
84enum TlsOptions {
85    SSL_OPTION_DISABLE_EMPTY_FRAGMENTS = 0x01,
86    SSL_OPTION_DISABLE_SESSION_TICKETS = 0x02,
87    SSL_OPTION_DISABLE_COMPRESSION = 0x04,
88    SSL_OPTION_DISABLE_SERVER_NAME_INDICATION = 0x08,
89    SSL_OPTION_DISABLE_LEGACY_RENEGOTIATION = 0x10,
90    SSL_OPTION_DISABLE_SESSION_SHARING = 0x20,
91    SSL_OPTION_DISABLE_SESSION_PERSISTENCE = 0x40,
92    SSL_OPTION_DISABLE_SERVER_CIPHER_PREFERENCE = 0x80
93};
94
95enum TLSProtocol { TLS_V1_2, TLS_V1_3, UNKNOW_PROTOCOL };
96
97enum class Cipher { DES_CBC, DES_EDE3_CBC, RC2_CBC, AES_128_CBC, AES_192_CBC, AES_256_CBC };
98
99enum VerifyMode { ONE_WAY_MODE = 0, TWO_WAY_MODE };
100} // namespace TlsSocket
101} // namespace NetStack
102} // namespace OHOS
103#endif // COMMUNICATION_NETSTACK_TLS_H
104