Code Monkey home page Code Monkey logo

jwtpp's Introduction

jwtpp

JSON Object Signing and Encryption library for C++

Codacy Badge Build Status Codecov

Dependencies:

Built and tested with:

  • GCC
    • C++11
    • С++14
    • С++17
  • СLang
    • C++11
    • С++14
    • С++17

Supported features:

  • Sign
  • Verify

Supported algorithms

Alg Status
HS256 Supported
HS384 Supported
HS512 Supported
RS256 Supported
RS384 Supported
RS512 Supported
ES256 Supported
ES384 Supported
ES512 Supported
PS256 Supported
PS384 Supported
PS512 Supported
EdDSA Supported

Claims

Claim Options Status
ess set,verify Supported
sub set,verify Supported
aud set,verify Supported
exp set,verify Supported
nbf set,verify Supported
iat set,verify Supported
jti set,verify Supported

How to use

Refer to tests dir

How to build/install

CMake sources deps

add_subdirectory()

System-wide installation

On MacOS OPENSSL_ROOT_DIR might need to be specified. Add -DOPENSSL_ROOT_DIR=$(brew --prefix openssl) to cmake stage

git clone https://github.com/troian/jwtpp
mkdir build && cd build
cmake -Wno-dev -DCMAKE_INSTALL_PREFIX=<install prefix> ..
make install

Homebrew

brew tap troian/tap
brew install jwtpp

TODO

  • Documentation
  • Examples
  • Tests

How to contribute

Just do it! :)

jwtpp's People

Contributors

codacy-badger avatar gelldur avatar hbzzhtt avatar ihmc3jn09hk avatar kachanovskiy avatar kakaly avatar olafvdspek avatar onchere avatar sa2304 avatar troian avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

jwtpp's Issues

expire time verification?

Hi troian, thank you for the awesome work. May I have an example on how to control as well as perform a verification on the JWT expiration? I dont see an example in the "tests/" folder.

Make jwtpp::claims::set a template class

  • Provide single claims::set::any() method that accepts a template parameter (value).
  • Make std::string default template argument to keep compatability with older code.
  • Also make claims::has & claims::check template classes.

hmac.cpp:68:11: error: aggregate ‘HMAC_CTX hmac’ has incomplete type and cannot be defined

libssl-dev:amd64                       1.1.0f-3+deb9u1

olaf@debian:~/josepp/build$ make
Scanning dependencies of target josepp-static
[  9%] Building CXX object CMakeFiles/josepp-static.dir/src/tools.cpp.o
[ 18%] Building CXX object CMakeFiles/josepp-static.dir/src/claims.cpp.o
[ 27%] Building CXX object CMakeFiles/josepp-static.dir/src/crypto.cpp.o
[ 36%] Building CXX object CMakeFiles/josepp-static.dir/src/hmac.cpp.o
/home/olaf/josepp/src/hmac.cpp: In member function ‘virtual std::__cxx11::string jose::hmac::sign(const string&)’:
/home/olaf/josepp/src/hmac.cpp:68:11: error: aggregate ‘HMAC_CTX hmac’ has incomplete type and cannot be defined
  HMAC_CTX hmac;
           ^~~~
/home/olaf/josepp/src/hmac.cpp:69:21: error: ‘HMAC_CTX_init’ was not declared in this scope
  HMAC_CTX_init(&hmac);
                     ^
/home/olaf/josepp/src/hmac.cpp:77:24: error: ‘HMAC_CTX_cleanup’ was not declared in this scope
  HMAC_CTX_cleanup(&hmac);

https://www.openssl.org/docs/man1.1.0/crypto/HMAC_CTX_free.html

Unable to build on Mac. Cmake throws "package 'jsoncpp' not found"

MacOS 10.15.4

tried installing with brew:
Error: No available formula with the name "jwtpp"

tried building with Cmake:

cmake -Wno-dev -DCMAKE_TOOLCHAIN_FILE=/Users/xxxxx/Projects/vcpkg/scripts/buildsystems/vcpkg.cmake -DCMAKE_INSTALL_PREFIX=/usr/local/ ..

...
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/local/Cellar/[email protected]/1.1.1d/lib/libcrypto.dylib (found version "1.1.1d")
-- Found PkgConfig: /usr/local/bin/pkg-config (found version "0.29.2")
-- Checking for module 'jsoncpp'
-- No package 'jsoncpp' found
CMake Error at /usr/local/Cellar/cmake/3.15.5/share/cmake/Modules/FindPkgConfig.cmake:458 (message):
A required package was not found
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.15.5/share/cmake/Modules/FindPkgConfig.cmake:637 (_pkg_check_modules_internal)
CMakeLists.txt:39 (pkg_check_modules)
-- Configuring incomplete, errors occurred!

