Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use OpenSSL 3, bump lua and lua-openssl, and use pcre2 #279

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
[submodule "deps/lrexlib"]
path = deps/lrexlib
url = https://github.com/rrthomas/lrexlib.git
[submodule "deps/pcre"]
path = deps/pcre
url = https://github.com/luvit/pcre.git
[submodule "deps/lpeg"]
path = deps/lpeg
url = https://github.com/luvit/lpeg.git
[submodule "deps/pcre2"]
path = deps/pcre2
url = https://github.com/PCRE2Project/pcre2
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 2.8.9)
cmake_minimum_required(VERSION 3.24)

if(WIN32)
set(projects C ASM ASM_MASM)
Expand Down Expand Up @@ -60,8 +60,8 @@ option(WithSharedLibluv "Shared or Static libluv" OFF)
option(WithOpenSSL "Include OpenSSL" OFF)
option(WithOpenSSLASM "Enable Assembly Optimizations" OFF)
option(WithSharedOpenSSL "Shared or Static OpenSSL" ON)
option(WithPCRE "Include PCRE" OFF)
option(WithSharedPCRE "Shared or Static PCRE" OFF)
option(WithPCRE2 "Include PCRE2" OFF)
option(WithSharedPCRE2 "Shared or Static PCRE2" OFF)
option(WithLPEG "Include LPEG" OFF)
option(WithSharedLPEG "Shared or Static LPEG" OFF)
option(WithZLIB "Include ZLIB" OFF)
Expand Down Expand Up @@ -119,9 +119,9 @@ if (WithOpenSSL)
include(deps/openssl.cmake)
endif (WithOpenSSL)

if (WithPCRE)
include (deps/pcre.cmake)
endif (WithPCRE)
if (WithPCRE2)
include (deps/pcre2.cmake)
endif (WithPCRE2)

if (WithLPEG)
set(LPEGLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/lpeg)
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ tiny: deps/luv/CMakeLists.txt

# Configure the build with openssl statically included
regular: deps/luv/CMakeLists.txt
cmake $(CMAKE_FLAGS) $(CPACK_FLAGS) -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF
cmake $(CMAKE_FLAGS) $(CPACK_FLAGS) -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF

regular-asm: deps/luv/CMakeLists.txt
cmake $(CMAKE_FLAGS) $(CPACK_FLAGS) -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithOpenSSLASM=ON -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF
cmake $(CMAKE_FLAGS) $(CPACK_FLAGS) -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithOpenSSLASM=ON -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF

# Configure the build with shared openssl
regular-shared:
cmake $(CMAKE_FLAGS) $(CPACK_FLAGS) -DWithOpenSSL=ON -DWithSharedOpenSSL=ON -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF
cmake $(CMAKE_FLAGS) $(CPACK_FLAGS) -DWithOpenSSL=ON -DWithSharedOpenSSL=ON -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF

package: deps/luv/CMakeLists.txt
cmake --build build -- package
Expand Down
24 changes: 0 additions & 24 deletions cmake/Modules/FindPCRE.cmake

This file was deleted.

24 changes: 24 additions & 0 deletions cmake/Modules/FindPCRE2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

FIND_PATH(PCRE2_INCLUDE_DIR NAMES PCRE2.h)

# Look for the library.
FIND_LIBRARY(PCRE2_LIBRARY NAMES PCRE2)

# Handle the QUIETLY and REQUIRED arguments and set PCRE2_FOUND to TRUE if all listed variables are TRUE.
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCRE2 DEFAULT_MSG PCRE2_LIBRARY PCRE2_INCLUDE_DIR)

# Copy the results to the output variables.
IF(PCRE2_FOUND)
SET(PCRE2_LIBRARIES ${PCRE2_LIBRARY})
SET(PCRE2_INCLUDE_DIRS ${PCRE2_INCLUDE_DIR})
SET(PCRE2_UNIT_WIDTH ${PCRE2_CODE_UNIT_WIDTH})
ELSE(PCRE2_FOUND)
SET(PCRE2_LIBRARIES)
SET(PCRE2_INCLUDE_DIRS)
SET(PCRE2_UNIT_WIDTH)
ENDIF(PCRE2_FOUND)

ADD_DEFINITIONS( -DPCRE2_CODE_UNIT_WIDTH=${PCRE2_UNIT_WIDTH} )

MARK_AS_ADVANCED(PCRE2_INCLUDE_DIRS PCRE2_LIBRARIES PCRE2_UNIT_WIDTH)
8 changes: 5 additions & 3 deletions deps/lrexlib.cmake
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
set(LREXLIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/deps/lrexlib)

add_definitions( -DPCRE2_CODE_UNIT_WIDTH=8 )

include_directories(
${LREXLIB_DIR}/src
)

add_library(lrexlib
${LREXLIB_DIR}/src/common.c
${LREXLIB_DIR}/src/pcre/lpcre.c
${LREXLIB_DIR}/src/pcre/lpcre_f.c
${LREXLIB_DIR}/src/pcre2/lpcre2.c
${LREXLIB_DIR}/src/pcre2/lpcre2_f.c
)

