keypin.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright (c) 2014-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_KEYPIN_H
  4. #define TOR_KEYPIN_H
  5. #include "lib/testsupport/testsupport.h"
  6. int keypin_check_and_add(const uint8_t *rsa_id_digest,
  7. const uint8_t *ed25519_id_key,
  8. const int replace_existing_entry);
  9. int keypin_check(const uint8_t *rsa_id_digest,
  10. const uint8_t *ed25519_id_key);
  11. int keypin_close_journal(void);
  12. #ifdef HAVE_MODULE_DIRAUTH
  13. int keypin_open_journal(const char *fname);
  14. int keypin_load_journal(const char *fname);
  15. #else
  16. static inline int
  17. keypin_open_journal(const char *fname)
  18. {
  19. (void)fname;
  20. return 0;
  21. }
  22. static inline int
  23. keypin_load_journal(const char *fname)
  24. {
  25. (void)fname;
  26. return 0;
  27. }
  28. #endif /* defined(HAVE_MODULE_DIRAUTH) */
  29. void keypin_clear(void);
  30. int keypin_check_lone_rsa(const uint8_t *rsa_id_digest);
  31. #define KEYPIN_FOUND 0
  32. #define KEYPIN_ADDED 1
  33. #define KEYPIN_MISMATCH -1
  34. #define KEYPIN_NOT_FOUND -2
  35. #ifdef KEYPIN_PRIVATE
  36. /**
  37. * In-memory representation of a key-pinning table entry.
  38. */
  39. typedef struct keypin_ent_st {
  40. HT_ENTRY(keypin_ent_st) rsamap_node;
  41. HT_ENTRY(keypin_ent_st) edmap_node;
  42. /** SHA1 hash of the RSA key */
  43. uint8_t rsa_id[DIGEST_LEN];
  44. /** Ed2219 key. */
  45. uint8_t ed25519_key[DIGEST256_LEN];
  46. } keypin_ent_t;
  47. STATIC keypin_ent_t * keypin_parse_journal_line(const char *cp);
  48. STATIC int keypin_load_journal_impl(const char *data, size_t size);
  49. MOCK_DECL(STATIC void, keypin_add_entry_to_map, (keypin_ent_t *ent));
  50. #endif /* defined(KEYPIN_PRIVATE) */
  51. #endif /* !defined(TOR_KEYPIN_H) */