Ticket #39362: patch-smime_keys.diff
File patch-smime_keys.diff, 2.2 KB (added by wjb+macport@…, 11 years ago) |
---|
-
smime_keys.pl
a b 80 80 # OPS 81 81 # 82 82 83 sub get_certs { 84 my $file = shift; 85 return undef unless (defined($file) && -e $file); 86 87 open IN, "<$file"; 88 89 my @certs = (); 90 my $in_cert = 0; 91 my $cert = q{}; 92 while ( <IN> ) { 93 $in_cert = 1 if ( /^-----BEGIN CERTIFICATE-----$/ ); 94 $cert .= $_; 95 96 if ( /^-----END CERTIFICATE-----$/ ) { 97 push @certs, $cert; 98 $cert = q{}; 99 $in_cert = 0; 100 } 101 } 102 103 return @certs; 104 } 105 83 106 if(@ARGV == 1 and $ARGV[0] eq "init") { 84 107 init_paths; 85 108 } … … 90 113 change_label($ARGV[1]); 91 114 } 92 115 elsif(@ARGV == 2 and $ARGV[0] eq "add_cert") { 93 my $format = -B $ARGV[1] ? 'DER' : 'PEM'; 94 my $cmd = "$opensslbin x509 -noout -hash -in $ARGV[1] -inform $format"; 116 foreach my $cert ( get_certs( $ARGV[1] ) ) { 117 118 my $file = sprintf( '/tmp/smime-%d.%d', $$, int(rand( 999999 ) ) ); 119 print STDERR "TMPFILE: $file\n"; 120 if ( -e $file ) { 121 die( "ERROR: TMPFILE $file existss?!?!" ); 122 } 123 open OUT, ">$file"; 124 print OUT $cert; 125 close OUT; 126 127 my $format = -B $file ? 'DER' : 'PEM'; 128 my $cmd = "$opensslbin x509 -noout -hash -in $file -inform $format"; 95 129 my $cert_hash = `$cmd`; 96 130 $? and die "'$cmd' returned $?"; 97 131 chomp($cert_hash); 98 132 my $label = query_label; 99 &add_certificate($ARGV[1], \$cert_hash, 1, $label, '?'); 133 &add_certificate($file, \$cert_hash, 1, $label, '?'); 134 unlink $file; 135 } 100 136 } 101 137 elsif(@ARGV == 2 and $ARGV[0] eq "add_pem") { 102 138 -e $ARGV[1] and -s $ARGV[1] or die("$ARGV[1] is nonexistent or empty."); … … 380 416 print "the key ID. This has to be _one_ word (no whitespaces).\n\n"; 381 417 382 418 print "Enter label: "; 383 chomp($input = <STDIN>); 419 $input = <STDIN>; 420 chomp($input) if ( defined($input) ); 384 421 385 my ($label, $junk) = split(/\s/, $input, 2) ;422 my ($label, $junk) = split(/\s/, $input, 2) if ( defined($input) ); 386 423 387 424 defined $junk 388 425 and print "\nUsing '$label' as label; ignoring '$junk'\n";