x509.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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/crypt_ops/compat_openssl.h"
  13. #include "lib/testsupport/testsupport.h"
  14. /* Opaque structure to hold an X509 certificate. */
  15. typedef struct tor_x509_cert_t tor_x509_cert_t;
  16. #ifdef ENABLE_OPENSSL
  17. struct x509_st;
  18. #endif
  19. /** Structure that we use for a single certificate. */
  20. struct tor_x509_cert_t {
  21. #ifdef ENABLE_OPENSSL
  22. struct x509_st *cert;
  23. #endif
  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. MOCK_DECL(struct x509_st *, tor_tls_create_certificate,
  31. (crypto_pk_t *rsa,
  32. crypto_pk_t *rsa_sign,
  33. const char *cname,
  34. const char *cname_sign,
  35. unsigned int cert_lifetime));
  36. MOCK_DECL(tor_x509_cert_t *, tor_x509_cert_new,
  37. (struct x509_st *x509_cert));
  38. #ifdef TOR_UNIT_TESTS
  39. tor_x509_cert_t *tor_x509_cert_replace_expiration(
  40. const tor_x509_cert_t *inp,
  41. time_t new_expiration_time,
  42. crypto_pk_t *signing_key);
  43. #endif
  44. tor_x509_cert_t *tor_x509_cert_dup(const tor_x509_cert_t *cert);
  45. void tor_x509_cert_free_(tor_x509_cert_t *cert);
  46. #define tor_x509_cert_free(c) \
  47. FREE_AND_NULL(tor_x509_cert_t, tor_x509_cert_free_, (c))
  48. tor_x509_cert_t *tor_x509_cert_decode(const uint8_t *certificate,
  49. size_t certificate_len);
  50. void tor_x509_cert_get_der(const tor_x509_cert_t *cert,
  51. const uint8_t **encoded_out, size_t *size_out);
  52. const common_digests_t *tor_x509_cert_get_id_digests(
  53. const tor_x509_cert_t *cert);
  54. const common_digests_t *tor_x509_cert_get_cert_digests(
  55. const tor_x509_cert_t *cert);
  56. crypto_pk_t *tor_tls_cert_get_key(tor_x509_cert_t *cert);
  57. int tor_tls_cert_is_valid(int severity,
  58. const tor_x509_cert_t *cert,
  59. const tor_x509_cert_t *signing_cert,
  60. time_t now,
  61. int check_rsa_1024);
  62. int check_cert_lifetime_internal(int severity, const X509 *cert,
  63. time_t now,
  64. int past_tolerance, int future_tolerance);
  65. #endif