2
0

dane.h 3.5 KB

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