set_target_properties(lrexlib PROPERTIES
COMPILE_FLAGS "-DLUA_LIB -DLUA_COMPAT_APIINTCASTS -DVERSION=\\\"2.8.0\\\"")
target_link_libraries(lrexlib pcre)
target_link_libraries(lrexlib pcre2)

set(EXTRA_LIBS ${EXTRA_LIBS} lrexlib)
2 changes: 1 addition & 1 deletion deps/lua-openssl
Submodule lua-openssl updated 76 files
+7 −1 .github/asan.supp
+5 −5 .github/shell/build.sh
+3 −3 .github/shell/make_rockspec.sh
+2 −2 .github/shell/setup_lua.sh
+61 −0 .github/workflows/check.yml
+18 −93 .github/workflows/ci.yml
+79 −0 .github/workflows/codeql.yml
+40 −0 .github/workflows/libressl.yml
+0 −1 CMakeLists.txt
+23 −85 LICENSE
+31 −10 Makefile
+11 −8 README.md
+1 −1 deps/lua-compat
+9 −3 openssl-scm-0.rockspec
+295 −300 src/asn1.c
+46 −47 src/bio.c
+23 −18 src/cipher.c
+88 −92 src/cms.c
+203 −161 src/compat.c
+1 −1 src/config.ld
+62 −49 src/crl.c
+174 −133 src/csr.c
+2 −0 src/dh.c
+98 −109 src/digest.c
+2 −0 src/dsa.c
+27 −18 src/ec.c
+2 −1 src/hmac.c
+2 −0 src/lbn.c
+0 −4 src/misc.c
+556 −269 src/ocsp.c
+108 −120 src/openssl.c
+13 −2 src/openssl.h
+5 −4 src/ots.c
+14 −12 src/pkcs12.c
+62 −72 src/pkcs7.c
+453 −420 src/pkey.c
+17 −13 src/private.h
+28 −29 src/rsa.c
+4 −4 src/sk.h
+20 −14 src/ssl.c
+0 −517 src/stdatomic.h
+29 −27 src/th-lock.c
+115 −146 src/x509.c
+1 −2 src/xalgor.c
+1 −2 src/xattrs.c
+42 −51 src/xexts.c
+108 −65 src/xname.c
+2 −1 src/xstore.c
+2 −2 test/0.engine.lua
+1 −1 test/0.tcp_c.lua
+26 −5 test/1.asn1.lua
+4 −2 test/1.x509_extension.lua
+21 −8 test/1.x509_name.lua
+15 −4 test/2.digest.lua
+15 −7 test/3.cipher.lua
+22 −2 test/4.pkey.lua
+25 −1 test/5.ts.lua
+34 −13 test/5.x509.lua
+16 −2 test/5.x509_crl.lua
+16 −9 test/5.x509_req.lua
+1 −1 test/6.pkcs7.lua
+1 −1 test/8.bio_c.lua
+1 −1 test/8.bio_dtls_c.lua
+1 −1 test/8.bio_dtls_s.lua
+1 −1 test/8.bio_s.lua
+1 −1 test/8.ssl_c.lua
+1 −1 test/8.ssl_s.lua
+1 −1 test/9.issue.lua
+44 −35 test/9.ocsp.lua
+2 −3 test/dh.lua
+14 −0 test/ec.lua
+10 −2 test/helper.lua
+1 −1 test/luv/ssl.lua
+10 −5 test/rsa.lua
+18 −5 test/sm2.lua
+9 −0 test/test.lua
5 changes: 3 additions & 2 deletions deps/openssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ else (WithSharedOpenSSL)

