Rewrite the X509_NAME parser

The old parser was a mess. It has to deal with X509_NAME using a
slightly different in-memory represtation than tasn_dec expects, and it
has to populate cached fields. On top of that, the handling of the cache
was not thread-safe.

It previously worked by first using the tasn_dec machinery to parse a
STACK_OF(STACK_OF(X509_NAME_ENTRY)), and then flattening it. Then it
makes a *new* STACK_OF(STACK_OF(X509_NAME_ENTRY)) with canonicalized
fields. Then it re-encodes that with tasn_enc to save the canonicalized
form.

Instead of all that, parse with CBS so we don't need an allocated
intermediate representation. We can just write it out into the
X509_NAME representation as we parse it.

For the two cached fields, fix the thread-safety issue by wrapping it in
a struct and managing it with an atomic pointer. I had vaguely hoped we
could avoid this, but that seems too complicated with the API we've got.
When computing the cached encodings, rather than making a new allocated
intermediate representation, we can just write a canonicalized encoder
and write it straight into a single CBB, so we only have one growable
array's worth of buffer.

It's faster too!

Before:
Did 1319499 Parse X.509 certificate operations in 5001015us (263846.2 ops/sec)
After:
Did 1794529 Parse X.509 certificate operations in 5000632us (358860.4 ops/sec)

Subsequent CLs will make the API const-correct, test threading, and
embed the X509_NAMEs into the X509 struct.

One nuisance: it's hard for an infallible x509_name_init to initialize
a STACK_OF(X509_NAME_ENTRY). For now I just made the zero state legal
and the add function materializes the STACK_OF on demand. We don't
expose the underlying object, so it doesn't matter much. Really we
should stop believing in fallible mallocs.

Bug: 42290417, 42290269
Change-Id: I0081c75dc06c76c3863eb9418e61262953c9179f
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/81891
Auto-Submit: David Benjamin <davidben@google.com>
Commit-Queue: David Benjamin <davidben@google.com>
Reviewed-by: Adam Langley <agl@google.com>
9 files changed
tree: 8d79e18ffde2be2b6db41705a9a2cf4b6d063e7a
  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: