Fix no-ocsp
[openssl.git] / util / fipslink.pl
index 4b07036419e8d3c1e4703ca33e3e1036b5423ec9..7b16e04fb9da7a752254600f6b7d096e2d653780 100644 (file)
@@ -33,12 +33,12 @@ check_hash($sha1_exe, "fipscanister.lib");
 
 print "Integrity check OK\n";
 
-if (grep /fips_premain\.obj/,@ARGV) {
+if (is_premain_linked(@ARGV)) {
        print "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c\n";
        system "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c";
        die "First stage Compile failure" if $? != 0;
 } elsif (!defined($ENV{FIPS_SIG})) {
-       die "no fips_premain.obj";
+       die "no fips_premain.obj linked";
 }
 
 print "$fips_link @ARGV\n";
@@ -46,7 +46,8 @@ system "$fips_link @ARGV";
 die "First stage Link failure" if $? != 0;
 
 if (defined($ENV{FIPS_SIG})) {
-       system "$ENV{FIPS_SIG} $fips_target"
+       print "$ENV{FIPS_SIG} $fips_target\n";
+       system "$ENV{FIPS_SIG} $fips_target";
        die "$ENV{FIPS_SIG} $fips_target failed" if $? != 0;
        exit;
 }
@@ -58,7 +59,7 @@ open my $sha1_res, '<', $fips_target.".sha1" or die "Get hash failure";
 $fips_hash=<$sha1_res>;
 close $sha1_res;
 unlink $fips_target.".sha1";
-chomp $fips_hash;
+$fips_hash =~ s|\R$||;          # Better chomp
 die "Get hash failure" if $? != 0;
 
 
@@ -71,6 +72,22 @@ print "$fips_link @ARGV\n";
 system "$fips_link @ARGV";
 die "Second stage Link failure" if $? != 0;
 
+sub is_premain_linked
+       {
+       return 1 if (grep /fips_premain\.obj/,@_);
+       foreach (@_)
+               {
+               if (/^@(.*)/ && -f $1)
+                       {
+                       open FD,$1 or die "can't open $1";
+                       my $ret = (grep /fips_premain\.obj/,<FD>)?1:0;
+                       close FD;
+                       return $ret;
+                       }
+               }
+       return 0;
+       }
+
 sub check_hash
        {
        my ($sha1_exe, $filename) = @_;
@@ -80,8 +97,8 @@ sub check_hash
        $hashfile = <IN>;
        close IN;
        $hashval = `$sha1_exe ${fips_libdir}/$filename`;
-       chomp $hashfile;
-       chomp $hashval;
+       $hashfile =~ s|\R$||;    # Better chomp
+       $hashval =~ s|\R$||;     # Better chomp
        $hashfile =~ s/^.*=\s+//;
        $hashval =~ s/^.*=\s+//;
        die "Invalid hash syntax in file" if (length($hashfile) != 40);