Debian Codegraph @

crt/s2n/docs/BUILD.md

raw symbols SCIP
1 # Building s2n-tls
2
3 s2n-tls can be built as follows:
4
5 <details open>
6 <summary>Ubuntu</summary>
7
8 ```bash
9 # install build dependencies
10 sudo apt update
11 sudo apt install cmake
12
13 # install a libcrypto
14 sudo apt install libssl-dev
15
16 # build s2n-tls
17 cmake . -Bbuild \
18 -DCMAKE_BUILD_TYPE=Release \
19 -DCMAKE_INSTALL_PREFIX=./s2n-tls-install
20 cmake --build build -j $(nproc)
21 CTEST_PARALLEL_LEVEL=$(nproc) ctest --test-dir build
22 cmake --install build
23 ```
24 </details>
25
26 <details>
27 <summary>MacOS</summary>
28
29 ```bash
30 # install build dependencies
31 brew install cmake
32
33 # install a libcrypto
34 brew install openssl@3
35
36 # build s2n-tls
37 cmake . -Bbuild \
38 -DCMAKE_BUILD_TYPE=Release \
39 -DCMAKE_PREFIX_PATH=$(dirname $(dirname $(brew list openssl@3|grep libcrypto.dylib))) \
40 -DCMAKE_INSTALL_PREFIX=./s2n-tls-install
41 cmake --build build -j $(sysctl -n hw.ncpu)
42 CTEST_PARALLEL_LEVEL=$(sysctl -n hw.ncpu) ctest --test-dir build
43 cmake --install build
44 ```
45 </details>
46
47 <details>
48 <summary>AL2</summary>
49
50 ```bash
51 # install build dependencies
52 sudo yum groupinstall "Development Tools"
53 sudo yum install cmake3
54
55 # install a libcrypto
56 sudo yum install openssl-devel
57
58 # build s2n-tls
59 cmake3 . -Bbuild \
60 -DCMAKE_BUILD_TYPE=Release \
61 -DCMAKE_INSTALL_PREFIX=./s2n-tls-install \
62 -DCMAKE_EXE_LINKER_FLAGS="-lcrypto -lz"
63 cmake3 --build build -j $(nproc)
64 cd build
65 CTEST_PARALLEL_LEVEL=$(nproc) ctest3
66 cd ..
67 cmake3 --install build
68 ```
69 </details>
70
71 Note that we currently do not support building on Windows. See https://github.com/aws/s2n-tls/issues/497 for more information.
72
73 Using the commands above, the libraries and headers will be located in the `s2n-tls-install` directory.
74
75 The s2nc and s2nd test utilities are not installed by default, but can be found in the `build/bin` directory. To also install s2nc and s2nd, add `-DS2N_INSTALL_S2NC_S2ND=1` to the cmake command.
76
77 ## Consuming s2n-tls via CMake
78
79 s2n-tls ships with modern CMake finder scripts if CMake is used for the build. To take advantage of this from your CMake script, all you need to do to compile and link against s2n-tls in your project is:
80
81 ````bash
82 find_package(s2n)
83
84 ....
85
86 target_link_libraries(yourExecutableOrLibrary AWS::s2n)
87 ````
88
89 And when invoking CMake for your project, do one of two things:
90 1. Set the `CMAKE_INSTALL_PREFIX` variable with the path to your s2n-tls build.
91 2. If you have globally installed s2n-tls, do nothing, it will automatically be found.
92
93 ## Configuring the s2n-tls build
94
95 s2n-tls can be configured with the following CMake options. Each option can be set by passing a `-D<option>=<value>` flag to CMake.
96 - [**`CMAKE_BUILD_TYPE`**](https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html): Sets the build type. Some of the possible build types are as follows:
97 - `Release`: Produce an optimized s2n-tls library artifact with no debug info. This option should be used when building s2n-tls for use in production.
98 - `Debug`: Produce an unoptimized library artifact with debug info. This option can be used when developing for or with s2n-tls. The debug symbols produced with this build can be used with GDB and other utilities to help with debugging.
99 - [**`CMAKE_INSTALL_PREFIX`**](https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX.html): Specifies where the s2n-tls library artifacts are placed when installing s2n-tls.
100 - [**`CMAKE_PREFIX_PATH`**](https://cmake.org/cmake/help/latest/variable/CMAKE_PREFIX_PATH.html): Specifies install locations used by CMake to search for library dependencies. This option can be used to link s2n-tls to a specific libcrypto. See the [Building with a specific libcrypto](#building-with-a-specific-libcrypto) section for more information on building with different libcryptos.
101 - [**`BUILD_SHARED_LIBS`**](https://cmake.org/cmake/help/latest/variable/BUILD_SHARED_LIBS.html): Specifies whether a static or shared s2n-tls library artifact will be produced during the build. Defaults to `OFF`, building a static library. If set to `ON`, a shared library will be produced instead.
102
103 The entire list of s2n-tls CMake options can be viewed with the following command:
104
105 ```bash
106 cmake . -LH
107 ```
108
109 ## Building with a specific libcrypto
110
111 s2n-tls has a dependency on a libcrypto library. A supported libcrypto must be linked to s2n-tls when building. The following libcrypto libraries are currently supported:
112 - [AWS-LC](https://github.com/aws/aws-lc)
113 - Limited ["Sandboxing"](https://github.com/aws/aws-lc/blob/main/SANDBOXING.md) is only supported and tested with AWS-LC.
114 - [PQ key exchange](https://aws.github.io/s2n-tls/usage-guide/ch15-post-quantum.html) is only supported with AWS-LC.
115 - FIPS mode is supported with versions of AWS-LC [that support
116 FIPS](https://github.com/aws/aws-lc/blob/main/crypto/fipsmodule/FIPS.md).
117 - [OpenSSL](https://www.openssl.org/) (versions 1.0.2 - 3.0)
118 - ChaChaPoly is not supported before Openssl-1.1.1.
119 - RSA-PSS is not supported before Openssl-1.1.1.
120 - RC4 is not supported with Openssl-3.0 or later.
121 - FIPS mode is supported with FIPS-validated versions of Openssl-3.0, with caveats: see [details](#openssl-fips).
122 - [BoringSSL](https://boringssl.googlesource.com/boringssl)
123 - OCSP features are not supported with BoringSSL.
124 - FIPS mode is not supported with BoringSSL.
125 - [LibreSSL](https://www.libressl.org/)
126
127 By default, s2n-tls will attempt to find a system libcrypto to link with when building. However, this search can be overridden to any of the above libcryptos by specifying the install directory with the `CMAKE_PREFIX_PATH` flag.
128
129 For help building a desired libcrypto on your platform, please consult the project's build documentation.
130
131 ### AWS-LC
132
133 [AWS-LC](https://github.com/aws/aws-lc) is the recommended libcrypto to use with s2n-tls due to increased performance and security. See the [AWS-LC build documentation](https://github.com/aws/aws-lc/blob/main/BUILDING.md) for information on building AWS-LC.
134
135 The `CMAKE_INSTALL_PREFIX` option can be provided when building AWS-LC to specify where AWS-LC will be installed. The install path for AWS-LC should be provided when building s2n-tls, via the `CMAKE_PREFIX_PATH` option. This will ensure that s2n-tls is able to find the AWS-LC library artifact to link with.
136
137 ### AWS-LC FIPS
138
139 s2n-tls supports FIPS mode when built with a FIPS validated version of aws-lc. See the [AWS-LC FIPS documentation](https://github.com/aws/aws-lc/blob/main/crypto/fipsmodule/FIPS.md) for more information. The security policy listed for each FIPS validation includes instructions for how to build the validated version.
140
141 ### Openssl FIPS
142
143 You should consider using AWS-LC if you require FIPS. AWS-LC is s2n-tls's recommended libcrypto: see [Why AWS-LC?](https://github.com/aws/aws-lc/blob/main/README.md#why-aws-lc). You can use the `S2N_INTERN_LIBCRYPTO` CMake option to "intern" AWS-LC and keep it isolated to s2n-tls if AWS-LC symbols would conflict with Openssl symbols in your environment.
144
145 But if you must use Openssl instead of AWS-LC, then s2n-tls does support FIPS mode when built with a FIPS-validated version of Openssl. See the [Openssl FIPS documentation](https://github.com/openssl/openssl/blob/master/README-FIPS.md) for how to build a FIPS-validated version of Openssl.
146
147 Note that currently s2n-tls only supports the Openssl-3.0 version of FIPS-validated Openssl. Openssl-3.0 has a FIPS 140-2 certificate, NOT a FIPS 140-3 certificate. If you require FIPS 140-3, consider using AWS-LC instead. Once Openssl releases a FIPS 140-3 validated version (currently planned for Openssl-3.5), then the s2n-tls integration can be updated. Because of the significant changes made in FIPS 140-3, simply building s2n-tls with a FIPS 140-3 validated version of Openssl will not meet all FIPS 140-3 requirements.
148
149 When running in FIPS mode with Openssl, s2n-tls does not support RSA 1024 certificates (https://github.com/aws/s2n-tls/issues/5200) or ChaChaPoly (https://github.com/aws/s2n-tls/issues/5199), even if allowed by the configured security policy. As with non-FIPS Openssl, RC4 is also not supported.
150
151 s2n-tls requires that Openssl be configured with the default provider in addition to the FIPS provider. The base provider is NOT sufficient. s2n-tls assumes that non-FIPS algorithms like MD5 and SHA1 are available even when built with FIPS-validated Openssl. If you are following the [Openssl documentation for how to configure FIPS](https://docs.openssl.org/master/man7/fips_module/), your openssl.cnf must include:
152 ```
153 [provider_sect]
154 default = default_sect
155 fips = fips_sect
156
157 [default_sect]
158 activate = 1
159 ```
160 Note the use of `default` instead of `base`. You can see the openssl.cnf that s2n-tls uses for testing [here](https://github.com/aws/s2n-tls/blob/main/codebuild/bin/s2n_fips_openssl.cnf).
161
162
163 ## Other build methods
164
165 ### Ninja build system
166
167 [Ninja](https://ninja-build.org/) can be specified as the build system with CMake, which can increase build performance:
168
169 <details open>
170 <summary>Ubuntu</summary>
171
172 ```bash
173 # install ninja
174 sudo apt update
175 sudo apt install ninja-build
176
177 # build s2n-tls with ninja
178 cmake . -Bbuild -GNinja \
179 -DCMAKE_BUILD_TYPE=Release \
180 -DCMAKE_INSTALL_PREFIX=./s2n-tls-install
181 ninja -C build -j $(nproc)
182 CTEST_PARALLEL_LEVEL=$(nproc) ninja -C build test
183 ninja -C build install
184 ```
185 </details>
186
187 ### Traditional Makefile
188
189 CMake is the preferred build system for s2n-tls since it includes updated build features and supports the most platforms. However, building s2n-tls with a traditional Makefile is also supported on some platforms. With make, the desired libcrypto install path must be set with the `LIBCRYPTO_ROOT` environment variable.
190
191 <details open>
192 <summary>Ubuntu</summary>
193
194 ```bash
195 LIBCRYPTO_ROOT=/usr/local/ssl make
196 ```
197 </details>
198
199 ### Nix
200
201 s2n-tls supports building with Nix, which can be used for s2n-tls development to set up an environment that closely matches our CI. If Nix is installed, s2n-tls can be built with the following:
202
203 ```bash
204 nix develop
205 configure; build
206 ```
207
208 For more information on installing Nix and using Nix with s2n-tls, see the [s2n-tls Nix documentation](../nix/README.md).
209
210 ## mlock() and system limits
211
212 Internally s2n-tls uses mlock() to prevent memory from being swapped to disk. The
213 s2n-tls build tests may fail in some environments where the default limit on locked
214 memory is too low. To check this limit, run:
215
216 ```bash
217 ulimit -l
218 ```
219
220 to raise the limit, consult the documentation for your platform.
221
222 ### Disabling mlock()
223
224 To disable s2n-tls's mlock behavior, run your application with the `S2N_DONT_MLOCK` environment variable set to 1.
225 s2n-tls also reads this for unit tests. Try setting this environment variable before running the unit tests if you're having mlock failures.
226
227 ## Cross Compiling for 32 Bit Platforms
228
229 There is an example toolchain for 32 bit cross-compiling in [`cmake/toolchains/32-bit.toolchain`](../cmake/toolchains/32-bit.toolchain).
230
231 First, you will need access to a 32 bit version of libcrypto. Many linux distributions are [multi-arch](https://help.ubuntu.com/community/MultiArch) compatible which allows you to download 32 bit packages on a 64 bit platform. This can be done with the following:
232
233 <details open>
234 <summary>Ubuntu</summary>
235
236 ```bash
237 # install build dependencies
238 sudo apt update
239 sudo apt install cmake clang gcc-multilib
240
241 # we're interested in i386 (32 bit) architectures
242 sudo dpkg --add-architecture i386
243
244 # install the 32 bit (i386) version of libcrypto
245 sudo apt install libssl-dev:i386
246
247 # wipe the build directory to clear the CMake cache
248 rm -rf build
249
250 # build with the toolchain
251 cmake . -Bbuild -DCMAKE_TOOLCHAIN_FILE=cmake/toolchains/32-bit.toolchain
252 cmake --build ./build -j $(nproc)
253 CTEST_PARALLEL_LEVEL=$(nproc) ctest --test-dir build
254 ```
255 </details>
256
257 ## RAND engine override
258
259 > **Note:** The custom RAND engine was removed as part of the DRBG deprecation. s2n-tls now delegates all randomness directly to the linked libcrypto or to `/dev/urandom` (for older libcryptos like OpenSSL 1.0.2 that lack `RAND_priv_bytes` and `RAND_public_bytes`). The `S2N_OVERRIDE_LIBCRYPTO_RAND_ENGINE` CMake flag is retained for backwards compatibility but is a no-op.