diff Framework/PostgreSQL/PostgreSQLParameters.cpp @ 80:16df1a6ea452 db-changes

Fix issue #105 (Unable to connect to PostgreSQL database using SSL)
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 10 Jan 2019 12:53:00 +0100
parents 714c5d2bee76
children 4cd7e45b671e
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLParameters.cpp	Tue Jan 08 14:37:41 2019 +0100
+++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp	Thu Jan 10 12:53:00 2019 +0100
@@ -37,6 +37,7 @@
     password_ = "";
     database_.clear();
     uri_.clear();
+    ssl_ = false;
     lock_ = true;
   }
 
@@ -84,6 +85,8 @@
       {
         SetPassword(s);
       }
+
+      ssl_ = configuration.GetBooleanValue("EnableSsl", false);
     }
 
     lock_ = configuration.GetBooleanValue("Lock", true);  // Use locking by default
@@ -174,7 +177,11 @@
   {
     if (uri_.empty())
     {
-      target = std::string("sslmode=disable") +  // TODO WHY SSL DOES NOT WORK? ("SSL error: wrong version number")
+      // Note about SSL: "require" means that "I want my data to be
+      // encrypted, and I accept the overhead. I trust that the
+      // network will make sure I always connect to the server I want."
+      // https://www.postgresql.org/docs/current/libpq-ssl.html
+      target = std::string(ssl_ ? "sslmode=require" : "sslmode=disable") +
         " user=" + username_ + 
         " host=" + host_ + 
         " port=" + boost::lexical_cast<std::string>(port_);