Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overhaul curl's usage of CAs. #1431

Merged
merged 18 commits into from
Apr 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5e31d97
Overhaul curl's usage of CAs.
bbockelm Mar 18, 2021
75f631e
Add support for certfile directive for TPC handler.
bbockelm Mar 18, 2021
c84668f
Provide a pure-environment override for the XrdTpc cadir.
bbockelm Mar 18, 2021
399d5a7
XrdTpc: Switch update variables to std::atomics.
bbockelm Mar 19, 2021
1fe8f5d
XrdTpc: Remove deprecated readdir_r.
bbockelm Mar 19, 2021
5793ac7
Remove use of smart pointers.
bbockelm Mar 25, 2021
97deb89
XrdTpc: Pass filename to parsing / exporting functions.
bbockelm Mar 28, 2021
2719b4b
XrdTpc: Use XrdSysFD functions where possible for CLOEXEC protection.
bbockelm Mar 28, 2021
380f476
XrdTpc: If NSS hack is needed and fails, do not startup server.
bbockelm Mar 28, 2021
5f49669
XrdTls: Move temp CA generator code into core XrdTls.
bbockelm Mar 28, 2021
ab5fad4
XrdTpc: Remove XrdTpcNSSSupport implementation.
bbockelm Mar 28, 2021
1eb60a5
XrdTls: HACK - temporarily link crypto files into XrdUtils.
bbockelm Mar 28, 2021
c3dc4c1
XrdTls: Extend XrdCryptosslX509Crl to load / write CRLs to a FILE*
bbockelm Mar 28, 2021
342ba6c
XrdTls: HACK - add CRLs to XrdUtils. Revert when we understand linki…
bbockelm Mar 28, 2021
399fc03
XrdTls: Add CRL concatenation support to TempCA manager.
bbockelm Mar 28, 2021
7d3a823
XrdTls: Remove XrdTlsTempCA from its dedicated namespace.
bbockelm Mar 30, 2021
639e6e3
XrdTls: Convert TempCA loader to a separate thread.
bbockelm Apr 4, 2021
87b341c
XrdTls: Refactor temp CA code to use ADMINPATH directory.
bbockelm Apr 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/XrdCrypto/XrdCryptosslAux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ XrdSutBucket *XrdCryptosslX509ExportChain(XrdCryptoX509Chain *chain,
}

//____________________________________________________________________________
int XrdCryptosslX509ToFile(XrdCryptoX509 *x509, FILE *file)
int XrdCryptosslX509ToFile(XrdCryptoX509 *x509, FILE *file, const char *fname)
{
// Dump a single X509 certificate to a file in PEM format.
EPNAME("X509ChainToFile");
Expand All @@ -310,7 +310,7 @@ int XrdCryptosslX509ToFile(XrdCryptoX509 *x509, FILE *file)
}

if (PEM_write_X509(file, (X509 *)x509->Opaque()) != 1) {
DEBUG("error while writing certificate");
DEBUG("error while writing certificate " << fname);
return -1;
}

Expand Down Expand Up @@ -465,14 +465,15 @@ int XrdCryptosslX509ParseFile(const char *fname,
return 0;
}

auto retval = XrdCryptosslX509ParseFile(fcer, chain);
auto retval = XrdCryptosslX509ParseFile(fcer, chain, fname);
fclose(fcer);
return retval;
}

