Skip to content

Commit 43c951f

Browse files
committed
Add support for OpenSSL 1.1.0
This commit is relatively major refactoring of the `openssl-sys` crate as well as the `openssl` crate itself. The end goal here was to support OpenSSL 1.1.0, and lots of other various tweaks happened along the way. The major new features are: * OpenSSL 1.1.0 is supported * OpenSSL 0.9.8 is no longer supported (aka all OSX users by default) * All FFI bindings are verified with the `ctest` crate (same way as the `libc` crate) * CI matrixes are vastly expanded to include 32/64 of all platforms, more OpenSSL version coverage, as well as ARM coverage on Linux * The `c_helpers` module is completely removed along with the `gcc` dependency. * The `openssl-sys` build script was completely rewritten * Now uses `OPENSSL_DIR` to find the installation, not include/lib env vars. * Better error messages for mismatched versions. * Better error messages for failing to find OpenSSL on a platform (more can be done here) * Probing of OpenSSL build-time configuration to inform the API of the `*-sys` crate. * Many Cargo features have been removed as they're now enabled by default. As this is a breaking change to both the `openssl` and `openssl-sys` crates this will necessitate a major version bump of both. There's still a few more API questions remaining but let's hash that out on a PR! Closes #452
1 parent c1e4134 commit 43c951f

38 files changed

+2508
-1438
lines changed

.travis.yml

Lines changed: 81 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,86 @@
11
language: rust
2-
sudo: false
3-
addons:
4-
apt:
5-
packages:
6-
- gcc-arm-linux-gnueabihf
7-
rust:
8-
- nightly
9-
- 1.9.0
10-
os:
11-
- osx
12-
- linux
2+
sudo: required
3+
rust: stable
4+
dist: trusty
5+
136
env:
14-
matrix:
15-
- TEST_FEATURES=false
16-
- TEST_FEATURES=true
7+
global:
8+
- TARGET=x86_64-unknown-linux-gnu
179
matrix:
18-
# include:
19-
# - os: linux
20-
# env: TARGET=arm-unknown-linux-gnueabihf TEST_FEATURES=true
21-
# rust: 1.7.0
22-
exclude:
23-
- os: osx
24-
env: TEST_FEATURES=true
10+
include:
11+
# ARM-bit version compat
12+
- env: >
13+
TARGET=arm-unknown-linux-gnueabihf
14+
BUILD_OPENSSL_VERSION=1.0.2h
15+
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc
16+
QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
17+
RUST_TEST_THREADS=1
18+
addons:
19+
apt:
20+
packages:
21+
- gcc-arm-linux-gnueabihf
22+
- qemu-user-static
23+
- libc6-dev-armhf-cross
24+
- binfmt-support
25+
- env: >
26+
TARGET=arm-unknown-linux-gnueabihf
27+
BUILD_OPENSSL_VERSION=1.1.0b
28+
CARGO_TARGET_ARM_UNKNOWN_LINUX_GNUEABIHF_LINKER=arm-linux-gnueabihf-gcc
29+
QEMU_LD_PREFIX=/usr/arm-linux-gnueabihf
30+
RUST_TEST_THREADS=1
31+
addons:
32+
apt:
33+
packages:
34+
- gcc-arm-linux-gnueabihf
35+
- qemu-user-static
36+
- libc6-dev-armhf-cross
37+
- binfmt-support
38+
39+
# Minimum version supported
40+
- rust: 1.9.0
41+
42+
# beta/nightly channels
43+
- rust: beta
44+
- rust: nightly
45+
46+
# 64-bit version compat
47+
- env: BUILD_OPENSSL_VERSION=1.0.1u
48+
- env: BUILD_OPENSSL_VERSION=1.0.2h
49+
- env: BUILD_OPENSSL_VERSION=1.1.0b
50+
51+
# 32-bit version compat
52+
- env: TARGET=i686-unknown-linux-gnu BUILD_OPENSSL_VERSION=1.0.1u
53+
addons:
54+
apt:
55+
packages:
56+
- gcc-multilib
57+
- env: TARGET=i686-unknown-linux-gnu BUILD_OPENSSL_VERSION=1.0.2h
58+
addons:
59+
apt:
60+
packages:
61+
- gcc-multilib
62+
- env: TARGET=i686-unknown-linux-gnu BUILD_OPENSSL_VERSION=1.1.0b
63+
addons:
64+
apt:
65+
packages:
66+
- gcc-multilib
67+
68+
# osx 32/64
69+
- os: osx
70+
env: TARGET=x86_64-apple-darwin
71+
- os: osx
72+
env: TARGET=i686-apple-darwin
73+
install: brew uninstall openssl && brew install openssl --universal
74+
75+
2576
before_install:
26-
- ./openssl/test/build.sh
77+
- ./openssl/test/build.sh
78+
- curl https://static.rust-lang.org/rustup.sh |
79+
sh -s -- --add-target=$TARGET --disable-sudo -y --prefix=`rustc --print sysroot`
2780
script:
28-
- ./openssl/test/run.sh
81+
- ./openssl/test/run.sh
82+
83+
cache:
84+
cargo: true
85+
directories:
86+
- $HOME/openssl

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[workspace]
2-
members = ["openssl", "openssl-sys"]
2+
members = ["openssl", "openssl-sys", "systest"]

