XRootD
Loading...
Searching...
No Matches
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#include <openssl/x509.h>
33
35
36// Forward dec'ls.
37class XrdSysError;
38
52public:
53 class TempCAGuard;
54
60 XrdTlsTempCA(XrdSysError *log, std::string ca_dir, bool build_store = true);
62
69 bool IsValid() const {XrdSysMutexHelper lock(m_mutex);
70 return m_ca_file.get() && m_crl_file.get()
71 && (!m_build_store || m_ca_store.get());}
72
76 std::string CAFilename() const {XrdSysMutexHelper lock(m_mutex); return m_ca_file ? *m_ca_file : "";}
77
81 std::string CRLFilename() const {XrdSysMutexHelper lock(m_mutex); return m_crl_file ? *m_crl_file : "";}
82
87 bool atLeastOneValidCRLFound() const {XrdSysMutexHelper lock(m_mutex); return m_atLeastOneCRLFound;}
88
105 std::shared_ptr<X509_STORE> CAStore() const {XrdSysMutexHelper lock(m_mutex); return m_ca_store;}
106
111 public:
112 static std::unique_ptr<TempCAGuard> create(XrdSysError &, const std::string &ca_tmp_dir);
113
114 int getCAFD() const {return m_ca_fd;}
115 std::string getCAFilename() const {return m_ca_fname;}
116
117 int getCRLFD() const {return m_crl_fd;}
118 std::string getCRLFilename() const {return m_crl_fname;}
119
123 bool commit();
124
125 TempCAGuard(const TempCAGuard &) = delete;
126
127 ~TempCAGuard();
128
129 private:
130 TempCAGuard(int ca_fd, int crl_fd, const std::string &ca_tmp_dir, const std::string &ca_fname, const std::string &crl_fname);
131
132 int m_ca_fd{-1};
133 int m_crl_fd{-1};
134 std::string m_ca_tmp_dir;
135 std::string m_ca_fname;
136 std::string m_crl_fname;
137 };
138
139
140private:
147 bool Maintenance();
148
158 std::shared_ptr<X509_STORE> BuildCAStore(const std::string &ca_fname,
159 const std::string &crl_fname,
160 bool use_crls);
161
165 static void *MaintenanceThread(void *myself_raw);
166
171 int m_maintenance_pipe_r{-1};
172 int m_maintenance_pipe_w{-1};
173 int m_maintenance_thread_pipe_r{-1};
174 int m_maintenance_thread_pipe_w{-1};
175 XrdSysError &m_log;
176 const std::string m_ca_dir;
177 const bool m_build_store;
178 // Guards the published state below; taken once per consumer request (not
179 // per I/O), so the critical sections are deliberately kept to a pointer copy.
180 mutable XrdSysMutex m_mutex;
181 std::shared_ptr<std::string> m_ca_file;
182 std::shared_ptr<std::string> m_crl_file;
183 std::shared_ptr<X509_STORE> m_ca_store;
184 bool m_atLeastOneCRLFound = false;
185
186 // After success, how long to wait until the next CA reload.
187 static constexpr unsigned m_update_interval = 900;
188 // After failure, how long to wait until the next CA reload.
189 static constexpr unsigned m_update_interval_failure = 10;
190};
static std::unique_ptr< TempCAGuard > create(XrdSysError &, const std::string &ca_tmp_dir)
std::string getCRLFilename() const
std::string getCAFilename() const
TempCAGuard(const TempCAGuard &)=delete
bool atLeastOneValidCRLFound() const
bool IsValid() const
std::shared_ptr< X509_STORE > CAStore() const
XrdTlsTempCA(XrdSysError *log, std::string ca_dir, bool build_store=true)
std::string CAFilename() const
std::string CRLFilename() const