-
Notifications
You must be signed in to change notification settings - Fork 149
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
Periodically reload verify cert store (stable) #1186
Merged
simonmichal
merged 2 commits into
xrootd:stable-4.12.x
from
bbockelm:reload_cert_store_stable
Apr 30, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,6 +91,8 @@ char *XrdHttpProtocol::gridmap = 0; | |
XrdOucGMap *XrdHttpProtocol::servGMap = 0; // Grid mapping service | ||
|
||
int XrdHttpProtocol::sslverifydepth = 9; | ||
XrdSysRWLock XrdHttpProtocol::x509_store_lock; | ||
X509_STORE *XrdHttpProtocol::verify_store = NULL; | ||
SSL_CTX *XrdHttpProtocol::sslctx = 0; | ||
BIO *XrdHttpProtocol::sslbio_err = 0; | ||
XrdCryptoFactory *XrdHttpProtocol::myCryptoFactory = 0; | ||
|
@@ -633,6 +635,19 @@ int XrdHttpProtocol::Process(XrdLink *lp) // We ignore the argument here | |
sbio = CreateBIO(Link); | ||
BIO_set_nbio(sbio, 1); | ||
ssl = SSL_new(sslctx); | ||
|
||
// On newer versions of OpenSSL, we use the periodically | ||
// updated store `verify_store` with the `x509_store_lock` | ||
// held; older OpenSSL versions are missing `SSL_set1_*_cert_store`, | ||
// so we simply rely on the global one in SSL_CTX. The latter | ||
// doesn't refresh the verify store, which causes issues with some | ||
// plugins. | ||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L | ||
XrdSysRWLockHelper scopedLock(x509_store_lock, true); | ||
SSL_set1_verify_cert_store(ssl, verify_store); | ||
SSL_set1_chain_cert_store(ssl, verify_store); | ||
#endif | ||
|
||
} | ||
|
||
if (!ssl) { | ||
|
@@ -1686,6 +1701,57 @@ extern "C" int verify_callback(int ok, X509_STORE_CTX * store) { | |
|
||
|
||
/// Initialization of the ssl security | ||
// Only scheduled on sufficiently new OpenSSL. | ||
|
||
class XrdCertStoreJob : XrdJob | ||
{ | ||
public: | ||
|
||
void DoIt() {XrdHttpProtocol::PeriodicUpdate(); | ||
Sched->Schedule((XrdJob *)this, time(0)+iVal); | ||
} | ||
|
||
XrdCertStoreJob(XrdScheduler *schP, int iV) | ||
: XrdJob("cert store updater"), | ||
Sched(schP), iVal(iV) | ||
{Sched->Schedule((XrdJob *)this, time(0)+iVal);} | ||
~XrdCertStoreJob() {} | ||
private: | ||
|
||
XrdScheduler *Sched; | ||
int iVal; | ||
}; | ||
|
||
void XrdHttpProtocol::PeriodicUpdate() { | ||
|
||
X509_STORE *new_store = PrepareStore(); | ||
TRACE(EMSG, "Updating new cert store"); | ||
if (new_store) { | ||
XrdSysRWLockHelper scopedLock(x509_store_lock, false); | ||
X509_STORE_free(verify_store); | ||
verify_store = new_store; | ||
} | ||
} | ||
|
||
X509_STORE *XrdHttpProtocol::PrepareStore() { | ||
X509_STORE *store = X509_STORE_new(); | ||
|
||
if (!store) { | ||
eDest.Say(" error: failed to allocate new certificate store"); | ||
return NULL; | ||
} | ||
|
||
X509_STORE_set_depth(store, sslverifydepth); | ||
X509_STORE_set_flags(store, X509_V_FLAG_ALLOW_PROXY_CERTS); | ||
|
||
if (!X509_STORE_load_locations(store, sslcafile, sslcadir)) { | ||
TRACE(EMSG, " Error setting the ca file or directory."); | ||
ERR_print_errors(sslbio_err); | ||
return NULL; | ||
} | ||
|
||
return store; | ||
} | ||
|
||
int XrdHttpProtocol::InitSecurity() { | ||
|
||
|
@@ -1767,6 +1833,20 @@ int XrdHttpProtocol::InitSecurity() { | |
} | ||
} | ||
|
||
// Initialize a store for use on individual SSL objects and schedule | ||
// a periodic update. These separate stores are only usable on versions | ||
// of OpenSSL 1.1.0 or later. | ||
#if OPENSSL_VERSION_NUMBER >= 0x010100000L | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
{ | ||
XrdSysRWLockHelper scopedLock(x509_store_lock, false); | ||
verify_store = PrepareStore(); | ||
if (!verify_store) { | ||
exit(1); | ||
} | ||
} | ||
new XrdCertStoreJob(Sched, 3600); | ||
#endif | ||
|
||
// Use default cipherlist filter if none is provided | ||
#if OPENSSL_VERSION_NUMBER >= 0x10002000L | ||
// For OpenSSL v1.0.2+ (EL7+), use recommended cipher list from Mozilla | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so fast, the test should be '>' not '>=' because OpenSSL 1.01 does not have the set1 functions. I know from your comment that you did compile it on SL6 but that only worked because someone must have upgraded their OpenSSL (which of course they should have). Unfortunately, lots of sites use RH6 out of the box and it comes with 1.0.1e-fips and it definitely won't compile! I think all of teh test should change and hen you'll be fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I understand this?
OPENSSL_VERSION_NUMBER >= 0x010100000L
should test for 1.1.0 or later. That is, it only enables this code if you are at least on 1.1.0 -- that should exclude any variant of RHEL6.(FWIW - the OpenSSL RPM I tested against was
openssl-1.0.1e-58.el6_10.x86_64
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it is intentional, but it will also exclude any variant of RHEL7, as e.g. both Centos7 and CC7 have openssl
1.0.2k
. From what I seeSSL_set1_verify_cert_store
&SSL_set1_chain_cert_store
are available in OpenSSL 1.0.2 (see e.g. https://github.com/openssl/openssl/blob/OpenSSL_1_0_2k/ssl/ssl.h). If we would like to include RHEL7 we should test forOPENSSL_VERSION_NUMBER >= 0x10002000L
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Argh - sorry, I haven't been able to sit down and get to this in the last two days (which have each had >6hrs of Zoom meetings...). You're right, this is too strict.