README.md

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66

77
## Building
88

9-
rust-openssl depends on both the OpenSSL runtime libraries and headers.
9+
rust-openssl depends on the OpenSSL runtime libraries version 1.0.1 or above.
10+
Currently the libraries need to be present in the build environment before this
11+
crate is compiled, and some instructions of how to do this are in the sections
12+
below.
1013

1114
### Linux
1215

13-
On Linux, you can install OpenSSL via your package manager. The headers are
14-
sometimes provided in a separate package than the runtime libraries - look for
15-
something like `openssl-devel` or `libssl-dev`.
16+
On Linux, you can typically install OpenSSL via your package manager. The
17+
headers are sometimes provided in a separate package than the runtime libraries
18+
- look for something like `openssl-devel` or `libssl-dev`.
1619

1720
```bash
1821
# On Ubuntu
@@ -23,79 +26,78 @@ sudo pacman -S openssl
2326
sudo dnf install openssl-devel
2427
```
2528

29+
If installation via a package manager is not possible, or if you're cross
30+
compiling to a separate target, you'll typically need to compile OpenSSL from
31+
source. That can normally be done with:
32+
33+
```
34+
curl -O https://www.openssl.org/source/openssl-1.1.0b.tar.gz
35+
tar xf openssl-1.1.0b.tar.gz
36+
cd openssl-1.1.0b
37+
export CC=...
38+
./Configure --prefix=... linux-x86_64 -fPIC
39+
make -j$(nproc)
40+
make install
41+
```
42+
2643
### OSX
2744

28-
OpenSSL 0.9.8 is preinstalled on OSX. Some features are only available when
29-
linking against OpenSSL 1.0.0 or greater; see below on how to point
30-
rust-openssl to a separate installation. OSX releases starting at 10.11, "El
31-
Capitan", no longer include OpenSSL headers which will prevent the `openssl`
32-
crate from compiling.
45+
Although OpenSSL 0.9.8 is preinstalled on OSX this library is being phased out
46+
of OSX and this crate also does not support this version of OpenSSL. To use this
47+
crate on OSX you'll need to install OpenSSL via some alternate means, typically
48+
homebrew:
3349

34-
For OSX 10.11 you can use brew to install OpenSSL and then set the environment variables
35-
as described below.
3650
```bash
3751
brew install openssl
38-
export OPENSSL_INCLUDE_DIR=`brew --prefix openssl`/include
39-
export OPENSSL_LIB_DIR=`brew --prefix openssl`/lib
4052
```
4153

42-
May be necessary clean the repository with `cargo clean` before build again.
54+
### Windows MSVC
4355

44-
### Windows
56+
On MSVC it's unfortunately not always a trivial process acquiring OpenSSL.
57+
Perhaps the easiest way to do this right now is to download [precompiled
58+
binaries] and install them on your system. Currently it's recommended to
59+
install the 1.1.0b light installation if you're choosing this route.
4560