jsoncpp is built with vcpkg as described in jsoncpp repo. tried installing it with brew as well.

build issues with VS2010

Hi,

out of the box, josepp does not build with VS2010 due to being written in proper C++11 :), which is a problem for VS2010 as it does not fully implement it.

I have finally managed to compile it with VS2010, so I can provide you a PR to fix this, if the following fixes look ok to you - I had to:

  1. remove "final" from class definitions
  2. remove type aliases (and replace them with typedefs)
  3. remove delegating constructors (copying initialization list from non-default constructor)
  4. remove variadic template use in make_shared methods in claims (seems ok, as these methods are never used)
  5. change enum classes to plain enums (shouldn't change semantics since enum classes do not contain methods)
  6. remove std::bind from lambda use in tests (looks ok as lambda's capture list is empty) - can also be done by replacing lambda with a normal function returning bool

I have also made some minor changes to CMake files:

  1. changed explicit use of pkg-config (not supported on Windows) to Unix-only
  2. compiler flags also made platform-specific
  3. for some reason, jwtpp-test is added as test instead of above configured josepp-test

Let me know if you need this.

Thanks.
Sergey.

undefined reference to `jwtpp::claims::claims()`

Hi troian,
I have the following problem:
When inserting the following line into my code:

jwtpp::claims cl;

I get the following error code when building:

undefined reference to `jwtpp::claims::claims()`

The same with:

std::string key = "some";
std::string value = "test";
cl.set().any(key, value);
undefined reference to `jwtpp::claims::set::any(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

and

std::string encoded = jws::sign_bearer(cl, signer);
undefined reference to `jwtpp::jws::sign_bearer[abi:cxx11](jwtpp::claims&, std::shared_ptr<jwtpp::crypto>)'

and

jwtpp::sp_jws jws = jws::parse(encoded);
undefined reference to `jwtpp::jws::parse(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)'

On the other hand the following lines work:

cl.set().nbf(value);
cl.set().exp(value);
jwtpp::sp_crypto signer = std::make_shared<jwtpp::hmac>("secret", jwtpp::alg_t::HS256);

I used the tests as a guide and examples.

Could you please help me?

CMakeLists.txt:

cmake_minimum_required(VERSION 3.0.0)
project(project VERSION 0.1.0)

include(CTest)
enable_testing()

find_package(OpenSSL REQUIRED)

# C++ Library 
add_subdirectory(jsoncpp)
get_target_property(jsoncpp/include jsoncpp_lib INTERFACE_INCLUDE_DIRECTORIES)
include_directories(jsoncpp/include)
add_library(jwtpp INTERFACE)
target_include_directories(jwtpp INTERFACE jwtpp/include)

add_executable(project main.cpp libraries_cpp_jwtpp_2.cpp)

target_link_libraries(project jwtpp jsoncpp_lib)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
include(CPack)

Build failed on VS 10

Configure project
$ full/path/to/cmake-3.17.0/bin/cmake.exe -G "Visual Studio 10" .. - DCMAKE_INSTALL_PREFIX:PATH="full/path/to/install/dir/jwt" -DJSONCPP_WITH_POST_BUILD_UNITTEST=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DJsonCPP_INCLUDE_DIRS "full/path/to/jsoncpp/include/jsoncpp" -DJsonCPP_LIBRARIES "full/path/to/jsoncpp/lib/jsoncpp.lib"

image

Additional Dependencies

  1. jsoncpp [build succeed] with Visual Studio Code 10 and produces:
    7>Build succeeded.
    7>
    7>Time Elapsed 00:00:09.40
    9>------ Skipped Build: Project: jsoncpp_check, Configuration: Debug Win32 ------
    9>Project not selected to build for this solution configuration
    ========== Build: 6 succeeded, 0 failed, 0 up-to-date, 3 skipped ==========

and INSTALL target succeed too

1> -- Install configuration: "Debug"
1> -- Installing: full/path/to/jsoncpp/lib/pkgconfig/jsoncpp.pc
1> -- Installing: full/path/to/jsoncpp/lib/jsoncpp.lib
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/assertions.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/autolink.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/config.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/features.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/forwards.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/json.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/reader.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/value.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/version.h
1> -- Installing: full/path/to/jsoncpp/include/jsoncpp/json/writer.h

but build failed with errors

3>ClCompile:
3> b64.cpp
2> crypto.cpp
3> claims.cpp
3> crypto.cpp
2>full\path\to\josepp/digest.hpp(48): error C3409: empty attribute block is not allowed
2>full\path\to\josepp/digest.hpp(48): error C2143: syntax error : missing ']' before '['
2>full\path\to\josepp/digest.hpp(48): error C2337: 'fallthrough' : attribute not found
2>full\path\to\josepp/digest.hpp(48): error C2143: syntax error : missing ';' before ']'
2>full\path\to\josepp/digest.hpp(49): warning C4482: nonstandard extension used: enum 'jose::digest::type' used in qualified name
2>full\path\to\josepp/digest.hpp(51): warning C4482: nonstandard extension used: enum 'jose::digest::type' used in qualified name
2>full\path\to\josepp/digest.hpp(53): warning C4482: nonstandard extension used: enum 'jose::digest::type' used in qualified name
2>full\path\to\josepp/sstring.hh(37): error C3646: 'noexcept' : unknown override specifier
2>full\path\toude\export\josepp/sstring.hh(50) : see reference to class template instantiation 'jose::secure_allocator' being compiled
2>full\path\to\josepp/sstring.hh(37): error C2253: 'secure_allocator' : pure specifier or abstract override specifier only allowed on virtual function
2>full\path\to\josepp/sstring.hh(39): error C3646: 'noexcept' : unknown override specifier
2>full\path\to\josepp/sstring.hh(44): error C3646: 'noexcept' : unknown override specifier
2>full\path\to\josepp/sstring.hh(46): error C3646: 'noexcept' : unknown override specifier
2>full\path\to\josepp/sstring.hh(52): error C2143: syntax error : missing ';' before '='
2>full\path\to\josepp/sstring.hh(52): error C2873: 'secure_string' : symbol cannot be used in a using-declaration
2>full\path\to\josepp/sstring.hh(52): error C2513: 'int' : no variable declared before '='
2>full\path\to\josepp/crypto.hpp(63): error C2873: 'password_cb' : symbol cannot be used in a using-declaration
2>full\path\to\josepp/crypto.hpp(63): error C2143: syntax error : missing ';' before '='
2>full\path\to\josepp/crypto.hpp(63): error C2065: 'secure_string' : undeclared identifier
2>full\path\to\josepp/crypto.hpp(63): error C2065: 'pass' : undeclared identifier
2>full\path\to\josepp/crypto.hpp(63): error C2062: type 'int' unexpected
2>full\path\to\josepp/crypto.hpp(66): error C2143: syntax error : missing ';' before '{'

and ...

Missing stringstream include

Hi,

I'm finding I'm getting compilation errors in claims.cpp and tools.cpp:

josepp/src/claims.cpp:63:22: error: invalid use of incomplete type ‘std::stringstream’ {aka ‘class std::__cxx11::basic_stringstream’}
josepp/src/tools.cpp: In function ‘Json::Value jose::unmarshal(const string&)’:
/home/steve/development/p4root/im/extlib/josepp/src/tools.cpp:45:22: error: invalid use of incomplete type ‘std::stringstream’ {aka ‘class std::__cxx11::basic_stringstream’}

Not sure why I get these and you don't (possibly unique to my Fedora 29?), but it's easily fixed by adding the include in both files.

Adding the include in both files makes for a clean build/install.

Steve.

shared_ptr vs const& arguments

std::string jws::sign(const std::string &data, sp_crypto c)
{
   	return std::move(c->sign(data));
}

I think shared_ptr should be const shared_ptr& to avoid copy (ref count inc / dec) of the shared_ptr. Even better might be to use const crypto&.

How to decrypt the payload?

Hey,

I have a question about decryption. I can see the APIs to encrypt and verify a JWS. But, I am wondering how to get the payload out of the encrypted data. I do see an API called parse() which returns a shared_ptr to the JWS object. But, there seems to be no public API to get the data out of it. Could you please clarify this. If you have any suggestions for decrypting it, that would be great!

Thanks

Conan package

Hi,
Do you know about Conan?
I was planning to use your library in a personal project and found that jwtpp was not available in conan center.
Conan is modern dependency manager for C++. And will be great if your library will be available via package manager for other developers.

Thanks.

How to read keys from strings?

How does one read private and public keys from strings / files?
I saw jose::rsa::gen(1024) in the tests but couldn't find how to supply my own keys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.