//____________________________________________________________________________
int XrdCryptosslX509ParseFile(FILE *fcer,
XrdCryptoX509Chain *chain)
XrdCryptoX509Chain *chain,
const char *fname)
{
// Parse content of file 'fname' and add X509 certificates to
// chain (which must be initialized by the caller).
Expand Down Expand Up @@ -516,9 +517,9 @@ int XrdCryptosslX509ParseFile(FILE *fcer,
rewind(fcer);
RSA *rsap = 0;
if (!PEM_read_RSAPrivateKey(fcer, &rsap, 0, 0)) {
DEBUG("no RSA private key found in file");
DEBUG("no RSA private key found in file " << fname);
} else {
DEBUG("found a RSA private key in file");
DEBUG("found a RSA private key in file " << fname);
// We need to complete the key: we save it temporarly
// to a bio and check all the private keys of the
// loaded certificates
Expand Down
8 changes: 4 additions & 4 deletions src/XrdCrypto/XrdCryptosslAux.hh
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ bool XrdCryptosslX509VerifyChain(XrdCryptoX509Chain *chain, int &errcode);
XrdSutBucket *XrdCryptosslX509ExportChain(XrdCryptoX509Chain *c, bool key = 0);
// chain export to file (proxy file creation)
int XrdCryptosslX509ChainToFile(XrdCryptoX509Chain *c, const char *fn);
// export single certificate to file
extern "C" int XrdCryptosslX509ToFile(XrdCryptoX509 *x509, FILE *file);
// export single certificate to file; fname is solely for debug message purposes
extern "C" int XrdCryptosslX509ToFile(XrdCryptoX509 *x509, FILE *file, const char *fname);
// certificates from file parsing
int XrdCryptosslX509ParseFile(const char *fname, XrdCryptoX509Chain *c);
// certificates from FILE object
extern "C" int XrdCryptosslX509ParseFile(FILE *file, XrdCryptoX509Chain *c);
// certificates from FILE object; fname is solely for debug message purposes
extern "C" int XrdCryptosslX509ParseFile(FILE *file, XrdCryptoX509Chain *c, const char *fname);
// certificates from bucket parsing
int XrdCryptosslX509ParseBucket(XrdSutBucket *b, XrdCryptoX509Chain *c);
// certificates from STACK_OF(X509*)
Expand Down
4 changes: 4 additions & 0 deletions src/XrdSys/XrdSysFD.hh
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ inline int XrdSysFD_Socketpair(int domain, int type, int protocol, int sfd[2])
}
#endif

// openat is part of POSIX.1-2008; in Linux, BSD, and Solaris
bbockelm marked this conversation as resolved.
Show resolved Hide resolved
inline int XrdSysFD_Openat(int dirfd, const char *pathname, int flags)
{return openat(dirfd, pathname, flags | O_CLOEXEC);}

inline bool XrdSysFD_Yield(int fd)
{int fdFlags = fcntl(fd, F_GETFD);
if (fdFlags < 0) return false;
Expand Down
11 changes: 6 additions & 5 deletions src/XrdTpc/XrdTpcNSSSupport.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <curl/curl.h>

#include "XrdSys/XrdSysError.hh"
#include "XrdSys/XrdSysFD.hh"
#include "XrdSys/XrdSysPlugin.hh"
#include "XrdCrypto/XrdCryptoX509Chain.hh"
#include "XrdCrypto/XrdCryptosslAux.hh"
Expand Down Expand Up @@ -82,7 +83,7 @@ class CASet {
const int m_output_fd;

decltype(&XrdCryptosslX509ToFile) m_x509_to_file_func;
int (*m_file_to_x509_func)(FILE *file, XrdCryptoX509Chain *c);
int (*m_file_to_x509_func)(FILE *file, XrdCryptoX509Chain *c, const char *fname);
};


Expand All @@ -92,7 +93,7 @@ CASet::processFile(file_smart_ptr &fp, const std::string &fname)
XrdCryptoX509Chain chain;
// Not checking return value here; function returns `0` on error and
// if no certificate is found.
(*m_file_to_x509_func)(fp.get(), &chain);
(*m_file_to_x509_func)(fp.get(), &chain, fname.c_str());

auto ca = chain.Begin();
// Note we purposely leak the outputfp here; we are just borrowing the handle.
Expand All @@ -115,7 +116,7 @@ CASet::processFile(file_smart_ptr &fp, const std::string &fname)
//m_log.Emsg("CAset", "New CA with hash", fname.c_str(), hash_ptr);
m_known_cas.insert(hash_ptr);

if ((*m_x509_to_file_func)(ca, outputfp)) {
if ((*m_x509_to_file_func)(ca, outputfp, fname.c_str())) {
m_log.Emsg("CAset", "Failed to write out CA", fname.c_str());
return false;
}
Expand Down Expand Up @@ -197,7 +198,7 @@ XrdTpcNSSSupport::Maintenance()
}
CASet builder(new_file->getFD(), m_log, m_x509_to_file_func, m_file_to_x509_func);

int fddir = open(m_ca_dir.c_str(), O_DIRECTORY);
int fddir = XrdSysFD_Open(m_ca_dir.c_str(), O_DIRECTORY);
if (fddir < 0) {
m_log.Emsg("XrdTpc", "Failed to open the CA directory", m_ca_dir.c_str());
return false;
Expand All @@ -214,7 +215,7 @@ XrdTpcNSSSupport::Maintenance()
//m_log.Emsg("Will parse file for CA certificates", result->d_name);
if (result->d_type != DT_REG && result->d_type != DT_LNK) {continue;}
if (result->d_name[0] == '.') {continue;}
int fd = openat(fddir, result->d_name, O_RDONLY);
int fd = XrdSysFD_Openat(fddir, result->d_name, O_RDONLY);
if (fd < 0) {
m_log.Emsg("XrdTpc", "Failed to open certificate file", result->d_name, strerror(errno));
closedir(dirp);
Expand Down