xrootd
XrdTlsTempCA.hh
Go to the documentation of this file.
1 /******************************************************************************/
2 /* */
3 /* X r d T l s T e m p C A . h h */
4 /* */
5 /* (c) 2021 by the Board of Trustees of the Leland Stanford, Jr., University */
6 /* Produced by Brian Bockelman */
7 /* */
8 /* This file is part of the XRootD software suite. */
9 /* */
10 /* XRootD is free software: you can redistribute it and/or modify it under */
11 /* the terms of the GNU Lesser General Public License as published by the */
12 /* Free Software Foundation, either version 3 of the License, or (at your */
13 /* option) any later version. */
14 /* */
15 /* XRootD is distributed in the hope that it will be useful, but WITHOUT */
16 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or */
17 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public */
18 /* License for more details. */
19 /* */
20 /* You should have received a copy of the GNU Lesser General Public License */
21 /* along with XRootD in a file called COPYING.LESSER (LGPL license) and file */
22 /* COPYING (GPL license). If not, see <http://www.gnu.org/licenses/>. */
23 /* */
24 /* The copyright holder's institutional names and contributor's names may not */
25 /* be used to endorse or promote products derived from this software without */
26 /* specific prior written permission of the institution or contributor. */
27 /******************************************************************************/
28 
29 #include <string>
30 #include <memory>
31 
32 // Forward dec'ls.
33 class XrdSysError;
34 
43 class XrdTlsTempCA {
44 public:
45  class TempCAGuard;
46 
47  XrdTlsTempCA(XrdSysError *log, std::string ca_dir);
48  ~XrdTlsTempCA();
49 
53  bool IsValid() const {return m_ca_file.get() && m_crl_file.get();}
54 
58  std::string CAFilename() const {auto file_ref = m_ca_file; return file_ref ? *file_ref : "";}
59 
63  std::string CRLFilename() const {auto file_ref = m_crl_file; return file_ref ? *file_ref : "";}
64 
68  class TempCAGuard {
69  public:
70  static std::unique_ptr<TempCAGuard> create(XrdSysError &, const std::string &ca_tmp_dir);
71 
72  int getCAFD() const {return m_ca_fd;}
73  std::string getCAFilename() const {return m_ca_fname;}
74 
75  int getCRLFD() const {return m_crl_fd;}
76  std::string getCRLFilename() const {return m_crl_fname;}
77 
81  bool commit();
82 
83  TempCAGuard(const TempCAGuard &) = delete;
84 
85  ~TempCAGuard();
86 
87  private:
88  TempCAGuard(int ca_fd, int crl_fd, const std::string &ca_tmp_dir, const std::string &ca_fname, const std::string &crl_fname);
89 
90  int m_ca_fd{-1};
91  int m_crl_fd{-1};
92  std::string m_ca_tmp_dir;
93  std::string m_ca_fname;
94  std::string m_crl_fname;
95  };
96 
97 
98 private:
105  bool Maintenance();
106 
110  static void *MaintenanceThread(void *myself_raw);
111 
121  const std::string m_ca_dir;
122  std::shared_ptr<std::string> m_ca_file;
123  std::shared_ptr<std::string> m_crl_file;
124 
125  // After success, how long to wait until the next CA reload.
126  static constexpr unsigned m_update_interval = 900;
127  // After failure, how long to wait until the next CA reload.
128  static constexpr unsigned m_update_interval_failure = 10;
129 };
std::string getCAFilename() const
Definition: XrdTlsTempCA.hh:73
std::shared_ptr< std::string > m_ca_file
Definition: XrdTlsTempCA.hh:122
std::string CAFilename() const
Definition: XrdTlsTempCA.hh:58
int m_maintenance_thread_pipe_r
Definition: XrdTlsTempCA.hh:118
int getCAFD() const
Definition: XrdTlsTempCA.hh:72
int getCRLFD() const
Definition: XrdTlsTempCA.hh:75
std::shared_ptr< std::string > m_crl_file
Definition: XrdTlsTempCA.hh:123
Definition: XrdSysError.hh:89
static constexpr unsigned m_update_interval
Definition: XrdTlsTempCA.hh:126
std::string m_crl_fname
Definition: XrdTlsTempCA.hh:94
bool Maintenance()
std::string getCRLFilename() const
Definition: XrdTlsTempCA.hh:76
XrdSysError & m_log
Definition: XrdTlsTempCA.hh:120
TempCAGuard(const TempCAGuard &)=delete
std::string m_ca_tmp_dir
Definition: XrdTlsTempCA.hh:92
static void * MaintenanceThread(void *myself_raw)
XrdTlsTempCA(XrdSysError *log, std::string ca_dir)
static constexpr unsigned m_update_interval_failure
Definition: XrdTlsTempCA.hh:128
const std::string m_ca_dir
Definition: XrdTlsTempCA.hh:121
Definition: XrdTlsTempCA.hh:68
Definition: XrdTlsTempCA.hh:43
std::string CRLFilename() const
Definition: XrdTlsTempCA.hh:63
int m_maintenance_pipe_w
Definition: XrdTlsTempCA.hh:117
static std::unique_ptr< TempCAGuard > create(XrdSysError &, const std::string &ca_tmp_dir)
int m_ca_fd
Definition: XrdTlsTempCA.hh:90
int m_crl_fd
Definition: XrdTlsTempCA.hh:91
bool IsValid() const
Definition: XrdTlsTempCA.hh:53
int m_maintenance_pipe_r
Definition: XrdTlsTempCA.hh:116
int m_maintenance_thread_pipe_w
Definition: XrdTlsTempCA.hh:119
std::string m_ca_fname
Definition: XrdTlsTempCA.hh:93