early-access version 2862

This commit is contained in:
pineappleEA
2022-07-26 03:25:01 +02:00
parent 1f02fcfc6e
commit ba84d02a09
211 changed files with 53330 additions and 31 deletions

View File

@@ -0,0 +1,22 @@
# The set of languages for which implicit dependencies are needed:
set(CMAKE_DEPENDS_LANGUAGES
"CXX"
)
# The set of files for implicit dependencies of each language:
set(CMAKE_DEPENDS_CHECK_CXX
"/Users/amuralid/dev_test/cpp-jwt/examples/simple_ex1.cc" "/Users/amuralid/dev_test/cpp-jwt/examples/CMakeFiles/simple_ex1.dir/simple_ex1.cc.o"
)
set(CMAKE_CXX_COMPILER_ID "Clang")
# The include file search paths:
set(CMAKE_CXX_TARGET_INCLUDE_PATH
"include"
"/usr/local/Cellar/openssl/1.0.2j/include"
)
# Targets to which this target links.
set(CMAKE_TARGET_LINKED_INFO_FILES
)
# Fortran module output directory.
set(CMAKE_Fortran_TARGET_MODULE_DIR "")

View File

@@ -0,0 +1,10 @@
file(REMOVE_RECURSE
"CMakeFiles/simple_ex1.dir/simple_ex1.cc.o"
"simple_ex1.pdb"
"simple_ex1"
)
# Per-language clean rules from dependency scanning.
foreach(lang CXX)
include(CMakeFiles/simple_ex1.dir/cmake_clean_${lang}.cmake OPTIONAL)
endforeach()

View File

@@ -0,0 +1,3 @@
CMAKE_PROGRESS_1 = 1
CMAKE_PROGRESS_2 = 2

24
externals/cpp-jwt/examples/CMakeLists.txt vendored Executable file
View File

