Fix cmake

This commit is contained in:
hax0kartik 2020-02-23 06:18:32 -08:00
parent 46d77ee849
commit b1ce0ec0e8
4 changed files with 39 additions and 12 deletions

View File

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

View File

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

View File

@ -4,7 +4,7 @@
#if HAVE_LIBJWT
#include <jwt.h>
#else
#include "jwt.h"
#include "jwt_cpp.h"
#endif
#include <algorithm>
#if HAVE_LIBCRYPTO
@ -21,18 +21,19 @@ std::pair <std::string, unsigned int> 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 ) {