Skip to content

Commit d4a0c27

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.
1 parent 5f532c2 commit d4a0c27

File tree

2 files changed

+190
-0
lines changed

2 files changed

+190
-0
lines changed

deps/openssl/doc/UPGRADING.md

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

0 commit comments

Comments
 (0)