Crypt-JWS
view release on metacpan or search on metacpan
Makefile.PL view on Meta::CPAN
use 5.010000;
use strict;
use warnings;
use ExtUtils::MakeMaker;
use ExtUtils::Depends;
use Config;
# Crypt::JWS binds libcrypto (OpenSSL) for JWS signing and verification.
# Unlike Fetch, where TLS is optional, libcrypto is the whole point here:
# configure fails loudly when it is missing. Detection follows the house
# cascade - pkg-config, then a compile probe, then homebrew keg paths -
# and API differences between OpenSSL 1.1 and 3.x are FEATURE probed
# (never version sniffed): the 3.x provider API via EVP_PKEY_fromdata,
# the 1.1 struct API via RSA_set0_key.
my $DEFINE = '';
my $LIBS = '';
my $INC = '-Iinclude';
my ($ssl_cflags, $ssl_libs);
if (system('pkg-config --exists libcrypto >/dev/null 2>&1') == 0) {
chomp($ssl_cflags = `pkg-config --cflags libcrypto 2>/dev/null`);
chomp($ssl_libs = `pkg-config --libs libcrypto 2>/dev/null`);
$ssl_libs ||= '-lcrypto';
}
if (!$ssl_libs && probe_crypto('')) {
($ssl_cflags, $ssl_libs) = ('', '-lcrypto');
}
if (!$ssl_libs) { # homebrew keg-only path (no pkg-config on macOS)
for my $p ('/opt/homebrew/opt/openssl', '/opt/homebrew/opt/openssl@3',
'/opt/homebrew/opt/openssl@1.1',
'/usr/local/opt/openssl', '/usr/local/opt/openssl@3',
'/usr/local/opt/openssl@1.1') {
next unless -d "$p/include";
if (probe_crypto("-I$p/include -L$p/lib")) {
($ssl_cflags, $ssl_libs) = ("-I$p/include", "-L$p/lib -lcrypto");
last;
}
}
}
na("Crypt::JWS requires OpenSSL's libcrypto (install libssl-dev / "
. "openssl-devel / brew install openssl)")
unless $ssl_libs;
$INC .= " $ssl_cflags" if $ssl_cflags;
$LIBS .= " $ssl_libs";
print "Found libcrypto: $ssl_libs\n";
# --- feature probes --------------------------------------------------------
if (probe('fromdata', $ssl_cflags,
"#include <openssl/evp.h>\n#include <openssl/core_names.h>\n#include <openssl/param_build.h>",
'OSSL_PARAM_BLD *b = OSSL_PARAM_BLD_new(); EVP_PKEY_CTX *c = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL); (void)b; (void)c; return EVP_PKEY_fromdata_init(c);',
$ssl_libs)) {
$DEFINE .= ' -DCJWS_HAVE_FROMDATA';
print "Found EVP_PKEY_fromdata: OpenSSL 3.x provider key import.\n";
}
elsif (probe('set0', $ssl_cflags,
"#include <openssl/rsa.h>\n#include <openssl/ec.h>",
'RSA *r = RSA_new(); (void)RSA_set0_key(r, 0, 0, 0); EC_KEY *k = EC_KEY_new_by_curve_name(415); (void)k; return 0;',
$ssl_libs)) {
$DEFINE .= ' -DCJWS_HAVE_SET0';
print "Found RSA_set0_key: OpenSSL 1.1 struct key import.\n";
}
else {
na("libcrypto found but neither EVP_PKEY_fromdata (3.x) nor "
. "RSA_set0_key (1.1) compiled - OpenSSL 1.1.0 or newer (or "
. "LibreSSL 2.7+) is required");
}
# --- ExtUtils::Depends: consume frj_abi.h, provide jws_abi.h --------------
# Crypt::JWS is BOTH a consumer (File::Raw::JSON's frj_abi decodes and
( run in 0.495 second using v1.01-cache-2.11-cpan-e7c6538aa59 )