~ubuntu-branches/ubuntu/saucy/curl/saucy-201307251546

« back to all changes in this revision

Viewing changes to lib/mk-ca-bundle.pl

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2013-02-12 08:54:32 UTC
  • mfrom: (3.4.34 sid)
  • Revision ID: package-import@ubuntu.com-20130212085432-r1fyi0b37enr93pp
Tags: 7.29.0-1ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Drop dependencies not in main:
    + Build-Depends: Drop stunnel4 and libssh2-1-dev.
    + Drop libssh2-1-dev from binary package Depends.
  - Add new libcurl3-udeb package.
  - Add new curl-udeb package.
* Add warning to debian/patches/series.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
# *                            | (__| |_| |  _ <| |___
7
7
# *                             \___|\___/|_| \_\_____|
8
8
# *
9
 
# * Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
 
9
# * Copyright (C) 1998 - 2013, Daniel Stenberg, <daniel@haxx.se>, et al.
10
10
# *
11
11
# * This software is licensed as described in the file COPYING, which
12
12
# * you should have received as part of this distribution. The terms
34
34
use MIME::Base64;
35
35
use LWP::UserAgent;
36
36
use strict;
37
 
use vars qw($opt_b $opt_h $opt_i $opt_l $opt_n $opt_q $opt_t $opt_u $opt_v);
 
37
use vars qw($opt_b $opt_f $opt_h $opt_i $opt_l $opt_n $opt_q $opt_t $opt_u $opt_v);
38
38
 
39
39
my $url = 'http://mxr.mozilla.org/mozilla/source/security/nss/lib/ckfw/builtins/certdata.txt?raw=1';
40
40
# If the OpenSSL commandline is not in search path you can configure it here!
41
41
my $openssl = 'openssl';
42
42
 
43
 
my $version = '1.16';
 
43
my $version = '1.17';
44
44
 
45
 
getopts('bhilnqtuv');
 
45
getopts('bfhilnqtuv');
46
46
 
47
47
if ($opt_i) {
48
48
  print ("=" x 78 . "\n");
58
58
 
59
59
$0 =~ s@.*(/|\\)@@;
60
60
if ($opt_h) {
61
 
  printf("Usage:\t%s [-b] [-i] [-l] [-n] [-q] [-t] [-u] [-v] [<outputfile>]\n", $0);
 
61
  printf("Usage:\t%s [-b] [-f] [-i] [-l] [-n] [-q] [-t] [-u] [-v] [<outputfile>]\n", $0);
62
62
  print "\t-b\tbackup an existing version of ca-bundle.crt\n";
 
63
  print "\t-f\tforce rebuild even if certdata.txt is current\n";
63
64
  print "\t-i\tprint version info about used modules\n";
64
65
  print "\t-l\tprint license info about certdata.txt\n";
65
66
  print "\t-n\tno download of certdata.txt (to use existing)\n";
73
74
my $crt = $ARGV[0] || 'ca-bundle.crt';
74
75
(my $txt = $url) =~ s@(.*/|\?.*)@@g;
75
76
 
 
77
my $stdout = $crt eq '-';
76
78
my $resp;
 
79
my $fetched;
77
80
 
78
81
unless ($opt_n and -e $txt) {
79
 
  print "Downloading '$txt' ...\n" if (!$opt_q);
 
82
  print STDERR "Downloading '$txt' ...\n" if (!$opt_q);
80
83
  my $ua  = new LWP::UserAgent(agent => "$0/$version");
81
84
  $ua->env_proxy();
82
85
  $resp = $ua->mirror($url, $txt);
83
86
  if ($resp && $resp->code eq '304') {
84
 
    print "Not modified\n" unless $opt_q;
85
 
    exit 0;
86
 
  }
87
 
}
88
 
 
89
 
my $currentdate = scalar gmtime($resp ? $resp->last_modified : (stat($txt))[9]);
90
 
 
91
 
if ($opt_b && -e $crt) {
92
 
  my $bk = 1;
93
 
  while (-e "$crt.~${bk}~") {
94
 
    $bk++;
95
 
  }
96
 
  rename $crt, "$crt.~${bk}~";
97
 
}
 
87
    print STDERR "Not modified\n" unless $opt_q;
 
88
    exit 0 if -e $crt && !$opt_f;
 
89
  } else {
 
90
      $fetched = 1;
 
91
  }
 
92
  if( !$resp || $resp->code !~ /^(?:200|304)$/ ) {
 
93
      print STDERR "Unable to download latest data: "
 
94
        . ($resp? $resp->code . ' - ' . $resp->message : "LWP failed") . "\n"
 
95
        unless $opt_q;
 
96
      exit 1 if -e $crt || ! -r $txt;
 
97
  }
 
98
}
 
99
 
 
100
my $currentdate = scalar gmtime($fetched ? $resp->last_modified : (stat($txt))[9]);
98
101
 
