summaryrefslogtreecommitdiff
path: root/Echolot
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2002-07-06 01:31:39 +0000
committerPeter Palfrader <peter@palfrader.org>2002-07-06 01:31:39 +0000
commit35c85d14557e95e32546eedcaac7e39839073ebd (patch)
tree653920689a5da58945d1081a6d751c170b20114c /Echolot
parent93280fea38fe311792758ac25aff1dce1e43e884 (diff)
Build pgp keyrings
Diffstat (limited to 'Echolot')
-rw-r--r--Echolot/Config.pm3
-rw-r--r--Echolot/Stats.pm140
2 files changed, 138 insertions, 5 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 <peter@palfrader.org>
-# $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 <peter@palfrader.org>
-# $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;