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