@@ -0,0 +1,24 @@
set(CERT_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rsa_256")
set(CMAKE_CXX_FLAGS
"${CMAKE_CXX_FLAGS} -DCERT_ROOT_DIR=\"\\\"${CERT_ROOT_DIR}\\\"\"")
add_executable(simple_ex1 simple_ex1.cc)
target_link_libraries(simple_ex1 ${PROJECT_NAME})
add_test(
NAME simple_ex1
COMMAND ./simple_ex1
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_executable(simple_ex2 simple_ex2.cc)
target_link_libraries(simple_ex2 ${PROJECT_NAME})
add_test(
NAME simple_ex2
COMMAND ./simple_ex2
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
add_executable(simple_ex3_rsa simple_ex3_rsa.cc)
target_link_libraries(simple_ex3_rsa ${PROJECT_NAME})
add_test(
NAME simple_ex3_rsa
COMMAND ./simple_ex3_rsa
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})

View File

@@ -0,0 +1,15 @@
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQC4fkg/JYyN3Skr6RYLiAd/Yhl02TE3/HzHSNPnCaRdUakGp9og
7oXBMcoadFDjnoSq1sz+gUHnpoO7s2fwkD5Q4OnCBGD3oKP2A4PlOOWD2B2cVmMq
X/vf1nAA/343496jsbfgkh1Q7LTzR0IXfdii0o1UCbvrVCuaBoyiv4TxWQIDAQAB
AoGAWA5uDTWu0Ecuz3aAvyA9896up8bCZyZrp/JqsWs4uBGxyytyQSWXUY6iF95M
fVe7mo7LaO3ottgTKBOJGJjAJKnfwXRn8/NV/Q5oHx48sPGDoUUtyMrRbZpeLM1L
gpFX715XWrtALInWPlVG1OfkQQLv4K7mwveM0cez0bWPUsECQQDuPK9IL7WuO2WR
s6pGEHBc3/MMk6I+vqJ+rJMgJjCC/Wjeyo6U3xTNipJRJL5L/Y8iMqpWCrYOjpo8
+1p4FXqDAkEAxj/FcVhXl3NMco6D9u0LxTAmqavMzmXDmODVW2m1K3+rQWQDqXqr
FQ9WQq0LSsqiwRul6hrd0EmCkNJqpCMN8wJBAIz06uDTGbPVAOuMWhrKbzEEcFHo
p/5n3M0GXqaO8fUO6pWnU2VR+IUEkD3id5WOmLmrMI1oGP/T7/5U2dpjGvECQEBq
0k4tJXEJvupuUoT2q19scPOq5kaenHrde5ZTd9HljxEVXXdBa7vRGvdZYRTxWQck
Y7n49uBKMom6RXqGBW8CQQCrnub4stg6dwdpnmZmEtAE4VqNSZeV5UWz7+l7+R+B
ENtNlIgyQfE6NpOc3Fr/uy3IQjaHcOOwIKI0GMJww9sC
-----END RSA PRIVATE KEY-----

View File

@@ -0,0 +1,6 @@
-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC4fkg/JYyN3Skr6RYLiAd/Yhl0
2TE3/HzHSNPnCaRdUakGp9og7oXBMcoadFDjnoSq1sz+gUHnpoO7s2fwkD5Q4OnC
BGD3oKP2A4PlOOWD2B2cVmMqX/vf1nAA/343496jsbfgkh1Q7LTzR0IXfdii0o1U
CbvrVCuaBoyiv4TxWQIDAQAB
-----END PUBLIC KEY-----

21
externals/cpp-jwt/examples/simple_ex1.cc vendored Executable file
View File

@@ -0,0 +1,21 @@
#include <iostream>
#include "jwt/jwt.hpp"
int main() {
using namespace jwt::params;
auto key = "secret"; //Secret to use for the algorithm
//Create JWT object
jwt::jwt_object obj{algorithm("HS256"), payload({{"some", "payload"}}), secret(key)};
//Get the encoded string/assertion
auto enc_str = obj.signature();
std::cout << enc_str << std::endl;
//Decode
auto dec_obj = jwt::decode(enc_str, algorithms({"HS256"}), secret(key));
std::cout << dec_obj.header() << std::endl;
std::cout << dec_obj.payload() << std::endl;
return 0;
}

48
externals/cpp-jwt/examples/simple_ex2.cc vendored Executable file
View File

@@ -0,0 +1,48 @@
#include <chrono>
#include <cassert>
#include <iostream>
#include "jwt/jwt.hpp"
int main() {
using namespace jwt::params;
jwt::jwt_object obj{algorithm("HS256"), secret("secret"), payload({{"user", "admin"}})};
//Use add_claim API to add claim values which are
// _not_ strings.
// For eg: `iat` and `exp` claims below.
// Other claims could have been added in the payload
// function above as they are just stringy things.
obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "test")
.add_claim("id", "a-b-c-d-e-f-1-2-3")
.add_claim("iat", 1513862371)
.add_claim("exp", std::chrono::system_clock::now() + std::chrono::seconds{10})
;
//Use `has_claim` to check if the claim exists or not
assert (obj.has_claim("iss"));
assert (obj.has_claim("exp"));
//Use `has_claim_with_value` to check if the claim exists
//with a specific value or not.
assert (obj.payload().has_claim_with_value("id", "a-b-c-d-e-f-1-2-3"));
assert (obj.payload().has_claim_with_value("iat", 1513862371));
//Remove a claim using `remove_claim` API.
//Most APIs have an overload which takes enum class type as well
//It can be used interchangeably with strings.
obj.remove_claim(jwt::registered_claims::expiration);
assert (!obj.has_claim("exp"));
//Using `add_claim` with extra features.
//Check return status and overwrite
assert (!obj.payload().add_claim("sub", "new test", false/*overwrite*/));
// Overwrite an existing claim
assert (obj.payload().add_claim("sub", "new test", true/*overwrite*/));
assert (obj.payload().has_claim_with_value("sub", "new test"));
return 0;
}

82
externals/cpp-jwt/examples/simple_ex3_rsa.cc vendored Executable file
View File

@@ -0,0 +1,82 @@
#include <chrono>
#include <cassert>
#include <fstream>
#include <string>
#include <iostream>
#include "jwt/jwt.hpp"
/***
* STEPS TO GENERATE RSA PRIVATE PUBLIC KEYPAIR.
*
* 1. openssl genrsa -out jwtRS256.key 1024
* 2. openssl rsa -in jwtRS256.key -pubout -outform PEM -out jwtRS256.key.pub
*/
std::string read_from_file(const std::string& path)
{
std::string contents;
std::ifstream is{path, std::ifstream::binary};
if (is) {
// get length of file:
is.seekg (0, is.end);
auto length = is.tellg();
is.seekg (0, is.beg);
contents.resize(length);
is.read(&contents[0], length);
if (!is) {
is.close();
return {};
}
} else {
std::cerr << "FILE not FOUND!!" << std::endl;
}
is.close();
return contents;
}
int main() {
using namespace jwt::params;
const std::string priv_key_path = std::string{CERT_ROOT_DIR} + "/jwtRS256.key";
const std::string pub_key_path = std::string{CERT_ROOT_DIR} + "/jwtRS256.key.pub";
auto priv_key = read_from_file(priv_key_path);
jwt::jwt_object obj{algorithm("RS256"), secret(priv_key), payload({{"user", "admin"}})};
//Use add_claim API to add claim values which are
// _not_ strings.
// For eg: `iat` and `exp` claims below.
// Other claims could have been added in the payload
// function above as they are just stringy things.
obj.add_claim("iss", "arun.muralidharan")
.add_claim("sub", "test")
.add_claim("id", "a-b-c-d-e-f-1-2-3")
.add_claim("iat", 1513862371)
.add_claim("exp", std::chrono::system_clock::now() + std::chrono::seconds{10})
;
//Use `has_claim` to check if the claim exists or not
assert (obj.has_claim("iss"));
assert (obj.has_claim("exp"));
//Use `has_claim_with_value` to check if the claim exists
//with a specific value or not.
assert (obj.payload().has_claim_with_value("id", "a-b-c-d-e-f-1-2-3"));
assert (obj.payload().has_claim_with_value("iat", 1513862371));
auto pub_key = read_from_file(pub_key_path);
std::error_code ec{};
auto sign = obj.signature(ec);
if (ec) {
std::cerr << ec.message() << std::endl;
return 1;
}
auto dec_obj = jwt::decode(sign, algorithms({"RS256"}), verify(false), secret(pub_key));
return 0;
}