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