summaryrefslogtreecommitdiff
path: root/src/keytrans/gnutls-helpers.h
blob: bf54af0f93ec1a3f75951a715d1c1874b3dfb5e2 (plain)
  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. #include <gnutls/gnutls.h>
  5. #include <gnutls/openpgp.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #include <errno.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <unistd.h>
  13. #include <stdarg.h>
  14. /* Functions to help dealing with GnuTLS for monkeysphere key
  15. translation projects: */
  16. /* set everything up, including logging levels. Return 0 on
  17. success */
  18. int init_gnutls();
  19. /* logging and output functions: */
  20. void err(int level, const char* fmt, ...);
  21. void logfunc(int level, const char* string);
  22. /* basic datum manipulations: */
  23. void init_datum(gnutls_datum_t* d);
  24. void copy_datum(gnutls_datum_t* dest, const gnutls_datum_t* src);
  25. int compare_data(const gnutls_datum_t* a, const gnutls_datum_t* b);
  26. void free_datum(gnutls_datum_t* d);
  27. int write_datum_fd(int fd, const gnutls_datum_t* d);
  28. int write_datum_fd_with_length(int fd, const gnutls_datum_t* d);
  29. int write_data_fd_with_length(int fd, const gnutls_datum_t** d, unsigned int num);
  30. /* set up a datum from a null-terminated string */
  31. int datum_from_string(gnutls_datum_t* d, const char* str);
  32. /* keyid manipulations: */
  33. typedef unsigned char printable_keyid[16];
  34. void init_keyid(gnutls_openpgp_keyid_t keyid);
  35. void make_keyid_printable(printable_keyid out, gnutls_openpgp_keyid_t keyid);
  36. void collapse_printable_keyid(gnutls_openpgp_keyid_t out, printable_keyid in);
  37. int convert_string_to_keyid(gnutls_openpgp_keyid_t out, const char* str);
  38. int convert_string_to_printable_keyid(printable_keyid out, const char* str);
  39. /* you must have twice as many bytes in the out buffer as in the in buffer */
  40. void hex_print_data(char* out, const unsigned char* in, size_t incount);
  41. /* expects a null-terminated string as in, containing an even number
  42. of hexadecimal characters.
  43. returns length in *bits* of raw data as output.
  44. the out buffer must be at least half as long as in to hold the
  45. output. if out is NULL, no output will be generated, but the
  46. length will still be returned.
  47. */
  48. unsigned int hexstring2bin(unsigned char* out, const char* in);
  49. /* functions to get data into datum objects: */
  50. /* read the passed-in string, store in a single datum */
  51. int set_datum_string(gnutls_datum_t* d, const char* s);
  52. /* read the passed-in file descriptor until EOF, store in a single
  53. datum */
  54. int set_datum_fd(gnutls_datum_t* d, int fd);
  55. /* read the file indicated (by name) in the fname parameter. store
  56. its entire contents in a single datum. */
  57. int set_datum_file(gnutls_datum_t* d, const char* fname);
  58. /* set up file descriptor pipe for writing (child process pid gets
  59. stored in pid, fd is returned)*/
  60. int create_writing_pipe(pid_t* pid, const char* path, char* const argv[]);
  61. /* return 0 if userid matches the monkeysphere spec for ssh host user IDs */
  62. int validate_ssh_host_userid(const char* userid);
  63. /* how many bytes will it take to write out this datum in OpenPGP MPI form? */
  64. size_t get_openpgp_mpi_size(gnutls_datum_t* d);
  65. /* write the MPI stored in gnutls_datum_t to file descriptor fd: */
  66. int write_openpgp_mpi_to_fd(int fd, gnutls_datum_t* d);