-
Notifications
You must be signed in to change notification settings - Fork 287
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
Fixes for CPP-928, and trusted certs #493
Open
maxdymond
wants to merge
2
commits into
datastax:master
Choose a base branch
from
Metaswitch:cpp-928-and-trusted-certs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+69
−52
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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
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
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
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
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
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
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 |
---|---|---|
|
@@ -228,22 +228,6 @@ static int SSL_CTX_use_certificate_chain_bio(SSL_CTX* ctx, BIO* in) { | |
return ret; | ||
} | ||
|
||
static X509* load_cert(const char* cert, size_t cert_size) { | ||
BIO* bio = BIO_new_mem_buf(const_cast<char*>(cert), cert_size); | ||
if (bio == NULL) { | ||
return NULL; | ||
} | ||
|
||
X509* x509 = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL); | ||
if (x509 == NULL) { | ||
ssl_log_errors("Unable to load certificate"); | ||
} | ||
|
||
BIO_free_all(bio); | ||
|
||
return x509; | ||
} | ||
|
||
static EVP_PKEY* load_key(const char* key, size_t key_size, const char* password) { | ||
BIO* bio = BIO_new_mem_buf(const_cast<char*>(key), key_size); | ||
if (bio == NULL) { | ||
|
@@ -489,8 +473,8 @@ void OpenSslSession::verify() { | |
return; | ||
} | ||
} else if (verify_flags_ & | ||
CASS_SSL_VERIFY_PEER_IDENTITY_DNS) { // Match using hostnames (including wildcards) | ||
switch (OpenSslVerifyIdentity::match_dns(peer_cert, hostname_)) { | ||
CASS_SSL_VERIFY_PEER_IDENTITY_DNS) { // Match using the server name (including wildcards) | ||
switch (OpenSslVerifyIdentity::match_dns(peer_cert, sni_server_name_)) { | ||
case OpenSslVerifyIdentity::MATCH: | ||
// Success | ||
break; | ||
|
@@ -556,13 +540,30 @@ SslSession* OpenSslContext::create_session(const Address& address, const String& | |
} | ||
|
||
CassError OpenSslContext::add_trusted_cert(const char* cert, size_t cert_length) { | ||
X509* x509 = load_cert(cert, cert_length); | ||
if (x509 == NULL) { | ||
BIO* bio = BIO_new_mem_buf(const_cast<char*>(cert), cert_length); | ||
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. +1 on loading the whole cert chain. Awesome! |
||
if (bio == NULL) { | ||
return CASS_ERROR_SSL_INVALID_CERT; | ||
} | ||
|
||
X509_STORE_add_cert(trusted_store_, x509); | ||
X509_free(x509); | ||
int num_certs = 0; | ||
|
||
// Iterate over the bio, reading out as many certificates as possible. | ||
for (X509* cert = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL); | ||
cert != NULL; | ||
cert = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL)) | ||
{ | ||
X509_STORE_add_cert(trusted_store_, cert); | ||
X509_free(cert); | ||
num_certs++; | ||
} | ||
|
||
BIO_free_all(bio); | ||
|
||
// If no certificates were read from the bio, that is an error. | ||
if (num_certs == 0) { | ||
ssl_log_errors("Unable to load certificate(s)"); | ||
return CASS_ERROR_SSL_INVALID_CERT; | ||
} | ||
|
||
return CASS_OK; | ||
} | ||
|
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
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
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.
Maybe this is a bug. If it's present in a SAN or the CN the it should probably be valid? I'd need to dig into that more.
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.
From
ssl_openssl_impl.cpp
Those functions only return
NO_SAN_PRESENT
ifX509_get_ext_d2i
returns NULL, otherwise it then checks the SAN stack and returns either NO_MATCH, INVALID_CERT or MATCH.