oatpp / oatpp-openssl

OpenSSL adaptor for Oat++ applications

Home Page:https://oatpp.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there an "example-openssl" project?

hhashoww opened this issue · comments

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??

  • AppComponent.hpp
  #include "oatpp-openssl/Config.hpp"
  #include "oatpp-openssl/server/ConnectionProvider.hpp"
...
  /**
   *  Create ConnectionProvider component which listens on the port 8443 (https)
   */
  OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::openssl::server::ConnectionProvider>, serverConnectionProvider)
  ([] {
    const char* crtFile = "cert/test_cert.crt";
    const char* pemFile = "cert/test_key.pem";

    auto config = oatpp::openssl::Config::createDefaultServerConfigShared(pemFile, crtFile);
    auto connectionProvider = oatpp::openssl::server::ConnectionProvider::createShared(config, {"localhost", 8443});
    return connectionProvider;
  }());
...
  • App.cpp
  // Get connection provider component (https)
  OATPP_COMPONENT(std::shared_ptr<oatpp::openssl::server::ConnectionProvider>, connectionProvider);

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 :)

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?

Oops!

I made a typo for my certificate filename

I think this ticket can be closed

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}/
)