Skip to content

Commit

Permalink
mbedtls: Code exists now, but not fully working
Browse files Browse the repository at this point in the history
Status:
- HS256/384/512 Works
- ES Reads keys, fails signing and verifying
- RS ""
- EdDSA Does not read keys
- PS Does not read keys

Signed-off-by: Ben Collins <[email protected]>
  • Loading branch information
benmcollins committed Jan 13, 2025
1 parent a4492de commit e9d0bf0
Show file tree
Hide file tree
Showing 5 changed files with 549 additions and 142 deletions.
21 changes: 19 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ if (NOT DEFINED WITH_GNUTLS)
endif()

option(WITH_GNUTLS "Whether to use GnuTLS (default is auto detect)" ON)
option(WITH_MBEDTLS "Whether to use mbedTLS (default is OFF)" OFF)
option(WITH_TESTS "Whether to build and run the testsuite (default is ON)" ON)

# Need at least one of these
# Optional
if (WITH_GNUTLS)
if (NOT GNUTLS_AUTO)
set(GNUTLS_REQUIRED REQUIRED)
endif()
pkg_check_modules(GNUTLS gnutls>=3.6.0 IMPORTED_TARGET
${GNUTLS_REQUIRED})
endif()
if (WITH_MBEDTLS)
pkg_check_modules(MBEDTLS mbedcrypto>=3.6.0 IMPORTED_TARGET)
endif()

# Required
pkg_check_modules(OPENSSL openssl>=3.0.0 IMPORTED_TARGET
REQUIRED)

Expand Down Expand Up @@ -102,6 +107,16 @@ if (GNUTLS_FOUND)
# libjwt/gnutls/jwk-parse.c
endif()

if (MBEDTLS_FOUND)
set(HAVE_CRYPTO TRUE)
add_definitions(-DHAVE_MBEDTLS)
target_link_libraries(jwt PUBLIC PkgConfig::MBEDTLS)
target_link_libraries(jwt_static PUBLIC PkgConfig::MBEDTLS)
list(APPEND JWT_SOURCES
libjwt/mbedtls/sign-verify.c)
# libjwt/mbedtls/jwk-parse.c
endif()

set(HAVE_CRYPTO TRUE)
add_definitions(-DHAVE_OPENSSL)
target_link_libraries(jwt PUBLIC PkgConfig::OPENSSL)
Expand Down Expand Up @@ -184,10 +199,12 @@ install(EXPORT ${LIBJWT_PROJECT}Targets

# For pkg-config users
unset(LIBJWT_LDFLAGS)
foreach (FLAG ${JANSSON_LDFLAGS} ${OPENSSL_LDFLAGS} ${GNUTLS_LDFLAGS})
foreach (FLAG ${JANSSON_LDFLAGS} ${OPENSSL_LDFLAGS} ${GNUTLS_LDFLAGS}
${MBEDTLS_LDFLAGS})
string(APPEND LIBJWT_LDFLAGS " " ${FLAG})
endforeach()


configure_file(libjwt/libjwt.pc.in libjwt.pc @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/libjwt.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
Expand Down
2 changes: 0 additions & 2 deletions libjwt/mbedtls/jwk-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include <mbedtls/ssl.h>

#include <jwt.h>

#include "jwt-private.h"
Expand Down
Loading

0 comments on commit e9d0bf0

Please sign in to comment.