Goby3  3.1.5a
2024.05.23
jwt::helper Namespace Reference

A collection for working with certificates. More...

Functions

std::string extract_pubkey_from_cert (const std::string &certstr, const std::string &pw, std::error_code &ec)
 Extract the public key of a pem certificate. More...
 
std::string extract_pubkey_from_cert (const std::string &certstr, const std::string &pw="")
 Extract the public key of a pem certificate. More...
 
template<typename Decode >
std::string convert_base64_der_to_pem (const std::string &cert_base64_der_str, Decode decode, std::error_code &ec)
 Convert the certificate provided as base64 DER to PEM. More...
 
template<typename Decode >
std::string convert_base64_der_to_pem (const std::string &cert_base64_der_str, Decode decode)
 Convert the certificate provided as base64 DER to PEM. More...
 
std::string convert_base64_der_to_pem (const std::string &cert_base64_der_str, std::error_code &ec)
 Convert the certificate provided as base64 DER to PEM. More...
 
std::string convert_base64_der_to_pem (const std::string &cert_base64_der_str)
 Convert the certificate provided as base64 DER to PEM. More...
 
std::shared_ptr< EVP_PKEY > load_public_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_public_key_from_string (const std::string &key, const std::string &password="")
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_private_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a private key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_private_key_from_string (const std::string &key, const std::string &password="")
 Load a private key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_public_ec_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_public_ec_key_from_string (const std::string &key, const std::string &password="")
 Load a public key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_private_ec_key_from_string (const std::string &key, const std::string &password, std::error_code &ec)
 Load a private key from a string. More...
 
std::shared_ptr< EVP_PKEY > load_private_ec_key_from_string (const std::string &key, const std::string &password="")
 Load a private key from a string. More...
 
std::string bn2raw (const BIGNUM *bn)
 
std::unique_ptr< BIGNUM, decltype(&BN_free)> raw2bn (const std::string &raw)
 

Detailed Description

A collection for working with certificates.

