-
Notifications
You must be signed in to change notification settings - Fork 0
/
stripkey.c
80 lines (74 loc) · 2.54 KB
/
stripkey.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* stripkey.c - Strip a key of all signatures except self-sigs.
*
* Copyright 2004 Daniel Silverstone <[email protected]>
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include "charfuncs.h"
#include "cleankey.h"
#include "keyid.h"
#include "keystructs.h"
#include "mem.h"
#include "parsekey.h"
#include "decodekey.h"
int main(int argc, char** argv) {
struct openpgp_packet_list *packets = NULL;
struct openpgp_packet_list *list_end = NULL;
struct openpgp_publickey *keys = NULL;
struct openpgp_publickey *key = NULL;
struct openpgp_signedpacket_list *uid = NULL;
struct openpgp_packet_list *sig = NULL;
struct openpgp_packet_list *prevsig = NULL;
uint64_t my_key = 0;
if( argc > 1 )
my_key = strtoull( argv[1], NULL, 16 );
/* expect a stream of openpgp packets on stdin comprising some keys */
/* strip each key of everything but its pubkey component, uids and
* selfsigs and revsigs on those selfsigs */
read_openpgp_stream( stdin_getchar, NULL, &packets, 0 );
parse_keys( packets, &keys );
free_packet_list(packets);
packets = NULL;
cleankeys(NULL, &keys, ONAK_CLEAN_ALL);
/* Iterate over the keys... */
for( key = keys; key; key = key->next ) {
uint64_t keyid;
get_keyid( key, &keyid );
for( uid = key->uids; uid; uid = uid->next ) {
REPEATTHISUID:
for( sig = uid->sigs, prevsig = NULL;
sig;
prevsig = sig, sig = sig->next ) {
uint64_t thissig = sig_keyid( sig->packet );
if( thissig != keyid && thissig != my_key ) {
/* Don't care about this packet... */
if( prevsig ) {
prevsig->next = sig->next;
} else {
uid->sigs = sig->next;
}
sig->next = NULL;
free_packet_list( sig );
goto REPEATTHISUID;
}
}
}
}
flatten_publickey( keys, &packets, &list_end );
write_openpgp_stream( stdout_putchar, NULL, packets );
return 0;
}