1 /* 2 * Copyright (c) 2024 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 NETSTACK_TLS_CONFIG_ENHANCED_H 17 #define NETSTACK_TLS_CONFIG_ENHANCED_H 18 19 #include <functional> 20 #include <map> 21 #include <netdb.h> 22 #include <string> 23 #include <vector> 24 #include <optional> 25 #include <memory> 26 #include <unordered_set> 27 28 #include "securec.h" 29 30 namespace OHOS::NetStack::TlsSocket { 31 enum class CipherSuite { 32 INVALID = -1, 33 TLS_AES_128_GCM_SHA256 = 0x1301, 34 TLS_AES_256_GCM_SHA384 = 0x1302, 35 TLS_CHACHA20_POLY1305_SHA256 = 0x1303, 36 TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = 0xc02b, 37 TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = 0xc02f, 38 TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = 0xc02c, 39 TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = 0xc030, 40 TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = 0xcca9, 41 TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = 0xcca8, 42 TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = 0x009c, 43 TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = 0x009d, 44 TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = 0xc009, 45 TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = 0xc013, 46 TLS_RSA_WITH_AES_128_GCM_SHA256 = 0xc00a, 47 TLS_RSA_WITH_AES_256_GCM_SHA384 = 0xc014, 48 TLS_RSA_WITH_AES_128_CBC_SHA = 0x002f, 49 TLS_RSA_WITH_AES_256_CBC_SHA = 0x0035, 50 TLS_RSA_WITH_3DES_EDE_CBC_SHA = 0x000a, 51 }; 52 53 enum class TlsVersion { 54 DEFAULT = 0, 55 TLSv1_0 = 4, 56 TLSv1_1 = 5, 57 TLSv1_2 = 6, 58 TLSv1_3 = 7, 59 }; 60 61 enum class CertType { 62 PEM, 63 DER, 64 P12, 65 }; 66 67 struct ClientCertificate { 68 CertType type = CertType::PEM; 69 [[nodiscard]] std::string GetCertTypeString() const; 70 }; 71 72 struct TlsCipherString { 73 std::string ciperSuiteString; 74 std::string tlsV13CiperSuiteString; 75 }; 76 77 struct TlsVersionRange { 78 std::optional<TlsVersion> min; 79 std::optional<TlsVersion> max; 80 }; 81 82 [[nodiscard]] CipherSuite GetCipherSuiteFromStandardName(const std::string &standardName); 83 [[nodiscard]] std::string GetInnerNameFromCipherSuite(CipherSuite cipherSuite); 84 [[nodiscard]] TlsVersion ConvertTlsVersion(const std::string &tlsVersion); 85 [[nodiscard]] TlsVersionRange ConvertTlsVersion(TlsVersion tlsVersion); 86 [[nodiscard]] TlsCipherString ConvertCipherSuiteToCipherString(const std::unordered_set<CipherSuite> &cipherSuite); 87 88 enum class HashAlgorithm { 89 SHA256, 90 INVALID, 91 }; 92 93 [[nodiscard]] HashAlgorithm GetHashAlgorithm(const std::string &hashAlgorithm); 94 95 struct IpAndPort { 96 std::string ip; 97 uint16_t port = 0; 98 }; 99 100 struct DnsServers : public std::vector<IpAndPort> { 101 [[nodiscard]] std::string ToString() const; 102 }; 103 104 struct TransferRangeItem { 105 std::optional<int64_t> from; 106 std::optional<int64_t> to; 107 }; 108 109 struct TransferRange : public std::vector<TransferRangeItem> { 110 [[nodiscard]] std::string ToHeaderString() const; 111 }; 112 } // namespace OHOS::NetStack::TlsSocket 113 #endif // NETSTACK_TLS_CONFIG_ENHANCED_H 114