Mercurial > hg > orthanc-databases
comparison 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 |
comparison
equal
deleted
inserted
replaced
79:cb0aac9bbada | 80:16df1a6ea452 |
---|---|
35 port_ = 5432; | 35 port_ = 5432; |
36 username_ = ""; | 36 username_ = ""; |
37 password_ = ""; | 37 password_ = ""; |
38 database_.clear(); | 38 database_.clear(); |
39 uri_.clear(); | 39 uri_.clear(); |
40 ssl_ = false; | |
40 lock_ = true; | 41 lock_ = true; |
41 } | 42 } |
42 | 43 |
43 | 44 |
44 PostgreSQLParameters::PostgreSQLParameters() | 45 PostgreSQLParameters::PostgreSQLParameters() |
82 | 83 |
83 if (configuration.LookupStringValue(s, "Password")) | 84 if (configuration.LookupStringValue(s, "Password")) |
84 { | 85 { |
85 SetPassword(s); | 86 SetPassword(s); |
86 } | 87 } |
88 | |
89 ssl_ = configuration.GetBooleanValue("EnableSsl", false); | |
87 } | 90 } |
88 | 91 |
89 lock_ = configuration.GetBooleanValue("Lock", true); // Use locking by default | 92 lock_ = configuration.GetBooleanValue("Lock", true); // Use locking by default |
90 } | 93 } |
91 | 94 |
172 | 175 |
173 void PostgreSQLParameters::Format(std::string& target) const | 176 void PostgreSQLParameters::Format(std::string& target) const |
174 { | 177 { |
175 if (uri_.empty()) | 178 if (uri_.empty()) |
176 { | 179 { |
177 target = std::string("sslmode=disable") + // TODO WHY SSL DOES NOT WORK? ("SSL error: wrong version number") | 180 // Note about SSL: "require" means that "I want my data to be |
181 // encrypted, and I accept the overhead. I trust that the | |
182 // network will make sure I always connect to the server I want." | |
183 // https://www.postgresql.org/docs/current/libpq-ssl.html | |
184 target = std::string(ssl_ ? "sslmode=require" : "sslmode=disable") + | |
178 " user=" + username_ + | 185 " user=" + username_ + |
179 " host=" + host_ + | 186 " host=" + host_ + |
180 " port=" + boost::lexical_cast<std::string>(port_); | 187 " port=" + boost::lexical_cast<std::string>(port_); |
181 | 188 |
182 if (!password_.empty()) | 189 if (!password_.empty()) |