Tor 0.4.9.0-alpha-dev
keypin.h
Go to the documentation of this file.
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
13
14int keypin_check_and_add(const uint8_t *rsa_id_digest,
15 const uint8_t *ed25519_id_key,
16 const int replace_existing_entry);
17int keypin_check(const uint8_t *rsa_id_digest,
18 const uint8_t *ed25519_id_key);
19int keypin_close_journal(void);
20
21#ifdef HAVE_MODULE_DIRAUTH
22int keypin_open_journal(const char *fname);
23int keypin_load_journal(const char *fname);
24#else
25static inline int
26keypin_open_journal(const char *fname)
27{
28 (void)fname;
29 return 0;
30}
31static inline int
32keypin_load_journal(const char *fname)
33{
34 (void)fname;
35 return 0;
36}
37#endif /* defined(HAVE_MODULE_DIRAUTH) */
38void keypin_clear(void);
39int 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 */
53typedef 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
62STATIC keypin_ent_t * keypin_parse_journal_line(const char *cp);
63STATIC int keypin_load_journal_impl(const char *data, size_t size);
64
65MOCK_DECL(STATIC void, keypin_add_entry_to_map, (keypin_ent_t *ent));
66#endif /* defined(KEYPIN_PRIVATE) */
67
68#endif /* !defined(TOR_KEYPIN_H) */
#define DIGEST_LEN
Definition: digest_sizes.h:20
#define DIGEST256_LEN
Definition: digest_sizes.h:23
STATIC void keypin_add_entry_to_map(keypin_ent_t *ent)
Definition: keypin.c:216
int keypin_load_journal(const char *fname)
Definition: keypin.c:448
STATIC int keypin_load_journal_impl(const char *data, size_t size)
Definition: keypin.c:374
int keypin_open_journal(const char *fname)
Definition: keypin.c:301
STATIC keypin_ent_t * keypin_parse_journal_line(const char *cp)
Definition: keypin.c:468
void keypin_clear(void)
Definition: keypin.c:487
int keypin_check_lone_rsa(const uint8_t *rsa_id_digest)
Definition: keypin.c:280
int keypin_check(const uint8_t *rsa_id_digest, const uint8_t *ed25519_id_key)
Definition: keypin.c:153
int keypin_check_and_add(const uint8_t *rsa_id_digest, const uint8_t *ed25519_id_key, const int replace_existing_entry)
Definition: keypin.c:140
int keypin_close_journal(void)
Definition: keypin.c:335
Macros to implement mocking and selective exposure for the test code.
#define STATIC
Definition: testsupport.h:32
#define MOCK_DECL(rv, funcname, arglist)
Definition: testsupport.h:127