torcert.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* Copyright (c) 2014, 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_FLAG_INCLUDE_SIGNING_KEY 0x1
  11. /** An ed25519-signed certificate as used throughout the Tor protocol.
  12. **/
  13. typedef struct tor_cert_st {
  14. /** The key authenticated by this certificate */
  15. ed25519_public_key_t signed_key;
  16. /** The key that signed this certificate. This value may be unset if the
  17. * certificate has never been checked, and didn't include its own key. */
  18. ed25519_public_key_t signing_key;
  19. /** A time after which this certificate will no longer be valid. */
  20. time_t valid_until;
  21. /** The encoded representation of this certificate */
  22. uint8_t *encoded;
  23. /** The length of <b>encoded</b> */
  24. size_t encoded_len;
  25. /** One of CERT_TYPE_... */
  26. uint8_t cert_type;
  27. /** True iff we received a signing key embedded in this certificate */
  28. unsigned signing_key_included : 1;
  29. /** True iff we checked the signature and found it bad */
  30. unsigned sig_bad : 1;
  31. /** True iff we checked the signature and found it correct */
  32. unsigned sig_ok : 1;
  33. /** True iff we checked the signature and first found that the cert
  34. * had expired */
  35. unsigned cert_expired : 1;
  36. /** True iff we checked the signature and found the whole cert valid */
  37. unsigned cert_valid : 1;
  38. } tor_cert_t;
  39. tor_cert_t *tor_cert_create(const ed25519_keypair_t *signing_key,
  40. uint8_t cert_type,
  41. const ed25519_public_key_t *signed_key,
  42. time_t now, time_t lifetime,
  43. uint32_t flags);
  44. tor_cert_t *tor_cert_parse(const uint8_t *cert, size_t certlen);
  45. void tor_cert_free(tor_cert_t *cert);
  46. int tor_cert_get_checkable_sig(ed25519_checkable_t *checkable_out,
  47. const tor_cert_t *out,
  48. const ed25519_public_key_t *pubkey);
  49. int tor_cert_checksig(tor_cert_t *cert,
  50. const ed25519_public_key_t *pubkey, time_t now);
  51. #endif