oatpp / oatpp-openssl

OpenSSL adaptor for Oat++ applications
https://oatpp.io/
Apache License 2.0
13 stars 22 forks source link

Is there an "example-openssl" project? #13

Closed hhashoww closed 2 years ago

hhashoww commented 2 years ago

Hi,

I'd like to use OpenSSL to replace Libressl but I cannot find the right way to integrate oatpp-openssl module into my oat++ project is there any example project just like https://github.com/oatpp/example-libressl??

And I got the following compiling errors

...
../http_server/lib/win64/liboatpp-openssl.a(ConnectionProvider.cpp.obj):ConnectionProvider.cpp:(.text$_ZN9__gnu_cxx13new_allocatorIN5oatpp7network3tcp6server18ConnectionProviderEE9constructIS5_JRKNS2_7AddressERbEEEvPT_DpOT0_[_ZN9__gnu_cxx13new_allocatorIN5oatpp7network3tcp6server18ConnectionProviderEE9constructIS5_JRKNS2_7AddressERbEEEvPT_DpOT0_]+0x5c): undefined reference to `oatpp::network::tcp::server::ConnectionProvider::ConnectionProvider(oatpp::network::Address const&, bool)'
../http_server/lib/win64/liboatpp-openssl.a(ConnectionProvider.cpp.obj):ConnectionProvider.cpp:(.rdata$.refptr._ZN5oatpp7network18ConnectionProvider13PROPERTY_PORTE[.refptr._ZN5oatpp7network18ConnectionProvider13PROPERTY_PORTE]+0x0): undefined reference to `oatpp::network::ConnectionProvider::PROPERTY_PORT'
../http_server/lib/win64/liboatpp-openssl.a(ConnectionProvider.cpp.obj):ConnectionProvider.cpp:(.rdata$.refptr._ZN5oatpp7network18ConnectionProvider13PROPERTY_HOSTE[.refptr._ZN5oatpp7network18ConnectionProvider13PROPERTY_HOSTE]+0x0): undefined reference to `oatpp::network::ConnectionProvider::PROPERTY_HOST'
...

thank you :)

hhashoww commented 2 years ago

Update:

I solved my problem by switching the order in the "CMakeLists.txt"

    ${oatpp-openssl}
    ${oatpp}

But when I start my server, the error message is:

terminate called after throwing an instance of 'std::runtime_error'
  what():  [oatpp::openssl::configurer::CertificateChainFile::configure()]: Error. Call to 'SSL_CTX_use_certificate_chain_file' failed.

I use the certificate keys in the https://github.com/oatpp/example-libressl/tree/master/cert is that OK?

hhashoww commented 2 years ago

Oops!

I made a typo for my certificate filename

I think this ticket can be closed

hhashoww commented 2 years ago

I'm using MSYS2 on windows environment So the OpenSSL::Crypto & OpenSSL::SSL are from MSYS2 package server And I use MinGW to build the oatpp-openssl related libraries for my project

This is my CMakeLists.txt

cmake_minimum_required(VERSION 3.14)

project(HttpServer LANGUAGES CXX)

## add executable
add_executable(${PROJECT_NAME}
  src/app_component.hpp
  src/controller/controller.cpp
  src/controller/controller.hpp
  src/dto/dtos.hpp
  src/app.cpp
)

## For windows only
if(CMAKE_HOST_WIN32)
  set(ADDITIONAL_LIBS ws2_32)
  find_library(oatpp NAMES liboatpp.a HINTS ${PROJECT_SOURCE_DIR}/lib/win64)
  if(NOT oatpp)
    message(FATAL_ERROR "Library liboatpp was not found!")
  endif()

  find_library(oatpp-openssl NAMES liboatpp-openssl.a HINTS ${PROJECT_SOURCE_DIR}/lib/win64)
  if(NOT oatpp-openssl)
    message(FATAL_ERROR "Library liboatpp-openssl was not found!")
  endif()

  find_library(oatpp-test NAMES liboatpp-test.a HINTS ${PROJECT_SOURCE_DIR}/lib/win64)
  if(NOT oatpp-test)
    message(FATAL_ERROR "Library liboatpp-test was not found!")
  endif()
endif()

# From MSYS2
find_package(OpenSSL REQUIRED)

target_link_libraries(${PROJECT_NAME}
  PUBLIC
    ${oatpp-openssl}
    ${oatpp}

    # must be last in the command
    OpenSSL::SSL
    OpenSSL::Crypto
)

target_include_directories(${PROJECT_NAME}
  PUBLIC 
    src 
    ${PROJECT_SOURCE_DIR}/include
  INTERFACE
    ${PROJECT_SOURCE_DIR}/
)