• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
28 #include <iostream>
29 #include <string>
30 #include <memory>
31 #include <chrono>
32 #include <condition_variable>
33 #include <mutex>
34 #include <atomic>
35 
36 #include "utils/log_adapter.h"
37 #include "ps/core/comm_util.h"
38 #include "ps/constants.h"
39 #include "ps/core/file_configuration.h"
40 
41 namespace mindspore {
42 namespace ps {
43 namespace core {
44 class SSLClient {
45  public:
GetInstance()46   static SSLClient &GetInstance() {
47     static SSLClient instance;
48     return instance;
49   }
50   SSL_CTX *GetSSLCtx() const;
51 
52  private:
53   SSLClient();
54   virtual ~SSLClient();
55   SSLClient(const SSLClient &) = delete;
56   SSLClient &operator=(const SSLClient &) = delete;
57 
58   void InitSSL();
59   void CleanSSL();
60 
61   void StartCheckCertTime(const Configuration &config, const X509 *cert);
62   void StopCheckCertTime();
63 
64   SSL_CTX *ssl_ctx_;
65   std::unique_ptr<std::thread> check_time_thread_;
66   std::atomic<bool> running_;
67   std::atomic<bool> is_ready_;
68   std::mutex mutex_;
69   std::condition_variable cond_;
70 };
71 }  // namespace core
72 }  // namespace ps
73 }  // namespace mindspore
74 #endif  // MINDSPORE_CCSRC_PS_CORE_COMMUNICATOR_SSL_CLIENT_H_
75