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

SSL fixes for validator list (RIPD-1558) #2275

Closed
wants to merge 3 commits into from
Closed

Conversation

bachase
Copy link
Collaborator

@bachase bachase commented Nov 20, 2017

  • Configures domain name for SNI
  • On windows, uses wincrypt API to use system's root certificates.

Support Server Name Indication
Ensure windows uses available certificates
@bachase
Copy link
Collaborator Author

bachase commented Nov 20, 2017

The first commit is the only one required for published validator lists. I believe the second commit fixes remaining spots in rippled that with a similar issue, but I'm not sure that the current use of those classes requires the changes.

@codecov-io
Copy link

codecov-io commented Nov 20, 2017

Codecov Report

Merging #2275 into develop will decrease coverage by 0.01%.
The diff coverage is 33.33%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #2275      +/-   ##
===========================================
- Coverage    70.11%   70.09%   -0.02%     
===========================================
  Files          689      690       +1     
  Lines        50800    50808       +8     
===========================================
- Hits         35617    35613       -4     
- Misses       15183    15195      +12
Impacted Files Coverage Δ
src/ripple/app/misc/detail/WorkSSL.h 0% <0%> (ø) ⬆️
src/ripple/net/AutoSocket.h 0% <0%> (ø) ⬆️
src/ripple/net/impl/RegisterSSLCerts.cpp 100% <100%> (ø)
src/ripple/net/impl/HTTPClient.cpp 5.96% <33.33%> (-0.06%) ⬇️
src/ripple/basics/DecayingSample.h 77.77% <0%> (-8.34%) ⬇️
src/ripple/app/misc/SHAMapStoreImp.cpp 78.92% <0%> (-1.03%) ⬇️
src/ripple/net/impl/RPCSub.cpp 37.33% <0%> (-0.83%) ⬇️
src/ripple/app/main/Application.cpp 60.42% <0%> (-0.12%) ⬇️
src/ripple/protocol/impl/Serializer.cpp 70.3% <0%> (+0.34%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cafe18c...af0d609. Read the comment docs.

Copy link
Contributor

@wilsonianb wilsonianb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell, HTTPClient is only used by RPCSub (Subscription object for JSON-RPC), which seem to be deprecated
https://ripple.com/build/rippled-apis/#subscriptions

JSON-RPC support for subscription callbacks is deprecated and may not work as expected.

pContext->cbCertEncoded);
if (x509 != NULL)
{
X509_STORE_add_cert(store, x509);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this would fail, but should we log if it does?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably worth doing. I'll look into making an error_code.

}
}

CertFreeCertificateContext(pContext);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't pContext guaranteed to be NULL here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, will fix.

CertFreeCertificateContext(pContext);
CertCloseStore(hStore, 0);

SSL_CTX_set_cert_store(ctx.native_handle(), store);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, the reason we don't use SSL_CTX_set1_cert_store here is because
https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_cert_store.html

SSL_CTX_set_cert_store() does not increment the store's reference count, so it should not be used to assign an X509_STORE that is owned by another SSL_CTX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. I believe since we create the store above, we do not need to increment the reference count.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, it looks like the reference counted version is not available in the 1.0.* versions we are using.

//==============================================================================
#include <BeastConfig.h>
#include <ripple/net/RegisterSSLCerts.h>
#if BEAST_WINDOWS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like BEAST_WINDOWS is only used in src/ripple/beast/
Should a different macro be used here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can use boost predef instead.

{
X509* x509 = d2i_X509(
NULL,
(const unsigned char**)&pContext->pbCertEncoded,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d2i_X509 actually modifies the pointer taken as the second argument; I will fix to use a local instead.

@bachase
Copy link
Collaborator Author

bachase commented Nov 22, 2017

@HowardHinnant can you do a pass on the use of unique_ptr to manage the structures allocated from C apis? This is all in https://github.com/ripple/rippled/pull/2275/files#diff-f52b8187d06f944bb1c240a3c83c5d6a

Copy link
Contributor

@HowardHinnant HowardHinnant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me! The ownership properties of these functions looks complex and poorly documented. Nice use of comments to clarify what owns what and when.

Copy link
Contributor

@wilsonianb wilsonianb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't test on Windows but LGTM 👍
I think you could take or leave the HTTPClient changes if it really is deprecated.

ec = boost::system::error_code(
static_cast<int>(::ERR_get_error()),
boost::asio::error::get_ssl_category());
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ok as is (returning with ec and throwing if anything goes wrong), but I'm wondering if we could alternatively be ok calling continue here (and on line 85) and just having the caller log ec.

@bachase bachase added the Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required. label Nov 29, 2017
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2016 Ripple Labs Inc.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale date

@@ -754,6 +754,7 @@ def config_env(toolchain, variant, env):
'uuid.lib',
'odbc32.lib',
'odbccp32.lib',
'crypt32.lib'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: misaligned

Copy link
Contributor

@miguelportilla miguelportilla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@bachase
Copy link
Collaborator Author

bachase commented Nov 30, 2017

Merged as a4a43a4

@bachase bachase closed this Nov 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Passed Passed code review & PR owner thinks it's ready to merge. Perf sign-off may still be required.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants