dane.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * Copyright 2015-2016 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #ifndef OSSL_INTERNAL_DANE_H
  10. #define OSSL_INTERNAL_DANE_H
  11. #include <openssl/safestack.h>
  12. /*-
  13. * Certificate usages:
  14. * https://tools.ietf.org/html/rfc6698#section-2.1.1
  15. */
  16. #define DANETLS_USAGE_PKIX_TA 0
  17. #define DANETLS_USAGE_PKIX_EE 1
  18. #define DANETLS_USAGE_DANE_TA 2
  19. #define DANETLS_USAGE_DANE_EE 3
  20. #define DANETLS_USAGE_LAST DANETLS_USAGE_DANE_EE
  21. /*-
  22. * Selectors:
  23. * https://tools.ietf.org/html/rfc6698#section-2.1.2
  24. */
  25. #define DANETLS_SELECTOR_CERT 0
  26. #define DANETLS_SELECTOR_SPKI 1
  27. #define DANETLS_SELECTOR_LAST DANETLS_SELECTOR_SPKI
  28. /*-
  29. * Matching types:
  30. * https://tools.ietf.org/html/rfc6698#section-2.1.3
  31. */
  32. #define DANETLS_MATCHING_FULL 0
  33. #define DANETLS_MATCHING_2256 1
  34. #define DANETLS_MATCHING_2512 2
  35. #define DANETLS_MATCHING_LAST DANETLS_MATCHING_2512
  36. typedef struct danetls_record_st {
  37. uint8_t usage;
  38. uint8_t selector;
  39. uint8_t mtype;
  40. unsigned char *data;
  41. size_t dlen;
  42. EVP_PKEY *spki;
  43. } danetls_record;
  44. DEFINE_STACK_OF(danetls_record)
  45. /*
  46. * Shared DANE context
  47. */
  48. struct dane_ctx_st {
  49. const EVP_MD **mdevp; /* mtype -> digest */
  50. uint8_t *mdord; /* mtype -> preference */
  51. uint8_t mdmax; /* highest supported mtype */
  52. unsigned long flags; /* feature bitmask */
  53. };
  54. /*
  55. * Per connection DANE state
  56. */
  57. struct ssl_dane_st {
  58. struct dane_ctx_st *dctx;
  59. STACK_OF(danetls_record) *trecs;
  60. STACK_OF(X509) *certs; /* DANE-TA(2) Cert(0) Full(0) certs */
  61. danetls_record *mtlsa; /* Matching TLSA record */
  62. X509 *mcert; /* DANE matched cert */
  63. uint32_t umask; /* Usages present */
  64. int mdpth; /* Depth of matched cert */
  65. int pdpth; /* Depth of PKIX trust */
  66. unsigned long flags; /* feature bitmask */
  67. };
  68. #define DANETLS_ENABLED(dane) \
  69. ((dane) != NULL && sk_danetls_record_num((dane)->trecs) > 0)
  70. #define DANETLS_USAGE_BIT(u) (((uint32_t)1) << u)
  71. #define DANETLS_PKIX_TA_MASK (DANETLS_USAGE_BIT(DANETLS_USAGE_PKIX_TA))
  72. #define DANETLS_PKIX_EE_MASK (DANETLS_USAGE_BIT(DANETLS_USAGE_PKIX_EE))
  73. #define DANETLS_DANE_TA_MASK (DANETLS_USAGE_BIT(DANETLS_USAGE_DANE_TA))
  74. #define DANETLS_DANE_EE_MASK (DANETLS_USAGE_BIT(DANETLS_USAGE_DANE_EE))
  75. #define DANETLS_PKIX_MASK (DANETLS_PKIX_TA_MASK | DANETLS_PKIX_EE_MASK)
  76. #define DANETLS_DANE_MASK (DANETLS_DANE_TA_MASK | DANETLS_DANE_EE_MASK)
  77. #define DANETLS_TA_MASK (DANETLS_PKIX_TA_MASK | DANETLS_DANE_TA_MASK)
  78. #define DANETLS_EE_MASK (DANETLS_PKIX_EE_MASK | DANETLS_DANE_EE_MASK)
  79. #define DANETLS_HAS_PKIX(dane) ((dane) && ((dane)->umask & DANETLS_PKIX_MASK))
  80. #define DANETLS_HAS_DANE(dane) ((dane) && ((dane)->umask & DANETLS_DANE_MASK))
  81. #define DANETLS_HAS_TA(dane) ((dane) && ((dane)->umask & DANETLS_TA_MASK))
  82. #define DANETLS_HAS_EE(dane) ((dane) && ((dane)->umask & DANETLS_EE_MASK))
  83. #define DANETLS_HAS_PKIX_TA(dane) ((dane)&&((dane)->umask & DANETLS_PKIX_TA_MASK))
  84. #define DANETLS_HAS_PKIX_EE(dane) ((dane)&&((dane)->umask & DANETLS_PKIX_EE_MASK))
  85. #define DANETLS_HAS_DANE_TA(dane) ((dane)&&((dane)->umask & DANETLS_DANE_TA_MASK))
  86. #define DANETLS_HAS_DANE_EE(dane) ((dane)&&((dane)->umask & DANETLS_DANE_EE_MASK))
  87. #endif /* OSSL_INTERNAL_DANE_H */