1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_SSL_CLIENT_H_ 18 #define MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_SSL_CLIENT_H_ 19 20 #include <openssl/ssl.h> 21 #include <openssl/rand.h> 22 #include <openssl/err.h> 23 #include <openssl/evp.h> 24 #include <assert.h> 25 #include <openssl/pkcs12.h> 26 #include <openssl/bio.h> 27 #include <iostream> 28 #include <string> 29 #include <memory> 30 #include <chrono> 31 #include <condition_variable> 32 #include <mutex> 33 #include <atomic> 34 #include "utils/log_adapter.h" 35 #include "ps/core/comm_util.h" 36 #include "include/backend/distributed/ps/constants.h" 37 #include "ps/core/file_configuration.h" 38 #include "include/backend/distributed/ps/ps_context.h" 39 40 namespace mindspore { 41 namespace ps { 42 namespace core { 43 class SSLClient { 44 public: GetInstance()45 static SSLClient &GetInstance() { 46 static SSLClient instance; 47 return instance; 48 } 49 SSL_CTX *GetSSLCtx() const; 50 51 private: 52 SSLClient(); 53 virtual ~SSLClient(); 54 SSLClient(const SSLClient &) = delete; 55 SSLClient &operator=(const SSLClient &) = delete; 56 57 void InitSSL(); 58 void CleanSSL(); 59 60 void StartCheckCertTime(const Configuration &config, const X509 *cert); 61 void StopCheckCertTime(); 62 void InitSSLCtx(const Configuration &config, const X509 *cert, const EVP_PKEY *pkey, X509_CRL *crl, 63 std::string ca_path); 64 65 SSL_CTX *ssl_ctx_; 66 std::unique_ptr<std::thread> check_time_thread_; 67 std::atomic<bool> running_; 68 std::atomic<bool> is_ready_; 69 std::mutex mutex_; 70 std::condition_variable cond_; 71 }; 72 } // namespace core 73 } // namespace ps 74 } // namespace mindspore 75 #endif // MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_SSL_CLIENT_H_ 76