Update Debian Vcs-* fields to point to git repository
[onak.git] / stripkey.c
1 /*
2  * stripkey.c - Strip a key of all signatures except self-sigs.
3  *
4  * Copyright 2004 Daniel Silverstone <dsilvers@digital-scurf.org>
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU General Public License as published by the Free
8  * Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program; if not, write to the Free Software Foundation, Inc., 51
17  * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #include <getopt.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <unistd.h>
25 #include <fcntl.h>
26
27 #include "armor.h"
28 #include "charfuncs.h"
29 #include "cleankey.h"
30 #include "keydb.h"
31 #include "keyid.h"
32 #include "keyindex.h"
33 #include "keystructs.h"
34 #include "log.h"
35 #include "mem.h"
36 #include "merge.h"
37 #include "onak-conf.h"
38 #include "parsekey.h"
39 #include "photoid.h"
40 #include "decodekey.h"
41
42 int main(int argc, char** argv) {
43   struct openpgp_packet_list *packets = NULL;
44   struct openpgp_packet_list *list_end = NULL;
45   struct openpgp_publickey   *keys = NULL;
46   struct openpgp_publickey   *key = NULL;
47   struct openpgp_signedpacket_list *uid = NULL;
48   struct openpgp_packet_list *sig = NULL;
49   struct openpgp_packet_list *prevsig = NULL;
50   uint64_t my_key = 0;
51
52   if( argc > 1 )
53      my_key = strtoull( argv[1], NULL, 16 );
54    
55   /* expect a stream of openpgp packets on stdin comprising some keys */
56   /* strip each key of everything but its pubkey component, uids and
57    * selfsigs and revsigs on those selfsigs */
58
59   read_openpgp_stream( stdin_getchar, NULL, &packets, 0 );
60   parse_keys( packets, &keys );
61   free_packet_list(packets);
62   packets = NULL;
63   cleankeys( keys );
64   /* Iterate over the keys... */
65   for( key = keys; key; key = key->next ) {
66     uint64_t keyid;
67     get_keyid( key, &keyid );
68     for( uid = key->uids; uid; uid = uid->next ) {
69       REPEATTHISUID: 
70       for( sig = uid->sigs, prevsig = NULL; 
71            sig; 
72            prevsig = sig, sig = sig->next ) {
73         uint64_t thissig = sig_keyid( sig->packet );
74         if( thissig != keyid && thissig != my_key ) {
75           /* Don't care about this packet... */
76           if( prevsig ) {
77             prevsig->next = sig->next;
78           } else {
79             uid->sigs = sig->next;
80           }
81           sig->next = NULL;
82           free_packet_list( sig );
83           goto REPEATTHISUID;
84         }
85       }
86     }
87   }
88   flatten_publickey( keys, &packets, &list_end );
89   write_openpgp_stream( stdout_putchar, NULL, packets );
90   return 0;
91 }