Skip to content

Commit 734bd6c

Browse files
authored
PR 522 followup (#526)
Follow-up to PR 522. Fix the formatting issue that was breaking the Jenkins build for Ubuntu Bionic and add an integration test to validate the change.
1 parent 88aa754 commit 734bd6c

File tree

3 files changed

+64
-4
lines changed

3 files changed

+64
-4
lines changed

src/ssl/ssl_openssl_impl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,8 @@ CassError OpenSslContext::add_trusted_cert(const char* cert, size_t cert_length)
560560
int num_certs = 0;
561561

562562
// Iterate over the bio, reading out as many certificates as possible.
563-
for (X509* cert = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL);
564-
cert != NULL;
565-
cert = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL))
566-
{
563+
for (X509* cert = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL); cert != NULL;
564+
cert = PEM_read_bio_X509(bio, NULL, pem_password_callback, NULL)) {
567565
X509_STORE_add_cert(trusted_store_, cert);
568566
X509_free(cert);
569567
num_certs++;

tests/src/integration/ssl_certificates.hpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,22 @@ namespace test {
140140
* ssh-keygen -p \
141141
* -N invalid \
142142
* -f ssl/invalid/driver-private-invalid.pem
143+
*
144+
* # Building dummy PEM. Some tests below require multiple PEM-encoded
145+
* # certs in order to verify that we consider all input certs (and
146+
* # not just the first one)
147+
* keytool -genkeypair -noprompt -keyalg RSA -validity 36500 \
148+
* -alias dummy \
149+
* -keystore ssl/keystore.jks \
150+
* -storepass cassandra \
151+
* -keypass cassandra \
152+
* -dname "CN=1.2.3.4, OU=SomeOU, O=SomeO, L=Somewhere, ST=SomeState, C=US"
153+
*
154+
* keytool -exportcert -rfc -noprompt \
155+
* -alias dummy \
156+
* -keystore ssl/keystore.jks \
157+
* -storepass cassandra \
158+
* -file ssl/dummy.pem
143159
*/
144160

145161
static const unsigned char cassandra_crt[953] = {
@@ -557,6 +573,36 @@ class SslCertificates {
557573
"cAHazCFHOKxSQ/G7n+8xDx3r6jHxyE956u5jf5FRqUbaVIBMdg==\12"
558574
"-----END CERTIFICATE-----\12";
559575
}
576+
static const char* dummy_pem() {
577+
return "-----BEGIN CERTIFICATE-----\12"
578+
"MIIDcTCCAlmgAwIBAgIEKDL8hDANBgkqhkiG9w0BAQsFADBoMQswCQYDVQQGEwJV\12"
579+
"UzESMBAGA1UECBMJU29tZVN0YXRlMRIwEAYDVQQHEwlTb21ld2hlcmUxDjAMBgNV\12"
580+
"BAoTBVNvbWVPMQ8wDQYDVQQLEwZTb21lT1UxEDAOBgNVBAMTBzEuMi4zLjQwIBcN\12"
581+
"MjIwMzI1MjAzNzM3WhgPMjEyMjAzMDEyMDM3MzdaMGgxCzAJBgNVBAYTAlVTMRIw\12"
582+
"EAYDVQQIEwlTb21lU3RhdGUxEjAQBgNVBAcTCVNvbWV3aGVyZTEOMAwGA1UEChMF\12"
583+
"U29tZU8xDzANBgNVBAsTBlNvbWVPVTEQMA4GA1UEAxMHMS4yLjMuNDCCASIwDQYJ\12"
584+
"KoZIhvcNAQEBBQADggEPADCCAQoCggEBAIEmKUqWeRb9WGFLjE4OVOC99643Xz2s\12"
585+
"BahaHpoEvUW7r0gO6BxQ6b6KkiZbs5OfqX4MYheEUePQq3v2OJ1nAUTSiXDwCOUq\12"
586+
"3ZhS9CS4NlNaIqF4MIoPxaQYqG3jhUB/fNkg9o4DgrH0DmnGd6Mgw2/hUvNGq8IW\12"
587+
"JdlMgZGnX2cIhGQ0Cu/HV372IoYNotGEncyJEg/0ZiJDUyTWV91WoRY767GqIxn/\12"
588+
"lROrsiTzF/xzqcBdOCaMWP3et3X+jrk/i2957mw7bYYRuD415/pHlQqQQItkrmip\12"
589+
"uHJXHF8Ah0blqvFeUsBNMmzIAZblbLBbnc27tbqzUkRRjtR59suExukCAwEAAaMh\12"
590+
"MB8wHQYDVR0OBBYEFCECHg0GKw4U7/NSdq7QmEXgLydVMA0GCSqGSIb3DQEBCwUA\12"
591+
"A4IBAQAz5CAdtEcTa830ClNmR/FRLi0OkjmBd2neylflvQcpoMP/26vkdcf+5JqH\12"
592+
"+WRemkv5X7BgkdAyiQcQXal33i7ykPFjYzH0myMfknIFvmuxexgBth0cPFOsZw3x\12"
593+
"ouQSEkvVuR4q8hW77o9um0e61cTI5Qi6oToA1VXTzkwu8tcY4JcFkgskf4xRX9Qf\12"
594+
"VhuoLllozdhjShd8abWvYdZZEX3EdNVjMHWojPgEvgQzjKOOMz+EbT8YsF9+Nu1p\12"
595+
"INYMLWZ/2KDTcKOHEF2E0YbCbxiSEi32tjD40u39XcidA7vh0w9bHEujeqdQa9fs\12"
596+
"LDeLr91cBnfxzH8fxEj4iMkyV7gj\12"
597+
"-----END CERTIFICATE-----\12";
598+
}
599+
static const char* multi_cert_pem() {
600+
std::string combo = dummy_pem();
601+
combo.append("\n");
602+
combo.append(cassandra_pem());
603+
return combo.c_str();
604+
}
605+
560606
static const char* driver_private_pem_password() { return "driver"; }
561607

562608
static void write_ccm_server_files() {

tests/src/integration/tests/test_ssl.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,22 @@ CASSANDRA_INTEGRATION_TEST_F(SslTests, VerifyPeerIdentity) {
170170
write_and_read();
171171
}
172172

173+
/**
174+
* Ensures SSL connection verifying peer/server certificate while performing write and read
175+
* operations.
176+
*/
177+
CASSANDRA_INTEGRATION_TEST_F(SslTests, VerifyPeerMultipleCerts) {
178+
CHECK_FAILURE;
179+
180+
Ssl ssl;
181+
ssl.with_verify_flags(CASS_SSL_VERIFY_PEER_CERT);
182+
ssl.add_trusted_cert(SslCertificates::multi_cert_pem());
183+
184+
Cluster cluster = default_cluster().with_ssl(ssl);
185+
connect(cluster);
186+
write_and_read();
187+
}
188+
173189
/**
174190
* Ensures that when one node (in this case the whole cluster) is terminated and restarted the
175191
* driver will reconnect without throwing errors. Each stage (connect and reconnect) write and read

0 commit comments

Comments
 (0)