File dumpsigs of Package suse-build-key
93
1
#!/usr/bin/perl -w
2
# dump all keys contained in the keyring specified as argument
3
4
use strict;
5
6
my @keyring;
7
8
die "must specify keyring\n" unless @ARGV;
9
10
my $file = shift @ARGV;
11
unless ($file =~ /^\//) {
12
use Cwd qw/abs_path/;
13
$file = abs_path($file);
14
}
15
16
# XXX: workaround for colons in obs project names o_O
17
if ($file =~ /:/) {
18
use File::Temp qw/tempdir/;
19
my $tmpdir = tempdir( CLEANUP => 1);
20
my $nn = $file;
21
$nn =~ s/.*\///;
22
$nn = $tmpdir.'/'.$nn;
23
symlink($file, $nn) or die "failed to symlink: $!\n";
24
$file = $nn;
25
}
26
27
@keyring = ('--no-default-keyring', '--keyring='.$file);
28
29
my @line;
30
my $ver;
31
my $rel;
32
my $name;
33
my %names;
34
35
my @cmd = qw/--no-secmem-warning --no-options --list-sigs --list-options show-keyring --fixed-list-mode --with-colons/;
36
unshift @cmd, @keyring;
37
unshift @cmd, 'gpg';
38
#print join(' ', @cmd), "\n";
39
40
open(GPG, '-|', @cmd);
41
while (<GPG>) {
42
chomp;
43
next unless /^pub:/;
44
@line = split(':', $_);
45
my $id = $line[4];
46
$_ = <GPG>;
47
$_ = <GPG> if /^fpr:/;
48
chomp;
49
next unless /^uid:/;
50
@line = split(':', $_);
51
$name = $line[9];
52
while (1) {
53
$_ = <GPG>;
54
chomp;
55
next unless /^sig:/;
56
@line = split(':', $_);
57
next if $line[4] ne $id;
58
$ver = lc($id);
59
$ver =~ s/.*(........)$/$1/;
60
$rel = sprintf("%08x", $line[5]);
61
last;
62
}
63
$names{"gpg-pubkey-$ver-$rel"} = [ $id, $name ];
64
}
65
close GPG;
66
my $n;
67
68
for $n (sort keys %names) {
69
@cmd = qw/--no-options --no-secmem-warning --export-options export-minimal --export -a/;
70
push @cmd, $names{$n}[0];
71
unshift @cmd, @keyring;
72
unshift @cmd, 'gpg';
73
my $fn = $n.".asc";
74
unless (open(O, '>', $fn)) {
75
warn "failed to open $fn: $!";
76
next;
77
}
78
printf O "%s %s\n\n", $names{$n}[0], $names{$n}[1];
79
print "writing $fn\n";
80
#print join(' ', @cmd), "\n";
81
unless (open(GPG, '-|', @cmd)) {
82
warn "failed to exec gpg: $!";
83
close O;
84
unlink $fn;
85
next;
86
}
87
while(<GPG>) {
88
print O;
89
}
90
close GPG;
91
close O;
92
}
93