x509.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* Copyright (c) 2003, Roger Dingledine
  2. * Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson.
  3. * Copyright (c) 2007-2018, The Tor Project, Inc. */
  4. /* See LICENSE for licensing information */
  5. #ifndef TOR_X509_H
  6. #define TOR_X509_H
  7. /**
  8. * \file x509.h
  9. * \brief Headers for tortls.c
  10. **/
  11. #include "lib/crypt_ops/crypto_rsa.h"
  12. #include "lib/testsupport/testsupport.h"
  13. /* Opaque structure to hold an X509 certificate. */
  14. typedef struct tor_x509_cert_t tor_x509_cert_t;
  15. #ifdef ENABLE_OPENSSL
  16. typedef struct x509_st tor_x509_cert_impl_t;
  17. #endif
  18. #ifdef TOR_X509_PRIVATE
  19. /** Structure that we use for a single certificate. */
  20. struct tor_x509_cert_t {
  21. tor_x509_cert_impl_t *cert;
  22. uint8_t *encoded;
  23. size_t encoded_len;
  24. unsigned pkey_digests_set : 1;
  25. common_digests_t cert_digests;
  26. common_digests_t pkey_digests;
  27. };
  28. #endif
  29. void tor_tls_pick_certificate_lifetime(time_t now,
  30. unsigned cert_lifetime,
  31. time_t *start_time_out,
  32. time_t *end_time_out);
  33. MOCK_DECL(tor_x509_cert_impl_t *, tor_tls_create_certificate,
  34. (crypto_pk_t *rsa,
  35. crypto_pk_t *rsa_sign,
  36. const char *cname,
  37. const char *cname_sign,
  38. unsigned int cert_lifetime));
  39. MOCK_DECL(tor_x509_cert_t *, tor_x509_cert_new,
  40. (tor_x509_cert_impl_t *x509_cert));
  41. #ifdef TOR_UNIT_TESTS
  42. tor_x509_cert_t *tor_x509_cert_replace_expiration(
  43. const tor_x509_cert_t *inp,
  44. time_t new_expiration_time,
  45. crypto_pk_t *signing_key);
  46. #endif
  47. tor_x509_cert_t *tor_x509_cert_dup(const tor_x509_cert_t *cert);
  48. void tor_x509_cert_free_(tor_x509_cert_t *cert);
  49. #define tor_x509_cert_free(c) \
  50. FREE_AND_NULL(tor_x509_cert_t, tor_x509_cert_free_, (c))
  51. tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
  52. size_t certificate_len);
  53. const tor_x509_cert_impl_t *tor_x509_cert_get_impl(
  54. const tor_x509_cert_t *cert);
  55. void tor_x509_cert_get_der(const tor_x509_cert_t *cert,
  56. const uint8_t **encoded_out, size_t *size_out);
  57. const common_digests_t *tor_x509_cert_get_id_digests(
  58. const tor_x509_cert_t *cert);
  59. const common_digests_t *tor_x509_cert_get_cert_digests(
  60. const tor_x509_cert_t *cert);
  61. crypto_pk_t *tor_tls_cert_get_key(tor_x509_cert_t *cert);
  62. int tor_tls_cert_is_valid(int severity,
  63. const tor_x509_cert_t *cert,
  64. const tor_x509_cert_t *signing_cert,
  65. time_t now,
  66. int check_rsa_1024);
  67. int tor_x509_check_cert_lifetime_internal(int severity,
  68. const tor_x509_cert_impl_t *cert,
  69. time_t now,
  70. int past_tolerance,
  71. int future_tolerance);
  72. #endif