|
| 1 | +# SSL Backend Selection Support |
| 2 | + |
| 3 | +This document describes how to build Envoy with either BoringSSL (upstream default) or OpenSSL (via bssl-compat). |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The build system now supports selecting between two SSL backends: |
| 8 | +- **BoringSSL** (default) - The upstream SSL library used by Envoy |
| 9 | +- **OpenSSL** (via bssl-compat) - OpenSSL 3.0.x with a BoringSSL compatibility layer |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +### Building with BoringSSL (Default) |
| 14 | + |
| 15 | +Simply build as normal without any special flags: |
| 16 | + |
| 17 | +```bash |
| 18 | +bazel build //source/exe:envoy-static |
| 19 | +``` |
| 20 | + |
| 21 | +### Building with OpenSSL |
| 22 | + |
| 23 | +Use the `--config=openssl` flag (recommended): |
| 24 | + |
| 25 | +```bash |
| 26 | +bazel build --config=openssl //source/exe:envoy-static |
| 27 | +``` |
| 28 | + |
| 29 | +This automatically: |
| 30 | +- Sets `--define=ssl=openssl` to select the OpenSSL backend |
| 31 | +- Adds `-DENVOY_SSL_OPENSSL` compiler flag |
| 32 | +- Disables QUIC/HTTP3 support |
| 33 | +- Restricts tests to IPv4 only |
| 34 | + |
| 35 | +Alternatively, you can use just the define flag (not recommended as it doesn't apply other OpenSSL-specific settings): |
| 36 | + |
| 37 | +```bash |
| 38 | +bazel build --define=ssl=openssl //source/exe:envoy-static |
| 39 | +``` |
| 40 | + |
| 41 | +## Implementation Details |
| 42 | + |
| 43 | +### Build System Changes |
| 44 | + |
| 45 | +1. **Config Settings** (`bazel/BUILD`): |
| 46 | + - Added `ssl_openssl` config_setting for `--define=ssl=openssl` |
| 47 | + - Added `ssl_boringssl` config_setting for `--define=ssl=boringssl` |
| 48 | + |
| 49 | +2. **Aliases** (`bazel/BUILD`): |
| 50 | + - `//bazel:boringssl` now conditionally points to either `@boringssl//:ssl` or `@bssl-compat//:ssl` |
| 51 | + - `//bazel:boringcrypto` now conditionally points to either `@boringssl//:crypto` or `@bssl-compat//:crypto` |
| 52 | + |
| 53 | +3. **Dependencies** (`bazel/repositories.bzl`): |
| 54 | + - Both BoringSSL and OpenSSL (via bssl-compat) are loaded |
| 55 | + - Selection happens at build time via the aliases |
| 56 | + |
| 57 | +4. **Helper Function** (`bazel/envoy_select.bzl`): |
| 58 | + - Added `envoy_select_ssl()` for conditional compilation based on SSL backend |
| 59 | + - Example: `envoy_select_ssl(if_openssl = [...], if_boringssl = [...])` |
| 60 | + |
| 61 | +5. **Preprocessor Defines**: |
| 62 | + - When `ssl=openssl` is set, `-DENVOY_SSL_OPENSSL` is added to compilation flags |
| 63 | + - This allows source code to conditionally compile OpenSSL-specific code |
| 64 | + |
| 65 | +### Source Code Changes |
| 66 | + |
| 67 | +OpenSSL-specific code is wrapped with `#ifdef ENVOY_SSL_OPENSSL`: |
| 68 | + |
| 69 | +1. **SSL Socket** (`source/common/tls/ssl_socket.cc`): |
| 70 | + - EAGAIN handling in `SSL_ERROR_SSL` cases |
| 71 | + |
| 72 | +2. **Context Implementation** (`source/common/tls/context_impl.cc`): |
| 73 | + - Disabled `SSL_CTX_set_reverify_on_resume()` (not in bssl-compat) |
| 74 | + - Disabled `SSL_was_key_usage_invalid()` (not in bssl-compat) |
| 75 | + |
| 76 | +3. **BIO Handling** (`source/common/tls/io_handle_bio.cc`): |
| 77 | + - Added `io_handle_new()` and `io_handle_free()` for OpenSSL |
| 78 | + - Added BIO control commands for OpenSSL |
| 79 | + |
| 80 | +4. **Version Reporting** (`source/common/version/BUILD`): |
| 81 | + - Reports "OpenSSL" or "BoringSSL" based on build configuration |
| 82 | + |
| 83 | +### Configuration Files |
| 84 | + |
| 85 | +The `openssl/bazelrc` file automatically: |
| 86 | +- Sets `--define=ssl=openssl` |
| 87 | +- Adds `-DENVOY_SSL_OPENSSL` compiler flag |
| 88 | +- Disables QUIC/HTTP3 support |
| 89 | +- Restricts tests to IPv4 only |
| 90 | + |
| 91 | +## Test Considerations |
| 92 | + |
| 93 | +Some tests have different expectations for OpenSSL vs BoringSSL: |
| 94 | +- TLS fingerprints may differ |
| 95 | +- Cipher suite ordering may differ |
| 96 | +- Alert codes may differ |
| 97 | + |
| 98 | +Tests should use `#ifdef ENVOY_SSL_OPENSSL` to adjust expectations accordingly. |
| 99 | + |
| 100 | +## Migration Guide |
| 101 | + |
| 102 | +### For Users |
| 103 | + |
| 104 | +- To use BoringSSL: No changes needed (default behavior) |
| 105 | +- To use OpenSSL: Add `--define=ssl=openssl` to your build commands |
| 106 | + |
| 107 | +### For Developers |
| 108 | + |
| 109 | +When adding SSL-related code: |
| 110 | + |
| 111 | +1. **If the code works with both backends**: No special handling needed |
| 112 | + |
| 113 | +2. **If the code is OpenSSL-specific**: Wrap it with: |
| 114 | + ```cpp |
| 115 | + #ifdef ENVOY_SSL_OPENSSL |
| 116 | + // OpenSSL-specific code here |
| 117 | + #endif |
| 118 | + ``` |
| 119 | + |
| 120 | +3. **If the code is BoringSSL-specific**: Wrap it with: |
| 121 | + ```cpp |
| 122 | + #ifndef ENVOY_SSL_OPENSSL |
| 123 | + // BoringSSL-specific code here |
| 124 | + #endif |
| 125 | + ``` |
| 126 | + |
| 127 | +4. **For conditional build dependencies**: Use `envoy_select_ssl()` in BUILD files: |
| 128 | + ```python |
| 129 | + deps = [...] + envoy_select_ssl( |
| 130 | + if_openssl = ["//openssl/specific:dep"], |
| 131 | + if_boringssl = ["//boringssl/specific:dep"], |
| 132 | + ) |
| 133 | + ``` |
| 134 | + |
| 135 | +## Limitations |
| 136 | + |
| 137 | +When building with OpenSSL: |
| 138 | +- QUIC/HTTP3 support is disabled (OpenSSL doesn't provide QUIC implementation) |
| 139 | +- Some BoringSSL-specific APIs are not available |
| 140 | +- Test coverage may differ from BoringSSL builds |
0 commit comments