mirror of
https://github.com/allankoechke/jwt-cpp.git
synced 2026-11-30 10:18:40 +00:00
🧰 Linting and maintenance (#120)
* some manual fixes to obtain * fairly close enough * whitespace fixes * add comment * adding clang format + applied * add editorconfig (supported natively by github web editor) * apply linting to project * clean up CI workflows * zap vcpkg folder actual one is here https://github.com/microsoft/vcpkg/tree/master/ports/jwt-cpp * adding a logo * thin the lines in the pluses * use logo + more links to spec and examples * Create lint.yml * apply linting
This commit is contained in:
22
.clang-format
Normal file
22
.clang-format
Normal file
@@ -0,0 +1,22 @@
|
||||
BasedOnStyle: LLVM
|
||||
BreakBeforeBraces: Attach
|
||||
|
||||
ColumnLimit: 120 # Match GitHub UI
|
||||
|
||||
UseTab: Always
|
||||
TabWidth: 4
|
||||
IndentWidth: 4
|
||||
AccessModifierOffset: -4
|
||||
ContinuationIndentWidth: 4
|
||||
NamespaceIndentation: All
|
||||
IndentCaseLabels: false
|
||||
|
||||
PointerAlignment: Left
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
SpaceAfterTemplateKeyword: false
|
||||
AllowShortCaseLabelsOnASingleLine: true
|
||||
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
|
||||
FixNamespaceComments: true
|
||||
ReflowComments: false
|
||||
17
.editorconfig
Normal file
17
.editorconfig
Normal file
@@ -0,0 +1,17 @@
|
||||
root = true
|
||||
|
||||
[!*.{h,cpp}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
charset = utf-8
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.{h,cpp}]
|
||||
indent_style = tab
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
2
.github/actions/install/jsoncons/action.yml
vendored
2
.github/actions/install/jsoncons/action.yml
vendored
@@ -4,7 +4,7 @@ inputs:
|
||||
version:
|
||||
description: The desired jsoncons version to install
|
||||
required: false
|
||||
default: '0.159.0'
|
||||
default: "0.159.0"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
|
||||
2
.github/actions/install/libressl/action.yml
vendored
2
.github/actions/install/libressl/action.yml
vendored
@@ -4,7 +4,7 @@ inputs:
|
||||
version:
|
||||
description: The desired LibreSSL version to install
|
||||
required: false
|
||||
default: '3.3.0'
|
||||
default: "3.3.0"
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
|
||||
16
.github/logo.svg
vendored
Normal file
16
.github/logo.svg
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<svg viewBox="0 0 2450 750" width="2450" height="750" xmlns="http://www.w3.org/2000/svg">
|
||||
<g style="" transform="matrix(1.01, 0, 0, 1, 550, 140)">
|
||||
<path d="M -551.881 -175.95 L 1948.119 -175.95 L 1948.119 609.368 L -551.881 609.368 Z" clip-rule="evenodd" fill-rule="evenodd" style=""/>
|
||||
<path d="M -108.039 81.534 L -108.639 -86.566 L -202.439 -86.566 L -201.839 81.534 L -154.939 145.934 Z M -201.839 369.634 L -201.839 538.334 L -108.039 538.334 L -108.039 369.634 L -154.939 305.234 Z" fill="#fff" clip-rule="evenodd" fill-rule="evenodd"/>
|
||||
<path d="M -108.039 369.634 L -9.239 505.934 L 66.361 450.934 L -32.439 314.634 L -108.039 290.234 Z M -201.839 81.534 L -301.239 -54.766 L -376.839 0.234 L -278.039 136.434 L -201.839 160.834 Z" clip-rule="evenodd" fill-rule="evenodd" style="fill: rgb(101, 154, 210);"/>
|
||||
<path d="M -278.039 136.534 L -438.039 84.634 L -466.839 173.334 L -306.839 225.834 L -231.239 200.834 Z M -79.339 250.234 L -32.439 314.634 L 127.561 366.534 L 156.361 277.834 L -3.639 225.934 Z" fill="#00b9f1" clip-rule="evenodd" fill-rule="evenodd"/>
|
||||
<path d="M -3.739 225.934 L 156.261 173.434 L 127.461 84.734 L -32.539 136.634 L -79.439 201.034 Z M -306.839 225.934 L -466.839 277.834 L -438.039 366.534 L -278.039 314.634 L -231.139 250.234 Z" clip-rule="evenodd" fill-rule="evenodd" style="fill: rgb(0, 89, 156);"/>
|
||||
<path d="M -278.039 314.634 L -376.839 450.934 L -301.239 505.934 L -201.839 369.634 L -201.839 290.234 Z M -32.439 136.534 L 66.361 0.234 L -9.239 -54.766 L -108.039 81.434 L -108.039 160.834 Z" clip-rule="evenodd" fill-rule="evenodd" style="fill: rgb(0, 68, 130);"/>
|
||||
<path d="M 343.623 72.734 L 343.623 291.434 C 343.623 339.534 304.223 378.934 256.123 378.934 L 256.123 335.134 C 280.523 335.134 299.923 315.734 299.923 291.334 L 299.923 72.734 Z M 1142.423 116.534 L 1241.123 116.534 L 1241.123 72.834 L 1000.523 72.834 L 1000.523 116.534 L 1098.623 116.534 L 1098.623 379.034 L 1142.423 379.034 Z M 868.623 72.734 L 868.623 291.434 C 868.623 315.834 849.223 335.234 824.823 335.234 C 800.423 335.234 781.023 315.834 781.023 291.434 L 781.023 160.234 C 781.023 112.134 741.623 72.734 693.523 72.734 C 645.423 72.734 606.023 112.134 606.023 160.234 L 606.023 291.534 C 606.023 315.934 586.623 335.334 562.223 335.334 C 537.823 335.334 518.423 315.934 518.423 291.534 L 518.423 72.734 L 474.623 72.734 L 474.623 291.434 C 474.623 339.534 514.023 378.934 562.123 378.934 C 610.223 378.934 649.623 339.534 649.623 291.434 L 649.623 160.234 C 649.623 135.834 669.023 116.434 693.423 116.434 C 717.823 116.434 737.223 135.834 737.223 160.234 L 737.223 291.534 C 737.223 339.634 776.623 379.034 824.723 379.034 C 872.823 379.034 912.223 339.634 912.223 291.534 L 912.223 72.734 Z" fill="#fff" clip-rule="evenodd" fill-rule="evenodd"/>
|
||||
<g transform="matrix(6.824428, -0.018276, 0.018773, 7.009964, -218.175049, -971.69281)" style="">
|
||||
<polygon fill="#FFFFFF" points="255 168.508 241.666 168.508 241.666 155.175 234.334 155.175 234.334 168.508 221 168.508 221 175.841 234.334 175.841 234.334 189.175 241.666 189.175 241.666 175.841 255 175.841"/>
|
||||
<polygon fill="#FFFFFF" points="297.5 168.508 284.166 168.508 284.166 155.175 276.834 155.175 276.834 168.508 263.5 168.508 263.5 175.841 276.834 175.841 276.834 189.175 284.166 189.175 284.166 175.841 297.5 175.841"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 3.3 KiB |
11
.github/workflows/cmake.yml
vendored
11
.github/workflows/cmake.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: CMake Integration CI
|
||||
name: CMake CI
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -6,10 +6,11 @@ on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
paths:
|
||||
- 'CMakeLists.txt'
|
||||
- 'include/jwt-cpp/**'
|
||||
- 'tests/cmake/**'
|
||||
- '.github/workflows/cmake.yml'
|
||||
- "CMakeLists.txt"
|
||||
- "include/jwt-cpp/**"
|
||||
- "tests/cmake/**"
|
||||
- ".github/actions/**"
|
||||
- ".github/workflows/cmake.yml"
|
||||
|
||||
jobs:
|
||||
min-req:
|
||||
|
||||
28
.github/workflows/coverage.yml
vendored
28
.github/workflows/coverage.yml
vendored
@@ -6,34 +6,32 @@ on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
paths:
|
||||
- 'CMakeLists.txt'
|
||||
- 'include/jwt-cpp/**'
|
||||
- 'tests/*'
|
||||
- '.github/workflows/coverate.yml'
|
||||
- "CMakeLists.txt"
|
||||
- "include/jwt-cpp/**"
|
||||
- "tests/*"
|
||||
- ".github/actions/**"
|
||||
- ".github/workflows/coverate.yml"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install cmake
|
||||
uses: lukka/get-cmake@latest
|
||||
- name: install gtest
|
||||
uses: ./.github/actions/install/gtest
|
||||
- uses: lukka/get-cmake@latest
|
||||
- uses: ./.github/actions/install/gtest
|
||||
|
||||
- name: configure
|
||||
run: |
|
||||
mkdir build
|
||||
cd build
|
||||
cmake .. -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
|
||||
cmake .. -DJWT_BUILD_EXAMPLES=OFF -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug
|
||||
|
||||
- name: make
|
||||
run: cd build && make jwt-cpp-test coverage
|
||||
- name: run
|
||||
run: |
|
||||
cd build
|
||||
make jwt-cpp-test coverage
|
||||
|
||||
- name: Coveralls GitHub Action
|
||||
uses: coverallsapp/github-action@v1.1.1
|
||||
- uses: coverallsapp/github-action@v1.1.1
|
||||
with:
|
||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
path-to-lcov: build/coverage.info
|
||||
|
||||
2
.github/workflows/documentation.yml
vendored
2
.github/workflows/documentation.yml
vendored
@@ -9,10 +9,8 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: run doxygen
|
||||
uses: mattnotmitt/doxygen-action@v1
|
||||
|
||||
- name: deploy
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
|
||||
25
.github/workflows/libresssl.yml
vendored
25
.github/workflows/libresssl.yml
vendored
@@ -6,10 +6,11 @@ on:
|
||||
pull_request:
|
||||
branches: [master]
|
||||
paths:
|
||||
- 'CMakeLists.txt'
|
||||
- 'include/jwt-cpp/**'
|
||||
- 'tests/*'
|
||||
- '.github/workflows/libressl.yml'
|
||||
- "CMakeLists.txt"
|
||||
- "include/jwt-cpp/**"
|
||||
- "tests/*"
|
||||
- ".github/actions/**"
|
||||
- ".github/workflows/libressl.yml"
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -19,20 +20,16 @@ jobs:
|
||||
libressl: ["3.3.0", "3.2.2"]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: install cmake
|
||||
uses: lukka/get-cmake@latest
|
||||
- name: install gtest
|
||||
uses: ./.github/actions/install/gtest
|
||||
- name: install libressl
|
||||
uses: ./.github/actions/install/libressl
|
||||
- uses: lukka/get-cmake@latest
|
||||
- uses: ./.github/actions/install/gtest
|
||||
- uses: ./.github/actions/install/libressl
|
||||
with:
|
||||
version: ${{ matrix.libressl }}
|
||||
|
||||
- name: configure
|
||||
run: cmake . -DJWT_BUILD_TESTS=ON -DJWT_SSL_LIBRARY:STRING=LibreSSL
|
||||
|
||||
- name: make
|
||||
run: make
|
||||
- run: make
|
||||
|
||||
- name: test
|
||||
run: ./tests/jwt-cpp-test
|
||||
@@ -57,5 +54,5 @@ jobs:
|
||||
publish_branch: badges
|
||||
publish_dir: ./badges
|
||||
keep_files: true
|
||||
user_name: 'github-actions[bot]'
|
||||
user_email: 'github-actions[bot]@users.noreply.github.com'
|
||||
user_name: "github-actions[bot]"
|
||||
user_email: "github-actions[bot]@users.noreply.github.com"
|
||||
|
||||
23
.github/workflows/lint.yml
vendored
Normal file
23
.github/workflows/lint.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Lint CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
paths:
|
||||
- 'include/jwt-cpp/**.h'
|
||||
- 'tests/**.cpp'
|
||||
- '.github/workflows/lint.yml'
|
||||
|
||||
jobs:
|
||||
cpp:
|
||||
runs-on: ubuntu-20.04
|
||||
strategy:
|
||||
matrix:
|
||||
files: ["include/jwt-cpp/*.h", "tests/**.cpp"]
|
||||
steps:
|
||||
- run: sudo apt-get install clang-format-10
|
||||
- uses: actions/checkout@v2
|
||||
- run: clang-format-10 -i ${{ matrix.files }}
|
||||
- run: exit $(git status -s | wc -l)
|
||||
8
.github/workflows/traits.yml
vendored
8
.github/workflows/traits.yml
vendored
@@ -5,6 +5,12 @@ on:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
paths:
|
||||
- "CMakeLists.txt"
|
||||
- "include/jwt-cpp/**"
|
||||
- "tests/jsoncons/**"
|
||||
- ".github/actions/**"
|
||||
- ".github/workflows/traits.yml"
|
||||
|
||||
jobs:
|
||||
jsoncons:
|
||||
@@ -22,7 +28,7 @@ jobs:
|
||||
cmake .. -DJWT_BUILD_EXAMPLES=OFF
|
||||
sudo make install
|
||||
|
||||
- name: configure
|
||||
- name: test
|
||||
run: |
|
||||
cd tests/jsoncons
|
||||
cmake . -DCMAKE_PREFIX_PATH=/usr/local/cmake
|
||||
|
||||
20
README.md
20
README.md
@@ -1,4 +1,4 @@
|
||||
# jwt-cpp
|
||||
# 
|
||||
|
||||
[](https://github.com/Thalhammer/jwt-cpp/blob/master/LICENSE)
|
||||
[](https://app.codacy.com/app/Thalhammer/jwt-cpp?utm_source=github.com&utm_medium=referral&utm_content=Thalhammer/jwt-cpp&utm_campaign=Badge_Grade_Settings)
|
||||
@@ -7,12 +7,13 @@
|
||||
[](https://thalhammer.github.io/jwt-cpp/)
|
||||
[](https://github.com/Thalhammer/jwt-cpp/stargazers)
|
||||
|
||||
A header only library for creating and validating [JSON Web Tokens](https://tools.ietf.org/html/rfc7519) in C++11. For a great introduction, [read this](https://jwt.io/introduction/)
|
||||
A header only library for creating and validating [JSON Web Tokens](https://tools.ietf.org/html/rfc7519) in C++11. For a great introduction, [read this](https://jwt.io/introduction/).
|
||||
|
||||
## Signature algorithms
|
||||
|
||||
jwt-cpp supports all algorithms defined by the spec. The modular design of jwt-cpp allows one to add additional algorithms without any problems. If you need any feel free to open a pull request.
|
||||
For the sake of completeness, here is a list of all supported algorithms:
|
||||
jwt-cpp supports all the algorithms defined by the specifications. The modular design allows to easily add additional algorithms without any problems. If you need any feel free to create a pull request or [open an issue](https://github.com/Thalhammer/jwt-cpp/issues/new).
|
||||
|
||||
For completeness, here is a list of all supported algorithms:
|
||||
|
||||
| HMSC | RSA | ECDSA | PSS | EdDSA |
|
||||
| ----- | ----- | ----- | ----- | ------- |
|
||||
@@ -22,8 +23,7 @@ For the sake of completeness, here is a list of all supported algorithms:
|
||||
|
||||
## SSL Compatability
|
||||
|
||||
In the name of flexibility and extensibility, jwt-cpp supports both [OpenSSL](https://github.com/openssl/openssl) and [LibreSSL](https://github.com/libressl-portable/portable).
|
||||
These are the version which are tested:
|
||||
In the name of flexibility and extensibility, jwt-cpp supports both [OpenSSL](https://github.com/openssl/openssl) and [LibreSSL](https://github.com/libressl-portable/portable). These are the version which are, or have been, tested:
|
||||
|
||||
| OpenSSL | LibreSSL |
|
||||
| -------------- | --------------- |
|
||||
@@ -38,13 +38,13 @@ These are the version which are tested:
|
||||
|
||||
## Overview
|
||||
|
||||
Since 0.5.0-rc.0, there is no hard dependency on a JSON library; instead there's a generic `jwt::basic_claim` which is templated around the types required.It requires a traits type, which defines types for a value, object, array, string, number, integer and boolean, as well as methods to translate between them.
|
||||
There is no hard dependency on a JSON library. Instead, there's a generic `jwt::basic_claim` which is templated around type traits, which described the semantic [JSON types](https://json-schema.org/understanding-json-schema/reference/type.html) for a value, object, array, string, number, integer and boolean, as well as methods to translate between them.
|
||||
|
||||
```cpp
|
||||
jwt::basic_claim<my_favorite_json_library_traits> claim(json::object({{"json", true},{"example", 0}}));
|
||||
```
|
||||
|
||||
This allows for complete freedom when picking which libraries you want to use. For more information, [see below](#providing-your-own-json-traits-your-traits)
|
||||
This allows for complete freedom when picking which libraries you want to use. For more information, [see below](#providing-your-own-json-traits-your-traits).
|
||||
|
||||
In order to maintain compatibility, [picojson](https://github.com/kazuho/picojson) is still used to provide a specialized `jwt::claim` along with all helpers. Defining `JWT_DISABLE_PICOJSON` will remove this optional dependency.
|
||||
|
||||
@@ -52,7 +52,7 @@ As for the base64 requirements of JWTs, this libary provides `base.h` with all t
|
||||
|
||||
### Getting Started
|
||||
|
||||
Simple example of decoding a token and printing all claims ([try it out](https://github.com/Thalhammer/jwt-cpp/tree/master/example/print-claims.cpp)):
|
||||
Simple example of decoding a token and printing all [claims](https://tools.ietf.org/html/rfc7519#section-4) ([try it out](https://github.com/Thalhammer/jwt-cpp/tree/master/example/print-claims.cpp)):
|
||||
|
||||
```cpp
|
||||
#include <jwt-cpp/jwt.h>
|
||||
@@ -111,6 +111,8 @@ There are several key items that need to be provided to a `jwt::basic_claim` in
|
||||
|
||||
If ever you are not sure, the traits are heavily checked against static asserts to make sure you provide everything that's required.
|
||||
|
||||
> :warning: Not all JSON libraries are a like, you may need to extent certain types such that it can be used by jwt-cpp. See this [example](https://github.com/Thalhammer/jwt-cpp/blob/ac3de9e69bc698a464dacb256a1b50512843f092/tests/jsoncons/JsonconsTest.cpp).
|
||||
|
||||
```cpp
|
||||
struct my_favorite_json_library_traits {
|
||||
// Type Specifications
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
set(COVERAGE_CMAKE "${CMAKE_BINARY_DIR}/cmake/CodeCoverage.cmake")
|
||||
if(NOT EXISTS ${COVERAGE_CMAKE})
|
||||
set(COVERAGE_URL
|
||||
"https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake"
|
||||
)
|
||||
set(COVERAGE_URL "https://raw.githubusercontent.com/bilke/cmake-modules/master/CodeCoverage.cmake")
|
||||
file(DOWNLOAD ${COVERAGE_URL} ${COVERAGE_CMAKE})
|
||||
endif()
|
||||
|
||||
include(${COVERAGE_CMAKE})
|
||||
|
||||
function(setup_coverage TARGET)
|
||||
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs
|
||||
-ftest-coverage)
|
||||
target_compile_options(${TARGET} PRIVATE -g -O0 -fprofile-arcs -ftest-coverage)
|
||||
target_link_libraries(${TARGET} PRIVATE gcov)
|
||||
endfunction()
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
#include"jwt-cpp/jwt.h"
|
||||
#include<iostream>
|
||||
#include <chrono>
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
std::string token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTAwMjMxNzcsImV4cCI6MTY0MTU1OTE3NywiYXVkIjoid3d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5hbWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IEFkbWluaXN0cmF0b3IiXX0.5EOfHnBmpdPvRHAuVDttgJQvbFuGEF7fC4uBSXAGg6c";
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
for(auto& e : decoded.get_payload_claims())
|
||||
std::cout << e.first << " = " << e.second << std::endl;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.8)
|
||||
|
||||
project(conan-example)
|
||||
|
||||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
|
||||
conan_basic_setup()
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS})
|
||||
@@ -1,18 +1,17 @@
|
||||
Conan example
|
||||
|
||||
# Conan example
|
||||
|
||||
In the current directory on Linux environment
|
||||
```
|
||||
|
||||
```sh
|
||||
mkdir build && cd build
|
||||
conan install .. && cmake ..
|
||||
cmake --build .
|
||||
```
|
||||
|
||||
run executable
|
||||
```
|
||||
./bin/conan-example
|
||||
```
|
||||
the output:
|
||||
```
|
||||
|
||||
```sh
|
||||
$ ./bin/conan-example
|
||||
sub = "jrocket@example.com"
|
||||
iss = "Online JWT Builder"
|
||||
exp = 1641559177
|
||||
17
example/conan/main.cpp
Normal file
17
example/conan/main.cpp
Normal file
@@ -0,0 +1,17 @@
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
|
||||
std::string token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9."
|
||||
"eyJpc3MiOiJPbmxpbmUgSldUIEJ1aWxkZXIiLCJpYXQiOjE2MTAwMjMxNzcsImV4cCI6MTY0MTU1OTE3NywiYXVkIjoid3"
|
||||
"d3LmV4YW1wbGUuY29tIiwic3ViIjoianJvY2tldEBleGFtcGxlLmNvbSIsIkdpdmVuTmFtZSI6IkpvaG5ueSIsIlN1cm5h"
|
||||
"bWUiOiJSb2NrZXQiLCJFbWFpbCI6Impyb2NrZXRAZXhhbXBsZS5jb20iLCJSb2xlIjpbIk1hbmFnZXIiLCJQcm9qZWN0IE"
|
||||
"FkbWluaXN0cmF0b3IiXX0.5EOfHnBmpdPvRHAuVDttgJQvbFuGEF7fC4uBSXAGg6c";
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
for (auto& e : decoded.get_payload_claims())
|
||||
std::cout << e.first << " = " << e.second << std::endl;
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
#include <jwt-cpp/jwt.h>
|
||||
#include <iostream>
|
||||
#include <jwt-cpp/jwt.h>
|
||||
|
||||
int main(int argc, const char** argv) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
for (auto& e : decoded.get_payload_claims())
|
||||
|
||||
@@ -14,8 +14,7 @@ std::string make_pico_token() {
|
||||
|
||||
jwt::claim::set_t list{"once", "twice"};
|
||||
|
||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull,
|
||||
525936436ull};
|
||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
|
||||
|
||||
const auto time = jwt::date::clock::now();
|
||||
|
||||
@@ -30,8 +29,7 @@ std::string make_pico_token() {
|
||||
.set_payload_claim("integer", picojson::value(int64_t{12345}))
|
||||
.set_payload_claim("precision", picojson::value(12.345))
|
||||
.set_payload_claim("strings", jwt::claim(list))
|
||||
.set_payload_claim("array",
|
||||
jwt::claim(big_numbers.begin(), big_numbers.end()))
|
||||
.set_payload_claim("array", jwt::claim(big_numbers.begin(), big_numbers.end()))
|
||||
.set_payload_claim("object", from_raw_json)
|
||||
.sign(jwt::algorithm::none{});
|
||||
}
|
||||
@@ -69,43 +67,35 @@ std::string make_nlohmann_token() {
|
||||
}
|
||||
|
||||
static json::object_t as_object(const json& val) {
|
||||
if (val.type() != json::value_t::object)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::object) throw std::bad_cast();
|
||||
return val.get<json::object_t>();
|
||||
}
|
||||
|
||||
static std::string as_string(const json& val) {
|
||||
if (val.type() != json::value_t::string)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::string) throw std::bad_cast();
|
||||
return val.get<std::string>();
|
||||
}
|
||||
|
||||
static json::array_t as_array(const json& val) {
|
||||
if (val.type() != json::value_t::array)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::array) throw std::bad_cast();
|
||||
return val.get<json::array_t>();
|
||||
}
|
||||
|
||||
static int64_t as_int(const json& val) {
|
||||
switch(val.type())
|
||||
{
|
||||
switch (val.type()) {
|
||||
case json::value_t::number_integer:
|
||||
case json::value_t::number_unsigned:
|
||||
return val.get<int64_t>();
|
||||
default:
|
||||
throw std::bad_cast();
|
||||
case json::value_t::number_unsigned: return val.get<int64_t>();
|
||||
default: throw std::bad_cast();
|
||||
}
|
||||
}
|
||||
|
||||
static bool as_bool(const json& val) {
|
||||
if (val.type() != json::value_t::boolean)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::boolean) throw std::bad_cast();
|
||||
return val.get<bool>();
|
||||
}
|
||||
|
||||
static double as_number(const json& val) {
|
||||
if (val.type() != json::value_t::number_float)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::number_float) throw std::bad_cast();
|
||||
return val.get<double>();
|
||||
}
|
||||
|
||||
@@ -125,8 +115,7 @@ std::string make_nlohmann_token() {
|
||||
|
||||
claim::set_t list{"once", "twice"};
|
||||
|
||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull,
|
||||
525936436ull};
|
||||
std::vector<int64_t> big_numbers{727663072ull, 770979831ull, 427239169ull, 525936436ull};
|
||||
|
||||
const auto time = jwt::date::clock::now();
|
||||
|
||||
@@ -153,7 +142,6 @@ int main(int argc, const char **argv) {
|
||||
for (auto& e : decoded.get_payload_claims())
|
||||
std::cout << e.first << " = " << e.second << std::endl;
|
||||
|
||||
const auto api_array =
|
||||
decoded.get_payload_claims()["object"].to_json().get("api").get("array");
|
||||
const auto api_array = decoded.get_payload_claims()["object"].to_json().get("api").get("array");
|
||||
std::cout << "api array = " << api_array << std::endl;
|
||||
}
|
||||
|
||||
@@ -40,8 +40,7 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
|
||||
YwIDAQAB
|
||||
-----END PUBLIC KEY-----)";
|
||||
|
||||
auto token =
|
||||
jwt::create()
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWT")
|
||||
.set_id("rsa-create-example")
|
||||
|
||||
@@ -40,8 +40,7 @@ AziMCxS+VrRPDM+zfvpIJg3JljAh3PJHDiLu902v9w+Iplu1WyoB2aPfitxEhRN0
|
||||
YwIDAQAB
|
||||
-----END PUBLIC KEY-----)";
|
||||
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9."
|
||||
"VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-"
|
||||
"GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
@@ -50,10 +49,8 @@ YwIDAQAB
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-"
|
||||
"uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(
|
||||
rsa_pub_key, rsa_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
|
||||
@@ -29,8 +29,7 @@ namespace jwt {
|
||||
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}
|
||||
};
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/'}};
|
||||
return data;
|
||||
}
|
||||
static const std::string& fill() {
|
||||
@@ -47,8 +46,7 @@ namespace jwt {
|
||||
{'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
|
||||
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
|
||||
'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'}
|
||||
};
|
||||
'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '-', '_'}};
|
||||
return data;
|
||||
}
|
||||
static const std::string& fill() {
|
||||
@@ -81,7 +79,8 @@ namespace jwt {
|
||||
}
|
||||
|
||||
private:
|
||||
static std::string encode(const std::string& bin, const std::array<char, 64>& alphabet, const std::string& fill) {
|
||||
static std::string encode(const std::string& bin, const std::array<char, 64>& alphabet,
|
||||
const std::string& fill) {
|
||||
size_t size = bin.size();
|
||||
std::string res;
|
||||
|
||||
@@ -100,8 +99,7 @@ namespace jwt {
|
||||
res += alphabet[(triple >> 0 * 6) & 0x3F];
|
||||
}
|
||||
|
||||
if (fast_size == size)
|
||||
return res;
|
||||
if (fast_size == size) return res;
|
||||
|
||||
size_t mod = size % 3;
|
||||
|
||||
@@ -124,14 +122,14 @@ namespace jwt {
|
||||
res += alphabet[(triple >> 1 * 6) & 0x3F];
|
||||
res += fill;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static std::string decode(const std::string& base, const std::array<char, 64>& alphabet, const std::string& fill) {
|
||||
static std::string decode(const std::string& base, const std::array<char, 64>& alphabet,
|
||||
const std::string& fill) {
|
||||
size_t size = base.size();
|
||||
|
||||
size_t fill_cnt = 0;
|
||||
@@ -139,14 +137,12 @@ namespace jwt {
|
||||
if (base.substr(size - fill.size(), fill.size()) == fill) {
|
||||
fill_cnt++;
|
||||
size -= fill.size();
|
||||
if(fill_cnt > 2)
|
||||
throw std::runtime_error("Invalid input");
|
||||
}
|
||||
else break;
|
||||
if (fill_cnt > 2) throw std::runtime_error("Invalid input");
|
||||
} else
|
||||
break;
|
||||
}
|
||||
|
||||
if ((size + fill_cnt) % 4 != 0)
|
||||
throw std::runtime_error("Invalid input");
|
||||
if ((size + fill_cnt) % 4 != 0) throw std::runtime_error("Invalid input");
|
||||
|
||||
size_t out_size = size / 4 * 3;
|
||||
std::string res;
|
||||
@@ -154,8 +150,7 @@ namespace jwt {
|
||||
|
||||
auto get_sextet = [&](size_t offset) {
|
||||
for (size_t i = 0; i < alphabet.size(); i++) {
|
||||
if (alphabet[i] == base[offset])
|
||||
return static_cast<uint32_t>(i);
|
||||
if (alphabet[i] == base[offset]) return static_cast<uint32_t>(i);
|
||||
}
|
||||
throw std::runtime_error("Invalid input");
|
||||
};
|
||||
@@ -167,21 +162,16 @@ namespace jwt {
|
||||
uint32_t sextet_c = get_sextet(i++);
|
||||
uint32_t sextet_d = get_sextet(i++);
|
||||
|
||||
uint32_t triple = (sextet_a << 3 * 6)
|
||||
+ (sextet_b << 2 * 6)
|
||||
+ (sextet_c << 1 * 6)
|
||||
+ (sextet_d << 0 * 6);
|
||||
uint32_t triple = (sextet_a << 3 * 6) + (sextet_b << 2 * 6) + (sextet_c << 1 * 6) + (sextet_d << 0 * 6);
|
||||
|
||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
||||
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
||||
res += static_cast<char>((triple >> 0 * 8) & 0xFFU);
|
||||
}
|
||||
|
||||
if (fill_cnt == 0)
|
||||
return res;
|
||||
if (fill_cnt == 0) return res;
|
||||
|
||||
uint32_t triple = (get_sextet(fast_size) << 3 * 6)
|
||||
+ (get_sextet(fast_size + 1) << 2 * 6);
|
||||
uint32_t triple = (get_sextet(fast_size) << 3 * 6) + (get_sextet(fast_size + 1) << 2 * 6);
|
||||
|
||||
switch (fill_cnt) {
|
||||
case 1:
|
||||
@@ -189,11 +179,8 @@ namespace jwt {
|
||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
||||
res += static_cast<char>((triple >> 1 * 8) & 0xFFU);
|
||||
break;
|
||||
case 2:
|
||||
res += static_cast<char>((triple >> 2 * 8) & 0xFFU);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case 2: res += static_cast<char>((triple >> 2 * 8) & 0xFFU); break;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return res;
|
||||
@@ -202,17 +189,10 @@ namespace jwt {
|
||||
static std::string pad(const std::string& base, const std::string& fill) {
|
||||
std::string padding;
|
||||
switch (base.size() % 4) {
|
||||
case 1:
|
||||
padding += fill;
|
||||
JWT_FALLTHROUGH;
|
||||
case 2:
|
||||
padding += fill;
|
||||
JWT_FALLTHROUGH;
|
||||
case 3:
|
||||
padding += fill;
|
||||
JWT_FALLTHROUGH;
|
||||
default:
|
||||
break;
|
||||
case 1: padding += fill; JWT_FALLTHROUGH;
|
||||
case 2: padding += fill; JWT_FALLTHROUGH;
|
||||
case 3: padding += fill; JWT_FALLTHROUGH;
|
||||
default: break;
|
||||
}
|
||||
|
||||
return base + padding;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/base.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(BaseTest, Base64Decode) {
|
||||
ASSERT_EQ("1", jwt::base::decode<jwt::alphabet::base64>("MQ=="));
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(ClaimTest, AudienceAsString) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_TRUE(decoded.has_algorithm());
|
||||
@@ -25,11 +26,9 @@ TEST(ClaimTest, AudienceAsString) {
|
||||
}
|
||||
|
||||
TEST(ClaimTest, SetAudienceAsString) {
|
||||
auto token = jwt::create()
|
||||
.set_type("JWT")
|
||||
.set_audience("test")
|
||||
.sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4", token);
|
||||
auto token = jwt::create().set_type("JWT").set_audience("test").sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0.ny5Fa0vzAg7tNL95KWg_ecBNd3XP3tdAzq0SFA6diY4",
|
||||
token);
|
||||
}
|
||||
|
||||
TEST(ClaimTest, AudienceAsSet) {
|
||||
@@ -65,14 +64,9 @@ TEST(ClaimTest, SetAudienceAsSet) {
|
||||
}
|
||||
|
||||
TEST(ClaimTest, SetArray) {
|
||||
std::vector<int64_t> vect = {
|
||||
100,
|
||||
20,
|
||||
10
|
||||
};
|
||||
auto token = jwt::create()
|
||||
.set_payload_claim("test", jwt::claim(vect.begin(), vect.end()))
|
||||
.sign(jwt::algorithm::none{});
|
||||
std::vector<int64_t> vect = {100, 20, 10};
|
||||
auto token =
|
||||
jwt::create().set_payload_claim("test", jwt::claim(vect.begin(), vect.end())).sign(jwt::algorithm::none{});
|
||||
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
||||
}
|
||||
|
||||
@@ -82,16 +76,13 @@ TEST(ClaimTest, SetObject) {
|
||||
iss >> object;
|
||||
ASSERT_EQ(object.get_type(), jwt::json::type::object);
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_payload_claim("namespace", object)
|
||||
.sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
auto token = jwt::create().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token,
|
||||
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
}
|
||||
|
||||
TEST(ClaimTest, SetAlgorithm) {
|
||||
auto token = jwt::create()
|
||||
.set_algorithm("test")
|
||||
.sign(jwt::algorithm::none{});
|
||||
auto token = jwt::create().set_algorithm("test").sign(jwt::algorithm::none{});
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
ASSERT_EQ(decoded_token.get_algorithm(), "test");
|
||||
@@ -133,7 +124,8 @@ TEST(ClaimTest, PicoJSONTraitsAsDouble) {
|
||||
TEST(ClaimTest, MapOfClaim) {
|
||||
using map = jwt::details::map_of_claims<jwt::picojson_traits>;
|
||||
ASSERT_THROW(map::parse_claims(R"##(__ not json __)##"), jwt::error::invalid_json_exception);
|
||||
const map claims{ map::parse_claims(R"##({ "array": [1], "string" : "hello world", "number": 9.9, "bool": true})##") };
|
||||
const map claims{
|
||||
map::parse_claims(R"##({ "array": [1], "string" : "hello world", "number": 9.9, "bool": true})##")};
|
||||
|
||||
ASSERT_TRUE(claims.has_claim("array"));
|
||||
ASSERT_TRUE(claims.has_claim("string"));
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace {
|
||||
extern std::string google_cert;
|
||||
extern std::string google_cert_base64_der;
|
||||
extern std::string google_cert_key;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
TEST(HelperTest, Cert2Pubkey) {
|
||||
auto key = jwt::helper::extract_pubkey_from_cert(google_cert);
|
||||
@@ -27,16 +27,22 @@ TEST(HelperTest, ErrorCodeMessages) {
|
||||
ASSERT_EQ(std::error_code(jwt::error::ecdsa_error::ok).category().name(), std::string("ecdsa_error"));
|
||||
|
||||
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).message(), "no error");
|
||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_verification_error>(-1)).message(), "unknown signature verification error");
|
||||
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).category().name(), std::string("signature_verification_error"));
|
||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_verification_error>(-1)).message(),
|
||||
"unknown signature verification error");
|
||||
ASSERT_EQ(std::error_code(jwt::error::signature_verification_error::ok).category().name(),
|
||||
std::string("signature_verification_error"));
|
||||
|
||||
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).message(), "no error");
|
||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_generation_error>(-1)).message(), "unknown signature generation error");
|
||||
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).category().name(), std::string("signature_generation_error"));
|
||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::signature_generation_error>(-1)).message(),
|
||||
"unknown signature generation error");
|
||||
ASSERT_EQ(std::error_code(jwt::error::signature_generation_error::ok).category().name(),
|
||||
std::string("signature_generation_error"));
|
||||
|
||||
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).message(), "no error");
|
||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message(), "unknown token verification error");
|
||||
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).category().name(), std::string("token_verification_error"));
|
||||
ASSERT_EQ(std::error_code(static_cast<jwt::error::token_verification_error>(-1)).message(),
|
||||
"unknown token verification error");
|
||||
ASSERT_EQ(std::error_code(jwt::error::token_verification_error::ok).category().name(),
|
||||
std::string("token_verification_error"));
|
||||
|
||||
int i = 10;
|
||||
for (i = 10; i < 19; i++) {
|
||||
@@ -112,8 +118,7 @@ OpueYUG3NBcHP/5IzhUYIQJbGzlQaUaZBMaQeC8ZslMNLWI2
|
||||
-----END CERTIFICATE-----
|
||||
)";
|
||||
|
||||
std::string google_cert_base64_der =
|
||||
"MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD"
|
||||
std::string google_cert_base64_der = "MIIF8DCCBVmgAwIBAgIKYFOB9QABAACIvTANBgkqhkiG9w0BAQUFADBGMQswCQYD"
|
||||
"VQQGEwJVUzETMBEGA1UEChMKR29vZ2xlIEluYzEiMCAGA1UEAxMZR29vZ2xlIElu"
|
||||
"dGVybmV0IEF1dGhvcml0eTAeFw0xMzA1MjIxNTQ5MDRaFw0xMzEwMzEyMzU5NTla"
|
||||
"MGYxCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1N"
|
||||
@@ -151,4 +156,4 @@ MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEZkqSFGwqoVAatVMJ0QIu/0zUpOlv
|
||||
CZmrEfiNK/zSw2L+cgKWwM/B11zfIQ3bqzET+ictUNFCCpspbPBzx3saAg==
|
||||
-----END PUBLIC KEY-----
|
||||
)";
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -190,8 +190,7 @@ ftcs6dibdnbQtbX6o9E+KuvGHoNW5xcSjX8lwXTpopfvufPOLPcnFXi4UoYZ8NZ2
|
||||
flE/m/0zymX8I/Xu3+KKLhUnUROGC6zO3OnLHXCnEns=
|
||||
-----END CERTIFICATE-----
|
||||
)";
|
||||
std::string sample_cert_base64_der =
|
||||
"MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE"
|
||||
std::string sample_cert_base64_der = "MIIDHDCCAgSgAwIBAgIIGlbUz5cvweUwDQYJKoZIhvcNAQEFBQAwMTEvMC0GA1UE"
|
||||
"AxMmc2VjdXJldG9rZW4uc3lzdGVtLmdzZXJ2aWNlYWNjb3VudC5jb20wHhcNMTkw"
|
||||
"NDEwMjEyMDUxWhcNMTkwNDI3MDkzNTUxWjAxMS8wLQYDVQQDEyZzZWN1cmV0b2tl"
|
||||
"bi5zeXN0ZW0uZ3NlcnZpY2VhY2NvdW50LmNvbTCCASIwDQYJKoZIhvcNAQEBBQAD"
|
||||
@@ -218,4 +217,4 @@ l/FYE3iGT+uqAaPFCbMBgwIHv+n/1Kd+Dg2Z9flwknTVI3NjpD+YlGMHeJfY8HP4
|
||||
awIDAQAB
|
||||
-----END PUBLIC KEY-----
|
||||
)";
|
||||
}
|
||||
} // namespace test_keys
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#define JWT_DISABLE_PICOJSON // Make sure JWT compiles with this flag
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include "nlohmann/json.hpp"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
struct nlohmann_traits {
|
||||
using json = nlohmann::json;
|
||||
@@ -17,62 +17,48 @@ struct nlohmann_traits {
|
||||
static jwt::json::type get_type(const json& val) {
|
||||
using jwt::json::type;
|
||||
|
||||
if (val.type() == json::value_t::boolean)
|
||||
return type::boolean;
|
||||
if (val.type() == json::value_t::number_integer)
|
||||
return type::integer;
|
||||
if (val.type() == json::value_t::boolean) return type::boolean;
|
||||
if (val.type() == json::value_t::number_integer) return type::integer;
|
||||
if (val.type() == json::value_t::number_unsigned) // nlohmann internally tracks two types of integers
|
||||
return type::integer;
|
||||
if (val.type() == json::value_t::number_float)
|
||||
return type::number;
|
||||
if (val.type() == json::value_t::string)
|
||||
return type::string;
|
||||
if (val.type() == json::value_t::array)
|
||||
return type::array;
|
||||
if (val.type() == json::value_t::object)
|
||||
return type::object;
|
||||
if (val.type() == json::value_t::number_float) return type::number;
|
||||
if (val.type() == json::value_t::string) return type::string;
|
||||
if (val.type() == json::value_t::array) return type::array;
|
||||
if (val.type() == json::value_t::object) return type::object;
|
||||
|
||||
throw std::logic_error("invalid type");
|
||||
}
|
||||
|
||||
static json::object_t as_object(const json& val) {
|
||||
if (val.type() != json::value_t::object)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::object) throw std::bad_cast();
|
||||
return val.get<json::object_t>();
|
||||
}
|
||||
|
||||
static std::string as_string(const json& val) {
|
||||
if (val.type() != json::value_t::string)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::string) throw std::bad_cast();
|
||||
return val.get<std::string>();
|
||||
}
|
||||
|
||||
static json::array_t as_array(const json& val) {
|
||||
if (val.type() != json::value_t::array)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::array) throw std::bad_cast();
|
||||
return val.get<json::array_t>();
|
||||
}
|
||||
|
||||
static int64_t as_int(const json& val) {
|
||||
switch(val.type())
|
||||
{
|
||||
switch (val.type()) {
|
||||
case json::value_t::number_integer:
|
||||
case json::value_t::number_unsigned:
|
||||
return val.get<int64_t>();
|
||||
default:
|
||||
throw std::bad_cast();
|
||||
case json::value_t::number_unsigned: return val.get<int64_t>();
|
||||
default: throw std::bad_cast();
|
||||
}
|
||||
}
|
||||
|
||||
static bool as_bool(const json& val) {
|
||||
if (val.type() != json::value_t::boolean)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::boolean) throw std::bad_cast();
|
||||
return val.get<bool>();
|
||||
}
|
||||
|
||||
static double as_number(const json& val) {
|
||||
if (val.type() != json::value_t::number_float)
|
||||
throw std::bad_cast();
|
||||
if (val.type() != json::value_t::number_float) throw std::bad_cast();
|
||||
return val.get<double>();
|
||||
}
|
||||
|
||||
@@ -81,9 +67,7 @@ struct nlohmann_traits {
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string serialize(const json &val) {
|
||||
return val.dump();
|
||||
}
|
||||
static std::string serialize(const json& val) { return val.dump(); }
|
||||
};
|
||||
|
||||
TEST(NlohmannTest, BasicClaims) {
|
||||
@@ -95,8 +79,7 @@ TEST(NlohmannTest, BasicClaims) {
|
||||
}
|
||||
|
||||
TEST(NlohmannTest, AudienceAsString) {
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
||||
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||
auto decoded = jwt::decode<nlohmann_traits>(token);
|
||||
|
||||
@@ -122,11 +105,7 @@ TEST(NlohmannTest, AudienceAsString) {
|
||||
}
|
||||
|
||||
TEST(NlohmannTest, SetArray) {
|
||||
std::vector<int64_t> vect = {
|
||||
100,
|
||||
20,
|
||||
10
|
||||
};
|
||||
std::vector<int64_t> vect = {100, 20, 10};
|
||||
auto token = jwt::create<nlohmann_traits>()
|
||||
.set_payload_claim("test", jwt::basic_claim<nlohmann_traits>(vect.begin(), vect.end()))
|
||||
.sign(jwt::algorithm::none{});
|
||||
@@ -139,14 +118,15 @@ TEST(NlohmannTest, SetObject) {
|
||||
iss >> object;
|
||||
ASSERT_EQ(object.get_type(), jwt::json::type::object);
|
||||
|
||||
auto token = jwt::create<nlohmann_traits>()
|
||||
.set_payload_claim("namespace", object)
|
||||
.sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
auto token =
|
||||
jwt::create<nlohmann_traits>().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token,
|
||||
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
}
|
||||
|
||||
TEST(NlohmannTest, VerifyTokenHS256) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify<jwt::default_clock, nlohmann_traits>({})
|
||||
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#ifdef __linux__ // None of this stuff is going to work outside of linux!
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include <dlfcn.h>
|
||||
// TODO: Figure out why the tests fail on older openssl versions
|
||||
@@ -42,282 +42,295 @@ static uint64_t fail_EVP_DigestVerify = 0;
|
||||
|
||||
BIO* BIO_new(const BIO_METHOD* type) {
|
||||
static BIO* (*origMethod)(const BIO_METHOD*) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "BIO_new");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "BIO_new");
|
||||
bool fail = fail_BIO_new & 1;
|
||||
fail_BIO_new = fail_BIO_new >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(type);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(type);
|
||||
}
|
||||
|
||||
X509* PEM_read_bio_X509(BIO* bp, X509** x, pem_password_cb* cb, void* u) {
|
||||
static X509* (*origMethod)(BIO * bp, X509 * *x, pem_password_cb * cb, void* u) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_X509");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_X509");
|
||||
bool fail = fail_PEM_read_bio_X509 & 1;
|
||||
fail_PEM_read_bio_X509 = fail_PEM_read_bio_X509 >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(bp, x, cb, u);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(bp, x, cb, u);
|
||||
}
|
||||
|
||||
EVP_PKEY* X509_get_pubkey(X509* x) {
|
||||
static EVP_PKEY* (*origMethod)(X509*) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "X509_get_pubkey");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "X509_get_pubkey");
|
||||
bool fail = fail_X509_get_pubkey & 1;
|
||||
fail_X509_get_pubkey = fail_X509_get_pubkey >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(x);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(x);
|
||||
}
|
||||
|
||||
int PEM_write_bio_PUBKEY(BIO* bp, EVP_PKEY* x) {
|
||||
static int (*origMethod)(BIO * bp, EVP_PKEY * x) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_write_bio_PUBKEY");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_write_bio_PUBKEY");
|
||||
bool fail = fail_PEM_write_bio_PUBKEY & 1;
|
||||
fail_PEM_write_bio_PUBKEY = fail_PEM_write_bio_PUBKEY >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(bp, x);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(bp, x);
|
||||
}
|
||||
|
||||
int PEM_write_bio_X509(BIO* bp, X509* x) {
|
||||
static int (*origMethod)(BIO * bp, X509 * x) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_write_bio_X509");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_write_bio_X509");
|
||||
bool fail = fail_PEM_write_bio_cert & 1;
|
||||
fail_PEM_write_bio_cert = fail_PEM_write_bio_cert >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(bp, x);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(bp, x);
|
||||
}
|
||||
|
||||
long BIO_ctrl(BIO* bp, int cmd, long larg, void* parg) {
|
||||
static long (*origMethod)(BIO * bp, int cmd, long larg, void* parg) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "BIO_ctrl");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "BIO_ctrl");
|
||||
bool fail = fail_BIO_ctrl & 1;
|
||||
fail_BIO_ctrl = fail_BIO_ctrl >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(bp, cmd, larg, parg);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(bp, cmd, larg, parg);
|
||||
}
|
||||
|
||||
int BIO_write(BIO* b, const void* data, int dlen) {
|
||||
static int (*origMethod)(BIO * b, const void* data, int dlen) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "BIO_write");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "BIO_write");
|
||||
bool fail = fail_BIO_write & 1;
|
||||
fail_BIO_write = fail_BIO_write >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(b, data, dlen);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(b, data, dlen);
|
||||
}
|
||||
|
||||
EVP_PKEY* PEM_read_bio_PUBKEY(BIO* bp, EVP_PKEY** x, pem_password_cb* cb, void* u) {
|
||||
static EVP_PKEY* (*origMethod)(BIO * bp, EVP_PKEY * *x, pem_password_cb * cb, void* u) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_PUBKEY");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_PUBKEY");
|
||||
bool fail = fail_PEM_read_bio_PUBKEY & 1;
|
||||
fail_PEM_read_bio_PUBKEY = fail_PEM_read_bio_PUBKEY >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(bp, x, cb, u);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(bp, x, cb, u);
|
||||
}
|
||||
|
||||
EVP_PKEY* PEM_read_bio_PrivateKey(BIO* bp, EVP_PKEY** x, pem_password_cb* cb, void* u) {
|
||||
static EVP_PKEY* (*origMethod)(BIO * bp, EVP_PKEY * *x, pem_password_cb * cb, void* u) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_PrivateKey");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_PrivateKey");
|
||||
bool fail = fail_PEM_read_bio_PrivateKey & 1;
|
||||
fail_PEM_read_bio_PrivateKey = fail_PEM_read_bio_PrivateKey >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(bp, x, cb, u);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(bp, x, cb, u);
|
||||
}
|
||||
|
||||
EC_KEY* PEM_read_bio_EC_PUBKEY(BIO* bp, EC_KEY** x, pem_password_cb* cb, void* u) {
|
||||
static EC_KEY* (*origMethod)(BIO * bp, EC_KEY * *x, pem_password_cb * cb, void* u) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_EC_PUBKEY");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_EC_PUBKEY");
|
||||
bool fail = fail_PEM_read_bio_EC_PUBKEY & 1;
|
||||
fail_PEM_read_bio_EC_PUBKEY = fail_PEM_read_bio_EC_PUBKEY >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(bp, x, cb, u);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(bp, x, cb, u);
|
||||
}
|
||||
|
||||
EC_KEY* PEM_read_bio_ECPrivateKey(BIO* bp, EC_KEY** x, pem_password_cb* cb, void* u) {
|
||||
static EC_KEY* (*origMethod)(BIO * bp, EC_KEY * *x, pem_password_cb * cb, void* u) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_ECPrivateKey");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "PEM_read_bio_ECPrivateKey");
|
||||
bool fail = fail_PEM_read_bio_ECPrivateKey & 1;
|
||||
fail_PEM_read_bio_ECPrivateKey = fail_PEM_read_bio_ECPrivateKey >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(bp, x, cb, u);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(bp, x, cb, u);
|
||||
}
|
||||
|
||||
unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
|
||||
const unsigned char *d, size_t n, unsigned char *md,
|
||||
unsigned int *md_len) {
|
||||
static unsigned char *(*origMethod)(const EVP_MD *evp_md, const void *key, int key_len,
|
||||
const unsigned char *d, size_t n, unsigned char *md,
|
||||
unsigned int *md_len) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "HMAC");
|
||||
unsigned char* HMAC(const EVP_MD* evp_md, const void* key, int key_len, const unsigned char* d, size_t n,
|
||||
unsigned char* md, unsigned int* md_len) {
|
||||
static unsigned char* (*origMethod)(const EVP_MD* evp_md, const void* key, int key_len, const unsigned char* d,
|
||||
size_t n, unsigned char* md, unsigned int* md_len) = nullptr;
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "HMAC");
|
||||
bool fail = fail_HMAC & 1;
|
||||
fail_HMAC = fail_HMAC >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(evp_md, key, key_len, d, n, md, md_len);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(evp_md, key, key_len, d, n, md, md_len);
|
||||
}
|
||||
|
||||
EVP_MD_CTX* EVP_MD_CTX_new(void) {
|
||||
static EVP_MD_CTX* (*origMethod)(void) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_MD_CTX_new");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_MD_CTX_new");
|
||||
bool fail = fail_EVP_MD_CTX_new & 1;
|
||||
fail_EVP_MD_CTX_new = fail_EVP_MD_CTX_new >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod();
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod();
|
||||
}
|
||||
|
||||
int EVP_DigestInit(EVP_MD_CTX* ctx, const EVP_MD* type) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, const EVP_MD* type) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestInit");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestInit");
|
||||
bool fail = fail_EVP_DigestInit & 1;
|
||||
fail_EVP_DigestInit = fail_EVP_DigestInit >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, type);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, type);
|
||||
}
|
||||
|
||||
int EVP_DigestUpdate(EVP_MD_CTX* ctx, const void* d, size_t cnt) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, const void* d, size_t cnt) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestUpdate");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestUpdate");
|
||||
bool fail = fail_EVP_DigestUpdate & 1;
|
||||
fail_EVP_DigestUpdate = fail_EVP_DigestUpdate >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, d, cnt);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, d, cnt);
|
||||
}
|
||||
|
||||
int EVP_DigestFinal(EVP_MD_CTX* ctx, unsigned char* md, unsigned int* s) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, unsigned char* md, unsigned int* s) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestFinal");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestFinal");
|
||||
bool fail = fail_EVP_DigestFinal & 1;
|
||||
fail_EVP_DigestFinal = fail_EVP_DigestFinal >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, md, s);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, md, s);
|
||||
}
|
||||
|
||||
int EVP_SignFinal(EVP_MD_CTX* ctx, unsigned char* md, unsigned int* s, EVP_PKEY* pkey) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, unsigned char* md, unsigned int* s, EVP_PKEY* pkey) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_SignFinal");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_SignFinal");
|
||||
bool fail = fail_EVP_SignFinal & 1;
|
||||
fail_EVP_SignFinal = fail_EVP_SignFinal >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, md, s, pkey);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, md, s, pkey);
|
||||
}
|
||||
|
||||
int EVP_VerifyFinal(EVP_MD_CTX* ctx, const unsigned char* sigbuf, unsigned int siglen, EVP_PKEY* pkey) {
|
||||
static int(*origMethod)(EVP_MD_CTX *ctx, const unsigned char *sigbuf, unsigned int siglen, EVP_PKEY *pkey) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_VerifyFinal");
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, const unsigned char* sigbuf, unsigned int siglen, EVP_PKEY* pkey) =
|
||||
nullptr;
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_VerifyFinal");
|
||||
bool fail = fail_EVP_VerifyFinal & 1;
|
||||
fail_EVP_VerifyFinal = fail_EVP_VerifyFinal >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, sigbuf, siglen, pkey);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, sigbuf, siglen, pkey);
|
||||
}
|
||||
|
||||
int EC_KEY_check_key(const EC_KEY* key) {
|
||||
static int (*origMethod)(const EC_KEY* key) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EC_KEY_check_key");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EC_KEY_check_key");
|
||||
bool fail = fail_EC_KEY_check_key & 1;
|
||||
fail_EC_KEY_check_key = fail_EC_KEY_check_key >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(key);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(key);
|
||||
}
|
||||
|
||||
ECDSA_SIG* ECDSA_SIG_new(void) {
|
||||
static ECDSA_SIG* (*origMethod)() = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "ECDSA_SIG_new");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "ECDSA_SIG_new");
|
||||
bool fail = fail_ECDSA_SIG_new & 1;
|
||||
fail_ECDSA_SIG_new = fail_ECDSA_SIG_new >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod();
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod();
|
||||
}
|
||||
|
||||
ECDSA_SIG* ECDSA_do_sign(const unsigned char* dgst, int dgst_len, EC_KEY* eckey) {
|
||||
static ECDSA_SIG* (*origMethod)(const unsigned char* dgst, int dgst_len, EC_KEY* eckey) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "ECDSA_do_sign");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "ECDSA_do_sign");
|
||||
bool fail = fail_ECDSA_do_sign & 1;
|
||||
fail_ECDSA_do_sign = fail_ECDSA_do_sign >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(dgst, dgst_len, eckey);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(dgst, dgst_len, eckey);
|
||||
}
|
||||
|
||||
struct rsa_st* EVP_PKEY_get1_RSA(EVP_PKEY* pkey) {
|
||||
static struct rsa_st* (*origMethod)(EVP_PKEY * pkey) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_get1_RSA");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_PKEY_get1_RSA");
|
||||
bool fail = fail_EVP_PKEY_get1_RSA & 1;
|
||||
fail_EVP_PKEY_get1_RSA = fail_EVP_PKEY_get1_RSA >> 1;
|
||||
if(fail) return nullptr;
|
||||
else return origMethod(pkey);
|
||||
if (fail)
|
||||
return nullptr;
|
||||
else
|
||||
return origMethod(pkey);
|
||||
}
|
||||
|
||||
int EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e,
|
||||
EVP_PKEY *pkey) {
|
||||
static int(*origMethod)(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e,
|
||||
EVP_PKEY *pkey) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestSignInit");
|
||||
int EVP_DigestSignInit(EVP_MD_CTX* ctx, EVP_PKEY_CTX** pctx, const EVP_MD* type, ENGINE* e, EVP_PKEY* pkey) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, EVP_PKEY_CTX * *pctx, const EVP_MD* type, ENGINE* e, EVP_PKEY* pkey) =
|
||||
nullptr;
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestSignInit");
|
||||
bool fail = fail_EVP_DigestSignInit & 1;
|
||||
fail_EVP_DigestSignInit = fail_EVP_DigestSignInit >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx,pctx, type, e,pkey);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, pctx, type, e, pkey);
|
||||
}
|
||||
|
||||
int EVP_DigestSign(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
size_t *siglen, const unsigned char *tbs,
|
||||
size_t tbslen) {
|
||||
static int(*origMethod)(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
size_t *siglen, const unsigned char *tbs,
|
||||
int EVP_DigestSign(EVP_MD_CTX* ctx, unsigned char* sigret, size_t* siglen, const unsigned char* tbs, size_t tbslen) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, unsigned char* sigret, size_t* siglen, const unsigned char* tbs,
|
||||
size_t tbslen) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestSign");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestSign");
|
||||
bool fail = fail_EVP_DigestSign & 1;
|
||||
fail_EVP_DigestSign = fail_EVP_DigestSign >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, sigret, siglen, tbs, tbslen);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, sigret, siglen, tbs, tbslen);
|
||||
}
|
||||
|
||||
int EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e,
|
||||
EVP_PKEY *pkey) {
|
||||
static int(*origMethod)(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx,
|
||||
const EVP_MD *type, ENGINE *e,
|
||||
EVP_PKEY *pkey) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestVerifyInit");
|
||||
int EVP_DigestVerifyInit(EVP_MD_CTX* ctx, EVP_PKEY_CTX** pctx, const EVP_MD* type, ENGINE* e, EVP_PKEY* pkey) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, EVP_PKEY_CTX * *pctx, const EVP_MD* type, ENGINE* e, EVP_PKEY* pkey) =
|
||||
nullptr;
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestVerifyInit");
|
||||
bool fail = fail_EVP_DigestVerifyInit & 1;
|
||||
fail_EVP_DigestVerifyInit = fail_EVP_DigestVerifyInit >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx,pctx, type, e,pkey);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, pctx, type, e, pkey);
|
||||
}
|
||||
|
||||
int EVP_DigestVerify(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
size_t *siglen, const unsigned char *tbs,
|
||||
size_t tbslen) {
|
||||
static int(*origMethod)(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
size_t *siglen, const unsigned char *tbs,
|
||||
int EVP_DigestVerify(EVP_MD_CTX* ctx, unsigned char* sigret, size_t* siglen, const unsigned char* tbs, size_t tbslen) {
|
||||
static int (*origMethod)(EVP_MD_CTX * ctx, unsigned char* sigret, size_t* siglen, const unsigned char* tbs,
|
||||
size_t tbslen) = nullptr;
|
||||
if (origMethod == nullptr)
|
||||
origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestVerify");
|
||||
if (origMethod == nullptr) origMethod = (decltype(origMethod))dlsym(RTLD_NEXT, "EVP_DigestVerify");
|
||||
bool fail = fail_EVP_DigestVerify & 1;
|
||||
fail_EVP_DigestVerify = fail_EVP_DigestVerify >> 1;
|
||||
if(fail) return 0;
|
||||
else return origMethod(ctx, sigret, siglen, tbs, tbslen);
|
||||
if (fail)
|
||||
return 0;
|
||||
else
|
||||
return origMethod(ctx, sigret, siglen, tbs, tbslen);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -351,7 +364,7 @@ inline namespace test_keys {
|
||||
extern std::string ed448_priv_key;
|
||||
extern std::string ed448_pub_key;
|
||||
extern std::string ed448_pub_key_invalid;
|
||||
}
|
||||
} // namespace test_keys
|
||||
|
||||
TEST(OpenSSLErrorTest, ExtractPubkeyFromCertReference) {
|
||||
std::error_code ec;
|
||||
@@ -392,32 +405,26 @@ void run_multitest(const std::vector<multitest_entry>& mapping, Func fn) {
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, ExtractPubkeyFromCert) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_PEM_read_bio_X509, 1, jwt::error::rsa_error::cert_load_failed},
|
||||
{&fail_X509_get_pubkey, 1, jwt::error::rsa_error::get_key_failed},
|
||||
{&fail_PEM_write_bio_PUBKEY, 1, jwt::error::rsa_error::write_key_failed},
|
||||
{ &fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed }
|
||||
};
|
||||
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::helper::extract_pubkey_from_cert(sample_cert, "");
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const jwt::rsa_exception& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const jwt::rsa_exception& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, ExtractPubkeyFromCertErrorCode) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_PEM_read_bio_X509, 1, jwt::error::rsa_error::cert_load_failed},
|
||||
{&fail_X509_get_pubkey, 1, jwt::error::rsa_error::get_key_failed},
|
||||
{&fail_PEM_write_bio_PUBKEY, 1, jwt::error::rsa_error::write_key_failed},
|
||||
{ &fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed }
|
||||
};
|
||||
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
auto res = jwt::helper::extract_pubkey_from_cert(sample_cert, "", ec);
|
||||
@@ -426,28 +433,22 @@ TEST(OpenSSLErrorTest, ExtractPubkeyFromCertErrorCode) {
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, ConvertCertBase64DerToPem) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_PEM_write_bio_cert, 1, jwt::error::rsa_error::write_cert_failed},
|
||||
{ &fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed }
|
||||
};
|
||||
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::helper::convert_base64_der_to_pem(sample_cert_base64_der);
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const jwt::rsa_exception& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const jwt::rsa_exception& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, ConvertCertBase64DerToPemErrorCode) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_PEM_write_bio_cert, 1, jwt::error::rsa_error::write_cert_failed},
|
||||
{ &fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed }
|
||||
};
|
||||
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
auto res = jwt::helper::convert_base64_der_to_pem(sample_cert_base64_der, ec);
|
||||
@@ -461,28 +462,22 @@ TEST(OpenSSLErrorTest, LoadPublicKeyFromStringReference) {
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, LoadPublicKeyFromString) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{ &fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read }
|
||||
};
|
||||
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::helper::load_public_key_from_string(rsa_pub_key, "");
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const jwt::rsa_exception& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const jwt::rsa_exception& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, LoadPublicKeyFromStringErrorCode) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{ &fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read }
|
||||
};
|
||||
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
auto res = jwt::helper::load_public_key_from_string(rsa_pub_key, "", ec);
|
||||
@@ -496,28 +491,22 @@ TEST(OpenSSLErrorTest, LoadPublicKeyCertFromStringReference) {
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, LoadPublicKeyCertFromString) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{ &fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read }
|
||||
};
|
||||
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::helper::load_public_key_from_string(sample_cert, "");
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const jwt::rsa_exception& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const jwt::rsa_exception& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, LoadPublicKeyCertFromStringErrorCode) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{ &fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read }
|
||||
};
|
||||
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
auto res = jwt::helper::load_public_key_from_string(sample_cert, "", ec);
|
||||
@@ -531,28 +520,22 @@ TEST(OpenSSLErrorTest, LoadPrivateKeyFromStringReference) {
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, LoadPrivateKeyFromString) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{ &fail_PEM_read_bio_PrivateKey, 1, jwt::error::rsa_error::load_key_bio_read }
|
||||
};
|
||||
{&fail_PEM_read_bio_PrivateKey, 1, jwt::error::rsa_error::load_key_bio_read}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::helper::load_private_key_from_string(rsa_priv_key, "");
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const jwt::rsa_exception& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const jwt::rsa_exception& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, LoadPrivateKeyFromStringErrorCode) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{ &fail_PEM_read_bio_PrivateKey, 1, jwt::error::rsa_error::load_key_bio_read }
|
||||
};
|
||||
{&fail_PEM_read_bio_PrivateKey, 1, jwt::error::rsa_error::load_key_bio_read}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
auto res = jwt::helper::load_private_key_from_string(rsa_priv_key, "", ec);
|
||||
@@ -561,20 +544,15 @@ TEST(OpenSSLErrorTest, LoadPrivateKeyFromStringErrorCode) {
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, HMACSign) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_HMAC, 1, jwt::error::signature_generation_error::hmac_failed }
|
||||
};
|
||||
std::vector<multitest_entry> mapping{{&fail_HMAC, 1, jwt::error::signature_generation_error::hmac_failed}};
|
||||
|
||||
run_multitest(mapping, [&](std::error_code& ec){
|
||||
verify.verify(decoded_token, ec);
|
||||
});
|
||||
run_multitest(mapping, [&](std::error_code& ec) { verify.verify(decoded_token, ec); });
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, RS256Reference) {
|
||||
@@ -594,12 +572,11 @@ TEST(OpenSSLErrorTest, RS256Reference) {
|
||||
|
||||
TEST(OpenSSLErrorTest, RS256SignErrorCode) {
|
||||
jwt::algorithm::rs256 alg{rsa_pub_key, rsa_priv_key};
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed},
|
||||
{&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::signinit_failed},
|
||||
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::signupdate_failed},
|
||||
{ &fail_EVP_SignFinal, 1, jwt::error::signature_generation_error::signfinal_failed }
|
||||
};
|
||||
{&fail_EVP_SignFinal, 1, jwt::error::signature_generation_error::signfinal_failed}};
|
||||
|
||||
run_multitest(mapping, [&alg](std::error_code& ec) {
|
||||
auto res = alg.sign("testdata", ec);
|
||||
@@ -614,20 +591,17 @@ TEST(OpenSSLErrorTest, RS256VerifyErrorCode) {
|
||||
"AhzGkI9HdADu5YAJsUaLknDUV5hmundXQY8lhwQnKFXW0rl0H8DoFiPQErFmcKI6PA9NVGK/LSiqHqesNeg0wqCTxMmeT6pqI7FH9fDO"
|
||||
"CaBpwUJ4t5aKoytQ75t13OfUM7tfLlVkFZtI3RndhivxLA5d4Elt/Gv3RhDu6Eiom5NZ/pwRvP26Sox+FWapz3DGCil70H1iGSYu8ENa"
|
||||
"afUBCGGhT4sk7kl7zS6XiEpMobLq3A==");
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_verification_error::create_context_failed},
|
||||
{&fail_EVP_DigestInit, 1, jwt::error::signature_verification_error::verifyinit_failed},
|
||||
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_verification_error::verifyupdate_failed},
|
||||
{ &fail_EVP_VerifyFinal, 1, jwt::error::signature_verification_error::verifyfinal_failed }
|
||||
};
|
||||
{&fail_EVP_VerifyFinal, 1, jwt::error::signature_verification_error::verifyfinal_failed}};
|
||||
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec){
|
||||
alg.verify("testdata", signature, ec);
|
||||
});
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec) { alg.verify("testdata", signature, ec); });
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, ECDSAKey) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_BIO_new, 1, jwt::error::ecdsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::ecdsa_error::load_key_bio_write},
|
||||
{&fail_PEM_read_bio_EC_PUBKEY, 1, jwt::error::ecdsa_error::load_key_bio_read},
|
||||
@@ -642,15 +616,12 @@ TEST(OpenSSLErrorTest, ECDSAKey) {
|
||||
try {
|
||||
jwt::algorithm::es256 alg{ecdsa256_pub_key, ecdsa256_priv_key};
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const std::system_error& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const std::system_error& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, ECDSACertificate) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
{ &fail_BIO_new, 1, jwt::error::ecdsa_error::create_mem_bio_failed },
|
||||
std::vector<multitest_entry> mapping{{&fail_BIO_new, 1, jwt::error::ecdsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::ecdsa_error::load_key_bio_write},
|
||||
{&fail_PEM_read_bio_EC_PUBKEY, 1, jwt::error::ecdsa_error::load_key_bio_read},
|
||||
// extract_pubkey_from_cert
|
||||
@@ -658,16 +629,13 @@ TEST(OpenSSLErrorTest, ECDSACertificate) {
|
||||
{&fail_PEM_read_bio_X509, 1, jwt::error::rsa_error::cert_load_failed},
|
||||
{&fail_X509_get_pubkey, 1, jwt::error::rsa_error::get_key_failed},
|
||||
{&fail_PEM_write_bio_PUBKEY, 1, jwt::error::rsa_error::write_key_failed},
|
||||
{ &fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed }
|
||||
};
|
||||
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::algorithm::es256 alg{ecdsa256_certificate};
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const std::system_error& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const std::system_error& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -683,13 +651,12 @@ TEST(OpenSSLErrorTest, ES256Reference) {
|
||||
|
||||
TEST(OpenSSLErrorTest, ES256SignErrorCode) {
|
||||
jwt::algorithm::es256 alg{ecdsa256_pub_key, ecdsa256_priv_key};
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed},
|
||||
{&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::digestinit_failed},
|
||||
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed},
|
||||
{&fail_EVP_DigestFinal, 1, jwt::error::signature_generation_error::digestfinal_failed},
|
||||
{ &fail_ECDSA_do_sign, 1, jwt::error::signature_generation_error::ecdsa_do_sign_failed }
|
||||
};
|
||||
{&fail_ECDSA_do_sign, 1, jwt::error::signature_generation_error::ecdsa_do_sign_failed}};
|
||||
|
||||
run_multitest(mapping, [&alg](std::error_code& ec) {
|
||||
auto res = alg.sign("testdata", ec);
|
||||
@@ -701,7 +668,7 @@ TEST(OpenSSLErrorTest, ES256VerifyErrorCode) {
|
||||
jwt::algorithm::es256 alg{ecdsa256_pub_key, ecdsa256_priv_key};
|
||||
auto signature = jwt::base::decode<jwt::alphabet::base64>(
|
||||
"aC/NqyHfPw5FDA0yRAnrbkrAlXjsr0obRkCg/HgP+77QYJrAg6YKkKoJwMXjUX8fQrxXKTN7em5L9dtmOep37Q==");
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed},
|
||||
{&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::digestinit_failed},
|
||||
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed},
|
||||
@@ -709,9 +676,7 @@ TEST(OpenSSLErrorTest, ES256VerifyErrorCode) {
|
||||
{&fail_ECDSA_SIG_new, 1, jwt::error::signature_verification_error::create_context_failed},
|
||||
};
|
||||
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec){
|
||||
alg.verify("testdata", signature, ec);
|
||||
});
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec) { alg.verify("testdata", signature, ec); });
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, PS256Reference) {
|
||||
@@ -726,7 +691,7 @@ TEST(OpenSSLErrorTest, PS256Reference) {
|
||||
|
||||
TEST(OpenSSLErrorTest, PS256SignErrorCode) {
|
||||
jwt::algorithm::ps256 alg{rsa_pub_key, rsa_priv_key};
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed},
|
||||
{&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::digestinit_failed},
|
||||
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed},
|
||||
@@ -743,9 +708,14 @@ TEST(OpenSSLErrorTest, PS256SignErrorCode) {
|
||||
|
||||
TEST(OpenSSLErrorTest, PS256VerifyErrorCode) {
|
||||
jwt::algorithm::ps256 alg{rsa_pub_key, rsa_priv_key};
|
||||
std::string signature = "LMiWCiW0a/mbU6LK8EZaDQ6TGisqfD+LF46zUbzjhFt02J9yVuf3ZDNTdRgLKKP8nCJUx0SN+5CS2YD268Ioxau5bWs49RVCxtID5DcRpJlSo+Vk+dCmwxhQWHX8HNh3o7kBK5H8fLeTeupuSov+0hH3+GRrYJqZvCdbcadi6amNKCfeIl6a5mp2VCM55NsPoRxsmSzc1G7AHWb1ckOCsm3KY5BL6B074bHgoqO3yaLlKWLAcy4OYyRpJ/wnZQ9PPrhwdq/B59uW3x1QUCKYKgZeqZOoqIP1YgLwvEpPtXYutQCFr4eBKgV7vdtE0wgHR43ka16fi5L4SyaZv53NCg==";
|
||||
std::string signature =
|
||||
"LMiWCiW0a/"
|
||||
"mbU6LK8EZaDQ6TGisqfD+LF46zUbzjhFt02J9yVuf3ZDNTdRgLKKP8nCJUx0SN+5CS2YD268Ioxau5bWs49RVCxtID5DcRpJlSo+Vk+"
|
||||
"dCmwxhQWHX8HNh3o7kBK5H8fLeTeupuSov+0hH3+"
|
||||
"GRrYJqZvCdbcadi6amNKCfeIl6a5mp2VCM55NsPoRxsmSzc1G7AHWb1ckOCsm3KY5BL6B074bHgoqO3yaLlKWLAcy4OYyRpJ/wnZQ9PPrhwdq/"
|
||||
"B59uW3x1QUCKYKgZeqZOoqIP1YgLwvEpPtXYutQCFr4eBKgV7vdtE0wgHR43ka16fi5L4SyaZv53NCg==";
|
||||
signature = jwt::base::decode<jwt::alphabet::base64>(signature);
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed},
|
||||
{&fail_EVP_DigestInit, 1, jwt::error::signature_generation_error::digestinit_failed},
|
||||
{&fail_EVP_DigestUpdate, 1, jwt::error::signature_generation_error::digestupdate_failed},
|
||||
@@ -754,14 +724,12 @@ TEST(OpenSSLErrorTest, PS256VerifyErrorCode) {
|
||||
//TODO: RSA_public_decrypt
|
||||
};
|
||||
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec){
|
||||
alg.verify("testdata", signature, ec);
|
||||
});
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec) { alg.verify("testdata", signature, ec); });
|
||||
}
|
||||
|
||||
#ifndef OPENSSL110
|
||||
TEST(OpenSSLErrorTest, EdDSAKey) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
// load_private_key_from_string
|
||||
{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
@@ -776,15 +744,12 @@ TEST(OpenSSLErrorTest, EdDSAKey) {
|
||||
try {
|
||||
jwt::algorithm::ed25519 alg{ed25519_pub_key, ed25519_priv_key};
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const std::system_error& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const std::system_error& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
TEST(OpenSSLErrorTest, EdDSACertificate) {
|
||||
std::vector<multitest_entry> mapping = {
|
||||
// load_public_key_from_string
|
||||
std::vector<multitest_entry> mapping{// load_public_key_from_string
|
||||
{&fail_BIO_new, 1, jwt::error::rsa_error::create_mem_bio_failed},
|
||||
{&fail_BIO_write, 1, jwt::error::rsa_error::load_key_bio_write},
|
||||
{&fail_PEM_read_bio_PUBKEY, 1, jwt::error::rsa_error::load_key_bio_read},
|
||||
@@ -793,16 +758,13 @@ TEST(OpenSSLErrorTest, EdDSACertificate) {
|
||||
{&fail_PEM_read_bio_X509, 1, jwt::error::rsa_error::cert_load_failed},
|
||||
{&fail_X509_get_pubkey, 1, jwt::error::rsa_error::get_key_failed},
|
||||
{&fail_PEM_write_bio_PUBKEY, 1, jwt::error::rsa_error::write_key_failed},
|
||||
{ &fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed }
|
||||
};
|
||||
{&fail_BIO_ctrl, 1, jwt::error::rsa_error::convert_to_pem_failed}};
|
||||
|
||||
run_multitest(mapping, [](std::error_code& ec) {
|
||||
try {
|
||||
jwt::algorithm::ed25519 alg{ed25519_certificate};
|
||||
FAIL(); // Should never reach this
|
||||
} catch(const std::system_error& e) {
|
||||
ec = e.code();
|
||||
}
|
||||
} catch (const std::system_error& e) { ec = e.code(); }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -818,11 +780,10 @@ TEST(OpenSSLErrorTest, Ed25519Reference) {
|
||||
|
||||
TEST(OpenSSLErrorTest, Ed25519SignErrorCode) {
|
||||
jwt::algorithm::ed25519 alg{ed25519_pub_key, ed25519_priv_key};
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_generation_error::create_context_failed},
|
||||
{&fail_EVP_DigestSignInit, 1, jwt::error::signature_generation_error::signinit_failed},
|
||||
{ &fail_EVP_DigestSign, 1, jwt::error::signature_generation_error::signfinal_failed }
|
||||
};
|
||||
{&fail_EVP_DigestSign, 1, jwt::error::signature_generation_error::signfinal_failed}};
|
||||
|
||||
run_multitest(mapping, [&alg](std::error_code& ec) {
|
||||
auto res = alg.sign("testdata", ec);
|
||||
@@ -834,15 +795,12 @@ TEST(OpenSSLErrorTest, Ed25519VerifyErrorCode) {
|
||||
jwt::algorithm::ed25519 alg{ed25519_pub_key, ed25519_priv_key};
|
||||
auto signature = jwt::base::decode<jwt::alphabet::base64>(
|
||||
"aC/NqyHfPw5FDA0yRAnrbkrAlXjsr0obRkCg/HgP+77QYJrAg6YKkKoJwMXjUX8fQrxXKTN7em5L9dtmOep37Q==");
|
||||
std::vector<multitest_entry> mapping = {
|
||||
std::vector<multitest_entry> mapping{
|
||||
{&fail_EVP_MD_CTX_new, 1, jwt::error::signature_verification_error::create_context_failed},
|
||||
{&fail_EVP_DigestVerifyInit, 1, jwt::error::signature_verification_error::verifyinit_failed},
|
||||
{ &fail_EVP_DigestVerify, 1, jwt::error::signature_verification_error::verifyfinal_failed }
|
||||
};
|
||||
{&fail_EVP_DigestVerify, 1, jwt::error::signature_verification_error::verifyfinal_failed}};
|
||||
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec){
|
||||
alg.verify("testdata", signature, ec);
|
||||
});
|
||||
run_multitest(mapping, [&alg, &signature](std::error_code& ec) { alg.verify("testdata", signature, ec); });
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char* argv[]) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(TokenFormatTest, MissingDot) {
|
||||
ASSERT_THROW(jwt::decode("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9"), std::invalid_argument);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "jwt-cpp/jwt.h"
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
inline namespace test_keys {
|
||||
extern std::string rsa_priv_key;
|
||||
@@ -24,10 +24,11 @@ inline namespace test_keys {
|
||||
extern std::string ed448_priv_key;
|
||||
extern std::string ed448_pub_key;
|
||||
extern std::string ed448_pub_key_invalid;
|
||||
}
|
||||
} // namespace test_keys
|
||||
|
||||
TEST(TokenTest, DecodeToken) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_TRUE(decoded.has_algorithm());
|
||||
@@ -48,71 +49,57 @@ TEST(TokenTest, DecodeToken) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateToken) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::none{});
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::none{});
|
||||
ASSERT_EQ("eyJhbGciOiJub25lIiwidHlwIjoiSldTIn0.eyJpc3MiOiJhdXRoMCJ9.", token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenHS256) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::hs256{"secret"});
|
||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE", token);
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::hs256{"secret"});
|
||||
ASSERT_EQ("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE",
|
||||
token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenRS256) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
ASSERT_EQ(
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ", token);
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ",
|
||||
token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenRS512) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::rs512(rsa512_pub_key, rsa512_priv_key, "", ""));
|
||||
|
||||
ASSERT_EQ(
|
||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
|
||||
ASSERT_EQ("eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZSSQyLKvI0"
|
||||
"TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4GB"
|
||||
"hfGgejPBCBlGrQtqFGFdHHOjNHY", token);
|
||||
"hfGgejPBCBlGrQtqFGFdHHOjNHY",
|
||||
token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenPS256) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
// TODO: Find a better way to check if generated signature is valid
|
||||
// Can't do simple check for equal since pss adds random salt.
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenPS384) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ps384(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::ps384(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
// TODO: Find a better way to check if generated signature is valid
|
||||
// Can't do simple check for equal since pss adds random salt.
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenPS512) {
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ps512(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::ps512(rsa_pub_key, rsa_priv_key, "", ""));
|
||||
|
||||
// TODO: Find a better way to check if generated signature is valid
|
||||
// Can't do simple check for equal since pss adds random salt.
|
||||
@@ -120,110 +107,110 @@ TEST(TokenTest, CreateTokenPS512) {
|
||||
|
||||
TEST(TokenTest, CreateTokenES256) {
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es256("", ecdsa256_priv_key, "", ""));
|
||||
auto token =
|
||||
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es256("", ecdsa256_priv_key, "", ""));
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
|
||||
ASSERT_THROW(
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", "")).verify(decoded),
|
||||
jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key, "", "", "")).verify(decoded));
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES256NoPrivate) {
|
||||
|
||||
ASSERT_THROW([](){
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
|
||||
}(), jwt::signature_generation_exception);
|
||||
ASSERT_THROW(
|
||||
[]() {
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
|
||||
}(),
|
||||
jwt::signature_generation_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES384) {
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es384("", ecdsa384_priv_key, "", ""));
|
||||
auto token =
|
||||
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es384("", ecdsa384_priv_key, "", ""));
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
|
||||
ASSERT_THROW(
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", "")).verify(decoded),
|
||||
jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key, "", "", "")).verify(decoded));
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES384NoPrivate) {
|
||||
|
||||
ASSERT_THROW([](){
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
|
||||
}(), jwt::signature_generation_exception);
|
||||
ASSERT_THROW(
|
||||
[]() {
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
|
||||
}(),
|
||||
jwt::signature_generation_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES512) {
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es512("", ecdsa521_priv_key, "", ""));
|
||||
auto token =
|
||||
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::es512("", ecdsa521_priv_key, "", ""));
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
|
||||
ASSERT_THROW(
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", "")).verify(decoded),
|
||||
jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key, "", "", "")).verify(decoded));
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenES512NoPrivate) {
|
||||
|
||||
ASSERT_THROW([](){
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
|
||||
}(), jwt::signature_generation_exception);
|
||||
ASSERT_THROW(
|
||||
[]() {
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(
|
||||
jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
|
||||
}(),
|
||||
jwt::signature_generation_exception);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL110
|
||||
TEST(TokenTest, CreateTokenEd25519) {
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ed25519("", ed25519_priv_key, "", ""));
|
||||
auto token =
|
||||
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::ed25519("", ed25519_priv_key, "", ""));
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", "")).verify(decoded));
|
||||
ASSERT_THROW(
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", "")).verify(decoded),
|
||||
jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", "")).verify(decoded));
|
||||
}
|
||||
|
||||
TEST(TokenTest, CreateTokenEd448) {
|
||||
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::ed448("", ed448_priv_key, "", ""));
|
||||
auto token =
|
||||
jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::ed448("", ed448_priv_key, "", ""));
|
||||
|
||||
auto decoded = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", "")).verify(decoded), jwt::signature_verification_exception);
|
||||
ASSERT_THROW(
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", "")).verify(decoded),
|
||||
jwt::signature_verification_exception);
|
||||
ASSERT_NO_THROW(jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key, "", "", "")).verify(decoded));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(TokenTest, VerifyTokenWrongAlgorithm) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -234,8 +221,7 @@ TEST(TokenTest, VerifyTokenNoneFail) {
|
||||
// None algorithm should not have a signature
|
||||
std::string token = "eyJhbGciOiJub25lIiwidHlwIjoiSldUIn0.eyJpYXQiOjE1OTUyNjc1MTZ9.cmFuZG9tc2ln";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{});
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{});
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -243,22 +229,22 @@ TEST(TokenTest, VerifyTokenNoneFail) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256FailNoKey) {
|
||||
ASSERT_THROW([](){
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256("", "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
}(), jwt::rsa_exception);
|
||||
ASSERT_THROW(
|
||||
[]() {
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256("", "", "", "")).with_issuer("auth0");
|
||||
}(),
|
||||
jwt::rsa_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -266,14 +252,13 @@ TEST(TokenTest, VerifyTokenRS256) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256PublicOnly) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key, "", "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -281,14 +266,13 @@ TEST(TokenTest, VerifyTokenRS256PublicOnly) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256("", rsa_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs256("", rsa_priv_key, "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -296,14 +280,14 @@ TEST(TokenTest, VerifyTokenRS256PrivateOnly) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS256Fail) {
|
||||
std::string token = "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.VA2i1ui1cnoD6I3wnji1WAVCf29EekysvevGrT2GXqK1dDMc8"
|
||||
"HAZCTQxa1Q8NppnpYV-hlqxh-X3Bb0JOePTGzjynpNZoJh2aHZD-GKpZt7OO1Zp8AFWPZ3p8Cahq8536fD8RiBES9jRsvChZvOqA7gMcFc4"
|
||||
"YD0iZhNIcI7a654u5yPYyTlf5kjR97prCf_OXWRn-bYY74zna4p_bP9oWCL4BkaoRcMxi-IR7kmVcCnvbYqyIrKloXP2qPO442RBGqU7Ov9"
|
||||
"sGQxiVqtRHKXZR9RbfvjrErY1KGiCp9M5i2bsUHadZEY44FE2jiOmx-uc2z5c05CCXqVSpfCjWbh9gQ";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::rs256(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -311,7 +295,8 @@ TEST(TokenTest, VerifyTokenRS256Fail) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
@@ -325,13 +310,12 @@ TEST(TokenTest, VerifyTokenRS512) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512PublicOnly) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::rs512(rsa512_pub_key, "", "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -339,13 +323,13 @@ TEST(TokenTest, VerifyTokenRS512PublicOnly) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs512("", rsa512_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::rs512("", rsa512_priv_key, "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -353,13 +337,13 @@ TEST(TokenTest, VerifyTokenRS512PrivateOnly) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenRS512Fail) {
|
||||
std::string token = "eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
std::string token =
|
||||
"eyJhbGciOiJSUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.GZhnjtsvBl2_KDSxg4JW6xnmNjr2mWhYSZ"
|
||||
"SSQyLKvI0TK86sJKchkt_HDy2IC5l5BGRhq_Xv9pHdA1umidQZG3a7gWvHsujqybCBgBraMTd1wJrCl4QxFg2RYHhHbRqb9BnPJgFD_vryd4"
|
||||
"GBhfGgejPBCBlGrQtqFGFdHHOjNHY";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::rs512(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -367,33 +351,30 @@ TEST(TokenTest, VerifyTokenRS512Fail) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenHS256) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenHS256Fail) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "wrongsecret" })
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"wrongsecret"}).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenHS256FailSignatureLength) {
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkA";
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::hs256{ "secret" })
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::hs256{"secret"}).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
@@ -411,9 +392,7 @@ TEST(TokenTest, VerifyFail) {
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth");
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
@@ -424,17 +403,13 @@ TEST(TokenTest, VerifyFail) {
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0")
|
||||
.with_audience("test");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_audience("test");
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0")
|
||||
.with_subject("test");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_subject("test");
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
{
|
||||
@@ -465,33 +440,29 @@ TEST(TokenTest, VerifyFail) {
|
||||
}
|
||||
}
|
||||
{
|
||||
auto token = jwt::create()
|
||||
.set_issuer("auth0")
|
||||
.set_type("JWS")
|
||||
.sign(jwt::algorithm::none{});
|
||||
auto token = jwt::create().set_issuer("auth0").set_type("JWS").sign(jwt::algorithm::none{});
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
{
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::none{})
|
||||
.with_issuer("auth0")
|
||||
.with_audience("test");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::none{}).with_issuer("auth0").with_audience("test");
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::token_verification_exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES256FailNoKey) {
|
||||
ASSERT_THROW([](){
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::es256("", "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
}(), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(
|
||||
[]() {
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256("", "", "", "")).with_issuer("auth0");
|
||||
}(),
|
||||
jwt::ecdsa_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES256) {
|
||||
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
|
||||
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
|
||||
"4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
|
||||
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
@@ -500,17 +471,19 @@ TEST(TokenTest, VerifyTokenES256) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES256Fail) {
|
||||
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
|
||||
const std::string token = "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJhdXRoMCJ9.4iVk3-Y0v4RT4_9IaQlp-8dZ_"
|
||||
"4fsTzIylgrPTDLrEvTHBTyVS3tgPbr2_IZfLETtiKRqCg0aQ5sh9eIsTTwB1g";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", ""));
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es256(ecdsa256_pub_key_invalid, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES384) {
|
||||
const std::string token = "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-"
|
||||
"AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
|
||||
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
@@ -519,17 +492,21 @@ TEST(TokenTest, VerifyTokenES384) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES384Fail) {
|
||||
const std::string token = "eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFUzM4NCIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.nTUwWanmj_K1VZM5it1ES-1FbnmRDL-lH3V_Fem-"
|
||||
"AhMur9Q61yZfKIydrpdavkm_SMxEsUGPVoqkpoEsjFjrtzMDs5s9yaFYD_ydiy1dsn9VbcI55voA3XwEcWFiPHri";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", ""));
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es384(ecdsa384_pub_key_invalid, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES521) {
|
||||
const std::string token = "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY-r8gQd7BZ7whaj9Ft";
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-"
|
||||
"BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY"
|
||||
"-r8gQd7BZ7whaj9Ft";
|
||||
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
@@ -538,24 +515,26 @@ TEST(TokenTest, VerifyTokenES521) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenES521Fail) {
|
||||
const std::string token = "eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY-r8gQd7BZ7whaj9Ft";
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFUzUxMiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.ASF5hh9_Jyujzm3GRBttoth-3I6lCcwqun9Tt7Ekz9_23BN6-"
|
||||
"BFgwKidECWCNc4VINEqFEFdApC2y3YRdkpKX2etAWI7yYudAlxJ7Z17m6GwAoLOGaeNonsaKOe1UnC5W86eoXrCoPRgzsFTpKIb8NiolcYWjIY"
|
||||
"-r8gQd7BZ7whaj9Ft";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", ""));
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::es512(ecdsa521_pub_key_invalid, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256) {
|
||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
std::string token =
|
||||
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, rsa_priv_key, "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -563,14 +542,13 @@ TEST(TokenTest, VerifyTokenPS256) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256PublicOnly) {
|
||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
std::string token =
|
||||
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key, "", "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -578,14 +556,14 @@ TEST(TokenTest, VerifyTokenPS256PublicOnly) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256Fail) {
|
||||
std::string token = "eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
std::string token =
|
||||
"eyJhbGciOiJQUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.CJ4XjVWdbV6vXGZkD4GdJbtYc80SN9cmPOqRhZBRzOyDRqTFE"
|
||||
"4MsbdKyQuhAWcvuMOjn-24qOTjVMR_P_uTC1uG6WPLcucxZyLnbb56zbKnEklW2SX0mQnCGewr-93a_vDaFT6Cp45MsF_OwFPRCMaS5CJg-"
|
||||
"N5KY67UrVSr3s9nkuK9ZTQkyODHfyEUh9F_FhRCATGrb5G7_qHqBYvTvaPUXqzhhpCjN855Tocg7A24Hl0yMwM-XdasucW5xNdKjG_YCkis"
|
||||
"HX7ax--JiF5GNYCO61eLFteO4THUg-3Z0r4OlGqlppyWo5X5tjcxOZCvBh7WDWfkxA48KFZPRv0nlKA";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
auto verify =
|
||||
jwt::verify().allow_algorithm(jwt::algorithm::ps256(rsa_pub_key_invalid, "", "", "")).with_issuer("auth0");
|
||||
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
@@ -593,16 +571,17 @@ TEST(TokenTest, VerifyTokenPS256Fail) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenPS256FailNoKey) {
|
||||
ASSERT_THROW([](){
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ps256("", "", "", ""))
|
||||
.with_issuer("auth0");
|
||||
}(), jwt::rsa_exception);
|
||||
ASSERT_THROW(
|
||||
[]() {
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ps256("", "", "", "")).with_issuer("auth0");
|
||||
}(),
|
||||
jwt::rsa_exception);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL110
|
||||
TEST(TokenTest, VerifyTokenEd25519) {
|
||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
||||
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
|
||||
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key, "", "", ""));
|
||||
@@ -612,18 +591,19 @@ TEST(TokenTest, VerifyTokenEd25519) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenEd25519Fail) {
|
||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.OujgVcO8xQx5xLcAYWENCRU1SCGH5HcX4MX4o6wU3M4"
|
||||
"DOnKiNmc0O2AnvQlzr-9cgI4QGQzeC6gz_fgLoesADg";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", ""));
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed25519(ed25519_pub_key_invalid, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenEd448) {
|
||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
||||
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
|
||||
"A";
|
||||
|
||||
@@ -634,12 +614,12 @@ TEST(TokenTest, VerifyTokenEd448) {
|
||||
}
|
||||
|
||||
TEST(TokenTest, VerifyTokenEd448Fail) {
|
||||
const std::string token = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
||||
const std::string token =
|
||||
"eyJhbGciOiJFZERTQSIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.Aldes9jrXZXxfNjuovqmIZ3r2WF4yVXVr2Q8B8SkAmv"
|
||||
"Bsw_3MHs8HtgKeXbqKFYWpHOCtmZJcH-AWMvoY6FCNdQqbESGTkv58O6tFbXDD_nLejWNAOuvcO2LPMySmkVNQUopmQf_HO62Mug1ngepUDE"
|
||||
"A";
|
||||
|
||||
auto verify = jwt::verify()
|
||||
.allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", ""));
|
||||
auto verify = jwt::verify().allow_algorithm(jwt::algorithm::ed448(ed448_pub_key_invalid, "", "", ""));
|
||||
auto decoded_token = jwt::decode(token);
|
||||
|
||||
ASSERT_THROW(verify.verify(decoded_token), jwt::signature_verification_exception);
|
||||
@@ -648,9 +628,7 @@ TEST(TokenTest, VerifyTokenEd448Fail) {
|
||||
|
||||
struct test_clock {
|
||||
jwt::date n;
|
||||
jwt::date now() const {
|
||||
return n;
|
||||
}
|
||||
jwt::date now() const { return n; }
|
||||
};
|
||||
|
||||
TEST(TokenTest, VerifyTokenExpireFail) {
|
||||
@@ -757,7 +735,6 @@ TEST(TokenTest, ThrowInvalidKeyLength) {
|
||||
ASSERT_THROW(jwt::algorithm::es256(ecdsa384_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(jwt::algorithm::es256(ecdsa521_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||
|
||||
|
||||
ASSERT_THROW(jwt::algorithm::es384(ecdsa256_pub_key, ""), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(jwt::algorithm::es384("", ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(jwt::algorithm::es384(ecdsa256_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||
@@ -770,7 +747,6 @@ TEST(TokenTest, ThrowInvalidKeyLength) {
|
||||
ASSERT_THROW(jwt::algorithm::es384(ecdsa256_pub_key, ecdsa384_priv_key), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(jwt::algorithm::es384(ecdsa521_pub_key, ecdsa384_priv_key), jwt::ecdsa_exception);
|
||||
|
||||
|
||||
ASSERT_THROW(jwt::algorithm::es512(ecdsa256_pub_key, ""), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(jwt::algorithm::es512("", ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||
ASSERT_THROW(jwt::algorithm::es512(ecdsa256_pub_key, ecdsa256_priv_key), jwt::ecdsa_exception);
|
||||
|
||||
@@ -8,64 +8,51 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
struct jsoncons_traits
|
||||
{
|
||||
struct jsoncons_traits {
|
||||
using json = jsoncons::json;
|
||||
using value_type = json;
|
||||
struct object_type : json::object
|
||||
{
|
||||
struct object_type : json::object {
|
||||
using value_type = key_value_type;
|
||||
using mapped_type = key_value_type::value_type; // https://github.com/danielaparker/jsoncons/commit/1b1ceeb572f9a2db6d37cff47ac78a4f14e072e2#commitcomment-45391411
|
||||
using mapped_type = key_value_type::
|
||||
value_type; // https://github.com/danielaparker/jsoncons/commit/1b1ceeb572f9a2db6d37cff47ac78a4f14e072e2#commitcomment-45391411
|
||||
|
||||
object_type() = default;
|
||||
object_type(const object_type&) = default;
|
||||
object_type(const json::object& o) : json::object(o) {}
|
||||
object_type(object_type&&) = default;
|
||||
object_type(json::object&& o) : json::object(o) {}
|
||||
object_type &operator=(const object_type &o)
|
||||
{
|
||||
object_type& operator=(const object_type& o) {
|
||||
// avoid private deleted copy operator= https://github.com/danielaparker/jsoncons/pull/298
|
||||
object_type t(static_cast<const json::object&>(o));
|
||||
(*this) = std::move(t);
|
||||
return *this;
|
||||
}
|
||||
object_type &operator=(object_type &&o) noexcept
|
||||
{
|
||||
object_type& operator=(object_type&& o) noexcept {
|
||||
swap(o);
|
||||
return *this;
|
||||
}
|
||||
|
||||
mapped_type &operator[](const key_type &key)
|
||||
{
|
||||
auto ret = try_emplace(key); // https://github.com/microsoft/STL/blob/2914b4301c59dc7ffc09d16ac6f7979fde2b7f2c/stl/inc/map#L325
|
||||
mapped_type& operator[](const key_type& key) {
|
||||
auto ret = try_emplace(
|
||||
key); // https://github.com/microsoft/STL/blob/2914b4301c59dc7ffc09d16ac6f7979fde2b7f2c/stl/inc/map#L325
|
||||
return ret.first->value();
|
||||
}
|
||||
mapped_type &operator[](key_type &&key)
|
||||
{
|
||||
mapped_type& operator[](key_type&& key) {
|
||||
auto ret = try_emplace(key);
|
||||
return ret.first->value();
|
||||
}
|
||||
|
||||
const mapped_type &at(const key_type &key) const
|
||||
{
|
||||
const mapped_type& at(const key_type& key) const {
|
||||
auto target = find(key);
|
||||
if (target != end())
|
||||
{
|
||||
return target->value();
|
||||
}
|
||||
if (target != end()) { return target->value(); }
|
||||
|
||||
std::out_of_range("invalid key");
|
||||
}
|
||||
|
||||
size_t count(const key_type &key) const
|
||||
{
|
||||
size_t count(const key_type& key) const {
|
||||
size_t ret = 0;
|
||||
for (const_iterator first = begin(); first != end(); ++first)
|
||||
{
|
||||
if (first->key() == key)
|
||||
{
|
||||
++ret;
|
||||
}
|
||||
for (const_iterator first = begin(); first != end(); ++first) {
|
||||
if (first->key() == key) { ++ret; }
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -76,88 +63,64 @@ struct jsoncons_traits
|
||||
using integer_type = int64_t;
|
||||
using boolean_type = bool;
|
||||
|
||||
static jwt::json::type get_type(const json &val)
|
||||
{
|
||||
static jwt::json::type get_type(const json& val) {
|
||||
using jwt::json::type;
|
||||
|
||||
if (val.type() == jsoncons::json_type::bool_value)
|
||||
return type::boolean;
|
||||
if (val.type() == jsoncons::json_type::int64_value)
|
||||
return type::integer;
|
||||
if (val.type() == jsoncons::json_type::uint64_value)
|
||||
return type::integer;
|
||||
if (val.type() == jsoncons::json_type::half_value)
|
||||
return type::number;
|
||||
if (val.type() == jsoncons::json_type::double_value)
|
||||
return type::number;
|
||||
if (val.type() == jsoncons::json_type::string_value)
|
||||
return type::string;
|
||||
if (val.type() == jsoncons::json_type::array_value)
|
||||
return type::array;
|
||||
if (val.type() == jsoncons::json_type::object_value)
|
||||
return type::object;
|
||||
if (val.type() == jsoncons::json_type::bool_value) return type::boolean;
|
||||
if (val.type() == jsoncons::json_type::int64_value) return type::integer;
|
||||
if (val.type() == jsoncons::json_type::uint64_value) return type::integer;
|
||||
if (val.type() == jsoncons::json_type::half_value) return type::number;
|
||||
if (val.type() == jsoncons::json_type::double_value) return type::number;
|
||||
if (val.type() == jsoncons::json_type::string_value) return type::string;
|
||||
if (val.type() == jsoncons::json_type::array_value) return type::array;
|
||||
if (val.type() == jsoncons::json_type::object_value) return type::object;
|
||||
|
||||
throw std::logic_error("invalid type");
|
||||
}
|
||||
|
||||
static object_type as_object(const json &val)
|
||||
{
|
||||
if (val.type() != jsoncons::json_type::object_value)
|
||||
throw std::bad_cast();
|
||||
static object_type as_object(const json& val) {
|
||||
if (val.type() != jsoncons::json_type::object_value) throw std::bad_cast();
|
||||
return object_type(val.object_value());
|
||||
}
|
||||
|
||||
static array_type as_array(const json &val)
|
||||
{
|
||||
if (val.type() != jsoncons::json_type::array_value)
|
||||
throw std::bad_cast();
|
||||
static array_type as_array(const json& val) {
|
||||
if (val.type() != jsoncons::json_type::array_value) throw std::bad_cast();
|
||||
return val.array_value();
|
||||
}
|
||||
|
||||
static string_type as_string(const json &val)
|
||||
{
|
||||
if (val.type() != jsoncons::json_type::string_value)
|
||||
throw std::bad_cast();
|
||||
static string_type as_string(const json& val) {
|
||||
if (val.type() != jsoncons::json_type::string_value) throw std::bad_cast();
|
||||
return val.as_string();
|
||||
}
|
||||
|
||||
static number_type as_number(const json &val)
|
||||
{
|
||||
if (get_type(val) != jwt::json::type::number)
|
||||
throw std::bad_cast();
|
||||
static number_type as_number(const json& val) {
|
||||
if (get_type(val) != jwt::json::type::number) throw std::bad_cast();
|
||||
return val.as_double();
|
||||
}
|
||||
|
||||
static integer_type as_int(const json &val)
|
||||
{
|
||||
if (get_type(val) != jwt::json::type::integer)
|
||||
throw std::bad_cast();
|
||||
static integer_type as_int(const json& val) {
|
||||
if (get_type(val) != jwt::json::type::integer) throw std::bad_cast();
|
||||
return val.as<integer_type>();
|
||||
}
|
||||
|
||||
static boolean_type as_bool(const json &val)
|
||||
{
|
||||
if (val.type() != jsoncons::json_type::bool_value)
|
||||
throw std::bad_cast();
|
||||
static boolean_type as_bool(const json& val) {
|
||||
if (val.type() != jsoncons::json_type::bool_value) throw std::bad_cast();
|
||||
return val.as_bool();
|
||||
}
|
||||
|
||||
static bool parse(json &val, std::string str)
|
||||
{
|
||||
static bool parse(json& val, std::string str) {
|
||||
val = json::parse(str);
|
||||
return true;
|
||||
}
|
||||
|
||||
static std::string serialize(const json &val)
|
||||
{
|
||||
static std::string serialize(const json& val) {
|
||||
std::ostringstream os;
|
||||
os << jsoncons::print(val);
|
||||
return os.str();
|
||||
}
|
||||
};
|
||||
|
||||
TEST(JsonconsTest, BasicClaims)
|
||||
{
|
||||
TEST(JsonconsTest, BasicClaims) {
|
||||
using jsoncons_claim = jwt::basic_claim<jsoncons_traits>;
|
||||
|
||||
const auto string = jsoncons_claim(std::string("string"));
|
||||
@@ -165,11 +128,9 @@ TEST(JsonconsTest, BasicClaims)
|
||||
const auto integer = jsoncons_claim(159816816);
|
||||
}
|
||||
|
||||
TEST(JsonconsTest, AudienceAsString)
|
||||
{
|
||||
TEST(JsonconsTest, AudienceAsString) {
|
||||
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOiJ0ZXN0In0."
|
||||
"WZnM3SIiSRHsbO3O7Z2bmIzTJ4EC32HRBKfLznHhrh4";
|
||||
auto decoded = jwt::decode<jsoncons_traits>(token);
|
||||
|
||||
@@ -192,34 +153,29 @@ TEST(JsonconsTest, AudienceAsString)
|
||||
ASSERT_EQ("test", *aud.begin());
|
||||
}
|
||||
|
||||
TEST(JsonconsTest, SetArray)
|
||||
{
|
||||
std::vector<int64_t> vect = {
|
||||
100,
|
||||
20,
|
||||
10};
|
||||
TEST(JsonconsTest, SetArray) {
|
||||
std::vector<int64_t> vect = {100, 20, 10};
|
||||
auto token = jwt::create<jsoncons_traits>()
|
||||
.set_payload_claim("test", jwt::basic_claim<jsoncons_traits>(vect.begin(), vect.end()))
|
||||
.sign(jwt::algorithm::none{});
|
||||
ASSERT_EQ(token, "eyJhbGciOiJub25lIn0.eyJ0ZXN0IjpbMTAwLDIwLDEwXX0.");
|
||||
}
|
||||
|
||||
TEST(JsonconsTest, SetObject)
|
||||
{
|
||||
TEST(JsonconsTest, SetObject) {
|
||||
std::istringstream iss{"{\"api-x\": [1]}"};
|
||||
jwt::basic_claim<jsoncons_traits> object;
|
||||
iss >> object;
|
||||
ASSERT_EQ(object.get_type(), jwt::json::type::object);
|
||||
|
||||
auto token = jwt::create<jsoncons_traits>()
|
||||
.set_payload_claim("namespace", object)
|
||||
.sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token, "eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
auto token =
|
||||
jwt::create<jsoncons_traits>().set_payload_claim("namespace", object).sign(jwt::algorithm::hs256("test"));
|
||||
ASSERT_EQ(token,
|
||||
"eyJhbGciOiJIUzI1NiJ9.eyJuYW1lc3BhY2UiOnsiYXBpLXgiOlsxXX19.F8I6I2RcSF98bKa0IpIz09fRZtHr1CWnWKx2za-tFQA");
|
||||
}
|
||||
|
||||
TEST(JsonconsTest, VerifyTokenHS256)
|
||||
{
|
||||
std::string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
TEST(JsonconsTest, VerifyTokenHS256) {
|
||||
std::string token =
|
||||
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE";
|
||||
|
||||
auto verify = jwt::verify<jwt::default_clock, jsoncons_traits>({})
|
||||
.allow_algorithm(jwt::algorithm::hs256{"secret"})
|
||||
@@ -229,8 +185,7 @@ TEST(JsonconsTest, VerifyTokenHS256)
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(JsonconsTest, VerifyTokenExpirationValid)
|
||||
{
|
||||
TEST(JsonconsTest, VerifyTokenExpirationValid) {
|
||||
const auto token = jwt::create<jsoncons_traits>()
|
||||
.set_issuer("auth0")
|
||||
.set_issued_at(std::chrono::system_clock::now())
|
||||
@@ -245,8 +200,7 @@ TEST(JsonconsTest, VerifyTokenExpirationValid)
|
||||
verify.verify(decoded_token);
|
||||
}
|
||||
|
||||
TEST(JsonconsTest, VerifyTokenExpired)
|
||||
{
|
||||
TEST(JsonconsTest, VerifyTokenExpired) {
|
||||
const auto token = jwt::create<jsoncons_traits>()
|
||||
.set_issuer("auth0")
|
||||
.set_issued_at(std::chrono::system_clock::now() - std::chrono::seconds{3601})
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
Source: jwt-cpp
|
||||
Version: 2019-04-20
|
||||
Description: A header only library for creating and validating json web tokens in c++
|
||||
Build-Depends: openssl
|
||||
Homepage: https://thalhammer.it/projects/jwt_cpp
|
||||
@@ -1,31 +0,0 @@
|
||||
diff --git a/include/jwt-cpp/base.h b/include/jwt-cpp/base.h
|
||||
index dfca7fc..4d05c0b 100644
|
||||
--- a/include/jwt-cpp/base.h
|
||||
+++ b/include/jwt-cpp/base.h
|
||||
@@ -2,6 +2,10 @@
|
||||
#include <string>
|
||||
#include <array>
|
||||
|
||||
+#ifdef _MSC_VER
|
||||
+#pragma warning(disable : 4267)
|
||||
+#endif
|
||||
+
|
||||
namespace jwt {
|
||||
namespace alphabet {
|
||||
struct base64 {
|
||||
diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h
|
||||
index ec56810..313cef2 100644
|
||||
--- a/include/jwt-cpp/jwt.h
|
||||
+++ b/include/jwt-cpp/jwt.h
|
||||
@@ -12,6 +12,11 @@
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
+#ifdef _MSC_VER
|
||||
+#pragma warning(disable : 4267)
|
||||
+#pragma warning(disable : 4067)
|
||||
+#endif
|
||||
+
|
||||
//If openssl version less than 1.1
|
||||
#if OPENSSL_VERSION_NUMBER < 269484032
|
||||
#define OPENSSL10
|
||||
@@ -1,23 +0,0 @@
|
||||
#header-only library
|
||||
include(vcpkg_common_functions)
|
||||
|
||||
vcpkg_from_github(
|
||||
OUT_SOURCE_PATH SOURCE_PATH
|
||||
REPO Thalhammer/jwt-cpp
|
||||
REF f0e37a79f605312686065405dd720fc197cc3df0
|
||||
SHA512 ae83c205dbb340dedc58d0d3f0e2453c4edcf5ce43b401f49d02692dc8a2a4b7260f1ced05ddfa7c1d5d6f92446e232629ddbdf67a58a119b50c5c8163591598
|
||||
PATCHES fix-warning.patch)
|
||||
|
||||
vcpkg_configure_cmake(
|
||||
SOURCE_PATH ${SOURCE_PATH}/jwt-cpp
|
||||
OPTIONS -DBUILD_TESTS=OFF)
|
||||
|
||||
# Copy the constexpr header files
|
||||
vcpkg_install_cmake()
|
||||
|
||||
vcpkg_test_cmake(PACKAGE_NAME jwt-cpp)
|
||||
|
||||
# Put the licence file where vcpkg expects it
|
||||
file(COPY ${SOURCE_PATH}/LICENSE
|
||||
DESTINATION ${CURRENT_PACKAGES_DIR}/share/jwt-cpp)
|
||||
file(RENAME ${CURRENT_PACKAGES_DIR}/share/jwt-cpp/LICENSE ${CURRENT_PACKAGES_DIR}/share/jwt-cpp/copyright)
|
||||
Reference in New Issue
Block a user