File: stripkey.c

package info (click to toggle)
onak 0.3.6-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,088 kB
  • ctags: 606
  • sloc: ansic: 8,673; perl: 276; makefile: 131; sh: 36; sql: 21
file content (72 lines) | stat: -rw-r--r-- 2,068 bytes parent folder | download | duplicates (4)
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
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>

#include "armor.h"
#include "charfuncs.h"
#include "cleankey.h"
#include "keydb.h"
#include "keyid.h"
#include "keyindex.h"
#include "keystructs.h"
#include "log.h"
#include "mem.h"
#include "merge.h"
#include "onak-conf.h"
#include "parsekey.h"
#include "photoid.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;
  int result = 0;
  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 */

  result = read_openpgp_stream( stdin_getchar, NULL, &packets, 0 );
  result = parse_keys( packets, &keys );
  free_packet_list(packets);
  packets = NULL;
  result = cleankeys( keys );
  /* Iterate over the keys... */
  for( key = keys; key; key = key->next ) {
    uint64_t keyid = get_keyid( key );
    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( key, &packets, &list_end );
  }
  write_openpgp_stream( stdout_putchar, NULL, packets );
  return 0;
}