Skip to content

Commit

Permalink
more compat
Browse files Browse the repository at this point in the history
working on the matrix of wolfssl and libress and 1.1.0
  • Loading branch information
prince-chrismc committed Dec 21, 2023
1 parent b24a639 commit 1266a9b
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions example/jwks-verify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ int main() {
ASN1_INTEGER* serial_number = X509_get_serialNumber(cert.get());
ASN1_INTEGER_set(serial_number, 1); // serial number

X509_gmtime_adj(X509_getm_notBefore(cert.get()), 0); // now
X509_gmtime_adj(X509_getm_notAfter(cert.get()), 10 * 365 * 24 * 3600); // accepts secs
#if defined(JWT_OPENSSL_1_0_0)
auto x509_not_before = &X509_get_notBefore;
auto x509_not_after = &X509_get_notAfter;
#else
auto x509_not_before = &X509_getm_notBefore;
auto x509_not_after = &X509_getm_notAfter;
#endif
X509_gmtime_adj(x509_not_before(cert.get()), 0); // now
X509_gmtime_adj(x509_not_after(cert.get()), 10 * 365 * 24 * 3600); // accepts secs

X509_set_pubkey(cert.get(), pkey);
X509_NAME* name = X509_get_subject_name(cert.get());
Expand Down Expand Up @@ -99,19 +106,18 @@ int main() {
RSA_free(rsa);
BN_free(bne);
#endif
EVP_PKEY_free(pkey);

#if defined(JWT_OPENSSL_3_0)
BIGNUM* n = nullptr;
EVP_PKEY_get_bn_param(pkey, "n", &n);
BIGNUM* e = nullptr;
EVP_PKEY_get_bn_param(pkey, "e", &e);
#elif defined(JWT_OPENSSL_1_1_1) && !defined(LIBWOLFSSL_VERSION_HEX)
// wolfSSL is missing RSA_get0_n and needs RSA_get0_key
#elif defined(JWT_OPENSSL_1_1_1) && !defined(LIBWOLFSSL_VERSION_HEX) && !defined(LIBRESSL_VERSION_NUMBER)
// wolfSSL is missing RSA_get0_n and needs RSA_get0_key
RSA* r = EVP_PKEY_get1_RSA(pkey);
const BIGNUM* n = RSA_get0_n(r);
const BIGNUM* e = RSA_get0_e(r);
#elif defined(JWT_OPENSSL_1_1_0) || defined(LIBWOLFSSL_VERSION_HEX)
#elif defined(JWT_OPENSSL_1_1_0) || defined(LIBWOLFSSL_VERSION_HEX) || defined(LIBRESSL_VERSION_NUMBER)
const BIGNUM* n = nullptr;
const BIGNUM* e = nullptr;
RSA* r = EVP_PKEY_get1_RSA(pkey);
Expand All @@ -122,6 +128,8 @@ int main() {
BIGNUM* e = r->e;
#endif

EVP_PKEY_free(pkey);

const auto modulus =
jwt::base::trim<jwt::alphabet::base64url>(jwt::base::encode<jwt::alphabet::base64url>(jwt::helper::bn2raw(n)));
const auto exp =
Expand Down

0 comments on commit 1266a9b

Please sign in to comment.