dsully / perl-crypt-openssl-x509

Perl interface to OpenSSL's X509 module.
Other
25 stars 33 forks source link

support openssl v3; add const qualifier #100

Closed skaji closed 2 years ago

skaji commented 2 years ago

Description

Currently make fails against openssl v3:

❯ sw_vers
ProductName:    macOS
ProductVersion: 12.2.1
BuildVersion:   21D62

❯ perl -i -pe 's/openssl\\\@1.1/openssl\\\@3/' Makefile.PL

❯ perl Makefile.PL
Generating a Unix-style Makefile
Writing Makefile for Crypt::OpenSSL::X509
Writing MYMETA.yml and MYMETA.json

❯ make
cp X509.pm blib/lib/Crypt/OpenSSL/X509.pm
Running Mkbootstrap for X509 ()
chmod 644 "X509.bs"
"/Users/skaji/env/plenv/versions/5.34.0/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- X509.bs blib/arch/auto/Crypt/OpenSSL/X509/X509.bs 644
"/Users/skaji/env/plenv/versions/5.34.0/bin/perl" "/Users/skaji/env/plenv/versions/5.34.0/lib/perl5/site_perl/5.34.0/ExtUtils/xsubpp"  -typemap '/Users/skaji/env/plenv/versions/5.34.0/lib/perl5/5.34.0/ExtUtils/typemap' -typemap '/Users/skaji/src/github.com/dsully/perl-crypt-openssl-x509/typemap'  X509.xs > X509.xsc
Warning: Aliases 'subject_hash' and 'hash' have identical values in X509.xs, line 422
mv X509.xsc X509.c
cc -c  -I/usr/local/opt/openssl@3/include -fno-common -DPERL_DARWIN -mmacosx-version-min=12.2 -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -DPERL_USE_SAFE_PUTENV -Wno-error=implicit-function-declaration -O2 -g -Wall -Werror -Wno-deprecated-declarations -Wno-compound-token-split-by-macro   -DVERSION=\"1.913\" -DXS_VERSION=\"1.913\"  "-I/Users/skaji/env/plenv/versions/5.34.0/lib/perl5/5.34.0/darwin-2level/CORE"   X509.c
X509.xs:604:16: error: assigning to 'RSA *' (aka 'struct rsa_st *') from 'const struct rsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      rsa_pkey = EVP_PKEY_get0_RSA(pkey);
               ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:609:16: error: assigning to 'DSA *' (aka 'struct dsa_st *') from 'const struct dsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      dsa_pkey = EVP_PKEY_get0_DSA(pkey);
               ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:623:15: error: assigning to 'EC_KEY *' (aka 'struct ec_key_st *') from 'const struct ec_key_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
      ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
              ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:672:13: error: assigning to 'EC_KEY *' (aka 'struct ec_key_st *') from 'const struct ec_key_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:720:14: error: assigning to 'RSA *' (aka 'struct rsa_st *') from 'const struct rsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    rsa_pkey = EVP_PKEY_get0_RSA(pkey);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:729:14: error: assigning to 'DSA *' (aka 'struct dsa_st *') from 'const struct dsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    dsa_pkey = EVP_PKEY_get0_DSA(pkey);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:739:13: error: assigning to 'EC_KEY *' (aka 'struct ec_key_st *') from 'const struct ec_key_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:795:14: error: assigning to 'RSA *' (aka 'struct rsa_st *') from 'const struct rsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    rsa_pkey = EVP_PKEY_get0_RSA(pkey);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:898:14: error: assigning to 'RSA *' (aka 'struct rsa_st *') from 'const struct rsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    rsa_pkey = EVP_PKEY_get0_RSA(pkey);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:904:14: error: assigning to 'DSA *' (aka 'struct dsa_st *') from 'const struct dsa_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    dsa_pkey = EVP_PKEY_get0_DSA(pkey);
             ^ ~~~~~~~~~~~~~~~~~~~~~~~
X509.xs:911:13: error: assigning to 'EC_KEY *' (aka 'struct ec_key_st *') from 'const struct ec_key_st *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
    ec_pkey = EVP_PKEY_get0_EC_KEY(pkey);
            ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~
11 errors generated.
make: *** [X509.o] Error 1

In openssl v3, it seems that a lot of functions return const XXX types, not plain XXX types; so make fails. This PR adds const qualifier to some functions so that make passes against openssl v3.

Type of change

Please delete options that are not relevant.

Checklist:

Test / Development Platform Information

skaji commented 2 years ago

Maybe fix #91

jonasbn commented 2 years ago

@timlegge do you have time to do a review of PR from @skaji, I will get to it eventually, but more eyes would be beneficial

timlegge commented 2 years ago

@jonasbn I reviewed as above and it looks proper. This will be fine for any of the 3.0 versions (I think) but if you compile with DOPENSSL_NO_DEPRECATED_3_0_0 it will error on any of the things that were deprecated in 3.0.0 (and below I assume).

So there is still some work to be done to get full 3.0 compatibility.

jonasbn commented 2 years ago

Hi @skaji and @timlegge

This has been included in the release 1.9.14-TRIAL, just uploaded to PAUSE/CPAN.

Please let me know if you experience any issues or have any feedback. The 1.9.14 release will be made in due time depending on the outcome/feedback of the trial release.

Thanks for your contributions.