46-
On Windows, consider building with [mingw-w64](http://mingw-w64.org/).
47-
Build script will try to find mingw in `PATH` environment variable to provide
48-
Cargo with location where openssl libs from mingw-w64 package may be found.
61+
[precompiled binaries]: http://slproweb.com/products/Win32OpenSSL.html
4962

50-
mingw-w64 can be easily installed by using [MSYS2](http://msys2.github.io/). Install MSYS2 according to the instructions, and then, from an MSYS2 Shell, install mingw-w64:
63+
Once a precompiled binary is installed you can configure this crate to find the
64+
installation via an environment variable:
5165

52-
32-bit:
53-
```bash
54-
pacman -S mingw-w64-i686-gcc
55-
```
56-
57-
64-bit
58-
```bash
59-
pacman -S mingw-w64-x86_64-gcc
66+
```
67+
set OPENSSL_DIR=C:\OpenSSL-Win64
6068
```
6169

62-
and then install the mingw-w64 toolchain.
70+
After that, you're just a `cargo build` away!
6371

64-
32-bit:
65-
```bash
66-
pacman -S mingw-w64-i686-toolchain
67-
```
72+
### Windows GNU (MinGW)
6873

69-
64-bit:
70-
```bash
71-
pacman -S mingw-w64-x86_64-toolchain
72-
```
74+
The easiest way to acquire OpenSSL when working with MinGW is to ensure you're
75+
using [MSYS2](http://msys2.github.io) and to then execute:
7376

74-
Alternatively, install OpenSSL from [here][1]. Cargo will not be able to find OpenSSL if it's
75-
installed to the default location. You can either copy the `include/openssl`
76-
directory, `libssl32.dll`, and `libeay32.dll` to locations that Cargo can find
77-
or pass the location to Cargo via environment variables:
77+
```
78+
# 32-bit
79+
pacman -S mingw-w64-i686-openssl
7880
79-
```bash
80-
env OPENSSL_LIB_DIR=C:/OpenSSL-Win64 OPENSSL_INCLUDE_DIR=C:/OpenSSL-Win64/include cargo build
81+
# 64-bit
82+
pacman -S mingw-w64-x86_64-openssl
8183
```
8284

85+
And after that, a `cargo build` should be all you need!
86+
8387
### Manual configuration
8488

8589
rust-openssl's build script will by default attempt to locate OpenSSL via
86-
pkg-config. This will not work in some situations, for example, on systems that
87-
don't have pkg-config, when cross compiling, or when using a copy of OpenSSL
90+
pkg-config or other system-specific mechanisms. This will not work in some
91+
situations however, for example cross compiling or when using a copy of OpenSSL
8892
other than the normal system install.
8993

9094
The build script can be configured via environment variables:
91-
* `OPENSSL_LIB_DIR` - If specified, a directory that will be used to find
92-
OpenSSL runtime libraries.
93-
* `OPENSSL_INCLUDE_DIR` - If specified, a directory that will be used to find
94-
OpenSSL headers.
95-
* `OPENSSL_STATIC` - If specified, OpenSSL libraries will be statically rather
96-
than dynamically linked.
9795

98-
If either `OPENSSL_LIB_DIR` or `OPENSSL_INCLUDE_DIR` are specified, then the
99-
build script will skip the pkg-config step.
96+
* `OPENSSL_DIR` - If specified, a directory that will be used to find
97+
OpenSSL installation. It's expected that under this directory the `include`
98+
folder has header files and a `lib` folder has the runtime libraries.
99+
* `OPENSSL_STATIC` - If specified, OpenSSL libraries will be statically rather
100+
than dynamically linked.
100101

101-
[1]: http://slproweb.com/products/Win32OpenSSL.html
102+
If `OPENSSL_DIR` is specified, then the build script will skip the pkg-config
103+
step.

appveyor.yml

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
environment:
2-
OPENSSL_INCLUDE_DIR: C:\OpenSSL\include
3-
OPENSSL_LIB_DIR: C:\OpenSSL\lib
4-
OPENSSL_LIBS: ssleay32:libeay32
52
matrix:
6-
- TARGET: i686-pc-windows-gnu
7-
BITS: 32
8-
- TARGET: x86_64-pc-windows-msvc
9-
BITS: 64
3+
# 1.1.0, 64/32 bit
4+
- TARGET: i686-pc-windows-gnu
5+
BITS: 32
6+
MSYS2: 1
7+
OPENSSL_VERSION: 1_1_0b
8+
- TARGET: x86_64-pc-windows-msvc
9+
BITS: 64
10+
OPENSSL_VERSION: 1_1_0b
11+
OPENSSL_DIR: C:\OpenSSL
12+
13+
# 1.0.2, 64/32 bit
14+
- TARGET: x86_64-pc-windows-gnu
15+
BITS: 64
16+
MSYS2: 1
17+
OPENSSL_VERSION: 1_0_2j
18+
- TARGET: i686-pc-windows-msvc
19+
BITS: 32
20+
OPENSSL_VERSION: 1_0_2j
21+
OPENSSL_DIR: C:\OpenSSL
1022
install:
11-
- ps: Start-FileDownload "http://slproweb.com/download/Win${env:BITS}OpenSSL-1_0_2h.exe"
12-
- Win%BITS%OpenSSL-1_0_2h.exe /SILENT /VERYSILENT /SP- /DIR="C:\OpenSSL"
13-
- ps: Start-FileDownload "https://static.rust-lang.org/dist/rust-1.9.0-${env:TARGET}.exe"
14-
- rust-1.9.0-%TARGET%.exe /VERYSILENT /NORESTART /DIR="C:\Program Files (x86)\Rust"
15-
- SET PATH=%PATH%;C:\Program Files (x86)\Rust\bin
16-
- SET PATH=%PATH%;C:\MinGW\bin
23+
# install OpenSSL
24+
- ps: Start-FileDownload "http://slproweb.com/download/Win${env:BITS}OpenSSL-${env:OPENSSL_VERSION}.exe"
25+
- Win%BITS%OpenSSL-%OPENSSL_VERSION%.exe /SILENT /VERYSILENT /SP- /DIR="C:\OpenSSL"
26+
27+
# Install Rust
28+
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
29+
- rustup-init.exe -y --default-host %TARGET%
30+
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
31+
- if defined MSYS2 set PATH=C:\msys64\mingw%BITS%\bin;%PATH%
1732
- rustc -V
1833
- cargo -V
1934

2035
build: false
2136

22-
# Don't run doctests due to rust-lang/cargo#1592
2337
test_script:
24-
- cargo test --lib --manifest-path openssl/Cargo.toml
38+
- cargo run --manifest-path systest/Cargo.toml --target %TARGET%
39+
- cargo test --manifest-path openssl/Cargo.toml --target %TARGET%
2540

41+
cache:
42+
- target
43+
- C:\Users\appveyor\.cargo\registry

openssl-sys/Cargo.toml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,38 +10,12 @@ documentation = "https://sfackler.github.io/rust-openssl/doc/v0.7.17/openssl_sys
1010
links = "openssl"
1111
build = "build.rs"
1212

13-
[features]
14-
tlsv1_2 = []
15-
tlsv1_1 = []
16-
dtlsv1 = []
17-
dtlsv1_2 = []
18-
sslv2 = []
19-
sslv3 = []
20-
aes_xts = []
21-
aes_ctr = []
22-
npn = []
23-
alpn = []
24-
rfc5114 = []
25-
pkcs5_pbkdf2_hmac = []
26-
ecdh_auto = []
27-
hmac_clone = []
28-
2913
[dependencies]
3014
libc = "0.2"
3115

3216
[build-dependencies]
3317
pkg-config = "0.3"
3418

35-
[target.le32-unknown-nacl.dependencies]
36-
libressl-pnacl-sys = "2.1.0"
37-
[target.x86_64-unknown-nacl.dependencies]
38-
libressl-pnacl-sys = "2.1.0"
39-
[target.i686-unknown-nacl.dependencies]
40-
libressl-pnacl-sys = "2.1.0"
41-
[target.arm-unknown-nacl.dependencies]
42-
libressl-pnacl-sys = "2.1.0"
43-
44-
# Only here to make sure we link to these in a static build on Windows
4519
[target.'cfg(windows)'.dependencies]
4620
user32-sys = "0.2"
4721
gdi32-sys = "0.2"

0 commit comments

Comments
 (0)