~ubuntu-branches/ubuntu/natty/signing-party/natty

« back to all changes in this revision

Viewing changes to caff/caff

  • Committer: Bazaar Package Importer
  • Author(s): Franck Joncourt
  • Date: 2009-09-24 19:29:07 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: james.westby@ubuntu.com-20090924192907-2vk4ffjvc3070x6z
Tags: upstream-1.1.2
ImportĀ upstreamĀ versionĀ 1.1.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/perl -w
2
2
 
3
3
# caff  --  CA - Fire and Forget
4
 
# $Id: caff 429 2009-06-06 15:47:07Z thijs $
 
4
# $Id: caff 439 2009-08-30 10:12:07Z thialme-guest $
5
5
#
6
6
# Copyright (c) 2004, 2005, 2006 Peter Palfrader <peter@palfrader.org>
7
7
# Copyright (c) 2005, 2006 Christoph Berg <cb@df7cb.de>
323
323
use GnuPG::Interface;
324
324
 
325
325
my %CONFIG;
326
 
my $REVISION = '$Rev: 429 $';
 
326
my $REVISION = '$Rev: 439 $';
327
327
my ($REVISION_NUMER) = $REVISION =~ /(\d+)/;
328
328
my $VERSION = "0.0.0.$REVISION_NUMER";
329
329
 
330
330
 
 
331
##
 
332
# Display an error message on STDERR and then exit.
 
333
#
 
334
# @param $exitcode exit code status to use to end the program
 
335
# @param $line     error message to display on STDERR
 
336
#
 
337
sub myerror($$) {
 
338
        my ($exitcode, $line) = @_;
 
339
        print "[ERROR] $line\n";        
 
340
        exit $exitcode;
 
341
};
331
342
 
332
343
sub mywarn($) {
333
344
        my ($line) = @_;
891
902
        return $signed_by_me;
892
903
};
893
904
 
 
905
##
 
906
# Check the local user keys.
 
907
#
 
908
# This function checks if the keyids defined through the --local-user
 
909
# command line option or set in .caffrc are valid and known to be one of the
 
910
# keyids listed in ./caffrc. The last check ensure we have those keyids
 
911
# available in the caff's gnupghome directory.
 
912
#
 
913
# @return an array containing the local user keys\n
 
914
#         (undef) if no key has been specified
 
915
#
 
916
sub get_local_user_keys()
 
917
{
 
918
        my @local_user = ();
 
919
        my @key_list;
 
920
        
 
921
        # No user-defined key id has been specified by the user, no need for
 
922
        # further checks
 
923
        if (!$CONFIG{'local-user'}) {
 
924
                return (undef);
 
925
        }       
 
926
        
 
927
        # Parse the list of keys
 
928
        if (ref($CONFIG{'local-user'})) {
 
929
                @key_list = @{$CONFIG{'local-user'}};
 
930
        }
 
931
        else {
 
932
                @key_list = split /\s*,\s*/, $CONFIG{'local-user'};
 
933
        }
 
934
 
 
935
        # Check every key defined by the user...
 
936
        for my $user_key (@key_list) {
 
937
                
 
938
                $user_key =~ s/^0x//i;
 
939
                $user_key = uc($user_key);
 
940
                
 
941
                unless ($user_key =~ m/^([A-F0-9]{8}|[A-F0-9]{16}|[A-F0-9]{40})$/) {
 
942
                        mywarn "Local-user $user_key is not a valid keyid.";
 
943
                        next;
 
944
                }
 
945
                
 
946
                unless (grep (/$user_key$/, @{$CONFIG{'keyid'}})) {
 
947
                        mywarn "Local-user $user_key is not defined as one of your keyid in ./caffrc (it will not be used).";
 
948
                        next;
 
949
                }
 
950
                
 
951
                push (@local_user, $user_key);
 
952
        }
 
953
 
 
954
        # If no local-user key are valid, there is no need to go further
 
955
        unless (defined $local_user[0]) {
 
956
                myerror (1, "None of the local-user keys seem to be known as a keyid listed in ./caffrc.");
 
957
        }
 
958
 
 
959
        return @local_user;
 
960
}
 
961
 
894
962
 
895
963
###################
896
964
# argument handling
1074
1142
        $CONFIG{'no-sign'} = ! ask("Continue with signing?", 1);
1075
1143
}
1076
1144
        
1077
 
unless ($CONFIG{'no-sign'}) {
1078
 
        my @local_user;
1079
 
        if ($CONFIG{'local-user'}) {
1080
 
                if (ref($CONFIG{'local-user'})) {
1081
 
                        @local_user = @{$CONFIG{'local-user'}};
1082
 
                } else {
1083
 
                        @local_user = split /\s*,\s*/, $CONFIG{'local-user'};
1084
 
                };
1085
 
                foreach (@local_user) {
1086
 
                        s/^0x//i;
1087
 
                        unless (/^([A-F0-9]{8}|[A-F0-9]{16}|[A-F0-9]{40})$/i) {
1088
 
                                print STDERR "Local-user $_ is not a keyid.\n";
1089
 
                                usage(\*STDERR, 1);
1090
 
                        };
1091
 
                        $_ = uc($_);
1092
 
                };
1093
 
        } else {
1094
 
                @local_user = (undef);
1095
 
        };
 
1145
unless ($CONFIG{'no-sign'})
 
1146
{
 
1147
        my @local_user = &get_local_user_keys();
1096
1148
 
1097
1149
        info("Sign the following keys according to your policy, then exit gpg with 'save' after signing each key");
1098
1150
        for my $keyid (@keyids_ok) {