1*8fb009dcSAndroid Build Coastguard Worker# Porting from OpenSSL to BoringSSL 2*8fb009dcSAndroid Build Coastguard Worker 3*8fb009dcSAndroid Build Coastguard WorkerBoringSSL is an OpenSSL derivative and is mostly source-compatible, for the 4*8fb009dcSAndroid Build Coastguard Workersubset of OpenSSL retained. Libraries ideally need little to no changes for 5*8fb009dcSAndroid Build Coastguard WorkerBoringSSL support, provided they do not use removed APIs. In general, see if the 6*8fb009dcSAndroid Build Coastguard Workerlibrary compiles and, on failure, consult the documentation in the header files 7*8fb009dcSAndroid Build Coastguard Workerand see if problematic features can be removed. 8*8fb009dcSAndroid Build Coastguard Worker 9*8fb009dcSAndroid Build Coastguard WorkerBoringSSL's `OPENSSL_VERSION_NUMBER` matches the OpenSSL version it targets. 10*8fb009dcSAndroid Build Coastguard WorkerVersion checks for OpenSSL should ideally work as-is in BoringSSL. BoringSSL 11*8fb009dcSAndroid Build Coastguard Workeralso defines upstream's `OPENSSL_NO_*` feature macros corresponding to removed 12*8fb009dcSAndroid Build Coastguard Workerfeatures. If the preprocessor is needed, use these version checks or feature 13*8fb009dcSAndroid Build Coastguard Workermacros where possible, especially when patching third-party projects. Such 14*8fb009dcSAndroid Build Coastguard Workerpatches are more generally useful to OpenSSL consumers and thus more 15*8fb009dcSAndroid Build Coastguard Workerappropriate to send upstream. 16*8fb009dcSAndroid Build Coastguard Worker 17*8fb009dcSAndroid Build Coastguard WorkerIn some cases, BoringSSL-specific code may be necessary. Use the 18*8fb009dcSAndroid Build Coastguard Worker`OPENSSL_IS_BORINGSSL` preprocessor macro in `#ifdef`s. However, first contact 19*8fb009dcSAndroid Build Coastguard Workerthe BoringSSL maintainers about the missing APIs. We will typically add 20*8fb009dcSAndroid Build Coastguard Workercompatibility functions for convenience. In particular, *contact BoringSSL 21*8fb009dcSAndroid Build Coastguard Workermaintainers before working around missing OpenSSL 1.1.0 accessors*. BoringSSL 22*8fb009dcSAndroid Build Coastguard Workerwas originally derived from OpenSSL 1.0.2 but now targets OpenSSL 1.1.0. Some 23*8fb009dcSAndroid Build Coastguard Workernewer APIs may be missing but can be added on request. (Not all projects have 24*8fb009dcSAndroid Build Coastguard Workerbeen ported to OpenSSL 1.1.0, so BoringSSL also remains largely compatible with 25*8fb009dcSAndroid Build Coastguard WorkerOpenSSL 1.0.2.) 26*8fb009dcSAndroid Build Coastguard Worker 27*8fb009dcSAndroid Build Coastguard WorkerThe `OPENSSL_IS_BORINGSSL` macro may also be used to distinguish OpenSSL from 28*8fb009dcSAndroid Build Coastguard WorkerBoringSSL in configure scripts. Do not use the presence or absence of particular 29*8fb009dcSAndroid Build Coastguard Workersymbols to detect BoringSSL. 30*8fb009dcSAndroid Build Coastguard Worker 31*8fb009dcSAndroid Build Coastguard WorkerNote: BoringSSL does *not* have a stable API or ABI. It must be updated with its 32*8fb009dcSAndroid Build Coastguard Workerconsumers. It is not suitable for, say, a system library in a traditional Linux 33*8fb009dcSAndroid Build Coastguard Workerdistribution. For instance, Chromium statically links the specific revision of 34*8fb009dcSAndroid Build Coastguard WorkerBoringSSL it was built against. Likewise, Android's system-internal copy of 35*8fb009dcSAndroid Build Coastguard WorkerBoringSSL is not exposed by the NDK and must not be used by third-party 36*8fb009dcSAndroid Build Coastguard Workerapplications. 37*8fb009dcSAndroid Build Coastguard Worker 38*8fb009dcSAndroid Build Coastguard Worker 39*8fb009dcSAndroid Build Coastguard Worker## Major API changes 40*8fb009dcSAndroid Build Coastguard Worker 41*8fb009dcSAndroid Build Coastguard Worker### Integer types 42*8fb009dcSAndroid Build Coastguard Worker 43*8fb009dcSAndroid Build Coastguard WorkerSome APIs have been converted to use `size_t` for consistency and to avoid 44*8fb009dcSAndroid Build Coastguard Workerinteger overflows at the API boundary. (Existing logic uses a mismash of `int`, 45*8fb009dcSAndroid Build Coastguard Worker`long`, and `unsigned`.) For the most part, implicit casts mean that existing 46*8fb009dcSAndroid Build Coastguard Workercode continues to compile. In some cases, this may require BoringSSL-specific 47*8fb009dcSAndroid Build Coastguard Workercode, particularly to avoid compiler warnings. 48*8fb009dcSAndroid Build Coastguard Worker 49*8fb009dcSAndroid Build Coastguard WorkerMost notably, the `STACK_OF(T)` types have all been converted to use `size_t` 50*8fb009dcSAndroid Build Coastguard Workerinstead of `int` for indices and lengths. 51*8fb009dcSAndroid Build Coastguard Worker 52*8fb009dcSAndroid Build Coastguard Worker### Reference counts and opaque types 53*8fb009dcSAndroid Build Coastguard Worker 54*8fb009dcSAndroid Build Coastguard WorkerSome external consumers increment reference counts directly by calling 55*8fb009dcSAndroid Build Coastguard Worker`CRYPTO_add` with the corresponding `CRYPTO_LOCK_*` value. These APIs no longer 56*8fb009dcSAndroid Build Coastguard Workerexist in BoringSSL. Instead, code which increments reference counts should call 57*8fb009dcSAndroid Build Coastguard Workerthe corresponding `FOO_up_ref` function, such as `EVP_PKEY_up_ref`. 58*8fb009dcSAndroid Build Coastguard Worker 59*8fb009dcSAndroid Build Coastguard WorkerBoringSSL also hides some structs which were previously exposed in OpenSSL 60*8fb009dcSAndroid Build Coastguard Worker1.0.2, particularly in libssl. Use the relevant accessors instead. 61*8fb009dcSAndroid Build Coastguard Worker 62*8fb009dcSAndroid Build Coastguard WorkerNote that some of these APIs were added in OpenSSL 1.1.0, so projects which do 63*8fb009dcSAndroid Build Coastguard Workernot yet support 1.1.0 may need additional `#ifdef`s. Projects supporting OpenSSL 64*8fb009dcSAndroid Build Coastguard Worker1.1.0 should not require modification. 65*8fb009dcSAndroid Build Coastguard Worker 66*8fb009dcSAndroid Build Coastguard Worker### Error codes 67*8fb009dcSAndroid Build Coastguard Worker 68*8fb009dcSAndroid Build Coastguard WorkerOpenSSL's errors are extremely specific, leaking internals of the library, 69*8fb009dcSAndroid Build Coastguard Workerincluding even a function code for the function which emitted the error! As some 70*8fb009dcSAndroid Build Coastguard Workerlogic in BoringSSL has been rewritten, code which conditions on the error may 71*8fb009dcSAndroid Build Coastguard Workerbreak (grep for `ERR_GET_REASON` and `ERR_GET_FUNC`). This danger also exists 72*8fb009dcSAndroid Build Coastguard Workerwhen upgrading OpenSSL versions. 73*8fb009dcSAndroid Build Coastguard Worker 74*8fb009dcSAndroid Build Coastguard WorkerWhere possible, avoid conditioning on the exact error reason. Otherwise, a 75*8fb009dcSAndroid Build Coastguard WorkerBoringSSL `#ifdef` may be necessary. Exactly how best to resolve this issue is 76*8fb009dcSAndroid Build Coastguard Workerstill being determined. It's possible some new APIs will be added in the future. 77*8fb009dcSAndroid Build Coastguard Worker 78*8fb009dcSAndroid Build Coastguard WorkerFunction codes have been completely removed. Remove code which conditions on 79*8fb009dcSAndroid Build Coastguard Workerthese as it will break with the slightest change in the library, OpenSSL or 80*8fb009dcSAndroid Build Coastguard WorkerBoringSSL. 81*8fb009dcSAndroid Build Coastguard Worker 82*8fb009dcSAndroid Build Coastguard Worker### `*_ctrl` functions 83*8fb009dcSAndroid Build Coastguard Worker 84*8fb009dcSAndroid Build Coastguard WorkerSome OpenSSL APIs are implemented with `ioctl`-style functions such as 85*8fb009dcSAndroid Build Coastguard Worker`SSL_ctrl` and `EVP_PKEY_CTX_ctrl`, combined with convenience macros, such as 86*8fb009dcSAndroid Build Coastguard Worker 87*8fb009dcSAndroid Build Coastguard Worker # define SSL_CTX_set_mode(ctx,op) \ 88*8fb009dcSAndroid Build Coastguard Worker SSL_CTX_ctrl((ctx),SSL_CTRL_MODE,(op),NULL) 89*8fb009dcSAndroid Build Coastguard Worker 90*8fb009dcSAndroid Build Coastguard WorkerIn BoringSSL, these macros have been replaced with proper functions. The 91*8fb009dcSAndroid Build Coastguard Workerunderlying `_ctrl` functions have been removed. 92*8fb009dcSAndroid Build Coastguard Worker 93*8fb009dcSAndroid Build Coastguard WorkerFor convenience, `SSL_CTRL_*` values are retained as macros to `doesnt_exist` so 94*8fb009dcSAndroid Build Coastguard Workerexisting code which uses them (or the wrapper macros) in `#ifdef` expressions 95*8fb009dcSAndroid Build Coastguard Workerwill continue to function. However, the macros themselves will not work. 96*8fb009dcSAndroid Build Coastguard Worker 97*8fb009dcSAndroid Build Coastguard WorkerSwitch any `*_ctrl` callers to the macro/function versions. This works in both 98*8fb009dcSAndroid Build Coastguard WorkerOpenSSL and BoringSSL. Note that BoringSSL's function versions will be 99*8fb009dcSAndroid Build Coastguard Workertype-checked and may require more care with types. See the end of this 100*8fb009dcSAndroid Build Coastguard Workerdocument for a table of functions to use. 101*8fb009dcSAndroid Build Coastguard Worker 102*8fb009dcSAndroid Build Coastguard Worker### HMAC `EVP_PKEY`s 103*8fb009dcSAndroid Build Coastguard Worker 104*8fb009dcSAndroid Build Coastguard Worker`EVP_PKEY_HMAC` is removed. Use the `HMAC_*` functions in `hmac.h` instead. This 105*8fb009dcSAndroid Build Coastguard Workeris compatible with OpenSSL. 106*8fb009dcSAndroid Build Coastguard Worker 107*8fb009dcSAndroid Build Coastguard Worker### DSA `EVP_PKEY`s 108*8fb009dcSAndroid Build Coastguard Worker 109*8fb009dcSAndroid Build Coastguard Worker`EVP_PKEY_DSA` is deprecated. It is currently still possible to parse DER into a 110*8fb009dcSAndroid Build Coastguard WorkerDSA `EVP_PKEY`, but signing or verifying with those objects will not work. 111*8fb009dcSAndroid Build Coastguard Worker 112*8fb009dcSAndroid Build Coastguard Worker### DES 113*8fb009dcSAndroid Build Coastguard Worker 114*8fb009dcSAndroid Build Coastguard WorkerThe `DES_cblock` type has been switched from an array to a struct to avoid the 115*8fb009dcSAndroid Build Coastguard Workerpitfalls around array types in C. Where features which require DES cannot be 116*8fb009dcSAndroid Build Coastguard Workerdisabled, BoringSSL-specific codepaths may be necessary. 117*8fb009dcSAndroid Build Coastguard Worker 118*8fb009dcSAndroid Build Coastguard Worker### TLS renegotiation 119*8fb009dcSAndroid Build Coastguard Worker 120*8fb009dcSAndroid Build Coastguard WorkerOpenSSL enables TLS renegotiation by default and accepts renegotiation requests 121*8fb009dcSAndroid Build Coastguard Workerfrom the peer transparently. Renegotiation is an extremely problematic protocol 122*8fb009dcSAndroid Build Coastguard Workerfeature, so BoringSSL rejects peer renegotiations by default. 123*8fb009dcSAndroid Build Coastguard Worker 124*8fb009dcSAndroid Build Coastguard WorkerTo enable renegotiation, call `SSL_set_renegotiate_mode` and set it to 125*8fb009dcSAndroid Build Coastguard Worker`ssl_renegotiate_once` or `ssl_renegotiate_freely`. Renegotiation is only 126*8fb009dcSAndroid Build Coastguard Workersupported as a client in TLS and the HelloRequest must be received at a 127*8fb009dcSAndroid Build Coastguard Workerquiet point in the application protocol. This is sufficient to support the 128*8fb009dcSAndroid Build Coastguard Workercommon use of requesting a new client certificate between an HTTP request and 129*8fb009dcSAndroid Build Coastguard Workerresponse in (unpipelined) HTTP/1.1. 130*8fb009dcSAndroid Build Coastguard Worker 131*8fb009dcSAndroid Build Coastguard WorkerThings which do not work: 132*8fb009dcSAndroid Build Coastguard Worker 133*8fb009dcSAndroid Build Coastguard Worker* There is no support for renegotiation as a server. (Attempts by clients will 134*8fb009dcSAndroid Build Coastguard Worker result in a fatal alert so that ClientHello messages cannot be used to flood 135*8fb009dcSAndroid Build Coastguard Worker a server and escape higher-level limits.) 136*8fb009dcSAndroid Build Coastguard Worker 137*8fb009dcSAndroid Build Coastguard Worker* There is no support for renegotiation in DTLS. 138*8fb009dcSAndroid Build Coastguard Worker 139*8fb009dcSAndroid Build Coastguard Worker* There is no support for initiating renegotiation; `SSL_renegotiate` always 140*8fb009dcSAndroid Build Coastguard Worker fails and `SSL_set_state` does nothing. 141*8fb009dcSAndroid Build Coastguard Worker 142*8fb009dcSAndroid Build Coastguard Worker* Interleaving application data with the new handshake is forbidden. 143*8fb009dcSAndroid Build Coastguard Worker 144*8fb009dcSAndroid Build Coastguard Worker* If a HelloRequest is received while `SSL_write` has unsent application data, 145*8fb009dcSAndroid Build Coastguard Worker the renegotiation is rejected. 146*8fb009dcSAndroid Build Coastguard Worker 147*8fb009dcSAndroid Build Coastguard Worker* Renegotiation does not participate in session resumption. The client will 148*8fb009dcSAndroid Build Coastguard Worker not offer a session on renegotiation or resume any session established by a 149*8fb009dcSAndroid Build Coastguard Worker renegotiation handshake. 150*8fb009dcSAndroid Build Coastguard Worker 151*8fb009dcSAndroid Build Coastguard Worker* The server may not change its certificate in the renegotiation. This mitigates 152*8fb009dcSAndroid Build Coastguard Worker the [triple handshake attack](https://mitls.org/pages/attacks/3SHAKE). Any new 153*8fb009dcSAndroid Build Coastguard Worker stapled OCSP response and SCT list will be ignored. As no authentication state 154*8fb009dcSAndroid Build Coastguard Worker may change, BoringSSL will not re-verify the certificate on a renegotiation. 155*8fb009dcSAndroid Build Coastguard Worker Callbacks such as `SSL_CTX_set_custom_verify` will only run on the initial 156*8fb009dcSAndroid Build Coastguard Worker handshake. 157*8fb009dcSAndroid Build Coastguard Worker 158*8fb009dcSAndroid Build Coastguard Worker### Lowercase hexadecimal 159*8fb009dcSAndroid Build Coastguard Worker 160*8fb009dcSAndroid Build Coastguard WorkerBoringSSL's `BN_bn2hex` function uses lowercase hexadecimal digits instead of 161*8fb009dcSAndroid Build Coastguard Workeruppercase. Some code may require changes to avoid being sensitive to this 162*8fb009dcSAndroid Build Coastguard Workerdifference. 163*8fb009dcSAndroid Build Coastguard Worker 164*8fb009dcSAndroid Build Coastguard Worker### Legacy ASN.1 functions 165*8fb009dcSAndroid Build Coastguard Worker 166*8fb009dcSAndroid Build Coastguard WorkerOpenSSL's ASN.1 stack uses `d2i` functions for parsing. They have the form: 167*8fb009dcSAndroid Build Coastguard Worker 168*8fb009dcSAndroid Build Coastguard Worker RSA *d2i_RSAPrivateKey(RSA **out, const uint8_t **inp, long len); 169*8fb009dcSAndroid Build Coastguard Worker 170*8fb009dcSAndroid Build Coastguard WorkerIn addition to returning the result, OpenSSL places it in `*out` if `out` is 171*8fb009dcSAndroid Build Coastguard Workernot `NULL`. On input, if `*out` is not `NULL`, OpenSSL will usually (but not 172*8fb009dcSAndroid Build Coastguard Workeralways) reuse that object rather than allocating a new one. In BoringSSL, these 173*8fb009dcSAndroid Build Coastguard Workerfunctions will always allocate a new object and free the previous one. 174*8fb009dcSAndroid Build Coastguard Worker 175*8fb009dcSAndroid Build Coastguard WorkerEnsure that callers do not rely on this object reuse behavior. It is 176*8fb009dcSAndroid Build Coastguard Workerrecommended to avoid the `out` parameter completely and always pass in `NULL`. 177*8fb009dcSAndroid Build Coastguard WorkerIn most cases, even in OpenSSL, relying on object reuse is not safe because, on 178*8fb009dcSAndroid Build Coastguard Workerparse error, OpenSSL will free the reused object. Note that less error-prone 179*8fb009dcSAndroid Build Coastguard WorkerAPIs are available for BoringSSL-specific code (see below). 180*8fb009dcSAndroid Build Coastguard Worker 181*8fb009dcSAndroid Build Coastguard Worker### Memory allocation 182*8fb009dcSAndroid Build Coastguard Worker 183*8fb009dcSAndroid Build Coastguard WorkerOpenSSL provides wrappers `OPENSSL_malloc` and `OPENSSL_free` over the standard 184*8fb009dcSAndroid Build Coastguard Worker`malloc` and `free`. Memory allocated by OpenSSL should be released with 185*8fb009dcSAndroid Build Coastguard Worker`OPENSSL_free`, not the standard `free`. However, by default, they are 186*8fb009dcSAndroid Build Coastguard Workerimplemented directly using `malloc` and `free`, so code which mixes them up 187*8fb009dcSAndroid Build Coastguard Workerusually works. 188*8fb009dcSAndroid Build Coastguard Worker 189*8fb009dcSAndroid Build Coastguard WorkerIn BoringSSL, these functions maintain additional book-keeping to zero memory 190*8fb009dcSAndroid Build Coastguard Workeron `OPENSSL_free`, so any mixups must be fixed. 191*8fb009dcSAndroid Build Coastguard Worker 192*8fb009dcSAndroid Build Coastguard Worker## Optional BoringSSL-specific simplifications 193*8fb009dcSAndroid Build Coastguard Worker 194*8fb009dcSAndroid Build Coastguard WorkerBoringSSL makes some changes to OpenSSL which simplify the API but remain 195*8fb009dcSAndroid Build Coastguard Workercompatible with OpenSSL consumers. In general, consult the BoringSSL 196*8fb009dcSAndroid Build Coastguard Workerdocumentation for any functions in new BoringSSL-only code. 197*8fb009dcSAndroid Build Coastguard Worker 198*8fb009dcSAndroid Build Coastguard Worker### Return values 199*8fb009dcSAndroid Build Coastguard Worker 200*8fb009dcSAndroid Build Coastguard WorkerMost OpenSSL APIs return 1 on success and either 0 or -1 on failure. BoringSSL 201*8fb009dcSAndroid Build Coastguard Workerhas narrowed most of these to 1 on success and 0 on failure. BoringSSL-specific 202*8fb009dcSAndroid Build Coastguard Workercode may take advantage of the less error-prone APIs and use `!` to check for 203*8fb009dcSAndroid Build Coastguard Workererrors. 204*8fb009dcSAndroid Build Coastguard Worker 205*8fb009dcSAndroid Build Coastguard Worker### Initialization 206*8fb009dcSAndroid Build Coastguard Worker 207*8fb009dcSAndroid Build Coastguard WorkerOpenSSL has a number of different initialization functions for setting up error 208*8fb009dcSAndroid Build Coastguard Workerstrings and loading algorithms, etc. All of these functions still exist in 209*8fb009dcSAndroid Build Coastguard WorkerBoringSSL for convenience, but they do nothing and are not necessary. BoringSSL 210*8fb009dcSAndroid Build Coastguard Workerinternally initializes itself as needed. 211*8fb009dcSAndroid Build Coastguard Worker 212*8fb009dcSAndroid Build Coastguard Worker### Threading 213*8fb009dcSAndroid Build Coastguard Worker 214*8fb009dcSAndroid Build Coastguard WorkerOpenSSL provides a number of APIs to configure threading callbacks and set up 215*8fb009dcSAndroid Build Coastguard Workerlocks. Without initializing these, the library is not thread-safe. Configuring 216*8fb009dcSAndroid Build Coastguard Workerthese does nothing in BoringSSL. Instead, BoringSSL calls pthreads and the 217*8fb009dcSAndroid Build Coastguard Workercorresponding Windows APIs internally and is always thread-safe where the API 218*8fb009dcSAndroid Build Coastguard Workerguarantees it. 219*8fb009dcSAndroid Build Coastguard Worker 220*8fb009dcSAndroid Build Coastguard Worker### ASN.1 221*8fb009dcSAndroid Build Coastguard Worker 222*8fb009dcSAndroid Build Coastguard WorkerBoringSSL is in the process of deprecating OpenSSL's `d2i` and `i2d` in favor of 223*8fb009dcSAndroid Build Coastguard Workernew functions using the much less error-prone `CBS` and `CBB` types. 224*8fb009dcSAndroid Build Coastguard WorkerBoringSSL-only code should use those functions where available. 225*8fb009dcSAndroid Build Coastguard Worker 226*8fb009dcSAndroid Build Coastguard Worker 227*8fb009dcSAndroid Build Coastguard Worker## Replacements for `CTRL` values 228*8fb009dcSAndroid Build Coastguard Worker 229*8fb009dcSAndroid Build Coastguard WorkerWhen porting code which uses `SSL_CTX_ctrl` or `SSL_ctrl`, use the replacement 230*8fb009dcSAndroid Build Coastguard Workerfunctions below. If a function has both `SSL_CTX` and `SSL` variants, only the 231*8fb009dcSAndroid Build Coastguard Worker`SSL_CTX` version is listed. 232*8fb009dcSAndroid Build Coastguard Worker 233*8fb009dcSAndroid Build Coastguard WorkerNote some values correspond to multiple functions depending on the `larg` 234*8fb009dcSAndroid Build Coastguard Workerparameter. 235*8fb009dcSAndroid Build Coastguard Worker 236*8fb009dcSAndroid Build Coastguard Worker`CTRL` value | Replacement function(s) 237*8fb009dcSAndroid Build Coastguard Worker-------------|------------------------- 238*8fb009dcSAndroid Build Coastguard Worker`DTLS_CTRL_GET_TIMEOUT` | `DTLSv1_get_timeout` 239*8fb009dcSAndroid Build Coastguard Worker`DTLS_CTRL_HANDLE_TIMEOUT` | `DTLSv1_handle_timeout` 240*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_CHAIN` | `SSL_CTX_set0_chain` or `SSL_CTX_set1_chain` 241*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_CHAIN_CERT` | `SSL_add0_chain_cert` or `SSL_add1_chain_cert` 242*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_CLEAR_EXTRA_CHAIN_CERTS` | `SSL_CTX_clear_extra_chain_certs` 243*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_CLEAR_MODE` | `SSL_CTX_clear_mode` 244*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_CLEAR_OPTIONS` | `SSL_CTX_clear_options` 245*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_EXTRA_CHAIN_CERT` | `SSL_CTX_add_extra_chain_cert` 246*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_CHAIN_CERTS` | `SSL_CTX_get0_chain_certs` 247*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_CLIENT_CERT_TYPES` | `SSL_get0_certificate_types` 248*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_EXTRA_CHAIN_CERTS` | `SSL_CTX_get_extra_chain_certs` or `SSL_CTX_get_extra_chain_certs_only` 249*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_MAX_CERT_LIST` | `SSL_CTX_get_max_cert_list` 250*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_NUM_RENEGOTIATIONS` | `SSL_num_renegotiations` 251*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_READ_AHEAD` | `SSL_CTX_get_read_ahead` 252*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_RI_SUPPORT` | `SSL_get_secure_renegotiation_support` 253*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_SESSION_REUSED` | `SSL_session_reused` 254*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_SESS_CACHE_MODE` | `SSL_CTX_get_session_cache_mode` 255*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_SESS_CACHE_SIZE` | `SSL_CTX_sess_get_cache_size` 256*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_TLSEXT_TICKET_KEYS` | `SSL_CTX_get_tlsext_ticket_keys` 257*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_GET_TOTAL_RENEGOTIATIONS` | `SSL_total_renegotiations` 258*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_MODE` | `SSL_CTX_get_mode` or `SSL_CTX_set_mode` 259*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_NEED_TMP_RSA` | `SSL_CTX_need_tmp_RSA` is equivalent, but [*do not use this function*](https://freakattack.com/). (It is a no-op in BoringSSL.) 260*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_OPTIONS` | `SSL_CTX_get_options` or `SSL_CTX_set_options` 261*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SESS_NUMBER` | `SSL_CTX_sess_number` 262*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_CURVES` | `SSL_CTX_set1_curves` 263*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_ECDH_AUTO` | `SSL_CTX_set_ecdh_auto` 264*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_MAX_CERT_LIST` | `SSL_CTX_set_max_cert_list` 265*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_MAX_SEND_FRAGMENT` | `SSL_CTX_set_max_send_fragment` 266*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_MSG_CALLBACK` | `SSL_set_msg_callback` 267*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_MSG_CALLBACK_ARG` | `SSL_set_msg_callback_arg` 268*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_MTU` | `SSL_set_mtu` 269*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_READ_AHEAD` | `SSL_CTX_set_read_ahead` 270*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_SESS_CACHE_MODE` | `SSL_CTX_set_session_cache_mode` 271*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_SESS_CACHE_SIZE` | `SSL_CTX_sess_set_cache_size` 272*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TLSEXT_HOSTNAME` | `SSL_set_tlsext_host_name` 273*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TLSEXT_SERVERNAME_ARG` | `SSL_CTX_set_tlsext_servername_arg` 274*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TLSEXT_SERVERNAME_CB` | `SSL_CTX_set_tlsext_servername_callback` 275*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TLSEXT_TICKET_KEYS` | `SSL_CTX_set_tlsext_ticket_keys` 276*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TLSEXT_TICKET_KEY_CB` | `SSL_CTX_set_tlsext_ticket_key_cb` 277*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TMP_DH` | `SSL_CTX_set_tmp_dh` 278*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TMP_DH_CB` | `SSL_CTX_set_tmp_dh_callback` 279*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TMP_ECDH` | `SSL_CTX_set_tmp_ecdh` 280*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TMP_ECDH_CB` | `SSL_CTX_set_tmp_ecdh_callback` 281*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TMP_RSA` | `SSL_CTX_set_tmp_rsa` is equivalent, but [*do not use this function*](https://freakattack.com/). (It is a no-op in BoringSSL.) 282*8fb009dcSAndroid Build Coastguard Worker`SSL_CTRL_SET_TMP_RSA_CB` | `SSL_CTX_set_tmp_rsa_callback` is equivalent, but [*do not use this function*](https://freakattack.com/). (It is a no-op in BoringSSL.) 283*8fb009dcSAndroid Build Coastguard Worker 284*8fb009dcSAndroid Build Coastguard Worker## Significant API additions 285*8fb009dcSAndroid Build Coastguard Worker 286*8fb009dcSAndroid Build Coastguard WorkerIn some places, BoringSSL has added significant APIs. Use of these APIs goes beyound “porting” and means giving up on OpenSSL compatibility. 287*8fb009dcSAndroid Build Coastguard Worker 288*8fb009dcSAndroid Build Coastguard WorkerOne example of this has already been mentioned: the [CBS and CBB](https://commondatastorage.googleapis.com/chromium-boringssl-docs/bytestring.h.html) functions should be used whenever parsing or serialising data. 289*8fb009dcSAndroid Build Coastguard Worker 290*8fb009dcSAndroid Build Coastguard Worker### CRYPTO\_BUFFER 291*8fb009dcSAndroid Build Coastguard Worker 292*8fb009dcSAndroid Build Coastguard WorkerWith the standard OpenSSL APIs, when making many TLS connections, the certificate data for each connection is retained in memory in an expensive `X509` structure. Additionally, common certificates often appear in the chains for multiple connections and are needlessly duplicated in memory. 293*8fb009dcSAndroid Build Coastguard Worker 294*8fb009dcSAndroid Build Coastguard WorkerA [`CRYPTO_BUFFER`](https://commondatastorage.googleapis.com/chromium-boringssl-docs/pool.h.html) is just an opaque byte string. A `CRYPTO_BUFFER_POOL` is an intern table for these buffers, i.e. it ensures that only a single copy of any given byte string is kept for each pool. 295*8fb009dcSAndroid Build Coastguard Worker 296*8fb009dcSAndroid Build Coastguard WorkerThe function `TLS_with_buffers_method` returns an `SSL_METHOD` that avoids creating `X509` objects for certificates. Additionally, `SSL_CTX_set0_buffer_pool` can be used to install a pool on an `SSL_CTX` so that certificates can be deduplicated across connections and across `SSL_CTX`s. 297*8fb009dcSAndroid Build Coastguard Worker 298*8fb009dcSAndroid Build Coastguard WorkerWhen using these functions, the application also needs to ensure that it doesn't call other functions that deal with `X509` or `X509_NAME` objects. For example, `SSL_get_peer_certificate` or `SSL_get_peer_cert_chain`. Doing so will trigger an assert in debug mode and will result in NULLs in release mode. Instead, call the buffer-based alternatives such as `SSL_get0_peer_certificates`. (See [ssl.h](https://commondatastorage.googleapis.com/chromium-boringssl-docs/ssl.h.html) for functions taking or returning `CRYPTO_BUFFER`.) The buffer-based alternative functions will work even when not using `TLS_with_buffers_method`, thus application code can transition gradually. 299*8fb009dcSAndroid Build Coastguard Worker 300*8fb009dcSAndroid Build Coastguard WorkerIn order to use buffers, the application code also needs to implement its own certificate verification using `SSL_[CTX_]set_custom_verify`. Otherwise all connections will fail with a verification error. Auto-chaining is also disabled when using buffers. 301*8fb009dcSAndroid Build Coastguard Worker 302*8fb009dcSAndroid Build Coastguard WorkerOnce those changes have been completed, the whole of the OpenSSL X.509 and ASN.1 code should be eliminated by the linker if BoringSSL is linked statically. 303*8fb009dcSAndroid Build Coastguard Worker 304*8fb009dcSAndroid Build Coastguard Worker### Asynchronous and opaque private keys 305*8fb009dcSAndroid Build Coastguard Worker 306*8fb009dcSAndroid Build Coastguard WorkerOpenSSL offers the ENGINE API for implementing opaque private keys (i.e. private keys where software only has oracle access because the secrets are held in special hardware or on another machine). While the ENGINE API has been mostly removed from BoringSSL, it is still possible to support opaque keys in this way. However, when using such keys with TLS and BoringSSL, you should strongly prefer using `SSL_PRIVATE_KEY_METHOD` via `SSL[_CTX]_set_private_key_method`. This allows a handshake to be suspended while the private operation is in progress. It also supports more forms of opaque key as it exposes higher-level information about the operation to be performed. 307