Skip to content

Commit

Permalink
Merge pull request #218 from jai1/TLSV1
Browse files Browse the repository at this point in the history
Using TLSv1 since boost1_41 supports TLS v1.0
  • Loading branch information
jai1 authored Feb 22, 2017
2 parents 4ac21b4 + 9f17905 commit 1691778
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pulsar-client-cpp/include/pulsar/Auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

#include <vector>
#include <string>
#include <unordered_map>
#include <map>
#include <boost/shared_ptr.hpp>
#include <pulsar/Result.h>

#pragma GCC visibility push(default)

namespace pulsar {

typedef std::unordered_map<std::string, std::string> ParamMap;
typedef std::map<std::string, std::string> ParamMap;

class AuthenticationDataProvider {
public:
Expand Down
6 changes: 3 additions & 3 deletions pulsar-client-cpp/lib/Auth.cc
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ namespace pulsar {
if(!authParamsString.empty()) {
std::vector<std::string> params;
boost::algorithm::split(params, authParamsString, boost::is_any_of(","));
for(auto& p: params) {
std::vector<std::string> kv;
boost::algorithm::split(kv, p, boost::is_any_of(":"));
for(int i = 0; i<params.size(); i++) {
std::vector<std::string> kv;
boost::algorithm::split(kv, params[i], boost::is_any_of(":"));
if (kv.size() == 2) {
paramMap[kv[0]] = kv[1];
}
Expand Down
16 changes: 9 additions & 7 deletions pulsar-client-cpp/lib/ClientConnection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,16 @@ isTlsAllowInsecureConnection_(false) {
if (clientConfiguration.isUseTls()) {
using namespace boost::filesystem;

boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client);

#if BOOST_VERSION >= 105400
boost::asio::ssl::context ctx(executor_->io_service_, boost::asio::ssl::context::tlsv12_client);
#else
boost::asio::ssl::context ctx(executor_->io_service_, boost::asio::ssl::context::tlsv1_client);
#endif
if (clientConfiguration.isTlsAllowInsecureConnection()) {
ctx.set_verify_mode(boost::asio::ssl::verify_none);
ctx.set_verify_mode(boost::asio::ssl::context::verify_none);
isTlsAllowInsecureConnection_ = true;
} else {
ctx.set_verify_mode(boost::asio::ssl::verify_peer);
ctx.set_verify_mode(boost::asio::ssl::context::verify_peer);
std::string trustCertFilePath = clientConfiguration.getTlsTrustCertsFilePath();
if (exists(path(trustCertFilePath))) {
ctx.load_verify_file(trustCertFilePath);
Expand Down Expand Up @@ -229,14 +232,13 @@ void ClientConnection::handleTcpConnected(const boost::system::error_code& err,

if (tlsSocket_) {
if (!isTlsAllowInsecureConnection_) {
boost::system::error_code err;
Url service_url;
boost::system::error_code err;
Url service_url;
if (!Url::parse(address_, service_url)) {
LOG_ERROR(cnxString_ << "Invalid Url, unable to parse: " << err << " " << err.message());
close();
return;
}
tlsSocket_->set_verify_callback(boost::asio::ssl::rfc2818_verification(service_url.host()));
}
tlsSocket_->async_handshake(boost::asio::ssl::stream<tcp::socket>::client, boost::bind(&ClientConnection::handleHandshake, shared_from_this(), boost::asio::placeholders::error));
} else {
Expand Down
3 changes: 1 addition & 2 deletions pulsar-client-cpp/lib/ExecutorService.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ typedef boost::shared_ptr<boost::asio::ssl::stream<boost::asio::ip::tcp::socket&
typedef boost::shared_ptr<boost::asio::ip::tcp::resolver> TcpResolverPtr;
typedef boost::shared_ptr<boost::asio::deadline_timer> DeadlineTimerPtr;
class ExecutorService : private boost::noncopyable {

friend class ClientConnection;
public:
ExecutorService();
~ExecutorService();
Expand All @@ -43,7 +43,6 @@ class ExecutorService : private boost::noncopyable {
DeadlineTimerPtr createDeadlineTimer();
void postWork(boost::function<void(void)> task);
void close();

private:

/*
Expand Down

0 comments on commit 1691778

Please sign in to comment.