summaryrefslogtreecommitdiff
path: root/src/gpg2ssh/gnutls-helpers.h
blob: 9ea22a3491c90e8266fcd5a9b4c3c7c3f9a9732d (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(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. /* functions to get data into datum objects: */
  37. /* read the passed-in string, store in a single datum */
  38. int set_datum_string(gnutls_datum_t* d, const char* s);
  39. /* read the passed-in file descriptor until EOF, store in a single
  40. datum */
  41. int set_datum_fd(gnutls_datum_t* d, int fd);
  42. /* read the file indicated (by name) in the fname parameter. store
  43. its entire contents in a single datum. */
  44. int set_datum_file(gnutls_datum_t* d, const char* fname);
  45. /* set up file descriptor pipe for writing (child process pid gets
  46. stored in pid, fd is returned)*/
  47. int create_writing_pipe(pid_t* pid, const char* path, char* const argv[]);
  48. /* return 0 if userid matches the monkeysphere spec for ssh host user IDs */
  49. int validate_ssh_host_userid(const char* userid);
  50. /* how many bytes will it take to write out this datum in OpenPGP MPI form? */
  51. size_t get_openpgp_mpi_size(gnutls_datum_t* d);
  52. /* write the MPI stored in gnutls_datum_t to file descriptor fd: */
  53. int write_openpgp_mpi_to_fd(int fd, gnutls_datum_t* d);