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 namespace OHOS { 27 namespace NetStack { 28 namespace TlsSocket { 29 class TLSConfiguration { 30 public: 31 TLSConfiguration() = default; 32 explicit TLSConfiguration(TLSConfiguration *tlsConfiguration); 33 ~TLSConfiguration() = default; 34 TLSConfiguration(const TLSConfiguration &other); 35 TLSConfiguration &operator=(const TLSConfiguration &other); 36 37 void SetLocalCertificate(const TLSCertificate &certificate); 38 void SetLocalCertificate(const std::string &certificate); 39 [[nodiscard]] TLSCertificate GetLocalCertificate() const; 40 41 void SetCaCertificate(const TLSCertificate &certificate); 42 void SetCaCertificate(const std::vector<std::string> &certificate); 43 [[nodiscard]] std::vector<std::string> GetCaCertificate() const; 44 45 [[nodiscard]] const TLSKey &PrivateKey() const; 46 void SetPrivateKey(const TLSKey &key); 47 void SetPrivateKey(const SecureData &key, const SecureData &keyPass); 48 [[nodiscard]] TLSKey GetPrivateKey() const; 49 50 void SetProtocol(const std::string &Protocol); 51 void SetProtocol(const std::vector<std::string> &Protocol); 52 [[nodiscard]] TLSProtocol GetMinProtocol() const; 53 [[nodiscard]] TLSProtocol GetMaxProtocol() const; 54 [[nodiscard]] TLSProtocol GetProtocol() const; 55 56 void SetUseRemoteCipherPrefer(bool useRemoteCipherPrefer); 57 [[nodiscard]] bool GetUseRemoteCipherPrefer() const; 58 59 void SetCipherSuite(const std::string &cipherSuite); 60 [[nodiscard]] std::string GetCipherSuite() const; 61 62 [[nodiscard]] const X509CertRawData &GetCertificate() const; 63 void SetSignatureAlgorithms(const std::string &signatureAlgorithms); 64 [[nodiscard]] const std::string &GetSignatureAlgorithms() const; 65 [[nodiscard]] std::vector<CipherSuite> GetCipherSuiteVec() const; 66 67 void SetVerifyMode(VerifyMode verifyMode); 68 [[nodiscard]] VerifyMode GetVerifyMode() const; 69 70 private: 71 TLSProtocol minProtocol_ = TLS_V1_3; 72 TLSProtocol maxProtocol_ = TLS_V1_3; 73 TLSProtocol protocol_ = TLS_V1_3; 74 75 std::string cipherSuite_; 76 std::string signatureAlgorithms_; 77 std::string localCertString_; 78 79 bool useRemoteCipherPrefer_ = false; 80 81 std::vector<CipherSuite> cipherSuiteVec_; 82 83 TLSKey privateKey_; 84 TLSCertificate localCertificate_; 85 TLSCertificate caCertificate_; 86 std::vector<std::string> caCertificateChain_; 87 VerifyMode tlsVerifyMode_; 88 }; 89 } // namespace TlsSocket 90 } // namespace NetStack 91 } // namespace OHOS 92 #endif // COMMUNICATION_NETSTACK_TLS_CONFIGURATION_H 93