-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile.PL
3058 lines (2495 loc) · 101 KB
/
Makefile.PL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!perl
#===============================================================================
#
# Makefile.PL
#
# DESCRIPTION
# Top-level makefile creation script.
#
# COPYRIGHT
# Copyright (C) 2004-2009, 2012, 2014, 2015, 2017, 2020, 2021, 2023 Steve Hay.
# All rights reserved.
#
# LICENCE
# This script is free software; you can redistribute it and/or modify it under
# the same terms as Perl itself, i.e. under the terms of either the GNU
# General Public License or the Artistic License, as specified in the LICENCE
# file.
#
#===============================================================================
use 5.008001;
use strict;
use warnings;
use ExtUtils::MakeMaker 6.66;
use ExtUtils::MakeMaker qw(WriteMakefile);
#===============================================================================
# INITIALIZATION
#===============================================================================
our($VERSION, $YEAR);
BEGIN {
$VERSION = '2.11';
$YEAR = '2004-2009, 2012, 2014, 2015, 2017, 2020, 2021, 2023';
}
#===============================================================================
# MAIN PROGRAM
#===============================================================================
MAIN: {
my $cb = Filter::Crypto::_ConfigureBuild->new();
my @opt_specs = (
'prefix-dir|d=s',
'cipher-config|c=s',
'cipher-name|n=s',
'cipher-mode|m=s',
'pswd|p=s',
'key|k=s',
'rng|r=s',
'key-len|l=i',
'rc2-key-bits=i',
'rc5-rounds=i',
'install-script|i=s',
'build|b=s',
'unsafe-mode|u',
'debug-mode'
);
$cb->process_opts(\@opt_specs);
$cb->locate_openssl();
$cb->configure_cipher();
my $dir = $cb->query_build();
if ("@$dir" =~ /Decrypt/o) {
$cb->check_perl();
}
my $exe_files = $cb->query_script("@$dir" =~ /CryptFile/o ? 'y' : 'n');
$cb->setup_env();
my %configure_requires = ();
$configure_requires{'VMS::DCLsym'} = '0' if $^O eq 'VMS';
WriteMakefile(
NAME => 'Filter::Crypto',
ABSTRACT_FROM => 'lib/Filter/Crypto.pm',
AUTHOR => 'Steve Hay <[email protected]>',
LICENSE => 'perl_5',
VERSION_FROM => 'lib/Filter/Crypto.pm',
META_MERGE => {
'meta-spec' => {
version => 2
},
no_index => {
package => 'Filter::Crypto::_ConfigureBuild'
},
resources => {
repository => {
type => 'git',
web => 'https://github.com/steve-m-hay/Filter-Crypto'
}
},
optional_features => {
parfilter => {
description => 'PAR::Filter support',
prereqs => {
runtime => {
requires => {
'PAR::Filter' => '0'
}
},
test => {
requires => {
'Archive::Zip' => '0'
}
}
}
},
changestest => {
description => 'Changes testing',
prereqs => {
test => {
requires => {
'Test::CPAN::Changes' => '0'
}
}
}
},
critictest => {
description => 'Perl::Critic testing',
prereqs => {
test => {
requires => {
'Test::Perl::Critic' => '0'
}
}
}
},
podtest => {
description => 'POD testing',
prereqs => {
test => {
requires => {
'Test::Pod' => '1.00'
}
}
}
},
podcoveragetest => {
description => 'POD coverage testing',
prereqs => {
test => {
requires => {
'Test::Pod::Coverage' => '0.08'
}
}
}
}
}
},
MIN_PERL_VERSION => '5.008001',
CONFIGURE_REQUIRES => {
%configure_requires,
'Carp' => '0',
'Config' => '0',
'Cwd' => '0',
'ExtUtils::MakeMaker' => '6.66',
'Fcntl' => '0',
'File::Basename' => '0',
'File::Copy' => '0',
'File::Spec::Functions' => '0',
'Getopt::Long' => '0',
'Pod::Usage' => '1.15',
'Text::Wrap' => '0',
'constant' => '0',
'perl' => '5.008001',
'strict' => '0',
'warnings' => '0'
},
TEST_REQUIRES => {
'File::Path' => '0',
'FindBin' => '0',
'Test::More' => '0',
'blib' => '0'
},
PREREQ_PM => {
'Carp' => '0',
'Config' => '0',
'Cwd' => '0',
'Exporter' => '0',
'ExtUtils::MakeMaker' => '6.66',
'Fcntl' => '0',
'File::Basename' => '0',
'File::Copy' => '0',
'File::Find' => '0',
'File::Spec::Functions' => '0',
'File::Temp' => '0',
'Getopt::Long' => '0',
'Pod::Usage' => '1.15',
'Scalar::Util' => '0',
'Text::ParseWords' => '0',
'Text::Wrap' => '0',
'XSLoader' => '0',
'constant' => '0',
'strict' => '0',
'warnings' => '0'
},
DIR => $dir,
EXE_FILES => $exe_files,
clean => {
FILES => 'CipherConfig.h'
},
dist => {
PREOP => 'find $(DISTVNAME) -type d -print|xargs chmod 0755 && ' .
'find $(DISTVNAME) -type f -print|xargs chmod 0644 && ' .
'chmod 0755 $(DISTVNAME)/script/crypt_file',
TO_UNIX => 'find $(DISTVNAME) -type f -print|xargs dos2unix'
}
);
}
#===============================================================================
# MAKEMAKER OVERRIDES
#===============================================================================
# Method to temporarily remove the list of sub-directories when creating the
# (top-level) "test" target since our sub-directories have no tests of their
# own. This saves the bother of cd'ing into them and avoids the alarming "No
# tests defined..." message when running the top-level "test" target. (The
# sub-directories' Makefiles still have their own "test" targets, though, so
# anyone manually cd'ing into them and running those "test" targets will get the
# message about there being no tests.)
#
# This method is based on code taken from the MY::test() method in the top-level
# Makefile.PL script in the Tk distribution (version 804.032).
sub MY::test {
my($self, %args) = @_;
my $dir = delete $self->{DIR};
my $str = $self->MM::test(%args);
$self->{DIR} = $dir;
return $str;
}
#===============================================================================
# PRIVATE CLASS
#===============================================================================
{
package Filter::Crypto::_ConfigureBuild;
use Carp qw(croak);
use Config qw(%Config);
use Cwd qw(abs_path);
use ExtUtils::MakeMaker qw(prompt);
use Fcntl;
use File::Basename qw(basename dirname);
use File::Copy qw(copy);
use File::Spec::Functions qw(canonpath catdir catfile curdir
file_name_is_absolute path updir);
use Getopt::Long qw(GetOptions);
use Pod::Usage qw(pod2usage);
use Text::Wrap qw(wrap);
use constant CIPHER_NAME_DES => 'DES';
use constant CIPHER_NAME_DES_EDE => 'DES_EDE';
use constant CIPHER_NAME_DES_EDE3 => 'DES_EDE3';
use constant CIPHER_NAME_RC4 => 'RC4';
use constant CIPHER_NAME_IDEA => 'IDEA';
use constant CIPHER_NAME_RC2 => 'RC2';
use constant CIPHER_NAME_DESX => 'DESX';
use constant CIPHER_NAME_BLOWFISH => 'Blowfish';
use constant CIPHER_NAME_NULL => 'Null';
use constant CIPHER_NAME_RC5 => 'RC5';
use constant CIPHER_NAME_CAST5 => 'CAST5';
use constant CIPHER_NAME_AES => 'AES';
use constant CIPHER_MODE_ECB => 'ECB';
use constant CIPHER_MODE_CBC => 'CBC';
use constant CIPHER_MODE_CFB => 'CFB';
use constant CIPHER_MODE_OFB => 'OFB';
use constant CIPHER_KEY_GIVEN_PSWD => 1;
use constant CIPHER_KEY_RANDOM_PSWD => 2;
use constant CIPHER_KEY_GIVEN => 3;
use constant CIPHER_KEY_RANDOM => 4;
use constant RAND_OPTION_STR => 'rand';
use constant RAND_PSWD_LEN => 32;
use constant RNG_PERL_RAND => 'Perl';
use constant RNG_CRYPT_RANDOM => 'Crypt::Random';
use constant RNG_MATH_RANDOM => 'Math::Random';
use constant RNG_OPENSSL_RAND => 'OpenSSL';
use constant CIPHER_CONFIG_FILENAME => 'CipherConfig.h';
use constant BUILD_OPTION_BOTH => 'both';
use constant BUILD_OPTION_CRYPTFILE => 'CryptFile';
use constant BUILD_OPTION_DECRYPT => 'Decrypt';
#-------------------------------------------------------------------------------
# CLASS INITIALIZATION
#-------------------------------------------------------------------------------
our($VERSION, $YEAR, $Show_Found_Var_Indent);
BEGIN {
$VERSION = $main::VERSION;
$YEAR = $main::YEAR;
# Define indentation for show_found_var() method.
$Show_Found_Var_Indent = 37;
# Define protected accessor/mutator methods.
foreach my $prop (qw(
define inc libs opts
prefix_dir inc_dir ver_num ver_str lib_dir lib_name bin_file
cipher_name cipher_func cipher_needs_iv key_len rc2_key_bits rc5_rounds
pswd key))
{
no strict 'refs'; ## no critic (TestingAndDebugging::ProhibitNoStrict)
*$prop = sub {
use strict 'refs';
my $self = shift;
$self->{$prop} = shift if @_;
return $self->{$prop};
};
}
}
#-------------------------------------------------------------------------------
# PUBLIC API
#-------------------------------------------------------------------------------
sub new {
return bless {}, shift;
}
sub process_opts {
my($self, $opt_specs, $with_auto_install) = @_;
# Allow options to be introduced with a "/" character on Windows, as is
# common on those OSes, as well as the default set of characters.
if ($self->is_win32()) {
Getopt::Long::Configure('prefix_pattern=(--|-|\+|\/)');
}
# Deal with these common options immediately; have the rest stored in %opts.
my $opt_def = 0;
my %opts = (
'defaults' => sub { $ENV{PERL_MM_USE_DEFAULT} = 1; $opt_def = 1 },
'version' => sub { $self->exit_with_version() },
'help' => sub { $self->exit_with_help() },
'manpage' => sub { $self->exit_with_manpage() }
);
# Make sure that '-v' and '-h' unambiguously mean '--version' and '--help'
# respectively, even if other option specs beginning with 'v' or 'h' are
# given in @$opt_specs.
my @opt_specs = (
@$opt_specs,
'defaults',
'version|v',
'help|h|?',
'manpage|doc'
);
GetOptions(\%opts, @opt_specs) or
$self->exit_with_usage();
$self->opts(\%opts);
}
# This method is based on code taken from the can_run() method in the standard
# library module IPC::Cmd (version 0.92).
sub can_run {
my($self, $cmd) = @_;
if ($^O eq 'VMS') {
require VMS::DCLsym;
my $syms = VMS::DCLsym->new();
return $cmd if scalar $syms->getsym(uc $cmd);
}
return MM->maybe_command($cmd) if file_name_is_absolute($cmd);
foreach my $dir (path(), curdir()) {
next if !$dir or !-d $dir;
my $abs = catfile($dir, $cmd);
return $abs if $abs = MM->maybe_command($abs);
}
return;
}
sub query_script {
my($self, $default) = @_;
my $script_name = 'crypt_file';
my $install_script = $self->opts()->{'install-script'};
if (defined $install_script) {
if ($install_script =~ /^(?:y|n)$/io) {
$self->show_found_var(
'Using specified script option', $install_script
);
}
else {
$self->exit_with_error(3,
"Invalid 'install_script' option value '%s'", $install_script
);
}
}
else {
my $question = "Do you want to install '$script_name'?";
$default = 'y' unless defined $default;
$install_script = $self->prompt_yes_no($question, $default);
}
print "\n";
if ($install_script) {
return [ catfile('script', $script_name) ];
}
else {
return [];
}
}
# Method to store the build options in this process' environment so that they
# are available to the sub-directories' Makefile.PLs when they are run. Note
# that ExtUtils::MakeMaker's PASTHRU macro is not good enough because that only
# passes things through when "make Makefile" is run, which is too late for the
# processing of the LIBS option that Makefile.PL itself handles.
sub setup_env {
my $self = shift;
$ENV{__SHAY_PRIVATE_DEFINE} = $self->define();
$ENV{__SHAY_PRIVATE_INC} = $self->inc();
$ENV{__SHAY_PRIVATE_LIBS} = $self->libs();
}
# Method to check the perl being used isn't a "debug" mode build, unless
# Makefile.PL was invoked with the "--debug-mode" command-line option, in which
# case it is okay.
# Only check whether the DEBUGGING symbol is defined in perl's C compiler flags
# here. This is sufficient to catch all normal cases. Fuller checks are
# performed in Decrypt.xs's "BOOT" code (the check is only relevant when the
# Decrypt component is built).
sub check_perl {
my $self = shift;
return if exists $self->opts()->{'debug-mode'};
if ($Config{ccflags} =~ /(?:^|\s)-DDEBUGGING(?:\s|$)/o) {
$self->exit_with_error(134,
'OS unsupported: The "Decrypt" component requires a "release" ' .
'mode build of perl (i.e. one built without DEBUGGING)'
);
}
}
sub locate_openssl {
my $self = shift;
print "\n";
$self->query_prefix_dir();
print "\n";
$self->locate_inc_dir();
$self->set_inc();
$self->determine_ver_num();
$self->set_define();
$self->locate_lib_dir_and_file();
$self->set_libs();
$self->locate_bin_file();
print "\n";
}
sub configure_cipher {
my $self = shift;
my $cipher_config = $self->opts()->{'cipher-config'};
if (defined $cipher_config) {
if (-f $cipher_config) {
$self->show_found_var(
'Using specified configuration file', $cipher_config
);
$self->copy_cipher_config($cipher_config);
}
else {
$self->exit_with_error(100,
"No such configuration file '%s'", $cipher_config
);
}
}
else {
$self->query_cipher_name();
my $lc_cipher_name = lc $self->cipher_name();
my $cipher_config_method = "configure_${lc_cipher_name}_cipher";
$self->$cipher_config_method();
$self->query_pswd_or_key();
$self->write_cipher_config();
}
}
sub query_build {
my $self = shift;
my @build_options = (
[ BUILD_OPTION_BOTH, 'Build both components' ],
[ BUILD_OPTION_CRYPTFILE, 'Build CryptFile component only' ],
[ BUILD_OPTION_DECRYPT, 'Build Decrypt component only' ]
);
my $build = $self->opts()->{'build'};
if (defined $build) {
my %build_options = map { $_->[0] => 1 } @build_options;
if (exists $build_options{$build}) {
$self->show_found_var('Using specified build option', $build);
}
else {
$self->exit_with_error(101,
"Invalid 'build' option value '%s'", $build
);
}
}
else {
my $message = 'Build options:';
my $question = 'Which component(s) do you want to build?';
my $default = BUILD_OPTION_BOTH;
$build = $self->prompt_list(
$message, \@build_options, $question, $default
);
}
print "\n";
if ($build eq BUILD_OPTION_BOTH) {
return [ BUILD_OPTION_CRYPTFILE, BUILD_OPTION_DECRYPT ];
}
else {
return [ $build ];
}
}
#-------------------------------------------------------------------------------
# PROTECTED API
#-------------------------------------------------------------------------------
sub is_win32 {
return $^O =~ /^MSWin32$/io;
}
sub is_cygwin {
return $^O =~ /^cygwin$/io;
}
sub quote_str {
my($self, $string) = @_;
if ($string =~ / /o) {
my $q = ($^O =~ /^(?:MSWin32|NetWare|VMS)$/io) ? '"' : "'";
$string = $q . $string . $q;
}
return $string;
}
sub prompt_yes_no {
my($self, $question, $default) = @_;
my $answer = $self->prompt_validate(
-question => $question,
-default => $default,
-validate => sub { $_[0] =~ /^(?:y(?:es)?|no?)$/io }
);
return $answer =~ /^y/io ? 1 : 0;
}
sub prompt_dir {
my($self, $question, $default) = @_;
my $dir = $self->prompt_validate(
-question => $question,
-default => $default,
-validate => sub { -d $_[0] },
-errmsg => 'No such directory'
);
return canonpath(abs_path($dir));
}
sub prompt_list {
my($self, $message, $options, $question, $default) = @_;
my $num_options = scalar @$options;
my $len = length $num_options;
my %options = map { $_->[0] => 1 } @$options;
my $num_unique_options = scalar keys %options;
if ($num_unique_options != $num_options) {
$self->exit_with_error(4, 'Options in list are not unique');
}
my $default_num = 0;
for (my $i = 1; $i <= $num_options; $i++) {
$message .= sprintf "\n [%${len}d] %s", $i, $options->[$i - 1][1];
$default_num = $i if $options->[$i - 1][0] eq $default;
}
if ($default_num == 0) {
$self->exit_with_error(5, "Invalid default response '%s'", $default);
}
my $answer_num = $self->prompt_validate(
-message => $message,
-question => $question,
-default => $default_num,
-validate => sub {
$_[0] =~ /^[1-9](?:\d+)?$/o and $_[0] <= $num_options
}
);
return $options->[$answer_num - 1][0];
}
{
my %defaults = (
-question => '?',
-default => '',
-validate => sub { 1 },
-errmsg => 'Invalid response'
);
sub prompt_validate {
my $self = shift;
my %args = (%defaults, @_);
if (exists $args{-message}) {
print wrap('', '', $args{-message}), "\n";
}
my $input;
until (defined $input) {
$input = prompt($args{-question}, $args{-default});
unless ($args{-validate}->($input)) {
if ($self->use_default_response()) {
$self->exit_with_error(7,
"Invalid default response '%s'", $args{-default}
);
}
else {
print wrap('', '', $args{-errmsg}), "\n";
$input = undef;
}
}
}
return $input;
}
}
sub show_found_var {
my($self, $msg, $var) = @_;
local $Text::Wrap::break = qr{\s|(?<=[\\\\/]).{0}}o;
print wrap('', ' ' x $Show_Found_Var_Indent,
"$msg " . '.' x ($Show_Found_Var_Indent - length($msg) - 2) . " $var"
), "\n";
}
sub exit_with_version {
my $self = shift;
printf "This is %s %s.\n\n", basename($0), $main::VERSION;
print "Copyright (C) $YEAR Steve Hay. All rights reserved.\n\n";
print wrap('', '',
"This script is free software; you can redistribute it and/or modify " .
"it under the same terms as Perl itself, i.e. under the terms of " .
"either the GNU General Public License or the Artistic License, as " .
"specified in the LICENCE file.\n\n"
);
exit 1;
}
sub exit_with_help {
my $self = shift;
pod2usage(
-exitval => 1,
-verbose => 1
);
}
sub exit_with_manpage {
my $self = shift;
pod2usage(
-exitval => 1,
-verbose => 2
);
}
sub exit_with_usage {
my $self = shift;
pod2usage(
-exitval => 2,
-verbose => 0
);
}
sub exit_with_error {
my($self, $num, $msg) = splice @_, 0, 3;
$msg = sprintf $msg, @_ if @_;
# Load Carp::Heavy now, otherwise (before Perl 5.8.7) croak() clobbers $!
# when loading it.
require Carp::Heavy;
$! = $num;
croak("Error ($num): $msg");
}
# This method is based on code taken from the prompt() function in the standard
# library module ExtUtils::MakeMaker (version 6.92).
sub use_default_response {
my $self = shift;
return($ENV{PERL_MM_USE_DEFAULT} or (not $self->isa_tty() and eof STDIN));
}
# This method is based on code taken from the prompt() function in the standard
# library module ExtUtils::MakeMaker (version 6.92).
sub isa_tty {
my $self = shift;
## no critic (InputOutput::ProhibitInteractiveTest)
return(-t STDIN and (-t STDOUT or not (-f STDOUT or -c STDOUT)));
}
sub query_prefix_dir {
my $self = shift;
my $prefix_dir = $self->opts()->{'prefix-dir'};
if (defined $prefix_dir) {
$prefix_dir = canonpath(abs_path($prefix_dir));
if (-d $prefix_dir) {
$self->show_found_var(
'Using specified prefix directory', $prefix_dir
);
}
else {
$self->exit_with_error(102,
"No such prefix directory '%s'", $prefix_dir
);
}
}
else {
# Look for the main binary executable "openssl" and use the parent
# directory of where that is located; otherwise use the default prefix
# directory as specified in the latest OpenSSL's own INSTALL file if it
# exists.
my $bin_file;
if ($bin_file = $self->can_run('openssl')) {
if ($self->is_win32()) {
# Find out (if we can) which platform this binary was built for.
# This information is normally contained in the output of the
# binary's "version -a" command, labelled "platform: ".
my $quoted_bin_file = $self->quote_str($bin_file);
my $bin_cmd = "$quoted_bin_file version -a 2>&1";
my $bin_output = `$bin_cmd`;
my $bin_rc = $? >> 8;
if ($bin_rc) {
$self->exit_with_error(133,
"Could not get OpenSSL version information " .
"(%d):\n%s", $bin_rc, $bin_output
);
}
if ((my $platform) = $bin_output =~ /platform: ?(.*)$/imo) {
# If we have found a Cygwin binary then we had better not
# try to use it with our Win32 perl.
if ($platform =~ /^Cygwin/io) {
warn("Warning: Ignoring Cygwin OpenSSL binary " .
"'$bin_file' on Win32\n");
$bin_file = undef;
}
}
}
}
my $default;
if (defined $bin_file) {
# The binaries are normally located in a sub-directory (bin/,
# out32/, out32dll/, out32.dbg/, out32dll.dbg or out/) of the prefix
# directory. See locate_bin_file().
my $bin_dir = dirname($bin_file);
$default = canonpath(abs_path(catdir($bin_dir, updir())));
}
else {
$default = $self->is_win32() ? 'C:\\openssl' : '/usr/local/ssl';
unless (-d $default) {
if ($self->use_default_response()) {
$self->exit_with_error(132,
'OS unsupported: No OpenSSL/SSLeay directory found'
);
}
else {
$default = '';
}
}
}
my $question = 'Where is your OpenSSL?';
$prefix_dir = $self->prompt_dir($question, $default);
}
$self->prefix_dir($prefix_dir)
}
sub locate_inc_dir {
my $self = shift;
# NOTE: We support finding the header files of older OpenSSLs and SSLeays
# than we support so that we can report on the failed minimum requirement.
# The headers are normally located in the include/ sub-directory of the
# prefix directory.
# However, we may be working with a build directory rather than an
# installation directory, in which case the header files will be in a
# different sub-directory on "native" Windows platforms, in this case inc32/
# (0.9.0 onwards) or out/ (up to and including 0.8.1b), or even outinc/ for
# MinGW builds. Beware of version 0.6.0 build directories, which contain an
# include/ sub-directory containing "Shortcuts" to the real header files in
# the out/ sub-directory. Check for the presence of the "cyrypto.h" header
# file to be sure we find the correct sub-directory. The header files are
# now located in the openssl/ sub-directory of the include directory (0.9.3
# onwards), but were located in the include directory itself (up to and
# including 0.8.1b).
my $prefix_dir = $self->prefix_dir();
my($dir, $inc_dir);
if (-d ($dir = catdir($prefix_dir, 'include')) and
(-f catfile($dir, 'openssl', 'crypto.h') or
-f catfile($dir, 'crypto.h')))
{
$inc_dir = $dir;
}
elsif ($self->is_win32()) {
if (-d ($dir = catdir($prefix_dir, 'inc32')) and
(-f catfile($dir, 'openssl', 'crypto.h') or
-f catfile($dir, 'crypto.h')))
{
$inc_dir = $dir;
}
elsif (-d ($dir = catdir($prefix_dir, 'outinc')) and
(-f catfile($dir, 'openssl', 'crypto.h') or
-f catfile($dir, 'crypto.h')))
{
$inc_dir = $dir;
}
elsif (-d ($dir = catdir($prefix_dir, 'out')) and
-f catfile($dir, 'crypto.h'))
{
$inc_dir = $dir;
}
}
if (defined $inc_dir) {
$self->show_found_var('Found include directory', $inc_dir);
$self->inc_dir($inc_dir)
}
else {
$self->exit_with_error(103,
'No OpenSSL/SSLeay include directory found'
);
}
}
sub set_inc {
my $self = shift;
my $inc_dir = $self->quote_str($self->inc_dir());
$self->inc("-I$inc_dir");
}
sub determine_ver_num {
my $self = shift;
# NOTE: We support finding the version number of older OpenSSLs and SSLeays
# than we support so that we can report on the failed minimum requirement.
# The header files are now located in the openssl/ sub-directory of the
# include directory (0.9.3 onwards), but were located in the include
# directory itself (up to and including 0.8.1b).
my $inc_dir = $self->inc_dir();
my($dir, $inc_files_dir);
if (-d ($dir = catdir($inc_dir, 'openssl'))) {
$inc_files_dir = $dir;
}
else {
$inc_files_dir = $inc_dir;
}
# The version number is now specified by OPENSSL_VERSION_(MAJOR|MINOR|PATCH)
# #defines in the opensslv.h header file (3.0.0 onwards).
# The version number was specified by an OPENSSL_VERSION_NUMBER #define in
# the opensslv.h header file (0.9.2 onwards). That #define was in the
# crypto.h header file (0.9.1s), and was called SSLEAY_VERSION_NUMBER (from
# 0.6.0 to 0.9.0b inclusive). Earlier versions do not seem to have a
# version number defined in this way, but we do not support anything earlier
# anyway. The version number is specified as a hexadecimal integer of the
# form MNNFFPPS (major, minor, fix, patch, status [0 for dev, 1 to 14 for
# betas, and f for release) (0.9.5a onwards, but with the highest bit set in
# the patch byte for the 0.9.5s), or of the form MNNFFRBB (major, minor,
# fix, release, patch or beta) (0.9.3s, 0.9.4s and 0.9.5), or of the form
# MNFP (major, minor, fix, patch) (up to and including 0.9.2b).
my($file, $ver_file);
if (-f ($file = catfile($inc_files_dir, 'opensslv.h'))) {
$ver_file = $file;
}
elsif (-f ($file = catfile($inc_files_dir, 'crypto.h'))) {
$ver_file = $file;
}
else {
$self->exit_with_error(104,
'No OpenSSL/SSLeay version number header file found'
);
}
my %version;
if (open my $ver_fh, '<', $ver_file) {
while (<$ver_fh>) {
if (/^\#\s*define\s+(?:OPENSSL|SSLEAY)_VERSION_([A-Z]*)\s+
([^\s].*)/iox)
{
$version{$1} = $2;
}
}
close $ver_fh;
}
else {
$self->exit_with_error(105,
"Could not open version number header file '%s' for reading: %s",
$ver_file, $!
);
}
my($major, $minor, $fix, $patch, $ver_str, $status_str);
if (defined $version{MAJOR} and $version{MAJOR} =~ /\d+/o and
defined $version{MINOR} and $version{MINOR} =~ /\d+/o and
defined $version{PATCH} and $version{PATCH} =~ /\d+/o and
defined $version{STR} and $version{STR} =~ s/^"(.*)"$/$1/)
{
$major = int $version{MAJOR};
$minor = int $version{MINOR};
$fix = 0;
$patch = int $version{PATCH};
$ver_str = $version{STR};
$status_str = '';
}
elsif (defined $version{NUMBER} and $version{NUMBER} =~ /0x([0-9a-f]+)/io) {
my $ver_define = $1;
if (length $ver_define == 8 and
$ver_define =~ /^([0-9a-f])([0-9a-f]{2})([0-9a-f]{2})/io)
{
($major, $minor, $fix) = map { hex } ($1, $2, $3);
my $mmf_ver_num = $major * 10000 + $minor * 100 + $fix;
if ( $mmf_ver_num > 905 or
($mmf_ver_num == 905 and $ver_define !~ /100$/o))