11cb0ef41Sopenharmony_ci# Maintaining OpenSSL
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciOpenSSL is automatically updated by the [update-openssl-action][].
41cb0ef41Sopenharmony_ciThere is also a script in `tools/dep_updaters` that can be used to update it.
51cb0ef41Sopenharmony_ciThis document describes how to manually update `deps/openssl/`.
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_ciIf you need to provide updates across all active release lines you will
81cb0ef41Sopenharmony_cicurrently need to generate four PRs as follows:
91cb0ef41Sopenharmony_ci
101cb0ef41Sopenharmony_ci* a PR for `main` which is generated following the instructions
111cb0ef41Sopenharmony_ci  below for OpenSSL 3.x.x.
121cb0ef41Sopenharmony_ci* a PR for 18.x following the instructions in the v18.x-staging version
131cb0ef41Sopenharmony_ci  of this guide.
141cb0ef41Sopenharmony_ci* a PR for 16.x following the instructions in the v16.x-staging version
151cb0ef41Sopenharmony_ci  of this guide.
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci## Use of the quictls/openssl fork
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ciNode.js currently uses the quictls/openssl fork, which closely tracks
201cb0ef41Sopenharmony_cithe main openssl/openssl releases with the addition of APIs to support
211cb0ef41Sopenharmony_cithe QUIC protocol.
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ciDetails on the fork, as well as the latest sources, can be found at
241cb0ef41Sopenharmony_ci<https://github.com/quictls/openssl>.
251cb0ef41Sopenharmony_ci
261cb0ef41Sopenharmony_ciBranches are used per OpenSSL version (for instance,
271cb0ef41Sopenharmony_ci<https://github.com/quictls/openssl/tree/OpenSSL_1_1_1j+quic>).
281cb0ef41Sopenharmony_ci
291cb0ef41Sopenharmony_ci## Requirements
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_ci* Linux environment.
321cb0ef41Sopenharmony_ci* `perl` Only Perl version 5 is tested.
331cb0ef41Sopenharmony_ci* `nasm` (<https://www.nasm.us/>) Version 2.11 or higher is needed.
341cb0ef41Sopenharmony_ci* GNU `as` in binutils. Version 2.26 or higher is needed.
351cb0ef41Sopenharmony_ci
361cb0ef41Sopenharmony_ci## 0. Check requirements
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci```console
391cb0ef41Sopenharmony_ci% perl -v
401cb0ef41Sopenharmony_ci
411cb0ef41Sopenharmony_ciThis is perl 5, version 22, subversion 1 (v5.22.1) built for
421cb0ef41Sopenharmony_cix86_64-linux-gnu-thread-multi
431cb0ef41Sopenharmony_ci(with 60 registered patches, see perl -V for more detail)
441cb0ef41Sopenharmony_ci
451cb0ef41Sopenharmony_ci% as --version
461cb0ef41Sopenharmony_ciGNU assembler (GNU Binutils for Ubuntu) 2.26.1
471cb0ef41Sopenharmony_ciCopyright (C) 2015 Free Software Foundation, Inc.
481cb0ef41Sopenharmony_ci...
491cb0ef41Sopenharmony_ci% nasm -v
501cb0ef41Sopenharmony_ciNASM version 2.11.08
511cb0ef41Sopenharmony_ci```
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ci## 1. Obtain and extract new OpenSSL sources
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ciGet a new source from <https://github.com/quictls/openssl/tree/openssl-3.0.5+quic>
561cb0ef41Sopenharmony_ciand copy all files into `deps/openssl/openssl`. Then add all files and commit
571cb0ef41Sopenharmony_cithem. (The link above, and the branch, will change with each new OpenSSL
581cb0ef41Sopenharmony_cirelease).
591cb0ef41Sopenharmony_ci
601cb0ef41Sopenharmony_ci### OpenSSL 3.x.x
611cb0ef41Sopenharmony_ci
621cb0ef41Sopenharmony_ci```console
631cb0ef41Sopenharmony_ci% git clone https://github.com/quictls/openssl
641cb0ef41Sopenharmony_ci% cd openssl
651cb0ef41Sopenharmony_ci% cd ../node/deps/openssl
661cb0ef41Sopenharmony_ci% rm -rf openssl
671cb0ef41Sopenharmony_ci% cp -R ../../../openssl openssl
681cb0ef41Sopenharmony_ci% rm -rf openssl/.git* openssl/.travis*
691cb0ef41Sopenharmony_ci% git add --all openssl
701cb0ef41Sopenharmony_ci% git commit openssl
711cb0ef41Sopenharmony_ci```
721cb0ef41Sopenharmony_ci
731cb0ef41Sopenharmony_ci```text
741cb0ef41Sopenharmony_cideps: upgrade openssl sources to quictls/openssl-3.0.5+quic
751cb0ef41Sopenharmony_ci
761cb0ef41Sopenharmony_ciThis updates all sources in deps/openssl/openssl by:
771cb0ef41Sopenharmony_ci    $ git clone git@github.com:quictls/openssl.git
781cb0ef41Sopenharmony_ci    $ cd openssl
791cb0ef41Sopenharmony_ci    $ git checkout openssl-3.0.5+quic
801cb0ef41Sopenharmony_ci    $ cd ../node/deps/openssl
811cb0ef41Sopenharmony_ci    $ rm -rf openssl
821cb0ef41Sopenharmony_ci    $ cp -R ../../../openssl openssl
831cb0ef41Sopenharmony_ci    $ rm -rf openssl/.git* openssl/.travis*
841cb0ef41Sopenharmony_ci    $ git add --all openssl
851cb0ef41Sopenharmony_ci    $ git commit openssl
861cb0ef41Sopenharmony_ci```
871cb0ef41Sopenharmony_ci
881cb0ef41Sopenharmony_ci## 2. Execute `make` in `deps/openssl/config` directory
891cb0ef41Sopenharmony_ci
901cb0ef41Sopenharmony_ciUse `make` to regenerate all platform dependent files in
911cb0ef41Sopenharmony_ci`deps/openssl/config/archs/`:
921cb0ef41Sopenharmony_ci
931cb0ef41Sopenharmony_ci```console
941cb0ef41Sopenharmony_ci# On non-Linux machines
951cb0ef41Sopenharmony_ci% make gen-openssl
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ci# On Linux machines
981cb0ef41Sopenharmony_ci% make -C deps/openssl/config clean
991cb0ef41Sopenharmony_ci% make -C deps/openssl/config
1001cb0ef41Sopenharmony_ci```
1011cb0ef41Sopenharmony_ci
1021cb0ef41Sopenharmony_ci**Note**: If the 32-bit Windows is failing to compile run this workflow instead:
1031cb0ef41Sopenharmony_ci
1041cb0ef41Sopenharmony_ci```console
1051cb0ef41Sopenharmony_ci% make -C deps/openssl/config clean
1061cb0ef41Sopenharmony_ci# Edit deps/openssl/openssl/crypto/perlasm/x86asm.pl changing
1071cb0ef41Sopenharmony_ci# #ifdef to %ifdef to make it compatible to nasm on 32-bit Windows.
1081cb0ef41Sopenharmony_ci# See: https://github.com/nodejs/node/pull/43603#issuecomment-1170670844
1091cb0ef41Sopenharmony_ci# Reference: https://github.com/openssl/openssl/issues/18459
1101cb0ef41Sopenharmony_ci```
1111cb0ef41Sopenharmony_ci
1121cb0ef41Sopenharmony_ci## 3. Check diffs
1131cb0ef41Sopenharmony_ci
1141cb0ef41Sopenharmony_ciCheck diffs to ensure updates are right. Even if there are no updates in openssl
1151cb0ef41Sopenharmony_cisources, `buildinf.h` files will be updated because they have timestamp
1161cb0ef41Sopenharmony_cidata in them.
1171cb0ef41Sopenharmony_ci
1181cb0ef41Sopenharmony_ci```console
1191cb0ef41Sopenharmony_ci% git diff -- deps/openssl
1201cb0ef41Sopenharmony_ci```
1211cb0ef41Sopenharmony_ci
1221cb0ef41Sopenharmony_ci_Note_: On Windows, OpenSSL Configure generates a `makefile` that can be
1231cb0ef41Sopenharmony_ciused for the `nmake` command. The `make` command in step 2 (above) uses
1241cb0ef41Sopenharmony_ci`Makefile_VC-WIN64A` and `Makefile_VC-WIN32` that are manually
1251cb0ef41Sopenharmony_cicreated. When source files or build options are updated in Windows,
1261cb0ef41Sopenharmony_ciit needs to change these two Makefiles by hand. If you are not sure,
1271cb0ef41Sopenharmony_ciplease ask @shigeki for details.
1281cb0ef41Sopenharmony_ci
1291cb0ef41Sopenharmony_ci## 4. Commit and make test
1301cb0ef41Sopenharmony_ci
1311cb0ef41Sopenharmony_ciUpdate all architecture dependent files. Do not forget to git add or remove
1321cb0ef41Sopenharmony_cifiles if they are changed before committing:
1331cb0ef41Sopenharmony_ci
1341cb0ef41Sopenharmony_ci```console
1351cb0ef41Sopenharmony_ci% git add deps/openssl/config/archs
1361cb0ef41Sopenharmony_ci% git add deps/openssl/openssl
1371cb0ef41Sopenharmony_ci% git commit
1381cb0ef41Sopenharmony_ci```
1391cb0ef41Sopenharmony_ci
1401cb0ef41Sopenharmony_ciThe commit message can be written as (with the openssl version set
1411cb0ef41Sopenharmony_cito the relevant value):
1421cb0ef41Sopenharmony_ci
1431cb0ef41Sopenharmony_ci### OpenSSL 3.x.x
1441cb0ef41Sopenharmony_ci
1451cb0ef41Sopenharmony_ci```text
1461cb0ef41Sopenharmony_cideps: update archs files for quictls/openssl-3.0.5+quic
1471cb0ef41Sopenharmony_ci
1481cb0ef41Sopenharmony_ciAfter an OpenSSL source update, all the config files need to be
1491cb0ef41Sopenharmony_ciregenerated and committed by:
1501cb0ef41Sopenharmony_ci    $ make -C deps/openssl/config
1511cb0ef41Sopenharmony_ci    $ git add deps/openssl/config/archs
1521cb0ef41Sopenharmony_ci    $ git add deps/openssl/openssl
1531cb0ef41Sopenharmony_ci    $ git commit
1541cb0ef41Sopenharmony_ci```
1551cb0ef41Sopenharmony_ci
1561cb0ef41Sopenharmony_ciFinally, build Node.js and run the tests.
1571cb0ef41Sopenharmony_ci
1581cb0ef41Sopenharmony_ci[update-openssl-action]: ../../../.github/workflows/update-openssl.yml
159