These helpers are usefully when working with certificates OpenSSL APIs. For example, when dealing with JWKS (JSON Web Key Set)[https://tools.ietf.org/html/rfc7517] you maybe need to extract the modulus and exponent of an RSA Public Key.

Function Documentation

◆ bn2raw()

std::string jwt::helper::bn2raw ( const BIGNUM *  bn)
inline

Convert a OpenSSL BIGNUM to a std::string

Parameters
bnBIGNUM to convert
Returns
bignum as string

Definition at line 877 of file jwt.h.

◆ convert_base64_der_to_pem() [1/4]

std::string jwt::helper::convert_base64_der_to_pem ( const std::string &  cert_base64_der_str)
inline

Convert the certificate provided as base64 DER to PEM.

This is useful when using with JWKs as x5c claim is encoded as base64 DER. More info (here)[https://tools.ietf.org/html/rfc7517#section-4.7]

Parameters
cert_base64_der_strString containing the certificate encoded as base64 DER
Exceptions
rsa_exceptionif an error occurred

Definition at line 612 of file jwt.h.

◆ convert_base64_der_to_pem() [2/4]

template<typename Decode >
std::string jwt::helper::convert_base64_der_to_pem ( const std::string &  cert_base64_der_str,
Decode  decode 
)

Convert the certificate provided as base64 DER to PEM.

This is useful when using with JWKs as x5c claim is encoded as base64 DER. More info (here)[https://tools.ietf.org/html/rfc7517#section-4.7]

Template Parameters
Decodeis callabled, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64 decode and return the results.
Parameters
cert_base64_der_strString containing the certificate encoded as base64 DER
decodeThe function to decode the cert
Exceptions
rsa_exceptionif an error occurred

Definition at line 578 of file jwt.h.

◆ convert_base64_der_to_pem() [3/4]

template<typename Decode >
std::string jwt::helper::convert_base64_der_to_pem ( const std::string &  cert_base64_der_str,
Decode  decode,
std::error_code &  ec 
)

Convert the certificate provided as base64 DER to PEM.

This is useful when using with JWKs as x5c claim is encoded as base64 DER. More info (here)[https://tools.ietf.org/html/rfc7517#section-4.7]

Template Parameters
Decodeis callabled, taking a string_type and returns a string_type. It should ensure the padding of the input and then base64 decode and return the results.
Parameters
cert_base64_der_strString containing the certificate encoded as base64 DER
decodeThe function to decode the cert
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 530 of file jwt.h.

◆ convert_base64_der_to_pem() [4/4]

std::string jwt::helper::convert_base64_der_to_pem ( const std::string &  cert_base64_der_str,
std::error_code &  ec 
)
inline

Convert the certificate provided as base64 DER to PEM.

This is useful when using with JWKs as x5c claim is encoded as base64 DER. More info (here)[https://tools.ietf.org/html/rfc7517#section-4.7]

Parameters
cert_base64_der_strString containing the certificate encoded as base64 DER
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 595 of file jwt.h.

◆ extract_pubkey_from_cert() [1/2]

std::string jwt::helper::extract_pubkey_from_cert ( const std::string &  certstr,
const std::string &  pw,
std::error_code &  ec 
)
inline

Extract the public key of a pem certificate.

Parameters
certstrString containing the certificate encoded as pem
pwPassword used to decrypt certificate (leave empty if not encrypted)
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 451 of file jwt.h.

◆ extract_pubkey_from_cert() [2/2]

std::string jwt::helper::extract_pubkey_from_cert ( const std::string &  certstr,
const std::string &  pw = "" 
)
inline

Extract the public key of a pem certificate.

Parameters
certstrString containing the certificate encoded as pem
pwPassword used to decrypt certificate (leave empty if not encrypted)
Exceptions
rsa_exceptionif an error occurred

Definition at line 507 of file jwt.h.

◆ load_private_ec_key_from_string() [1/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_private_ec_key_from_string ( const std::string &  key,
const std::string &  password,
std::error_code &  ec 
)
inline

Load a private key from a string.

Parameters
keyString containing a private key as pem
passwordPassword used to decrypt key (leave empty if not encrypted)
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 823 of file jwt.h.

◆ load_private_ec_key_from_string() [2/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_private_ec_key_from_string ( const std::string &  key,
const std::string &  password = "" 
)
inline

Load a private key from a string.

Parameters
keyString containing a private key as pem
passwordPassword used to decrypt key (leave empty if not encrypted)
Exceptions
ecdsa_exceptionif an error occurred

Definition at line 857 of file jwt.h.

◆ load_private_key_from_string() [1/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_private_key_from_string ( const std::string &  key,
const std::string &  password,
std::error_code &  ec 
)
inline

Load a private key from a string.

Parameters
keyString containing a private key as pem
passwordPassword used to decrypt key (leave empty if not encrypted)
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 700 of file jwt.h.

◆ load_private_key_from_string() [2/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_private_key_from_string ( const std::string &  key,
const std::string &  password = "" 
)
inline

Load a private key from a string.

Parameters
keyString containing a private key as pem
passwordPassword used to decrypt key (leave empty if not encrypted)
Exceptions
rsa_exceptionif an error occurred

Definition at line 734 of file jwt.h.

◆ load_public_ec_key_from_string() [1/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_public_ec_key_from_string ( const std::string &  key,
const std::string &  password,
std::error_code &  ec 
)
inline

Load a public key from a string.

The string should contain a pem encoded certificate or public key

Parameters
keyString containing the certificate encoded as pem
passwordPassword used to decrypt certificate (leave empty if not encrypted)
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 752 of file jwt.h.

◆ load_public_ec_key_from_string() [2/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_public_ec_key_from_string ( const std::string &  key,
const std::string &  password = "" 
)
inline

Load a public key from a string.

The string should contain a pem encoded certificate or public key

Parameters
keyString containing the certificate or key encoded as pem
passwordPassword used to decrypt certificate or key (leave empty if not encrypted)
Exceptions
ecdsa_exceptionif an error occurred

Definition at line 807 of file jwt.h.

◆ load_public_key_from_string() [1/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_public_key_from_string ( const std::string &  key,
const std::string &  password,
std::error_code &  ec 
)
inline

Load a public key from a string.

The string should contain a pem encoded certificate or public key

Parameters
keyString containing the certificate encoded as pem
passwordPassword used to decrypt certificate (leave empty if not encrypted)
ecerror_code for error_detection (gets cleared if no error occures)

Definition at line 629 of file jwt.h.

◆ load_public_key_from_string() [2/2]

std::shared_ptr<EVP_PKEY> jwt::helper::load_public_key_from_string ( const std::string &  key,
const std::string &  password = "" 
)
inline

Load a public key from a string.

The string should contain a pem encoded certificate or public key

Parameters
keyString containing the certificate or key encoded as pem
passwordPassword used to decrypt certificate or key (leave empty if not encrypted)
Exceptions
rsa_exceptionif an error occurred

Definition at line 684 of file jwt.h.

◆ raw2bn()

std::unique_ptr<BIGNUM, decltype(&BN_free)> jwt::helper::raw2bn ( const std::string &  raw)
inline

Convert an std::string to a OpenSSL BIGNUM

Parameters
rawString to convert
Returns
BIGNUM representation

Definition at line 890 of file jwt.h.