Skip to content

Commit 4830b4b

Browse files
author
Shigeki Ohtsu
committed
deps: add docs to upgrade openssl
This document is intended to describe the procedure to upgrade openssl from 1.0.1m to 1.0.2a in io.js. Fixes: #589 PR-URL: #1389 Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
1 parent deb9d23 commit 4830b4b

File tree

2 files changed

+191
-0
lines changed

2 files changed

+191
-0
lines changed

deps/openssl/doc/UPGRADING.md

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
## How to upgrade openssl library in io.js
2+
3+
This document describes the procedure to upgrade openssl from 1.0.1m
4+
to 1.0.2a in io.js.
5+
6+
7+
### Build System and Upgrading Overview
8+
The openssl build system is based on the `Configure` perl script in
9+
`deps/openssl/openssl`. For example, running `Configure linux_x86-64`
10+
in the openssl repository generates `Makefile` and `opensslconf.h` for
11+
the linux_x86_64 target architecture.
12+
13+
The `Makefile` contains the list of asm files which are generated by
14+
perl scripts during build so that we can get the most of use of the
15+
hardware performance according to the type of cpus.
16+
17+
`Configure TABLE` shows various build parameters that depend on each
18+
os and arch.
19+
20+
In io.js, build target is defined as `--dest-os` and `--dest-cpu` in
21+
configure options which are different from the one that is defined in
22+
openssl and it's build system is gyp that is based on python,
23+
therefore we cannot use the openssl build system directly.
24+
25+
In order to build openssl with gyp in iojs, files of opensslconf.h and
26+
asm are generated in advance for several supported platforms.
27+
28+
Here is a map table to show conf(opensslconf.h) and asm between
29+
the openssl target and configuration parameters of os and cpu in iojs.
30+
The tested platform in CI are also listed.
31+
32+
| --dest-os | --dest-cpu | conf | asm | openssl target | CI |
33+
|---------- |----------- |----- |----- |------------------- |--- |
34+
| linux | ia32 | o | o |linux-elf | o |
35+
| linux | x32 | o | x(*2)|linux-x32 | x |
36+
| linux | x64 | o | o |linux-x86_64 | o |
37+
| linux | arm | o | o |linux-arm | o |
38+
| linux | arm64 | o | o |linux-aarch64 | o |
39+
| mac | ia32 | o | o |darwin-i386-cc | - |
40+
| mac | x64 | o | o |darwin64-x86_64-cc | o |
41+
| win | ia32 | o | o(*3)|VC-WIN32 | x |
42+
| win | x64 | o | o |VC-WIN64A | o |
43+
| solaris | ia32 | o | o |solaris-x86-gcc | o |
44+
| solaris | x64 | o | o |solaris64-x86_64-gcc| o |
45+
| freebsd | ia32 | o | o |BSD-x86 | o |
46+
| freebsd | x64 | o | o |BSD-x86_64 | o |
47+
| openbsd | ia32 | o | o |BSD-x86 | x |
48+
| openbsd | x64 | o | o |BSD-x86_64 | x |
49+
| others | ia32 | x(*1)| o | - | x |
50+
| others | x64 | x(*1)| o | - | x |
51+
| others | arm | x(*1)| o | - | x |
52+
| others | arm64 | x(*1)| o | - | x |
53+
| others | others | x(*1)| x(*2)| - | x |
54+
55+
- (*1) use linux-elf as a fallback configuration
56+
- (*2) no-asm used
57+
- (*3) currently masm (Microsoft Macro Assembler) is used but it's no
58+
longer supported in openssl. We need to move to use nasm or yasm.
59+
60+
All parameters such as sources, defines, cflags and others generated
61+
in openssl Makefile are written down into `deps/openssl/openssl.gypi`.
62+
63+
The header file of `deps/openssl/openssl/crypto/opensslconf.h` are
64+
generated by `Configure` and varies on each os and arch so that we
65+
made a new `deps/openssl/config/opensslconf.h`, where it includes each
66+
conf file from `deps/openssl/config/archs/*/opensslconf.h` by using
67+
pre-defined compiler macros. This procedure can be processed
68+
automatically with `deps/openssl/config/Makefile`
69+
70+
Assembler support is one of the key features in openssl, but asm files
71+
are dynamically generated with
72+
`deps/openssl/openssl/crypto/*/asm/*.pl` by perl during
73+
build. Furthermore, these perl scripts check the version of assembler
74+
and generate asm files according to the supported instructions in each
75+
compiler.
76+
77+
Since perl is not a build requirement in iojs, they all should be
78+
generated in advance and statically stored in the repository. We
79+
provide two sets of asm files, one is asm_latest(avx2 and addx
80+
supported) in `deps/openssl/asm` and the other asm_obsolete(without
81+
avx1/2 and addx) in `deps/openssl/asm_obsolute`, which depends on
82+
supported features in assemblers. Each directory has a `Makefile`
83+
to generate asm files with perl scripts in openssl sources.
84+
85+
`configure` and gyp check the version of assemblers such as gnu
86+
as(gas), llvm and Visual Studio. `deps/openssl/openssl.gypi`
87+
determines what asm files should be used, in which the asm_latest
88+
needs the version of gas >= 2.23, llvm >= 3.3 or MSVS_VERSION>='2012'
89+
(ml64 >= 12) as defined in
90+
https://github.com/openssl/openssl/blob/OpenSSL_1_0_2-stable/crypto/sha/asm/sha512-x86_64.pl#L112-L129,
91+
otherwise asm_obsolete are used.
92+
93+
The following is the detail instruction steps how to upgrade openssl
94+
version from 1.0.1m to 1.0.2a in iojs.
95+
96+
### 1. Replace openssl source in `deps/openssl/openssl`
97+
Remove old openssl sources in `deps/openssl/openssl` .
98+
Get original openssl sources from
99+
https://www.openssl.org/source/openssl-1.0.2a.tar.gz and extract all
100+
files into `deps/openssl/openssl` .
101+
102+
### 2. Apply private patches
103+
There are three kinds of private patches to be applied in openssl-1.0.2a.
104+
105+
- The two fixes of assembly error on ia32 win32. masm is no longer
106+
supported in openssl. We should move to use nasm or yasm in future
107+
version of iojs.
108+
109+
- The fix of openssl-cli built on win. Key press requirement of
110+
openssl-cli in win causes timeout failures of several tests.
111+
112+
- Backport patches for alt cert feature from openssl-1.1.x. Root certs
113+
of 1024bit RSA key length were deprecated in io.js. When a tls
114+
server has a cross root cert, io.js client leads CERT_UNTRUSTED
115+
error because openssl does not find alternate cert chains. This fix
116+
supports its feature but was made the current master which is
117+
openssl-1.1.x. We backported them privately into openssl-1.0.2 on
118+
iojs.
119+
120+
### 3. Replace openssl header files in `deps/openssl/openssl/include/openssl`
121+
all header files in `deps/openssl/openssl/include/openssl/*.h` are
122+
symbolic links in the distributed release tar.gz. They cause issues in
123+
Windows. They are replaced into the files to include a real header
124+
file such as
125+
````
126+
#include "../../crypto/aes/aes.h"
127+
````
128+
### 4. Change `opensslconf.h` so as to fit each platform.
129+
The opensslconf.h in each target was created in advance by typing
130+
`deps/openssl/openssl/Configure {target}` and copied
131+
into `deps/openssl/conf/archs/{target}/opensslconf.h`.
132+
`deps/openssl/conf/openssconf.h` includes each file according to its
133+
target by checking pre-defined compiler macros. These can be generated
134+
by using `deps/openssl/conf/Makefile`
135+
136+
We should remove OPENSSL_CPUID_OBJ define in opensslconf.h because it
137+
causes build error when --openss-no-asm option is specified. Instead,
138+
the OPENSSL_CPUID_OBJ is defined in `deps/openssl/openssl.gypi`
139+
according to the configure options.
140+
141+
One fix of opensslconf.h is needed in 64-bit MacOS.
142+
The current openssl release does not use RC4 asm since it explicitly
143+
specified as `$asm=~s/rc4\-[^:]+//;` in
144+
https://github.com/openssl/openssl/blob/OpenSSL_1_0_1-stable/Configure#L584
145+
But iojs has used RC4 asm on MacOS for long time. Fix type of RC4_INT
146+
into `unsigned int` in opensslconf.h of darwin64-x86_64-cc to work on
147+
the RC4 asm.
148+
149+
### 5. Update openssl.gyp and openssl.gypi
150+
Sources, cflags and define parameters that depends on each target can
151+
be obtained via `Configure TABLE`. Its list is put in the table of
152+
[define and cflags changes in openssl-1.0.2a](openssl_define_list.pdf)
153+
154+
There is no way to verify all necessary sources automatically. We can
155+
only carefully look at the source list and compiled objects in
156+
Makefile of openssl and compare the compiled objects that stored
157+
stored under `out/Release/obj.target/openssl/deps/openssl/' in iojs.
158+
159+
### 6. ASM files for openssl
160+
We provide two sets of asm files. One is for the latest assembler
161+
and the other is the older one.
162+
163+
### 6.1. asm files for the latest compiler
164+
This was made in `deps/openssl/asm/Makefile`
165+
- Updated asm files for each platforms which are required in
166+
openssl-1.0.2a.
167+
- Some perl files need CC and ASM envs. Added a check if these envs
168+
exist. Followed asm files are to be generated with CC=gcc and
169+
ASM=nasm on Linux. See
170+
`deps/openssl/openssl/crypto/sha/asm/sha512-x86_64.pl`
171+
- Added new 32bit targets/rules with a sse2 flag (OPENSSL_IA32_SSE2)
172+
to generate asm for use SSE2.
173+
- Generating sha512 asm files in x86_64 need output filename which
174+
has 512. Added new rules so as not to use stdout for outputs.
175+
- PERLASM_SCHEME of linux-armv4 is `void` as defined in openssl
176+
Configure. Changed its target/rule and all directories are moved
177+
from arm-elf-gas to arm-void-gas.
178+
- add a new rule for armv8 asm generation
179+
180+
With export environments of CC=gcc and ASM=nasm, then type make
181+
command and check if new asm files are generated.
182+
183+
### 6.2.asm files for the older compiler
184+
For older assembler, the version check of CC and ASM should be
185+
skipped in generating asm file with perl scripts.
186+
Copy files from `deps/openssl/asm` into
187+
`deps/openssl/asm/asm_obsolete` and change rules to generate asm files
188+
into this directories and remove the check of CC and ASM envs.
189+
190+
Without environments of CC and ASM, then type make command and check
191+
if new asm files for older compilers are generated.
83.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)