From 35c85d14557e95e32546eedcaac7e39839073ebd Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 6 Jul 2002 01:31:39 +0000 Subject: Build pgp keyrings --- Echolot/Config.pm | 3 +- Echolot/Stats.pm | 140 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- TODO | 1 - pingd | 7 +-- 4 files changed, 142 insertions(+), 9 deletions(-) diff --git a/Echolot/Config.pm b/Echolot/Config.pm index 0316afd..6bf37d5 100644 --- a/Echolot/Config.pm +++ b/Echolot/Config.pm @@ -1,7 +1,7 @@ package Echolot::Config; # (c) 2002 Peter Palfrader -# $Id: Config.pm,v 1.12 2002/07/06 00:50:27 weasel Exp $ +# $Id: Config.pm,v 1.13 2002/07/06 01:31:39 weasel Exp $ # =pod @@ -44,6 +44,7 @@ sub init($) { pinger_interval => 5*60, # send out pings every 5 minutes ping_every_nth_time => 48, # send out pings to the same remailer every 48 calls, i.e. every 4 hours buildstats => 5*60, # build statistics every 5 minutes + buildkeys => 8*60*60, # build keyring every 8 hours commitprospectives => 8*60*60, # commit prospective addresses every 8 hours expire => 24*60*60, # daily getkeyconf => 24*60*60, # daily diff --git a/Echolot/Stats.pm b/Echolot/Stats.pm index 2ed203f..9e17050 100644 --- a/Echolot/Stats.pm +++ b/Echolot/Stats.pm @@ -1,7 +1,7 @@ package Echolot::Stats; # (c) 2002 Peter Palfrader -# $Id: Stats.pm,v 1.10 2002/07/03 11:08:21 weasel Exp $ +# $Id: Stats.pm,v 1.11 2002/07/06 01:31:39 weasel Exp $ # =pod @@ -23,8 +23,7 @@ use Carp qw{cluck}; use constant DAYS => 12; use constant SECS_PER_DAY => 24 * 60 * 60; -#use constant DAYS => 12; -#use constant SECS_PER_DAY => 24 * 60 * 60; +use English; use Statistics::Distrib::Normal qw{}; @@ -435,9 +434,142 @@ sub build_mixring() { close(T2L); }; -sub build() { + + +sub build_pgpring_type($$$) { + my ($type, $GnuPG, $keyring) = @_; + + for my $remailer (Echolot::Globals::get()->{'storage'}->get_remailers()) { + next unless $remailer->{'showit'}; + my $addr = $remailer->{'address'}; + next unless Echolot::Globals::get()->{'storage'}->has_type($addr, $type); + + my %key; + for my $keyid (Echolot::Globals::get()->{'storage'}->get_keys($addr, $type)) { + my %new_key = Echolot::Globals::get()->{'storage'}->get_key($addr, $type, $keyid); + + if (!defined $key{'last_update'} || $key{'last_update'} < $new_key{'last_update'} ) { + %key = %new_key; + }; + }; + + # only if we have a conf + if ( defined Echolot::Globals::get()->{'storage'}->get_nick($addr) ) { + my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh ) + = ( IO::Handle->new(), + IO::Handle->new(), + IO::Handle->new(), + IO::Handle->new(), + ); + my $handles = GnuPG::Handles->new ( + stdin => $stdin_fh, + stdout => $stdout_fh, + stderr => $stderr_fh, + status => $status_fh + ); + my $pid = $GnuPG->wrap_call( + commands => [ '--import' ], + command_args => [qw{--no-options --no-default-keyring --fast-list-mode --keyring}, $keyring, '--', '-' ], + handles => $handles ); + print $stdin_fh $key{'key'}; + close($stdin_fh); + + my $stdout = join '', <$stdout_fh>; close($stdout_fh); + my $stderr = join '', <$stderr_fh>; close($stderr_fh); + my $status = join '', <$status_fh>; close($status_fh); + + waitpid $pid, 0; + + ($stdout eq '') or + cluck("GnuPG returned something in stdout '$stdout' while adding key for '$addr': So what?\n"); + unless ($status =~ /^^\[GNUPG:\] IMPORTED /m) { + if ($status =~ /^^\[GNUPG:\] IMPORT_RES /m) { + cluck("GnuPG status '$status' indicates more than one key for '$addr' imporeted. Ignoring.\n"); + } else { + cluck("GnuPG status '$status' didn't indicate key for '$addr' was imporeted correctly. Ignoring.\n"); + }; + }; + }; + }; + + return 1; +}; + +sub build_pgpring_export($$$) { + my ($GnuPG, $keyring, $file) = @_; + + my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh ) + = ( IO::Handle->new(), + IO::Handle->new(), + IO::Handle->new(), + IO::Handle->new(), + ); + my $handles = GnuPG::Handles->new ( + stdin => $stdin_fh, + stdout => $stdout_fh, + stderr => $stderr_fh, + status => $status_fh + ); + my $pid = $GnuPG->wrap_call( + commands => [ '--export' ], + command_args => [qw{--no-options --no-default-keyring --keyring}, $keyring ], + handles => $handles ); + close($stdin_fh); + + my $stdout = join '', <$stdout_fh>; close($stdout_fh); + my $stderr = join '', <$stderr_fh>; close($stderr_fh); + my $status = join '', <$status_fh>; close($status_fh); + + waitpid $pid, 0; + + open (F, ">$file") or + cluck ("Cannot open '$file': $!"), + return 0; + print F $stdout; + close F; + return 1; +}; + +sub build_pgpring() { + my $GnuPG = new GnuPG::Interface; + $GnuPG->options->hash_init( + armor => 1, + homedir => Echolot::Config::get()->{'gnupghome'} ); + $GnuPG->options->meta_interactive( 0 ); + + my $keyring = Echolot::Config::get()->{'tmpdir'}.'/'. + Echolot::Globals::get()->{'hostname'}.".".time.'.'.$PROCESS_ID.'_'.Echolot::Globals::get()->{'internalcounter'}++.'.keyring'; + + + build_pgpring_type('cpunk-rsa', $GnuPG, $keyring) or + cluck("build_pgpring_type failed"), + return undef; + + build_pgpring_export($GnuPG, $keyring, Echolot::Config::get()->{'resultdir'}.'/pgp-rsa.asc') or + cluck("build_pgpring_export failed"), + return undef; + + build_pgpring_type('cpunk-dsa', $GnuPG, $keyring) or + cluck("build_pgpring_type failed"), + return undef; + + build_pgpring_export($GnuPG, $keyring, Echolot::Config::get()->{'resultdir'}.'/pgp-all.asc') or + cluck("build_pgpring_export failed"), + return undef; + + + unlink ($keyring) or + cluck("Cannot unlink tmp keyring '$keyring'"), + return undef; + unlink ($keyring.'~'); # gnupg does those evil backups +}; + +sub build_stats() { build_lists(); +}; +sub build_keys() { build_mixring(); + build_pgpring(); }; 1; diff --git a/TODO b/TODO index 40b3f3b..29495dc 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,4 @@ for 2.0: - build pgp public rings build html files for *list for later: diff --git a/pingd b/pingd index 8023f0b..dac0562 100755 --- a/pingd +++ b/pingd @@ -1,7 +1,7 @@ #!/usr/bin/perl -wT # (c) 2002 Peter Palfrader -# $Id: pingd,v 1.17 2002/07/06 00:50:27 weasel Exp $ +# $Id: pingd,v 1.18 2002/07/06 01:31:39 weasel Exp $ # =pod @@ -341,7 +341,8 @@ sub daemon_run() { $scheduler->add('processmail' , Echolot::Config::get()->{'processmail'} , 0, \&Echolot::Mailin::process ); $scheduler->add('ping' , Echolot::Config::get()->{'pinger_interval'} , 0, \&Echolot::Pinger::send_pings ); - $scheduler->add('buildstats' , Echolot::Config::get()->{'buildstats'} , 0, \&Echolot::Stats::build ); + $scheduler->add('buildstats' , Echolot::Config::get()->{'buildstats'} , 0, \&Echolot::Stats::build_stats ); + $scheduler->add('buildkeys' , Echolot::Config::get()->{'buildkeys'} , 0, \&Echolot::Stats::build_keys ); $scheduler->add('buildthesaurus' , Echolot::Config::get()->{'build_thesaurus'} , 0, \&Echolot::Thesaurus::build_thesaurus ); $scheduler->add('commitprospectives' , Echolot::Config::get()->{'commitprospectives'} , 0, \&commit_prospective_address ); @@ -360,7 +361,7 @@ sub daemon_run() { sub send_sig($) { my ($sig) = @_; - die ("Pidfile '".Echolot::Config::get()->{'pidfile'}."' does exist\n") + die ("Pidfile '".Echolot::Config::get()->{'pidfile'}."' does not exist\n") unless pid_exists(); open (PIDFILE, '<'.Echolot::Config::get()->{'pidfile'}) or croak ("Cannot open pidfile '".Echolot::Config::get()->{'pidfile'}."': $!\n"); -- cgit v1.2.3