x509.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #ifdef ENABLE_OPENSSL
  25. uint8_t *encoded;
  26. size_t encoded_len;
  27. #endif
  28. unsigned pkey_digests_set : 1;
  29. common_digests_t cert_digests;
  30. common_digests_t pkey_digests;
  31. };
  32. #endif
  33. void tor_tls_pick_certificate_lifetime(time_t now,
  34. unsigned cert_lifetime,
  35. time_t *start_time_out,
  36. time_t *end_time_out);
  37. #ifdef TOR_UNIT_TESTS
  38. tor_x509_cert_t *tor_x509_cert_replace_expiration(
  39. const tor_x509_cert_t *inp,
  40. time_t new_expiration_time,
  41. crypto_pk_t *signing_key);
  42. #endif
  43. tor_x509_cert_t *tor_x509_cert_dup(const tor_x509_cert_t *cert);
  44. void tor_x509_cert_free_(tor_x509_cert_t *cert);
  45. #define tor_x509_cert_free(c) \
  46. FREE_AND_NULL(tor_x509_cert_t, tor_x509_cert_free_, (c))
  47. tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
  48. size_t certificate_len);
  49. void tor_x509_cert_get_der(const tor_x509_cert_t *cert,
  50. const uint8_t **encoded_out, size_t *size_out);
  51. const common_digests_t *tor_x509_cert_get_id_digests(
  52. const tor_x509_cert_t *cert);
  53. const common_digests_t *tor_x509_cert_get_cert_digests(
  54. const tor_x509_cert_t *cert);
  55. crypto_pk_t *tor_tls_cert_get_key(tor_x509_cert_t *cert);
  56. int tor_tls_cert_is_valid(int severity,
  57. const tor_x509_cert_t *cert,
  58. const tor_x509_cert_t *signing_cert,
  59. time_t now,
  60. int check_rsa_1024);
  61. #endif