-
Notifications
You must be signed in to change notification settings - Fork 346
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
Support OSRM routing through HTTPS #289
Comments
Yes, the current Also actually a prerequisite for #219. |
I just took a quick look at the SSL support in See patchdiff --git a/src/makefile b/src/makefile
index 320c437..1f316c4 100644
--- a/src/makefile
+++ b/src/makefile
@@ -6,7 +6,7 @@
# Variables.
CXX ?= g++
CXXFLAGS = -MMD -MP -I. -std=c++14 -Wextra -Wpedantic -Wall -O3
-LDLIBS = -lboost_system -lpthread
+LDLIBS = -lboost_system -lpthread -lssl -lcrypto
# Using all cpp files in current directory.
MAIN = ../bin/vroom
diff --git a/src/routing/http_wrapper.cpp b/src/routing/http_wrapper.cpp
index c28fc58..3a7aa39 100644
--- a/src/routing/http_wrapper.cpp
+++ b/src/routing/http_wrapper.cpp
@@ -8,6 +8,7 @@ All rights reserved (see LICENSE).
*/
#include <boost/asio.hpp>
+#include <boost/asio/ssl.hpp>
#include "routing/http_wrapper.h"
#include "utils/exception.h"
@@ -26,19 +27,24 @@ std::string HttpWrapper::send_then_receive(std::string query) const {
try {
boost::asio::io_service io_service;
+ boost::asio::ssl::context
+ ctx(io_service, boost::asio::ssl::context::method::sslv23_client);
+ boost::asio::ssl::stream<boost::asio::ip::tcp::socket> ssock(io_service,
+ ctx);
+
tcp::resolver r(io_service);
tcp::resolver::query q(_server.host, _server.port);
- tcp::socket s(io_service);
- boost::asio::connect(s, r.resolve(q));
+ boost::asio::connect(ssock.lowest_layer(), r.resolve(q));
+ ssock.handshake(boost::asio::ssl::stream_base::handshake_type::client);
- boost::asio::write(s, boost::asio::buffer(query));
+ boost::asio::write(ssock, boost::asio::buffer(query));
char buf[512];
boost::system::error_code error;
for (;;) {
- std::size_t len = s.read_some(boost::asio::buffer(buf), error);
+ std::size_t len = ssock.read_some(boost::asio::buffer(buf), error);
response.append(buf, len);
if (error == boost::asio::error::eof) {
// Connection closed cleanly.
diff --git a/src/routing/osrm_routed_wrapper.cpp b/src/routing/osrm_routed_wrapper.cpp
index 0142274..2f74c3a 100644
--- a/src/routing/osrm_routed_wrapper.cpp
+++ b/src/routing/osrm_routed_wrapper.cpp
@@ -56,7 +56,12 @@ OsrmRoutedWrapper::get_matrix(const std::vector<Location>& locs) const {
std::string response = this->send_then_receive(query);
// Removing headers.
- std::string json_content = response.substr(response.find("{"));
+ auto start = response.find("{");
+ assert(start != std::string::npos);
+ auto end = response.rfind("}");
+ assert(end != std::string::npos);
+
+ std::string json_content = response.substr(start, end - start + 1);
// Expected matrix size.
std::size_t m_size = locs.size(); Previously valid http requests does not work any more with this but at least it allows to test a remote server with https using:
This can serve as a basis for implementation. Maybe we need a command-line flag to decide whether to use http or https? |
Maybe is it more flexible if it is detected at runtime (by detecting 443 standard port) without command-line flag? |
Yes, good idea. Would only leave out use-cases with https on a non-standard port, but we can probably live with that. |
Actually, it is not possible to use OSRM routing through HTTPS:
vroom/src/routing/http_wrapper.cpp
Lines 34 to 36 in 2b0d14e
Error returned is: "Failed to connect to https://my_osrm_host:443"
Thanks for evaluating this feature request
The text was updated successfully, but these errors were encountered: