initial pass at converting PEM-encoded private keys into OpenPGP public keys.
[monkeysphere.git] / gnutls-helpers.h
1 /* Author: Daniel Kahn Gillmor <dkg@fifthhorseman.net> */
2 /* Date: Fri, 04 Apr 2008 19:31:16 -0400 */
3 /* License: GPL v3 or later */
4
5
6 #include <gnutls/gnutls.h>
7 #include <gnutls/openpgp.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <unistd.h>
15 #include <stdarg.h>
16
17 /* Functions to help dealing with GnuTLS for monkeysphere key
18    translation projects: */
19
20 /* set everything up, including logging levels.  Return 0 on
21    success */
22 int init_gnutls();
23
24 /* logging and output functions: */
25
26 void err(const char* fmt, ...);
27 void logfunc(int level, const char* string);
28
29 /* basic datum manipulations: */
30
31 void init_datum(gnutls_datum_t* d);
32 void copy_datum(gnutls_datum_t* dest, const gnutls_datum_t* src);
33 int compare_data(const gnutls_datum_t* a, const gnutls_datum_t* b);
34 void free_datum(gnutls_datum_t* d);
35 int write_datum_fd(int fd, const gnutls_datum_t* d);
36 int write_datum_fd_with_length(int fd, const gnutls_datum_t* d);
37 int write_data_fd_with_length(int fd, const gnutls_datum_t** d, unsigned int num);
38
39 /* set up a datum from a null-terminated string */
40 int datum_from_string(gnutls_datum_t* d, const char* str);
41
42 /* keyid manipulations: */
43 typedef unsigned char printable_keyid[16];
44
45 void init_keyid(gnutls_openpgp_keyid_t keyid);
46 void make_keyid_printable(printable_keyid out, gnutls_openpgp_keyid_t keyid);
47
48 /* functions to get data into datum objects: */
49
50 /* read the passed-in string, store in a single datum */
51 int set_datum_string(gnutls_datum_t* d, const char* s);
52
53 /* read the passed-in file descriptor until EOF, store in a single
54    datum */
55 int set_datum_fd(gnutls_datum_t* d, int fd);
56
57 /* read the file indicated (by name) in the fname parameter.  store
58    its entire contents in a single datum. */
59 int set_datum_file(gnutls_datum_t* d, const char* fname);
60
61 /* set up file descriptor pipe for writing (child process pid gets
62    stored in pid, fd is returned)*/
63 int create_writing_pipe(pid_t* pid, const char* path, char* const argv[]);
64
65 /* return 0 if userid matches the monkeysphere spec for ssh host user IDs */
66 int validate_ssh_host_userid(const char* userid);
67
68 /* how many bytes will it take to write out this datum in OpenPGP MPI form? */
69 size_t get_openpgp_mpi_size(gnutls_datum_t* d);
70
71 /* write the MPI stored in gnutls_datum_t to file descriptor fd: */
72 int write_openpgp_mpi_to_fd(int fd, gnutls_datum_t* d);