1 /* keymgmt.h - headers for keymgmt.c
2 */
3 
4 #include "idea.h" /* Declaration of IdeaCfbContext */
5 
6 /*	Return printable public key fragment. */
7 char *keyIDstring(byte *keyID);
8 char *key2IDstring(unitptr n);
9 extern char const blankkeyID[];
10 
11 /* Do an RSA key pair generation, and write them out to the keyring files. */
12 int dokeygen(char *numstr, char *numstr2, word32 factor1, word32 factor2, word32 mask1, word32 mask2, char *username);
13 
14 /* Edit the userid and/or pass phrase for an RSA key pair, and put them	back
15    into the ring files */
16 int dokeyedit(char *mcguffin, char *ringfile);
17 
18 /* Copy the first entry in key ring that has mcguffin string in userid and
19    put it into keyfile */
20 int extract_from_keyring (char *mcguffin, char *keyfile, char *ringfile,
21 						  boolean transflag);
22 
23 /* Lists all entries in keyring that have mcguffin string in userid */
24 int view_keyring(char *mcguffin, char *ringfile,
25 		 boolean show_signatures, boolean show_hashes);
26 
27 /* Signature-check all entries in keyring that have mcguffin string
28    in userid */
29 int dokeycheck(char *mcguffin, char *ringfile, int options);
30 /* options: */
31 #define	CHECK_ALL	0	/* Check all signatures */
32 #define CHECK_NEW	1	/* Only check new signatures */
33 
34 /* Allow user to remove signatures from keys in keyring that have mcguffin */
35 int remove_sigs(char *mcguffin, char *ringfile);
36 
37 /* Remove the first entry in key ring that has mcguffin string in userid */
38 int remove_from_keyring(byte *keyID, char *mcguffin,
39 			char *ringfile, boolean secring_too);
40 
41 /* Extract key fragment from modulus n */
42 void extract_keyID(byteptr keyID, unitptr n);
43 
44 /* Write message prefix keyID to a file */
45 void writekeyID(unitptr n, FILE *f);
46 
47 /* Extract public key corresponding to keyID or userid from keyfile */
48 int getpublickey(int flags, char *keyfile,
49 		 long *file_position, int *pktlen, byte *keyID,
50 		 byte *timestamp, byte *validity, byte *userid,
51 		 unitptr n, unitptr e, long *lastpos);
52 /* flags: */
53 #define	GPK_GIVEUP	1
54 #define	GPK_SHOW	2
55 #define	GPK_NORVK	4
56 #define	GPK_DISABLED	8
57 /* Flag used in getsecretkey() only - should it be GSK_? */
58 /* Prevents use of existing password list. */
59 #define GPK_ASKPASS	16
60 #define GPK_SECRET	32	/* We are actually getting a secret key */
time_point_put(size_t refs=0)61 #define GPK_INVRVK      64      /* revoked keys are invalid. */
62 
63 #ifdef MACTC5
64 int getfirstsecretkey(boolean giveup, boolean showkey, char *keyfile, byte *keyID,
65 	byte *timestamp, byte *validity, char *passp, boolean *hkey,
66 	byte *userid, unitptr n, unitptr e, unitptr d, unitptr p, unitptr q,
67 	unitptr u);
68 #endif
69 
70 /* Extract private key corresponding to keyID or userid from keyfile */
71 int getsecretkey(int flags, char *keyfile, byte *keyID, byte *timestamp, byte *validity,
72 			byte *hpass, boolean *hkey, byte *userid,
73 			unitptr n, unitptr e, unitptr d, unitptr p, unitptr q,
74 			unitptr u);
75 
76 /* Return true if ctb is one for a key in a keyring */
77 int is_key_ctb (byte ctb);
78 
79 /* Read next key packet from file f, return its ctb in *pctb, and advance
80  * the file pointer to point beyond the key packet.
81  */
82 short nextkeypacket(FILE *f, byte *pctb);
83 
84 /* Read the next key packet from file f, return info about it in the various
85  * pointers.  Most pointers can be NULL without breaking it.
86  */
87 short readkeypacket(FILE *f, struct IdeaCfbContext *cfb, byte *pctb,
88 	byte *timestamp, byte *validity, char *userid,
89 	unitptr n ,unitptr e, unitptr d, unitptr p, unitptr q, unitptr u,
90 	byte *sigkeyID, byte *keyctrl, byte *sigtype);
91 
92 /* Starting at key_position in keyfile, scan for the userid packet which
put(iter_type i,std::ios_base & ios,char_type fill,time_point<Clock,Duration> const & tp,const CharT * pattern,const CharT * pat_end) const93  * matches C string userid.  Return the packet position and size.
94  */
95 int getpubuserid(char *keyfile, long key_position, byte *userid,
96 	long *userid_position, int *userid_len, boolean exact_match);
97 
98 int getpubusersig(char *keyfile, long user_position, byte *sigkeyID,
99 	byte *timestamp, long *sig_position, int *sig_len);
100 
101 void getKeyHash( byte *hash, unitptr n, unitptr e );
102 void printKeyHash( byteptr hash, boolean indent );
103 
104 extern int is_compromised(FILE *f);
105 
106 int disable_key(char *, char *);
107 
108 void kv_title(FILE *fo);
109 
put(time_point_units<CharT> const & units_facet,iter_type s,std::ios_base & ios,char_type fill,time_point<Clock,Duration> const & tp,const CharT * pattern,const CharT * pat_end) const110 int  kvformat_keypacket(FILE *f, FILE *pgpout, boolean one_key,
111                         char *mcguffin, char *ringfile,
112                         boolean show_signatures, boolean show_hashes,
113                         int *keycounter);
114