Skip to content

Commit 9041c6f

Browse files
authored
Merge pull request #8 from timlegge/configuredapi
use Crypt::OpenSSL::ConfiguredAPI to determin the API level supported
2 parents 4021731 + 63caf53 commit 9041c6f

File tree

8 files changed

+90
-25
lines changed

8 files changed

+90
-25
lines changed

.github/workflows/linux.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
name: linux
22

33
on:
4-
- push
5-
4+
push:
5+
branches:
6+
- '*'
7+
tags-ignore:
8+
- '*'
9+
pull_request:
10+
branches:
11+
- '*'
612
jobs:
713
perl:
814
runs-on: ubuntu-latest

Makefile.PL

+31-5
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ use ExtUtils::MakeMaker;
1111
use Config;
1212
use File::Spec;
1313
use Crypt::OpenSSL::Guess;
14+
use Crypt::OpenSSL::ConfiguredAPI;
15+
1416
my %args;
1517

1618
my ($major, $minor, $patch) = openssl_version();
1719
print "Installed OpenSSL: $major.$minor.$patch\n";
1820

21+
my $version = ($major * 10000) + ($minor * 100);
22+
my $api = Crypt::OpenSSL::ConfiguredAPI::get_configured_api();
23+
print "API version read $api\n";
24+
25+
my $compat = $api ne 0 ? $api : $version;
26+
print "OPENSSL_COMPAT_API set to: $compat\n";
27+
1928
$args{INC} = openssl_inc_paths();
2029
$args{LIBS} = [openssl_lib_paths() . ' -lssl -lcrypto'];
2130

22-
my $cc_option_flags = $major ge 3 ? ' -DOPENSSL_API_COMPAT=30000' : ' -DOPENSSL_API_COMPAT=10100';
31+
my $cc_option_flags = " -DOPENSSL_API_COMPAT=$compat";
2332

