-
-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Update coverage.yml * adding a fuzz test * adding more fuzzing TBA how to handle input requirement of decode * base64 encoding input to avoid "obvious" exceptions trying out the EVP_ interface from #89 * fixing decode fuzz * accepting exceptions are normal After comparing with https://github.com/nlohmann/json/blob/v3.9.0/test/src/fuzzer-parse_json.cpp I must agree data can be random so it should be accepted * decoding twice should produce the same result again based on https://github.com/nlohmann/json/blob/v3.9.0/test/src/fuzzer-parse_json.cpp * fixing token decode fuzzer * adding corpus for fuzz tests + adding them to ci * removing numbers with more meaning descriptions * Update BaseEncodeFuzz.cpp * Update coverage.yml * Update coverage.yml * shrink interations * cleaning cmake * Update and rename coverage.yml to jwt.yml * Update lint.yml * Update jwt.yml * Update jwt.yml
- Loading branch information
1 parent
3d50121
commit 7fd8470
Showing
17 changed files
with
163 additions
and
69 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
name: JWT CI | ||
|
||
on: | ||
push: | ||
branches: [master] | ||
pull_request: | ||
branches: [master] | ||
|
||
jobs: | ||
coverage: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: lukka/get-cmake@latest | ||
- uses: ./.github/actions/install/gtest | ||
|
||
- name: configure | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake .. -DJWT_BUILD_EXAMPLES=OFF -DJWT_BUILD_TESTS=ON -DJWT_ENABLE_COVERAGE=ON -DCMAKE_BUILD_TYPE=Debug | ||
- name: run | ||
working-directory: build | ||
run: make jwt-cpp-test coverage | ||
|
||
- uses: coverallsapp/[email protected] | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
path-to-lcov: build/coverage.info | ||
|
||
fuzzing: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: lukka/get-cmake@latest | ||
- uses: ./.github/actions/install/gtest | ||
|
||
- name: configure | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake .. -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DJWT_ENABLE_FUZZING=ON | ||
- name: run | ||
working-directory: build | ||
run: | | ||
make jwt-cpp-fuzz-BaseEncodeFuzz jwt-cpp-fuzz-BaseDecodeFuzz jwt-cpp-fuzz-TokenDecodeFuzz | ||
./tests/fuzz/jwt-cpp-fuzz-BaseEncodeFuzz -runs=100000 | ||
./tests/fuzz/jwt-cpp-fuzz-BaseDecodeFuzz -runs=100000 ../tests/fuzz/decode-corpus | ||
./tests/fuzz/jwt-cpp-fuzz-TokenDecodeFuzz -runs=100000 ../tests/fuzz/token-corpus | ||
asan: ## Based on https://gist.github.com/jlblancoc/44be9d4d466f0a973b1f3808a8e56782 | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: lukka/get-cmake@latest | ||
- uses: ./.github/actions/install/gtest | ||
|
||
- name: configure | ||
run: | | ||
mkdir build | ||
cd build | ||
cmake .. -DJWT_BUILD_TESTS=ON -DCMAKE_CXX_FLAGS="-fsanitize=address -fsanitize=leak -g" \ | ||
-DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=leak -g" \ | ||
-DCMAKE_EXE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" \ | ||
-DCMAKE_MODULE_LINKER_FLAGS="-fsanitize=address -fsanitize=leak" | ||
- name: run | ||
working-directory: build | ||
run: | | ||
make | ||
export ASAN_OPTIONS=fast_unwind_on_malloc=0 | ||
./example/rsa-create | ||
./example/rsa-verify | ||
./tests/jwt-cpp-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <jwt-cpp/base.h> | ||
|
||
extern "C" { | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
try { | ||
const auto bin = jwt::base::decode<jwt::alphabet::base64>( | ||
std::string{(char *)Data, Size}); | ||
} catch (const std::runtime_error &) { | ||
// parse errors are ok, because input may be random bytes | ||
} | ||
return 0; // Non-zero return values are reserved for future use. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#include <jwt-cpp/base.h> | ||
|
||
extern "C" { | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
jwt::base::encode<jwt::alphabet::base64>(std::string{(char *)Data, Size}); | ||
return 0; // Non-zero return values are reserved for future use. | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
if(NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang) | ||
message(FATAL_ERROR "Fuzzing is only available on Clang") | ||
endif() | ||
|
||
function(ADD_FUZZING_EXECUTABLE TARGET) | ||
add_executable(jwt-cpp-fuzz-${TARGET} "${TARGET}.cpp") | ||
target_compile_options( | ||
jwt-cpp-fuzz-${TARGET} | ||
PRIVATE -g -O1 -fsanitize=fuzzer,address,signed-integer-overflow,undefined | ||
-fno-omit-frame-pointer) | ||
target_link_options( | ||
jwt-cpp-fuzz-${TARGET} PRIVATE | ||
-fsanitize=fuzzer,address,signed-integer-overflow,undefined | ||
-fno-omit-frame-pointer) | ||
target_link_libraries(jwt-cpp-fuzz-${TARGET} PRIVATE jwt-cpp::jwt-cpp) | ||
endfunction() | ||
|
||
add_fuzzing_executable(BaseEncodeFuzz) | ||
add_fuzzing_executable(BaseDecodeFuzz) | ||
add_fuzzing_executable(TokenDecodeFuzz) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <jwt-cpp/jwt.h> | ||
|
||
extern "C" { | ||
|
||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) { | ||
try { | ||
// step 1: parse input | ||
const auto jwt1 = jwt::decode(std::string{(char *)Data, Size}); | ||
|
||
try { | ||
// step 2: round trip | ||
std::string s1 = jwt1.get_token(); | ||
const auto jwt2 = jwt::decode(s1); | ||
|
||
// tokens must match | ||
if (s1 != jwt2.get_token()) | ||
abort(); | ||
} catch (...) { | ||
// parsing raw data twice must not fail | ||
abort(); | ||
} | ||
} catch (...) { | ||
// parse errors are ok, because input may be random bytes | ||
} | ||
|
||
return 0; // Non-zero return values are reserved for future use. | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
tests/fuzz/decode-corpus/086a3aa337038cac8a75a05131444f222e48aee8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FMF= |
1 change: 1 addition & 0 deletions
1
tests/fuzz/decode-corpus/8ebaef2304e91465585c8d7fcf4d9f939e08d6b4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eCy |
1 change: 1 addition & 0 deletions
1
tests/fuzz/decode-corpus/ba528234d9f6949ed9c9626c08a782f6e7c15b8b
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
FF== |
1 change: 1 addition & 0 deletions
1
tests/fuzz/decode-corpus/de1028a3fe87471f027522c3ed9ec02b8364a006
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eCyIcHzyc2RQHa1EchsP11BhieWRIdm2MToLRpVLKFGNKFvfXIEinoFpLv�� |
1 change: 1 addition & 0 deletions
1
tests/fuzz/decode-corpus/e8f531caaa67cecb1c7b162f3e1d4e320d79befd
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eCyI |
1 change: 1 addition & 0 deletions
1
tests/fuzz/token-corpus/9d891e731f75deae56884d79e9816736b7488080
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.. |
1 change: 1 addition & 0 deletions
1
tests/fuzz/token-corpus/ff384e2421a333cd52f259cec14c7f790d595db9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eyJhbGci.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXUyJ9.eyJpc3MiOiJhdXRoMCJ9.AbIJTDMFc7yUa5MhvcP03nJPyCPzZtQcGEp-zWfOkEE |