99
102
my $format = $opt_t ? "plain text and " : "";
100
 
open(CRT,">$crt") or die "Couldn't open $crt: $!";
 
103
if( $stdout ) {
 
104
    open(CRT, '> -') or die "Couldn't open STDOUT: $!\n";
 
105
} else {
 
106
    open(CRT,">$crt.~") or die "Couldn't open $crt.~: $!\n";
 
107
}
101
108
print CRT <<EOT;
102
109
##
103
110
## $crt -- Bundle of CA Root Certificates
117
124
 
118
125
EOT
119
126
 
120
 
close(CRT) or die "Couldn't close $crt: $!";
121
 
 
122
 
print "Processing  '$txt' ...\n" if (!$opt_q);
 
127
print STDERR "Processing  '$txt' ...\n" if (!$opt_q);
123
128
my $caname;
124
129
my $certnum = 0;
125
130
my $skipnum = 0;
126
131
my $start_of_cert = 0;
127
132
 
128
 
open(TXT,"$txt") or die "Couldn't open $txt: $!";
 
133
open(TXT,"$txt") or die "Couldn't open $txt: $!\n";
129
134
while (<TXT>) {
130
135
  if (/\*\*\*\*\* BEGIN LICENSE BLOCK \*\*\*\*\*/) {
131
 
    open(CRT, ">>$crt") or die "Couldn't open $crt: $!";
132
136
    print CRT;
133
137
    print if ($opt_l);
134
138
    while (<TXT>) {
136
140
      print if ($opt_l);
137
141
      last if (/\*\*\*\*\* END LICENSE BLOCK \*\*\*\*\*/);
138
142
    }
139
 
    close(CRT) or die "Couldn't close $crt: $!";
140
143
  }
141
144
  next if /^#|^\s*$/;
142
145
  chomp;
143
146
  if (/^CVS_ID\s+\"(.*)\"/) {
144
 
    open(CRT, ">>$crt") or die "Couldn't open $crt: $!";
145
147
    print CRT "# $1\n";
146
 
    close(CRT) or die "Couldn't close $crt: $!";
147
148
  }
148
149
 
149
150
  # this is a match for the start of a certificate
184
185
      my $pem = "-----BEGIN CERTIFICATE-----\n"
185
186
              . MIME::Base64::encode($data)
186
187
              . "-----END CERTIFICATE-----\n";
187
 
      open(CRT, ">>$crt") or die "Couldn't open $crt: $!";
188
188
      print CRT "\n$caname\n";
189
189
      print CRT ("=" x length($caname) . "\n");
190
190
      if (!$opt_t) {
191
191
        print CRT $pem;
192
192
      }
193
 
      close(CRT) or die "Couldn't close $crt: $!";
194
193
      if ($opt_t) {
195
 
        open(TMP, "|$openssl x509 -md5 -fingerprint -text -inform PEM >> $crt") or die "Couldn't open openssl pipe: $!";
 
194
        open(TMP, "|$openssl x509 -md5 -fingerprint -text -inform PEM >> $crt") or die "Couldn't open openssl pipe: $!\n";
196
195
        print TMP $pem;
197
 
        close(TMP) or die "Couldn't close openssl pipe: $!";
 
196
        close(TMP) or die "Couldn't close openssl pipe: $!\n";
198
197
      }
199
 
      print "Parsing: $caname\n" if ($opt_v);
 
198
      print STDERR "Parsing: $caname\n" if ($opt_v);
200
199
      $certnum ++;
201
200
      $start_of_cert = 0;
202
201
    }
203
202
  }
204
203
}
205
 
close(TXT) or die "Couldn't close $txt: $!";
 
204
close(TXT) or die "Couldn't close $txt: $!\n";
 
205
close(CRT) or die "Couldn't close $crt.~: $!\n";
 
206
unless( $stdout ) {
 
207
    if ($opt_b && -e $crt) {
 
208
        my $bk = 1;
 
209
        while (-e "$crt.~${bk}~") {
 
210
            $bk++;
 
211
        }
 
212
        rename $crt, "$crt.~${bk}~" or die "Failed to create backup $crt.~$bk}~: $!\n";
 
213
    } elsif( -e $crt ) {
 
214
        unlink( $crt ) or die "Failed to remove $crt: $!\n";
 
215
    }
 
216
    rename "$crt.~", $crt or die "Failed to rename $crt.~ to $crt: $!\n";
 
217
}
206
218
unlink $txt if ($opt_u);
207
 
print "Done ($certnum CA certs processed, $skipnum untrusted skipped).\n" if (!$opt_q);
 
219
print STDERR "Done ($certnum CA certs processed, $skipnum untrusted skipped).\n" if (!$opt_q);
208
220
 
209
221
exit;
210
222