From b1ce0ec0e8f188ca11eb903d2e416d67ca3d0a3d Mon Sep 17 00:00:00 2001 From: hax0kartik Date: Sun, 23 Feb 2020 06:18:32 -0800 Subject: [PATCH] Fix cmake --- CMakeLists.txt | 16 +++++------ cmake/Modules/FindLibJWT.cmake | 28 +++++++++++++++++++ .../include/jwt-cpp/{jwt.h => jwt_cpp.h} | 0 src/zm_crypt.cpp | 7 +++-- 4 files changed, 39 insertions(+), 12 deletions(-) create mode 100644 cmake/Modules/FindLibJWT.cmake rename src/jwt-cpp/include/jwt-cpp/{jwt.h => jwt_cpp.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index d10eb3f9c..4b9c06a90 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -348,16 +348,14 @@ else(JPEG_FOUND) endif(JPEG_FOUND) # LIBJWT -find_package(jwt) -if(JWT_FOUND) +find_package(LibJWT) +if(LIBJWT_FOUND) set(HAVE_LIBJWT 1) - list(APPEND ZM_LIB_BINS "${JWT_LIBRARIES}") - include_directories("${JWT_INCLUDE_DIR}") - set(CMKAE_REQUIRED_INCLUDES "${JWT_INCLUDE_DIR}") - set(optlibsfound "{optlibsfound} JWT") -else(JWT_FOUND) - set(optlibsnotfound "${optlibsnotfound} JWT") -endif(JWT_FOUND) + set(optlibsfound "${optlibsfound} LIBJWT") + list(APPEND ZM_BIN_LIBS "${LIBJWT_LIBRARY}") +else(LIBJWT_FOUND) + set(optlibsnotfound "${optlibsnotfound} LIBJWT") +endif(LIBJWT_FOUND) # OpenSSL find_package(OpenSSL) diff --git a/cmake/Modules/FindLibJWT.cmake b/cmake/Modules/FindLibJWT.cmake new file mode 100644 index 000000000..0dc5d8117 --- /dev/null +++ b/cmake/Modules/FindLibJWT.cmake @@ -0,0 +1,28 @@ +include(FindPackageHandleStandardArgs) + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_LIBJWT QUIET libjwt) + +find_path(LIBJWT_INCLUDE_DIR + NAMES jwt.h + HINTS ${PC_LIBJWT_INCLUDEDIR} ${PC_LIBJWT_INCLUDE_DIRS} + ) + +find_library(LIBJWT_LIBRARY + NAMES jwt libjwt liblibjwt + HINTS ${PC_LIBJWT_LIBDIR} ${PC_LIBJWT_LIBRARY_DIR} + ) + +find_package_handle_standard_args(LibJWT + REQUIRED_VARS LIBJWT_INCLUDE_DIR LIBJWT_LIBRARY + ) + +if(LIBJWT_FOUND) + add_library(libjwt STATIC IMPORTED GLOBAL) + set_target_properties(libjwt PROPERTIES + IMPORTED_LOCATION "${LIBJWT_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${LIBJWT_INCLUDE_DIR}" + ) +endif() + +mark_as_advanced(LIBJWT_INCLUDE_DIR LIBJWT_LIBRARY) \ No newline at end of file diff --git a/src/jwt-cpp/include/jwt-cpp/jwt.h b/src/jwt-cpp/include/jwt-cpp/jwt_cpp.h similarity index 100% rename from src/jwt-cpp/include/jwt-cpp/jwt.h rename to src/jwt-cpp/include/jwt-cpp/jwt_cpp.h diff --git a/src/zm_crypt.cpp b/src/zm_crypt.cpp index cc4363c22..62148ee23 100644 --- a/src/zm_crypt.cpp +++ b/src/zm_crypt.cpp @@ -4,7 +4,7 @@ #if HAVE_LIBJWT #include #else -#include "jwt.h" +#include "jwt_cpp.h" #endif #include #if HAVE_LIBCRYPTO @@ -21,18 +21,19 @@ std::pair verifyToken(std::string jwt_token_str, std unsigned int token_issued_at = 0; int err = 0; jwt_t *jwt = nullptr; + err = jwt_new(&jwt); if( err ) { Error("Unable to Allocate JWT object"); return std::make_pair("", 0); } - err = jwt_set_alg(jwt, JWT_ALG_HS256, key.c_str(), key.length()); + err = jwt_set_alg(jwt, JWT_ALG_HS256, (const unsigned char*)key.c_str(), key.length()); if( err ) { jwt_free(jwt); Error("Error setting Algorithm for JWT decode"); return std::make_pair("", 0); - s} + } err = jwt_decode(&jwt, jwt_token_str.c_str(), nullptr, 0); if( err ) {