2433
if ($Config::Config{cc} =~ /gcc/i) {
2534
$cc_option_flags .= $ENV{AUTHOR_TESTING} ? ' -Wall -Werror' : ' -Wall';
@@ -55,22 +64,33 @@ if ($Config{myuname} =~ /sunos|solaris/i) {
5564
my %WriteMakefileArgs = (
5665
"ABSTRACT" => "Sign a Certificate Signing Request in XS.",
5766
"AUTHOR" => "Timothy Legge <timlegge\@cpan.org>",
67+
"BUILD_REQUIRES" => {
68+
"Crypt::OpenSSL::ConfiguredAPI" => 0,
69+
"Crypt::OpenSSL::Guess" => 0
70+
},
5871
"CONFIGURE_REQUIRES" => {
72+
"Crypt::OpenSSL::ConfiguredAPI" => 0,
5973
"Crypt::OpenSSL::Guess" => 0,
6074
"ExtUtils::MakeMaker" => 0
6175
},
6276
"DISTNAME" => "Crypt-OpenSSL-SignCSR",
6377
"LICENSE" => "apache",
6478
"MIN_PERL_VERSION" => "5.014",
6579
"NAME" => "Crypt::OpenSSL::SignCSR",
66-
"PREREQ_PM" => {},
80+
"PREREQ_PM" => {
81+
"Exporter" => 0,
82+
"XSLoader" => 0
83+
},
6784
"TEST_REQUIRES" => {
85+
"Crypt::OpenSSL::Guess" => 0,
6886
"Crypt::OpenSSL::PKCS10" => "0.19",
6987
"Crypt::OpenSSL::RSA" => 0,
7088
"File::Slurper" => "0.012",
71-
"File::Which" => 0
89+
"File::Temp" => 0,
90+
"File::Which" => 0,
91+
"Test::More" => "0.88"
7292
},
73-
"VERSION" => "0.12",
93+
"VERSION" => "0.13",
7494
"test" => {
7595
"TESTS" => "t/*.t"
7696
}
@@ -82,10 +102,16 @@ my %WriteMakefileArgs = (
82102
);
83103

84104
my %FallbackPrereqs = (
105+
"Crypt::OpenSSL::ConfiguredAPI" => 0,
106+
"Crypt::OpenSSL::Guess" => 0,
85107
"Crypt::OpenSSL::PKCS10" => "0.19",
86108
"Crypt::OpenSSL::RSA" => 0,
109+
"Exporter" => 0,
87110
"File::Slurper" => "0.012",
88-
"File::Which" => 0
111+
"File::Temp" => 0,
112+
"File::Which" => 0,
113+
"Test::More" => "0.88",
114+
"XSLoader" => 0
89115
);
90116

91117
unless ( eval { ExtUtils::MakeMaker->VERSION('6.63_03') } ) {

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Arguments:
103103

104104
Get the number of days that is currently set.
105105

106-
Returns a number
106+
Returns the number of days or -1 for a failure.
107107

108108
# EXPORT
109109

SignCSR.xs

+13-13
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate,
8585
#endif
8686
return 0;
8787
} else {
88-
#if OPENSSL_API_COMPAT <= 10101
88+
#if OPENSSL_API_COMPAT <= 11000
8989
if (!ASN1_TIME_set_string(X509_get_notBefore(x), startdate))
9090
#else
9191
if (!ASN1_TIME_set_string_X509(X509_getm_notBefore(x), startdate))
@@ -100,7 +100,7 @@ int set_cert_times(X509 *x, const char *startdate, const char *enddate,
100100
#endif
101101
== NULL)
102102
return 0;
103-
#if OPENSSL_API_COMPAT < 10101
103+
#if OPENSSL_API_COMPAT <= 11000
104104
} else if (!ASN1_TIME_set_string(X509_get_notAfter(x), enddate)) {
105105
#else
106106
} else if (!ASN1_TIME_set_string_X509(X509_getm_notAfter(x), enddate)) {
@@ -437,18 +437,15 @@ char * get_digest(self)
437437
CODE:
438438
SV **svp;
439439

440+
RETVAL = SvPV_nolen(newSVpv("",0));
441+
440442
// Get the output format - default is pem format
441443
if (hv_exists(self, "digest", strlen("digest"))) {
442444
svp = hv_fetch(self, "digest", strlen("digest"), 0);
443445
if (SvROK(*svp)) {
444446
RETVAL = SvPV_nolen(SvRV(*svp));
445447
}
446448
}
447-
else {
448-
//FIXME this should probably get the default for openssl
449-
//but since nothing was set this is likely most accurate
450-
RETVAL = SvPV_nolen(newSVpv("",0));
451-
}
452449

453450
OUTPUT:
454451

@@ -493,16 +490,15 @@ char * get_format(self)
493490
CODE:
494491
SV **svp;
495492

493+
RETVAL = SvPV_nolen(newSVpv("",0));
494+
496495
// Get the output format - default is pem format
497496
if (hv_exists(self, "format", strlen("format"))) {
498497
svp = hv_fetch(self, "format", strlen("format"), 0);
499498
if (SvROK(*svp)) {
500499
RETVAL = SvPV_nolen(SvRV(*svp));
501500
}
502501
}
503-
else {
504-
RETVAL = SvPV_nolen(newSVpv("",0));
505-
}
506502

507503
OUTPUT:
508504

@@ -512,7 +508,7 @@ IV set_format(self, SV* format)
512508
HV * self;
513509

514510
CODE:
515-
IV ret = 0;
511+
RETVAL = 0;
516512

517513
if (sv_cmp(format, newSVpv("pem", 0)) == 0 ||
518514
sv_cmp(format, newSVpv("text", 0)) == 0 )
@@ -522,7 +518,7 @@ IV set_format(self, SV* format)
522518
else
523519
RETVAL = 1;
524520
} else {
525-
RETVAL = ret;
521+
RETVAL = 0;
526522
}
527523

528524
OUTPUT:
@@ -535,6 +531,7 @@ IV get_days(self)
535531
CODE:
536532
SV **svp;
537533

534+
RETVAL = -1;
538535
// Get the number of days for specified - default 365
539536
if (hv_exists(self, "days", strlen("days"))) {
540537
svp = hv_fetch(self, "days", strlen("days"), 0);
@@ -551,6 +548,7 @@ IV set_days(self, IV days)
551548
HV * self;
552549

553550
CODE:
551+
RETVAL = 0;
554552

555553
if((hv_store(self, "days", 4, newSViv(days), 0)) == NULL)
556554
RETVAL = 0;
@@ -582,7 +580,7 @@ SV * sign(self, request_SV)
582580
STRLEN digestname_length;
583581
IV days;
584582
SV * digest = NULL;
585-
SV * format;
583+
SV * format = NULL;
586584

587585
if (!hv_exists(self, "privkey", strlen("privkey")))
588586
croak("privkey not found in self!\n");
@@ -802,7 +800,9 @@ void signcsr_DESTROY(void)
802800

803801
CRYPTO_cleanup_all_ex_data();
804802
ERR_free_strings();
803+
#if OPENSSL_API_COMPAT < 10000
805804
ERR_remove_state(0);
805+
#endif
806806
EVP_cleanup();
807807

808808
#endif

cpanfile

+11
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
11
# This file is generated by Dist::Zilla::Plugin::CPANFile v6.030
22
# Do not edit this file directly. To change prereqs, edit the `dist.ini` file.
33

4+
requires "Exporter" => "0";
5+
requires "XSLoader" => "0";
46
requires "perl" => "5.014";
57

8+
on 'build' => sub {
9+
requires "Crypt::OpenSSL::ConfiguredAPI" => "0";
10+
requires "Crypt::OpenSSL::Guess" => "0";
11+
};
12+
613
on 'test' => sub {
14+
requires "Crypt::OpenSSL::Guess" => "0";
715
requires "Crypt::OpenSSL::PKCS10" => "0.19";
816
requires "Crypt::OpenSSL::RSA" => "0";
917
requires "File::Slurper" => "0.012";
18+
requires "File::Temp" => "0";
1019
requires "File::Which" => "0";
20+
requires "Test::More" => "0.88";
1121
};
1222

1323
on 'configure' => sub {
24+
requires "Crypt::OpenSSL::ConfiguredAPI" => "0";
1425
requires "Crypt::OpenSSL::Guess" => "0";
1526
requires "ExtUtils::MakeMaker" => "0";
1627
};

dist.ini

+14-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,21 @@ maintainer = Timothy Legge <[email protected]>
1414
-remove = MakeMaker
1515
-remove = Readme
1616

17+
[AutoPrereqs]
18+
skip = ^vars$
19+
skip = utf8
20+
skip = warnings
21+
skip = strict
22+
skip = overload
23+
skip = base
24+
25+
[Prereqs / BuildRequires]
26+
Crypt::OpenSSL::Guess = 0
27+
Crypt::OpenSSL::ConfiguredAPI = 0
28+
1729
[Prereqs / ConfigureRequires]
1830
Crypt::OpenSSL::Guess = 0
31+
Crypt::OpenSSL::ConfiguredAPI = 0
1932

2033
[Prereqs / RuntimeRequires]
2134
perl = 5.014
@@ -71,7 +84,7 @@ header_file = maint/Makefile_header.PL
7184
WriteMakefile_arg = %args
7285

7386
[Repository]
74-
git_remote = origin
87+
git_remote = upstream
7588

7689
[Bugtracker]
7790
web = https://github.com/perl-net-saml2/perl-Crypt-OpenSSL-SignCSR/issues

lib/Crypt/OpenSSL/SignCSR.pm

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use warnings;
77

88
require Exporter;
99

10-
our $VERSION = "0.12";
10+
our $VERSION = "0.13";
1111

1212
our @ISA = qw(Exporter);
1313

@@ -122,7 +122,7 @@ Arguments:
122122
123123
Get the number of days that is currently set.
124124
125-
Returns a number
125+
Returns the number of days or -1 for a failure.
126126
127127
=head1 EXPORT
128128

maint/Makefile_header.PL

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
use Config;
22
use File::Spec;
33
use Crypt::OpenSSL::Guess;
4+
use Crypt::OpenSSL::ConfiguredAPI;
5+
46
my %args;
57

68
my ($major, $minor, $patch) = openssl_version();
79
print "Installed OpenSSL: $major.$minor.$patch\n";
810

11+
my $version = ($major * 10000) + ($minor * 100);
12+
my $api = Crypt::OpenSSL::ConfiguredAPI::get_configured_api();
13+
print "API version read $api\n";
14+
15+
my $compat = $api ne 0 ? $api : $version;
16+
print "OPENSSL_COMPAT_API set to: $compat\n";
17+
918
$args{INC} = openssl_inc_paths();
1019
$args{LIBS} = [openssl_lib_paths() . ' -lssl -lcrypto'];
1120

12-
my $cc_option_flags = $major ge 3 ? ' -DOPENSSL_API_COMPAT=30000' : ' -DOPENSSL_API_COMPAT=10100';
21+
my $cc_option_flags = " -DOPENSSL_API_COMPAT=$compat";
1322

1423
if ($Config::Config{cc} =~ /gcc/i) {
1524
$cc_option_flags .= $ENV{AUTHOR_TESTING} ? ' -Wall -Werror' : ' -Wall';

0 commit comments

Comments
 (0)