torcert.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* Copyright (c) 2014-2019, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TORCERT_H_INCLUDED
  4. #define TORCERT_H_INCLUDED
  5. #include "lib/crypt_ops/crypto_ed25519.h"
  6. #include "lib/tls/x509.h"
  7. #define SIGNED_KEY_TYPE_ED25519 0x01
  8. #define CERT_TYPE_ID_SIGNING 0x04
  9. #define CERT_TYPE_SIGNING_LINK 0x05
  10. #define CERT_TYPE_SIGNING_AUTH 0x06
  11. #define CERT_TYPE_SIGNING_HS_DESC 0x08
  12. #define CERT_TYPE_AUTH_HS_IP_KEY 0x09
  13. #define CERT_TYPE_ONION_ID 0x0A
  14. #define CERT_TYPE_CROSS_HS_IP_KEYS 0x0B
  15. #define CERT_FLAG_INCLUDE_SIGNING_KEY 0x1
  16. /** An ed25519-signed certificate as used throughout the Tor protocol.
  17. **/
  18. typedef struct tor_cert_st {
  19. /** The key authenticated by this certificate */
  20. ed25519_public_key_t signed_key;
  21. /** The key that signed this certificate. This value may be unset if the
  22. * certificate has never been checked, and didn't include its own key. */
  23. ed25519_public_key_t signing_key;
  24. /** A time after which this certificate will no longer be valid. */
  25. time_t valid_until;
  26. /** The encoded representation of this certificate */
  27. uint8_t *encoded;
  28. /** The length of <b>encoded</b> */
  29. size_t encoded_len;
  30. /** One of CERT_TYPE_... */
  31. uint8_t cert_type;
  32. /** True iff we received a signing key embedded in this certificate */
  33. unsigned signing_key_included : 1;
  34. /** True iff we checked the signature and found it bad */
  35. unsigned sig_bad : 1;
  36. /** True iff we checked the signature and found it correct */
  37. unsigned sig_ok : 1;
  38. /** True iff we checked the signature and first found that the cert
  39. * had expired */
  40. unsigned cert_expired : 1;
  41. /** True iff we checked the signature and found the whole cert valid */
  42. unsigned cert_valid : 1;
  43. } tor_cert_t;
  44. struct tor_tls_t;
  45. tor_cert_t *tor_cert_create(const ed25519_keypair_t *signing_key,
  46. uint8_t cert_type,
  47. const ed25519_public_key_t *signed_key,
  48. time_t now, time_t lifetime,
  49. uint32_t flags);
  50. tor_cert_t *tor_cert_parse(const uint8_t *cert, size_t certlen);
  51. void tor_cert_free_(tor_cert_t *cert);
  52. #define tor_cert_free(cert) FREE_AND_NULL(tor_cert_t, tor_cert_free_, (cert))
  53. int tor_cert_get_checkable_sig(ed25519_checkable_t *checkable_out,
  54. const tor_cert_t *out,
  55. const ed25519_public_key_t *pubkey,
  56. time_t *expiration_out);
  57. int tor_cert_checksig(tor_cert_t *cert,
  58. const ed25519_public_key_t *pubkey, time_t now);
  59. const char *tor_cert_describe_signature_status(const tor_cert_t *cert);
  60. MOCK_DECL(tor_cert_t *,tor_cert_dup,(const tor_cert_t *cert));
  61. int tor_cert_eq(const tor_cert_t *cert1, const tor_cert_t *cert2);
  62. int tor_cert_opt_eq(const tor_cert_t *cert1, const tor_cert_t *cert2);
  63. ssize_t tor_make_rsa_ed25519_crosscert(const ed25519_public_key_t *ed_key,
  64. const crypto_pk_t *rsa_key,
  65. time_t expires,
  66. uint8_t **cert);
  67. MOCK_DECL(int,
  68. rsa_ed25519_crosscert_check, (const uint8_t *crosscert,
  69. const size_t crosscert_len,
  70. const crypto_pk_t *rsa_id_key,
  71. const ed25519_public_key_t *master_key,
  72. const time_t reject_if_expired_before));
  73. or_handshake_certs_t *or_handshake_certs_new(void);
  74. void or_handshake_certs_free_(or_handshake_certs_t *certs);
  75. #define or_handshake_certs_free(certs) \
  76. FREE_AND_NULL(or_handshake_certs_t, or_handshake_certs_free_, (certs))
  77. int or_handshake_certs_rsa_ok(int severity,
  78. or_handshake_certs_t *certs,
  79. //struct tor_tls_t *tls,
  80. tor_x509_cert_t *peer_cert,
  81. time_t now);
  82. int or_handshake_certs_ed25519_ok(int severity,
  83. or_handshake_certs_t *certs,
  84. //struct tor_tls_t *tls,
  85. tor_x509_cert_t *peer_cert,
  86. time_t now);
  87. void or_handshake_certs_check_both(int severity,
  88. or_handshake_certs_t *certs,
  89. //struct tor_tls_t *tls,
  90. tor_x509_cert_t *peer_cert,
  91. time_t now,
  92. const ed25519_public_key_t **ed_id_out,
  93. const common_digests_t **rsa_id_out);
  94. int tor_cert_encode_ed22519(const tor_cert_t *cert, char **cert_str_out);
  95. MOCK_DECL(int, check_tap_onion_key_crosscert,(const uint8_t *crosscert,
  96. int crosscert_len,
  97. const crypto_pk_t *onion_pkey,
  98. const ed25519_public_key_t *master_id_pkey,
  99. const uint8_t *rsa_id_digest));
  100. #endif /* !defined(TORCERT_H_INCLUDED) */