Skip to content

Commit

Permalink
ssl suport added
Browse files Browse the repository at this point in the history
  • Loading branch information
moneroexamples committed Dec 19, 2016
1 parent d44e0ad commit b906718
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 5 deletions.
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ set_property(TARGET common PROPERTY IMPORTED_LOCATION ${MONERO_LIBS_DIR}/libcomm
add_library(blocks STATIC IMPORTED)
set_property(TARGET blocks PROPERTY IMPORTED_LOCATION ${MONERO_LIBS_DIR}/libblocks.a)

add_library(crypto STATIC IMPORTED)
set_property(TARGET crypto
add_library(cryptoxmr STATIC IMPORTED)
set_property(TARGET cryptoxmr
PROPERTY IMPORTED_LOCATION ${MONERO_LIBS_DIR}/libcrypto.a)

add_library(cryptonote_core STATIC IMPORTED)
Expand Down Expand Up @@ -163,7 +163,7 @@ target_link_libraries(${PROJECT_NAME}
cryptonote_core
cryptonote_protocol
blockchain_db
crypto
cryptoxmr
blocks
lmdb
ringct
Expand All @@ -173,4 +173,6 @@ target_link_libraries(${PROJECT_NAME}
unbound
unwind
curl
dl)
dl
crypto
ssl)
50 changes: 49 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#define CROW_ENABLE_SSL

#include "ext/crow/crow.h"

Expand Down Expand Up @@ -41,11 +42,47 @@ int main(int ac, const char* av[]) {
auto bc_path_opt = opts.get_option<string>("bc-path");
auto custom_db_path_opt = opts.get_option<string>("custom-db-path");
auto deamon_url_opt = opts.get_option<string>("deamon-url");
auto ssl_crt_file_opt = opts.get_option<string>("ssl-crt-file");
auto ssl_key_file_opt = opts.get_option<string>("ssl-key-file");


//cast port number in string to uint16
uint16_t app_port = boost::lexical_cast<uint16_t>(*port_opt);


bool use_ssl {false};

string ssl_crt_file;
string ssl_key_file;

// check if ssl enabled and files exist

if (ssl_crt_file_opt and ssl_key_file_opt)
{
if (!boost::filesystem::exists(boost::filesystem::path(*ssl_crt_file_opt)))
{
cerr << "ssl_crt_file path: " << *ssl_crt_file_opt
<< "does not exist!" << endl;

return EXIT_FAILURE;
}

if (!boost::filesystem::exists(boost::filesystem::path(*ssl_key_file_opt)))
{
cerr << "ssl_key_file path: " << *ssl_key_file_opt
<< "does not exist!" << endl;

return EXIT_FAILURE;
}

ssl_crt_file = *ssl_crt_file_opt;
ssl_key_file = *ssl_key_file_opt;

use_ssl = true;
}



// get blockchain path
path blockchain_path;

Expand Down Expand Up @@ -271,7 +308,18 @@ int main(int ac, const char* av[]) {
});

// run the crow http server
app.port(app_port).multithreaded().run();

if (use_ssl)
{
cout << "Staring in ssl mode" << endl;
app.port(app_port).ssl_file(ssl_crt_file, ssl_key_file).multithreaded().run();
}
else
{
cout << "Staring in non-ssl mode" << endl;
app.port(app_port).multithreaded().run();
}


return EXIT_SUCCESS;
}
4 changes: 4 additions & 0 deletions src/CmdLineOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ namespace xmreg
"default port")
("bc-path,b", value<string>(),
"path to lmdb blockchain")
("ssl-crt-file", value<string>(),
"A path to crt file for ssl (https) functionality")
("ssl-key-file", value<string>(),
"A path to key file for ssl (https) functionality")
("custom-db-path,c", value<string>(),
"path to the custom lmdb database used for searching things")
("deamon-url,d", value<string>()->default_value("http:://127.0.0.1:18081"),
Expand Down

0 comments on commit b906718

Please sign in to comment.