ExternalProject_Add(openssl
PREFIX openssl
URL https://www.openssl.org/source/openssl-1.1.1m.tar.gz
URL_HASH SHA256=f89199be8b23ca45fc7cb9f1d8d3ee67312318286ad030f5316aca6462db6c96
URL https://www.openssl.org/source/openssl-3.1.1.tar.gz
URL_HASH SHA256=b3aa61334233b852b63ddb048df181177c2c659eb9d4376008118f9c08d07674
DOWNLOAD_EXTRACT_TIMESTAMP YES
LOG_BUILD ON
BUILD_IN_SOURCE YES
BUILD_COMMAND ${OPENSSL_BUILD_COMMAND}
Expand Down
1 change: 0 additions & 1 deletion deps/pcre
Submodule pcre deleted from 5c78f7
26 changes: 0 additions & 26 deletions deps/pcre.cmake

This file was deleted.

1 change: 1 addition & 0 deletions deps/pcre2
Submodule pcre2 added at 52c088
26 changes: 26 additions & 0 deletions deps/pcre2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

if (WithSharedPCRE2)
find_package(PCRE2 REQUIRED)
message("PCRE2 include dir: ${PCRE2_INCLUDE_DIR}")
message("PCRE2 libraries: ${PCRE2_LIBRARIES}")
include_directories(${PCRE2_INCLUDE_DIR})
link_directories(${PCRE2_ROOT_DIR}/lib)
list(APPEND LIB_LIST ${PCRE2_LIBRARIES})
else (WithSharedPCRE2)
SET(PCRE2_MATCH_LIMIT "150000" CACHE STRING
"Default limit on internal looping. See MATCH_LIMIT in config.h.in for details.")
OPTION(PCRE2_BUILD_PCREGREP "Build pcregrep" OFF)
OPTION(PCRE2_BUILD_TESTS "Build the tests" OFF)
OPTION(PCRE2_BUILD_PCRECPP "Build the PCRE C++ library (pcrecpp)." OFF)
SET(PCRE2_SUPPORT_UTF ON CACHE BOOL
"Enable support for Unicode Transformation Format (UTF-8/UTF-16/UTF-32) encoding.")

include_directories(${CMAKE_BINARY_DIR}/deps/pcre2)
add_subdirectory(deps/pcre2)
message("Enabling Static PCRE2")
list(APPEND EXTRA_LIBS pcre2)
add_definitions(-DPCRE_STATIC)
endif (WithSharedPCRE2)

add_definitions(-DWITH_PCRE2)
include(deps/lrexlib.cmake)
8 changes: 4 additions & 4 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ GOTO :build

:regular
ECHO "Building regular64"
cmake -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF -H. -Bbuild -G"%GENERATOR%" -Ax64
cmake -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF -H. -Bbuild -G"%GENERATOR%" -Ax64
GOTO :end

:regular-asm
ECHO "Building regular64 asm"
cmake -DWithOpenSSLASM=ON -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF -H. -Bbuild -G"%GENERATOR%" -Ax64
cmake -DWithOpenSSLASM=ON -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF -H. -Bbuild -G"%GENERATOR%" -Ax64
GOTO :end

:regular32
ECHO "Building regular32"
cmake -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF -H. -Bbuild -G"%GENERATOR%" -AWin32
cmake -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF -H. -Bbuild -G"%GENERATOR%" -AWin32
GOTO :end

:regular32-asm
ECHO "Building regular32 asm"
cmake -DWithOpenSSLASM=ON -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE=ON -DWithLPEG=ON -DWithSharedPCRE=OFF -H. -Bbuild -G"%GENERATOR%" -AWin32
cmake -DWithOpenSSLASM=ON -DWithOpenSSL=ON -DWithSharedOpenSSL=OFF -DWithPCRE2=ON -DWithLPEG=ON -DWithSharedPCRE2=OFF -H. -Bbuild -G"%GENERATOR%" -AWin32
GOTO :end

:tiny
Expand Down
9 changes: 6 additions & 3 deletions src/luvi.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include "./luvi.h"

LUALIB_API int luaopen_luvi(lua_State *L) {
#if defined(WITH_OPENSSL) || defined(WITH_PCRE)
#if defined(WITH_OPENSSL) || defined(WITH_PCRE2)
char buffer[1024];
#endif
lua_newtable(L);
Expand All @@ -33,8 +33,11 @@ LUALIB_API int luaopen_luvi(lua_State *L) {
lua_pushstring(L, buffer);
lua_setfield(L, -2, "ssl");
#endif
#ifdef WITH_PCRE
lua_pushstring(L, pcre_version());
#ifdef WITH_PCRE2
// lua_pushstring(L, pcre2_version());
char buf[64];
pcre2_config(PCRE2_CONFIG_VERSION, buf);
lua_pushstring (L, buf);
lua_setfield(L, -2, "rex");
#endif
#ifdef WITH_ZLIB
Expand Down
5 changes: 3 additions & 2 deletions src/luvi.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
#ifdef WITH_OPENSSL
#include "openssl.h"
#endif
#ifdef WITH_PCRE
#include "pcre.h"
#ifdef WITH_PCRE2
#define PCRE2_CODE_UNIT_WIDTH 8
#include "pcre2.h"
#endif
#ifdef WITH_ZLIB
#include "zlib.h"
Expand Down
10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#endif
#include "lminiz.c"
#include "snapshot.c"
#ifdef WITH_PCRE
int luaopen_rex_pcre(lua_State* L);
#ifdef WITH_PCRE2
int luaopen_rex_pcre2(lua_State* L);
#endif
#ifdef WITH_PLAIN_LUA
#include "../deps/bit.c"
Expand Down Expand Up @@ -95,10 +95,10 @@ static lua_State* vm_acquire(){
lua_setfield(L, -2, "lpeg");
#endif

#ifdef WITH_PCRE
lua_pushcfunction(L, luaopen_rex_pcre);
#ifdef WITH_PCRE2
lua_pushcfunction(L, luaopen_rex_pcre2);
lua_pushvalue(L, -1);
lua_setfield(L, -3, "rex_pcre");
lua_setfield(L, -3, "rex_pcre2");
lua_setfield(L, -2, "rex");
#endif

Expand Down