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_CONFIGURATION_H 17 #define COMMUNICATION_NETSTACK_TLS_CONFIGURATION_H 18 19 #include <memory> 20 #include <string> 21 #include <vector> 22 23 #include "tls.h" 24 #include "tls_certificate.h" 25 #include "tls_key.h" 26 #include "net_address.h" 27 namespace OHOS { 28 namespace NetStack { 29 namespace TlsSocket { 30 class TLSConfiguration { 31 public: 32 TLSConfiguration() = default; 33 explicit TLSConfiguration(TLSConfiguration *tlsConfiguration); 34 ~TLSConfiguration() = default; 35 TLSConfiguration(const TLSConfiguration &other); 36 TLSConfiguration &operator=(const TLSConfiguration &other); 37 38 void SetLocalCertificate(const TLSCertificate &certificate); 39 void SetLocalCertificate(const std::string &certificate); 40 [[nodiscard]] TLSCertificate GetLocalCertificate() const; 41 42 void SetCaCertificate(const TLSCertificate &certificate); 43 void SetCaCertificate(const std::vector<std::string> &certificate); 44 [[nodiscard]] std::vector<std::string> GetCaCertificate() const; 45 46 [[nodiscard]] const TLSKey &PrivateKey() const; 47 void SetPrivateKey(const TLSKey &key); 48 void SetPrivateKey(const SecureData &key, const SecureData &keyPass); 49 [[nodiscard]] TLSKey GetPrivateKey() const; 50 51 void SetProtocol(const std::string &Protocol); 52 void SetProtocol(const std::vector<std::string> &Protocol); 53 [[nodiscard]] TLSProtocol GetMinProtocol() const; 54 [[nodiscard]] TLSProtocol GetMaxProtocol() const; 55 [[nodiscard]] TLSProtocol GetProtocol() const; 56 57 void SetUseRemoteCipherPrefer(bool useRemoteCipherPrefer); 58 [[nodiscard]] bool GetUseRemoteCipherPrefer() const; 59 60 void SetCipherSuite(const std::string &cipherSuite); 61 [[nodiscard]] std::string GetCipherSuite() const; 62 63 [[nodiscard]] const X509CertRawData &GetCertificate() const; 64 void SetSignatureAlgorithms(const std::string &signatureAlgorithms); 65 [[nodiscard]] const std::string &GetSignatureAlgorithms() const; 66 [[nodiscard]] std::vector<CipherSuite> GetCipherSuiteVec() const; 67 68 void SetVerifyMode(VerifyMode verifyMode); 69 [[nodiscard]] VerifyMode GetVerifyMode() const; 70 71 void SetNetAddress(const Socket::NetAddress& address); 72 [[nodiscard]] Socket::NetAddress GetNetAddress() const; 73 74 void SetSkipFlag(bool whetherToSkip); 75 [[nodiscard]] bool GetSkipFlag() const; 76 77 private: 78 TLSProtocol minProtocol_ = TLS_V1_2; 79 TLSProtocol maxProtocol_ = TLS_V1_3; 80 TLSProtocol protocol_ = TLS_V1_3; 81 82 std::string cipherSuite_; 83 std::string signatureAlgorithms_; 84 std::string localCertString_; 85 86 bool useRemoteCipherPrefer_ = false; 87 88 std::vector<CipherSuite> cipherSuiteVec_; 89 90 TLSKey privateKey_; 91 TLSCertificate localCertificate_; 92 TLSCertificate caCertificate_; 93 std::vector<std::string> caCertificateChain_; 94 VerifyMode tlsVerifyMode_; 95 Socket::NetAddress netAddress_; 96 bool whetherToSkip_ = false; 97 }; 98 } // namespace TlsSocket 99 } // namespace NetStack 100 } // namespace OHOS 101 #endif // COMMUNICATION_NETSTACK_TLS_CONFIGURATION_H 102