Commit 934859cf authored by Nick Mathewson's avatar Nick Mathewson 🤹
Browse files

Move key-loading and crosscert-checking out of feature/relay

This is also used by onion services, so it needs to go in another
module.
parent c82163df
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -86,6 +86,8 @@ LIBTOR_APP_A_SOURCES = \
	src/feature/hs/hs_stats.c		\
	src/feature/hs_common/replaycache.c	\
	src/feature/hs_common/shared_random_client.c	\
	src/feature/keymgt/loadkey.c		\
	src/feature/dirauth/keypin.c		\
	src/feature/nodelist/authcert.c		\
	src/feature/nodelist/dirlist.c		\
	src/feature/nodelist/microdesc.c	\
@@ -289,6 +291,7 @@ noinst_HEADERS += \
	src/feature/hs/hsdir_index_st.h			\
	src/feature/hs_common/replaycache.h		\
	src/feature/hs_common/shared_random_client.h	\
	src/feature/keymgt/loadkey.h			\
	src/feature/nodelist/authcert.h			\
	src/feature/nodelist/authority_cert_st.h	\
	src/feature/nodelist/desc_store_st.h		\
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@
#include "core/or/relay.h"
#include "feature/rend/rendservice.h"
#include "feature/relay/router.h"
#include "feature/relay/routerkeys.h"
#include "feature/keymgt/loadkey.h"
//#include "feature/relay/routerkeys.h"
#include "feature/nodelist/node_select.h"
#include "feature/hs_common/shared_random_client.h"
#include "app/config/statefile.h"
+755 −0

File added.

Preview size limit exceeded, changes collapsed.

+55 −0
Original line number Diff line number Diff line
/* Copyright (c) 2001 Matej Pfajfar.
 * Copyright (c) 2001-2004, Roger Dingledine.
 * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
 * Copyright (c) 2007-2018, The Tor Project, Inc. */
/* See LICENSE for licensing information */

/**
 * \file loadkey.h
 * \brief Header file for loadkey.c
 **/

#ifndef TOR_LOADKEY_H
#define TOR_LOADKEY_H

#include "lib/crypt_ops/crypto_ed25519.h"

crypto_pk_t *init_key_from_file(const char *fname, int generate,
                                int severity, bool *created_out);

#define INIT_ED_KEY_CREATE                      (1u<<0)
#define INIT_ED_KEY_REPLACE                     (1u<<1)
#define INIT_ED_KEY_SPLIT                       (1u<<2)
#define INIT_ED_KEY_MISSING_SECRET_OK           (1u<<3)
#define INIT_ED_KEY_NEEDCERT                    (1u<<4)
#define INIT_ED_KEY_EXTRA_STRONG                (1u<<5)
#define INIT_ED_KEY_INCLUDE_SIGNING_KEY_IN_CERT (1u<<6)
#define INIT_ED_KEY_OMIT_SECRET                 (1u<<7)
#define INIT_ED_KEY_TRY_ENCRYPTED               (1u<<8)
#define INIT_ED_KEY_NO_REPAIR                   (1u<<9)
#define INIT_ED_KEY_SUGGEST_KEYGEN              (1u<<10)
#define INIT_ED_KEY_OFFLINE_SECRET              (1u<<11)
#define INIT_ED_KEY_EXPLICIT_FNAME              (1u<<12)

struct tor_cert_st;
ed25519_keypair_t *ed_key_init_from_file(const char *fname, uint32_t flags,
                                         int severity,
                                         const ed25519_keypair_t *signing_key,
                                         time_t now,
                                         time_t lifetime,
                                         uint8_t cert_type,
                                         struct tor_cert_st **cert_out,
                                         const or_options_t *options);
ed25519_keypair_t *ed_key_new(const ed25519_keypair_t *signing_key,
                              uint32_t flags,
                              time_t now,
                              time_t lifetime,
                              uint8_t cert_type,
                              struct tor_cert_st **cert_out);

int read_encrypted_secret_key(ed25519_secret_key_t *out,
                              const char *fname);
int write_encrypted_secret_key(const ed25519_secret_key_t *out,
                               const char *fname);

#endif
+37 −0
Original line number Diff line number Diff line
@@ -638,6 +638,43 @@ or_handshake_certs_ed25519_ok(int severity,
  return 1;
}

/** Check whether an RSA-TAP cross-certification is correct. Return 0 if it
 * is, -1 if it isn't. */
MOCK_IMPL(int,
check_tap_onion_key_crosscert,(const uint8_t *crosscert,
                               int crosscert_len,
                               const crypto_pk_t *onion_pkey,
                               const ed25519_public_key_t *master_id_pkey,
                               const uint8_t *rsa_id_digest))
{
  uint8_t *cc = tor_malloc(crypto_pk_keysize(onion_pkey));
  int cc_len =
    crypto_pk_public_checksig(onion_pkey,
                              (char*)cc,
                              crypto_pk_keysize(onion_pkey),
                              (const char*)crosscert,
                              crosscert_len);
  if (cc_len < 0) {
    goto err;
  }
  if (cc_len < DIGEST_LEN + ED25519_PUBKEY_LEN) {
    log_warn(LD_DIR, "Short signature on cross-certification with TAP key");
    goto err;
  }
  if (tor_memneq(cc, rsa_id_digest, DIGEST_LEN) ||
      tor_memneq(cc + DIGEST_LEN, master_id_pkey->pubkey,
                 ED25519_PUBKEY_LEN)) {
    log_warn(LD_DIR, "Incorrect cross-certification with TAP key");
    goto err;
  }

  tor_free(cc);
  return 0;
 err:
  tor_free(cc);
  return -1;
}

/**
 * Check the Ed certificates and/or the RSA certificates, as appropriate.  If
 * we obtained an Ed25519 identity, set *ed_id_out. If we obtained an RSA
Loading