x509.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_NSS
  16. typedef struct CERTCertificateStr tor_x509_cert_impl_t;
  17. #elif defined(ENABLE_OPENSSL)
  18. typedef struct x509_st tor_x509_cert_impl_t;
  19. #endif
  20. #ifdef TOR_X509_PRIVATE
  21. /** Structure that we use for a single certificate. */
  22. struct tor_x509_cert_t {
  23. tor_x509_cert_impl_t *cert;
  24. uint8_t *encoded;
  25. size_t encoded_len;
  26. unsigned pkey_digests_set : 1;
  27. common_digests_t cert_digests;
  28. common_digests_t pkey_digests;
  29. };
  30. #endif
  31. void tor_tls_pick_certificate_lifetime(time_t now,
  32. unsigned cert_lifetime,
  33. time_t *start_time_out,
  34. time_t *end_time_out);
  35. MOCK_DECL(tor_x509_cert_impl_t *, tor_tls_create_certificate,
  36. (crypto_pk_t *rsa,
  37. crypto_pk_t *rsa_sign,
  38. const char *cname,
  39. const char *cname_sign,
  40. unsigned int cert_lifetime));
  41. MOCK_DECL(tor_x509_cert_t *, tor_x509_cert_new,
  42. (tor_x509_cert_impl_t *x509_cert));
  43. #ifdef TOR_UNIT_TESTS
  44. tor_x509_cert_t *tor_x509_cert_replace_expiration(
  45. const tor_x509_cert_t *inp,
  46. time_t new_expiration_time,
  47. crypto_pk_t *signing_key);
  48. #endif
  49. tor_x509_cert_t *tor_x509_cert_dup(const tor_x509_cert_t *cert);
  50. void tor_x509_cert_free_(tor_x509_cert_t *cert);
  51. #define tor_x509_cert_free(c) \
  52. FREE_AND_NULL(tor_x509_cert_t, tor_x509_cert_free_, (c))
  53. tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
  54. size_t certificate_len);
  55. const tor_x509_cert_impl_t *tor_x509_cert_get_impl(
  56. const tor_x509_cert_t *cert);
  57. void tor_x509_cert_get_der(const tor_x509_cert_t *cert,
  58. const uint8_t **encoded_out, size_t *size_out);
  59. const common_digests_t *tor_x509_cert_get_id_digests(
  60. const tor_x509_cert_t *cert);
  61. const common_digests_t *tor_x509_cert_get_cert_digests(
  62. const tor_x509_cert_t *cert);
  63. crypto_pk_t *tor_tls_cert_get_key(tor_x509_cert_t *cert);
  64. int tor_tls_cert_is_valid(int severity,
  65. const tor_x509_cert_t *cert,
  66. const tor_x509_cert_t *signing_cert,
  67. time_t now,
  68. int check_rsa_1024);
  69. int tor_x509_check_cert_lifetime_internal(int severity,
  70. const tor_x509_cert_impl_t *cert,
  71. time_t now,
  72. int past_tolerance,
  73. int future_tolerance);
  74. #endif