Skip to content

Commit f1f3817

Browse files
committed
Update to the latest oatpp-libressl module interface.
1 parent c12edc9 commit f1f3817

File tree

5 files changed

+276
-30
lines changed

5 files changed

+276
-30
lines changed

CMakeLists.txt

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,37 +21,23 @@ target_include_directories(${project_name}-lib PUBLIC src)
2121
find_package(oatpp 0.19.10 REQUIRED)
2222
find_package(oatpp-libressl 0.19.10 REQUIRED)
2323

24-
target_link_libraries(${project_name}-lib
25-
PUBLIC oatpp::oatpp
26-
PUBLIC oatpp::oatpp-test
27-
PUBLIC oatpp::oatpp-libressl
28-
)
29-
30-
#################################################################
31-
## link libressl
24+
include(FindPkgConfig) # <-- include pkg-config needed by FindLibreSSL.cmake script
25+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") # <-- use FindLibreSSL.cmake in /cmake folder
3226

33-
include(FindPkgConfig)
27+
find_package(LibreSSL 3.0.0 REQUIRED)
3428

35-
pkg_check_modules(PKG_TLS REQUIRED libtls)
36-
pkg_check_modules(PKG_SSL REQUIRED libssl)
37-
pkg_check_modules(PKG_CRYPTO REQUIRED libcrypto)
29+
target_link_libraries(${project_name}-lib
3830

39-
target_include_directories(${project_name}-lib
40-
PUBLIC ${PKG_TLS_INCLUDE_DIRS}
41-
PUBLIC ${PKG_SSL_INCLUDE_DIRS}
42-
PUBLIC ${PKG_CRYPTO_INCLUDE_DIRS}
43-
)
31+
# Oat++ libraries
32+
PUBLIC oatpp::oatpp
33+
PUBLIC oatpp::oatpp-test
34+
PUBLIC oatpp::oatpp-libressl # <-- oatpp-libressl adapter
4435

45-
link_directories(
46-
${PKG_TLS_LIBRARY_DIRS}
47-
${PKG_SSL_LIBRARY_DIRS}
48-
${PKG_CRYPTO_LIBRARY_DIRS}
49-
)
36+
# LibreSSL libraries
37+
PUBLIC LibreSSL::TLS
38+
PUBLIC LibreSSL::SSL
39+
PUBLIC LibreSSL::Crypto
5040

51-
target_link_libraries(${project_name}-lib
52-
PUBLIC ${PKG_TLS_LIBRARIES}
53-
PUBLIC ${PKG_SSL_LIBRARIES}
54-
PUBLIC ${PKG_CRYPTO_LIBRARIES}
5541
)
5642

5743
#################################################################

azure-pipelines.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ jobs:
1010
pool:
1111
vmImage: 'Ubuntu 16.04'
1212
container:
13-
image: lganzzzo/ubuntu-cmake-libressl:latest
13+
image: lganzzzo/ubuntu-cmake:latest
1414
workspace:
1515
clean: all
1616
steps:
17+
- script: |
18+
sudo ./install-libressl.sh
19+
workingDirectory: utility
20+
displayName: 'install LibreSSL'
1721
- script: |
1822
sudo ./install-oatpp-modules.sh
1923
displayName: 'install oatpp modules'

cmake/FindLibreSSL.cmake

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
#[=======================================================================[
2+
3+
Copyright (c) 2019 John Norrbin <jlnorrbin@johnex.se>
4+
5+
Permission to use, copy, modify, and distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16+
17+
FindLibreSSL
18+
------------
19+
20+
Find the LibreSSL encryption library.
21+
22+
Optional Components
23+
^^^^^^^^^^^^^^^^^^^
24+
25+
This module supports two optional components: SSL and TLS. Both
26+
components have associated imported targets, as described below.
27+
28+
Imported Targets
29+
^^^^^^^^^^^^^^^^
30+
31+
This module defines the following imported targets:
32+
33+
LibreSSL::Crypto
34+
The LibreSSL crypto library, if found.
35+
36+
LibreSSL::SSL
37+
The LibreSSL ssl library, if found. Requires and includes LibreSSL::Crypto automatically.
38+
39+
LibreSSL::TLS
40+
The LibreSSL tls library, if found. Requires and includes LibreSSL::SSL and LibreSSL::Crypto automatically.
41+
42+
Result Variables
43+
^^^^^^^^^^^^^^^^
44+
45+
This module will set the following variables in your project:
46+
47+
LIBRESSL_FOUND
48+
System has the LibreSSL library. If no components are requested it only requires the crypto library.
49+
LIBRESSL_INCLUDE_DIR
50+
The LibreSSL include directory.
51+
LIBRESSL_CRYPTO_LIBRARY
52+
The LibreSSL crypto library.
53+
LIBRESSL_SSL_LIBRARY
54+
The LibreSSL SSL library.
55+
LIBRESSL_TLS_LIBRARY
56+
The LibreSSL TLS library.
57+
LIBRESSL_LIBRARIES
58+
All LibreSSL libraries.
59+
LIBRESSL_VERSION
60+
This is set to $major.$minor.$revision (e.g. 2.6.8).
61+
62+
Hints
63+
^^^^^
64+
65+
Set LIBRESSL_ROOT_DIR to the root directory of an LibreSSL installation.
66+
67+
]=======================================================================]
68+
69+
# Set Hints
70+
set(_LIBRESSL_ROOT_HINTS
71+
${LIBRESSL_ROOT_DIR}
72+
ENV LIBRESSL_ROOT_DIR
73+
)
74+
75+
# Set Paths
76+
if (WIN32)
77+
file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles)
78+
set(_LIBRESSL_ROOT_PATHS
79+
"${_programfiles}/LibreSSL"
80+
)
81+
unset(_programfiles)
82+
else()
83+
set(_LIBRESSL_ROOT_PATHS
84+
"/usr/local/"
85+
)
86+
endif()
87+
88+
# Combine
89+
set(_LIBRESSL_ROOT_HINTS_AND_PATHS
90+
HINTS ${_LIBRESSL_ROOT_HINTS}
91+
PATHS ${_LIBRESSL_ROOT_PATHS}
92+
)
93+
94+
# Find Include Path
95+
find_path(LIBRESSL_INCLUDE_DIR
96+
NAMES
97+
tls.h
98+
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
99+
PATH_SUFFIXES
100+
include
101+
)
102+
103+
# Find Crypto Library
104+
find_library(LIBRESSL_CRYPTO_LIBRARY
105+
NAMES
106+
libcrypto
107+
crypto
108+
NAMES_PER_DIR
109+
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
110+
PATH_SUFFIXES
111+
lib
112+
)
113+
114+
# Find SSL Library
115+
find_library(LIBRESSL_SSL_LIBRARY
116+
NAMES
117+
libssl
118+
ssl
119+
NAMES_PER_DIR
120+
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
121+
PATH_SUFFIXES
122+
lib
123+
)
124+
125+
# Find TLS Library
126+
find_library(LIBRESSL_TLS_LIBRARY
127+
NAMES
128+
libtls
129+
tls
130+
NAMES_PER_DIR
131+
${_LIBRESSL_ROOT_HINTS_AND_PATHS}
132+
PATH_SUFFIXES
133+
lib
134+
)
135+
136+
# Set Libraries
137+
set(LIBRESSL_LIBRARIES ${LIBRESSL_CRYPTO_LIBRARY} ${LIBRESSL_SSL_LIBRARY} ${LIBRESSL_TLS_LIBRARY})
138+
139+
# Mark Variables As Advanced
140+
mark_as_advanced(LIBRESSL_INCLUDE_DIR LIBRESSL_LIBRARIES LIBRESSL_CRYPTO_LIBRARY LIBRESSL_SSL_LIBRARY LIBRESSL_TLS_LIBRARY)
141+
142+
# Find Version File
143+
if(LIBRESSL_INCLUDE_DIR AND EXISTS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h")
144+
145+
# Get Version From File
146+
file(STRINGS "${LIBRESSL_INCLUDE_DIR}/openssl/opensslv.h" OPENSSLV.H REGEX "#define LIBRESSL_VERSION_TEXT[ ]+\".*\"")
147+
148+
# Match Version String
149+
string(REGEX REPLACE ".*\".*([0-9]+)\\.([0-9]+)\\.([0-9]+)\"" "\\1;\\2;\\3" LIBRESSL_VERSION_LIST "${OPENSSLV.H}")
150+
151+
# Split Parts
152+
list(GET LIBRESSL_VERSION_LIST 0 LIBRESSL_VERSION_MAJOR)
153+
list(GET LIBRESSL_VERSION_LIST 1 LIBRESSL_VERSION_MINOR)
154+
list(GET LIBRESSL_VERSION_LIST 2 LIBRESSL_VERSION_REVISION)
155+
156+
# Set Version String
157+
set(LIBRESSL_VERSION "${LIBRESSL_VERSION_MAJOR}.${LIBRESSL_VERSION_MINOR}.${LIBRESSL_VERSION_REVISION}")
158+
159+
endif()
160+
161+
# Set Find Package Arguments
162+
find_package_handle_standard_args(LibreSSL
163+
REQUIRED_VARS
164+
LIBRESSL_CRYPTO_LIBRARY
165+
LIBRESSL_INCLUDE_DIR
166+
VERSION_VAR
167+
LIBRESSL_VERSION
168+
HANDLE_COMPONENTS
169+
FAIL_MESSAGE
170+
"Could NOT find LibreSSL, try setting the path to LibreSSL using the LIBRESSL_ROOT_DIR environment variable"
171+
)
172+
173+
# LibreSSL Found
174+
if(LIBRESSL_FOUND)
175+
176+
# Set LibreSSL::Crypto
177+
if(NOT TARGET LibreSSL::Crypto AND EXISTS "${LIBRESSL_CRYPTO_LIBRARY}")
178+
179+
# Add Library
180+
add_library(LibreSSL::Crypto UNKNOWN IMPORTED)
181+
182+
# Set Properties
183+
set_target_properties(
184+
LibreSSL::Crypto
185+
PROPERTIES
186+
INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
187+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
188+
IMPORTED_LOCATION "${LIBRESSL_CRYPTO_LIBRARY}"
189+
)
190+
191+
endif() # LibreSSL::Crypto
192+
193+
# Set LibreSSL::SSL
194+
if(NOT TARGET LibreSSL::SSL AND EXISTS "${LIBRESSL_SSL_LIBRARY}")
195+
196+
# Add Library
197+
add_library(LibreSSL::SSL UNKNOWN IMPORTED)
198+
199+
# Set Properties
200+
set_target_properties(
201+
LibreSSL::SSL
202+
PROPERTIES
203+
INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
204+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
205+
IMPORTED_LOCATION "${LIBRESSL_SSL_LIBRARY}"
206+
INTERFACE_LINK_LIBRARIES LibreSSL::Crypto
207+
)
208+
209+
endif() # LibreSSL::SSL
210+
211+
# Set LibreSSL::TLS
212+
if(NOT TARGET LibreSSL::TLS AND EXISTS "${LIBRESSL_TLS_LIBRARY}")
213+
add_library(LibreSSL::TLS UNKNOWN IMPORTED)
214+
set_target_properties(
215+
LibreSSL::TLS
216+
PROPERTIES
217+
INTERFACE_INCLUDE_DIRECTORIES "${LIBRESSL_INCLUDE_DIR}"
218+
IMPORTED_LINK_INTERFACE_LANGUAGES "C"
219+
IMPORTED_LOCATION "${LIBRESSL_TLS_LIBRARY}"
220+
INTERFACE_LINK_LIBRARIES LibreSSL::SSL
221+
)
222+
223+
endif() # LibreSSL::TLS
224+
225+
endif(LIBRESSL_FOUND)

src/AppComponent.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ class AppComponent {
3838
* Create ConnectionProvider component which listens on the port
3939
*/
4040
OATPP_CREATE_COMPONENT(std::shared_ptr<oatpp::network::ServerConnectionProvider>, serverConnectionProvider)([] {
41-
/* non_blocking connections should be used with AsyncHttpConnectionHandler for AsyncIO */
41+
4242
OATPP_LOGD("oatpp::libressl::Config", "pem='%s'", CERT_PEM_PATH);
4343
OATPP_LOGD("oatpp::libressl::Config", "crt='%s'", CERT_CRT_PATH);
44-
auto config = oatpp::libressl::Config::createDefaultServerConfig(CERT_PEM_PATH, CERT_CRT_PATH);
44+
auto config = oatpp::libressl::Config::createDefaultServerConfigShared(CERT_CRT_PATH, CERT_PEM_PATH /* private key */);
4545

4646
/**
4747
* if you see such error:
@@ -50,7 +50,7 @@ class AppComponent {
5050
* Try to make sure you are using libtls, libssl, and libcrypto from the same package
5151
*/
5252

53-
return oatpp::libressl::server::ConnectionProvider::createShared(config, 8443, true /* true for non_blocking */);
53+
return oatpp::libressl::server::ConnectionProvider::createShared(config, 8443);
5454
}());
5555

5656
/**

utility/install-libressl.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/sh
2+
3+
mkdir tmp
4+
cd tmp
5+
6+
VERSION=3.0.2
7+
8+
#############################################
9+
## download libressl-$VERSION
10+
11+
wget https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-$VERSION.tar.gz
12+
13+
#############################################
14+
## clean dir
15+
16+
rm -rf libressl-$VERSION
17+
18+
#############################################
19+
## unpack
20+
21+
tar -xvzf libressl-$VERSION.tar.gz
22+
cd libressl-$VERSION
23+
24+
#############################################
25+
## build and install libressl
26+
27+
mkdir build && cd build
28+
29+
cmake -DCMAKE_BUILD_TYPE=Release ..
30+
make
31+
make install

0 commit comments

Comments
 (0)