torcert.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Copyright (c) 2014-2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TORCERT_H_INCLUDED
  4. #define TORCERT_H_INCLUDED
  5. #include "crypto_ed25519.h"
  6. #define SIGNED_KEY_TYPE_ED25519 0x01
  7. #define CERT_TYPE_ID_SIGNING 0x04
  8. #define CERT_TYPE_SIGNING_LINK 0x05
  9. #define CERT_TYPE_SIGNING_AUTH 0x06
  10. #define CERT_TYPE_ONION_ID 0x0A
  11. #define CERT_TYPE_HS_IP_ENC 0x0B
  12. #define CERT_FLAG_INCLUDE_SIGNING_KEY 0x1
  13. /** An ed25519-signed certificate as used throughout the Tor protocol.
  14. **/
  15. typedef struct tor_cert_st {
  16. /** The key authenticated by this certificate */
  17. ed25519_public_key_t signed_key;
  18. /** The key that signed this certificate. This value may be unset if the
  19. * certificate has never been checked, and didn't include its own key. */
  20. ed25519_public_key_t signing_key;
  21. /** A time after which this certificate will no longer be valid. */
  22. time_t valid_until;
  23. /** The encoded representation of this certificate */
  24. uint8_t *encoded;
  25. /** The length of <b>encoded</b> */
  26. size_t encoded_len;
  27. /** One of CERT_TYPE_... */
  28. uint8_t cert_type;
  29. /** True iff we received a signing key embedded in this certificate */
  30. unsigned signing_key_included : 1;
  31. /** True iff we checked the signature and found it bad */
  32. unsigned sig_bad : 1;
  33. /** True iff we checked the signature and found it correct */
  34. unsigned sig_ok : 1;
  35. /** True iff we checked the signature and first found that the cert
  36. * had expired */
  37. unsigned cert_expired : 1;
  38. /** True iff we checked the signature and found the whole cert valid */
  39. unsigned cert_valid : 1;
  40. } tor_cert_t;
  41. tor_cert_t *tor_cert_create(const ed25519_keypair_t *signing_key,
  42. uint8_t cert_type,
  43. const ed25519_public_key_t *signed_key,
  44. time_t now, time_t lifetime,
  45. uint32_t flags);
  46. tor_cert_t *tor_cert_parse(const uint8_t *cert, size_t certlen);
  47. void tor_cert_free(tor_cert_t *cert);
  48. int tor_cert_get_checkable_sig(ed25519_checkable_t *checkable_out,
  49. const tor_cert_t *out,
  50. const ed25519_public_key_t *pubkey);
  51. int tor_cert_checksig(tor_cert_t *cert,
  52. const ed25519_public_key_t *pubkey, time_t now);
  53. tor_cert_t *tor_cert_dup(const tor_cert_t *cert);
  54. int tor_cert_eq(const tor_cert_t *cert1, const tor_cert_t *cert2);
  55. int tor_cert_opt_eq(const tor_cert_t *cert1, const tor_cert_t *cert2);
  56. ssize_t tor_make_rsa_ed25519_crosscert(const ed25519_public_key_t *ed_key,
  57. const crypto_pk_t *rsa_key,
  58. time_t expires,
  59. uint8_t **cert);
  60. #endif