root/trunk/hotstuff/scripts/ghnssignature

Revision 446, 2.4 KB (checked in by josef, 4 years ago)

- adapt copyright headers to the updated licence

  • Property svn:executable set to *
Line 
1#!/usr/bin/env perl
2#
3# GHNS Signature - manage digital signatures on files in SVN-backed repository
4# Copyright (C) 2007 Josef Spillner <josef@kstuff.org>
5# Published under 'GNU AGPLv3 or later' conditions
6
7use strict;
8use XML::DOM;
9
10if(($ARGV[0] eq "-h") || ($ARGV[0] eq "--help") || (!$ARGV[0])){
11        print "Synopsis: ghnssignature --sign|--verify|--auto [<payloadfile>]\n";
12        print "\n";
13        print "If no payloadfile is given, it will scan all *.meta files to find\n";
14        print "them on its own.\n";
15        print "The --auto option will sign if needed, and add signature to SVN.\n";
16        exit;
17}
18
19my $mode = $ARGV[0];
20if(($mode eq "--sign") || ($mode eq "--verify") || ($mode eq "--auto")){
21}else{
22        print "Error: action must be --sign or --verify or --auto.\n";
23        exit 1;
24}
25
26my @files;
27if($ARGV[1]){
28        my $file = $ARGV[1];
29        push @files, $file;
30}else{
31        my @metafiles = glob("*.meta");
32        my $parser = new XML::DOM::Parser;
33        foreach my $metafile(@metafiles){
34                #print "??? $metafile\n";
35                my $doc = $parser->parsefile($metafile);
36                my $root = $doc->getDocumentElement();
37                my @payloads = $root->getElementsByTagName("payload");
38                foreach my $payload(@payloads){
39                        my $file = $payload->getFirstChild->getData;
40                        #print "!!! $file\n";
41                        push @files, $file;
42                }
43        }
44}
45
46my $identityfile = "identity.txt";
47if(!(-f $identityfile)){
48        print "Error: no file '$identityfile' found.\n";
49        exit 1;
50}
51
52open(F, $identityfile);
53my $id = <F>;
54close(F);
55
56chomp $id;
57if(!$id){
58        print "Error: couldn't read identity from '$identityfile'.\n";
59        exit 1;
60}
61
62sub verify{
63        my $file = shift(@_);
64        my $x = system("gpg --verify $file.asc");
65        return $x;
66}
67
68sub sign{
69        my $file = shift(@_);
70        my $id = shift(@_);
71        my $x = system("gpg --local-user $id --armor --detach-sign $file");
72        return $x;
73}
74
75if($mode eq "--verify"){
76        foreach my $file(@files){
77                my $x = verify($file);
78                if($x != 0){
79                        print "Error: cannot verify $file.asc.\n";
80                        exit $x;
81                }
82        }
83}
84
85if($mode eq "--sign"){
86        foreach my $file(@files){
87                my $x = sign($file, $id);
88                if($x != 0){
89                        print "Error: signature could not be created.\n";
90                        exit $x;
91                }
92        }
93}
94
95if($mode eq "--auto"){
96        foreach my $file(@files){
97                my $newsignature = 0;
98                my $x = -1;
99                if(!(-f "$file.asc")){
100                        $newsignature = 1;
101                }else{
102                        $x = verify($file);
103                }
104                if($x != 0){
105                        print "File $file needs to be signed...\n";
106                        my $x = sign($file, $id);
107                        if($x != 0){
108                                print "Error: signature could not be created.\n";
109                                exit $x;
110                        }
111                        if($newsignature){
112                                system("svn add $file.asc");
113                        }
114                }
115        }
116}
117
Note: See TracBrowser for help on using the browser.