2
0

X509Bundle.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include <stdexcept>
  3. #include "BellLogger.h"
  4. #include "mbedtls/ssl.h"
  5. namespace bell::X509Bundle {
  6. typedef struct crt_bundle_t {
  7. const uint8_t** crts;
  8. uint16_t num_certs;
  9. size_t x509_crt_bundle_len;
  10. } crt_bundle_t;
  11. static crt_bundle_t s_crt_bundle;
  12. static constexpr auto TAG = "X509Bundle";
  13. static constexpr auto CRT_HEADER_OFFSET = 4;
  14. static constexpr auto BUNDLE_HEADER_OFFSET = 2;
  15. int crtCheckCertificate(mbedtls_x509_crt* child, const uint8_t* pub_key_buf,
  16. size_t pub_key_len);
  17. /* This callback is called for every certificate in the chain. If the chain
  18. * is proper each intermediate certificate is validated through its parent
  19. * in the x509_crt_verify_chain() function. So this callback should
  20. * only verify the first untrusted link in the chain is signed by the
  21. * root certificate in the trusted bundle
  22. */
  23. int crtVerifyCallback(void* buf, mbedtls_x509_crt* crt, int depth,
  24. uint32_t* flags);
  25. /* Initialize the bundle into an array so we can do binary search for certs,
  26. the bundle generated by the python utility is already presorted by subject name
  27. */
  28. void init(const uint8_t* x509_bundle, size_t bundle_size);
  29. void attach(mbedtls_ssl_config* conf);
  30. bool shouldVerify();
  31. }; // namespace bell::X509Bundle