Rewrite X509's parser with CBS/CBB

In doing so, embed a whole host of types into X509. With all this, we
can *finally* add extra parameters to the parser, like lists of
supported algorithms or flag-protecting future changes. In the previous
state, it went through a very messy reflection-based framework.

Since we now control the parser entrypoint, this also means we can
handle the cached encoding differently. Just to make the
X509_parse_from_buffer and d2i_X509 flows more uniform, we now always
save a CRYPTO_BUFFER containing the whole certificate, and then
TBSCertificate marshalling finds the TBSCertificate from there. (Though
it is still possible to create X509 objects without CRYPTO_BUFFERs.)

That in turn means the generic ASN1_ENCODING path doesn't need to store
a CRYPTO_BUFFER anymore, so all that is now unwound. If we rewrite the
CSR and CRL parsers, then ASN1_ENCODING can be removed entirely.

As a bonus, this new parser is significantly faster!
Before:
Did 1037634 Parse X.509 certificate operations in 5000690us (207498.2 ops/sec)
After:
Did 1318068 Parse X.509 certificate operations in 5000462us (263589.2 ops/sec)

(The X509_NAME parser is still using tasn_dec, so there's still some
overhead there. This also does not remove the overhead from X509's
in-memory representation where lots of parts of the certificate get
copied separate allocations.)

Update-Note: This CL is not expected to change the external behavior of
the X.509 parser, but it's a lot of code that had to get shuffled
around, so if something funny happens around X.509, this is a likely
culprit.

Bug: 42290417
Change-Id: Ia4142f5e8d31b041176a545379c7df30e946a670
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81781
Reviewed-by: Adam Langley <agl@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
27 files changed
tree: 1082eb8907e5988aec6c69970e1dd9349bd76269
  1. .bcr/
  2. .github/
  3. cmake/
  4. crypto/
  5. decrepit/
  6. docs/
  7. fuzz/
  8. gen/
  9. include/
  10. infra/
  11. pki/
  12. rust/
  13. ssl/
  14. third_party/
  15. tool/
  16. util/
  17. .bazelignore
  18. .bazelrc
  19. .bazelversion
  20. .clang-format
  21. .gitignore
  22. API-CONVENTIONS.md
  23. AUTHORS
  24. BREAKING-CHANGES.md
  25. BUILD.bazel
  26. build.json
  27. BUILDING.md
  28. CMakeLists.txt
  29. codereview.settings
  30. CONTRIBUTING.md
  31. FUZZING.md
  32. go.mod
  33. go.sum
  34. INCORPORATING.md
  35. LICENSE
  36. MODULE.bazel
  37. MODULE.bazel.lock
  38. PORTING.md
  39. PrivacyInfo.xcprivacy
  40. README.md
  41. SANDBOXING.md
  42. STYLE.md
README.md

BoringSSL

BoringSSL is a fork of OpenSSL that is designed to meet Google's needs.

Although BoringSSL is an open source project, it is not intended for general use, as OpenSSL is. We don't recommend that third parties depend upon it. Doing so is likely to be frustrating because there are no guarantees of API or ABI stability.

Programs ship their own copies of BoringSSL when they use it and we update everything as needed when deciding to make API changes. This allows us to mostly avoid compromises in the name of compatibility. It works for us, but it may not work for you.

BoringSSL arose because Google used OpenSSL for many years in various ways and, over time, built up a large number of patches that were maintained while tracking upstream OpenSSL. As Google's product portfolio became more complex, more copies of OpenSSL sprung up and the effort involved in maintaining all these patches in multiple places was growing steadily.

Currently BoringSSL is the SSL library in Chrome/Chromium, Android (but it's not part of the NDK) and a number of other apps/programs.

Project links:

To file a security issue, use the Chromium process and mention in the report this is for BoringSSL. You can ignore the parts of the process that are specific to Chromium/Chrome.

There are other files in this directory which might be helpful: