-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
109 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
cmake_minimum_required(VERSION 3.15) | ||
project (ssl_test) | ||
|
||
set(PROJECT_INCLUDE_DIR | ||
${PROJECT_SOURCE_DIR}/include | ||
) | ||
|
||
set(TEST_SRCS | ||
ssltest.cpp | ||
) | ||
|
||
add_executable(ssltest ${TEST_SRCS}) | ||
target_link_libraries(ssltest ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES} z) | ||
target_compile_options(ssltest PRIVATE "${compiler_options}") | ||
|
||
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") | ||
set_target_properties(ssltest PROPERTIES COMPILE_FLAGS "--coverage -fprofile-arcs -ftest-coverage") | ||
target_link_libraries(ssltest gcov) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#define CROW_ENABLE_SSL | ||
#define CATCH_CONFIG_MAIN | ||
#define CROW_LOG_LEVEL 0 | ||
#define CROW_MAIN | ||
|
||
#include <thread> | ||
|
||
#include "../catch.hpp" | ||
#include "crow.h" | ||
|
||
#define LOCALHOST_ADDRESS "127.0.0.1" | ||
|
||
using namespace boost; | ||
|
||
//TODO SSL test with .pem file | ||
TEST_CASE("SSL") | ||
{ | ||
static char buf[2048]; | ||
//static char buf2[2048]; | ||
|
||
std::system("openssl req -newkey rsa:4096 -x509 -sha256 -days 365 -nodes -out test.crt -keyout test.key -subj '/CN=127.0.0.1'"); | ||
//std::system("cat test.key > test.pem"); | ||
//std::system("cat test.crt >> test.pem"); | ||
|
||
crow::SimpleApp app; | ||
//crow::SimpleApp app2; | ||
|
||
CROW_ROUTE(app, "/") | ||
([]() { | ||
return "Hello world, I'm keycrt."; | ||
}); | ||
/* | ||
CROW_ROUTE(app2, "/") | ||
([]() { | ||
return "Hello world, I'm pem."; | ||
}); | ||
*/ | ||
auto _ = async(std::launch::async, [&] { app.bindaddr(LOCALHOST_ADDRESS).port(45460).ssl_file("test.crt", "test.key").run(); }); | ||
//auto _1 = async(std::launch::async,[&] { app2.bindaddr(LOCALHOST_ADDRESS).port(45461).ssl_file("test.pem").run(); }); | ||
|
||
app.wait_for_server_start(); | ||
//app2.wait_for_server_start(); | ||
|
||
std::string sendmsg = "GET /\r\n\r\n"; | ||
|
||
asio::ssl::context ctx(asio::ssl::context::sslv23); | ||
|
||
asio::io_service is; | ||
{ | ||
std::cout << "started first one" << std::endl; | ||
|
||
asio::ssl::stream<asio::ip::tcp::socket> c(is, ctx); | ||
c.lowest_layer().connect(asio::ip::tcp::endpoint( | ||
asio::ip::address::from_string(LOCALHOST_ADDRESS), 45460)); | ||
|
||
c.handshake(asio::ssl::stream_base::client); | ||
|
||
c.write_some(asio::buffer(sendmsg)); | ||
|
||
size_t sz = c.read_some(asio::buffer(buf, 2048)); | ||
|
||
CHECK("Hello world, I'm keycrt." == std::string(buf).substr((sz - 24))); | ||
} | ||
|
||
/* | ||
asio::io_service is2; | ||
{ | ||
std::cout << "started second one" << std::endl; | ||
asio::ssl::stream<asio::ip::tcp::socket> c(is2, ctx); | ||
c.lowest_layer().connect(asio::ip::tcp::endpoint( | ||
asio::ip::address::from_string(LOCALHOST_ADDRESS), 45461)); | ||
c.handshake(asio::ssl::stream_base::client); | ||
c.write_some(asio::buffer(sendmsg)); | ||
size_t sz = c.read_some(asio::buffer(buf2, 2048)); | ||
CHECK("Hello world, I'm pem." == std::string(buf2).substr((sz - 21))); | ||
} | ||
*/ | ||
app.stop(); | ||
//app2.stop(); | ||
|
||
std::system("rm test.crt test.key" /*test.pem*/); | ||
} |