Skip to content

Commit 7e035a7

Browse files
authored
Merge pull request #538 from semarie/libressl
Add LibreSSL support
2 parents 593e530 + a70e27a commit 7e035a7

File tree

11 files changed

+667
-48
lines changed

11 files changed

+667
-48
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ matrix:
7272
packages:
7373
- gcc-multilib
7474

75+
# LibreSSL
76+
- env: BUILD_LIBRESSL_VERSION=2.5.0
7577

7678
before_install:
7779
- ./openssl/test/build.sh
@@ -83,4 +85,5 @@ script:
8385
cache:
8486
cargo: true
8587
directories:
88+
- $HOME/libressl
8689
- $HOME/openssl

openssl-sys/build.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ fn validate_headers(include_dirs: &[PathBuf],
247247
} else if version_text.contains("0x10100") {
248248
println!("cargo:rustc-cfg=ossl110");
249249
println!("cargo:version=110");
250+
} else if version_text.contains("0x20000000L") {
251+
// Check if it is really LibreSSL
252+
if version_header.lines().any(|l| {
253+
l.contains("define ") && l.contains("LIBRESSL_VERSION_NUMBER")
254+
}) {
255+
println!("cargo:rustc-cfg=libressl");
256+
println!("cargo:libressl=true");
257+
println!("cargo:version=101");
258+
}
250259
} else {
251260
panic!("
252261

openssl-sys/src/lib.rs

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ mod ossl110;
1717
#[cfg(ossl110)]
1818
pub use ossl110::*;
1919

20+
#[cfg(libressl)]
21+
mod libressl;
22+
#[cfg(libressl)]
23+
pub use libressl::*;
24+
2025
pub enum ASN1_INTEGER {}
2126
pub enum ASN1_STRING {}
2227
pub enum ASN1_TIME {}
@@ -1075,8 +1080,11 @@ pub const SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER: c_long = 0x2;
10751080
pub const SSL_MODE_AUTO_RETRY: c_long = 0x4;
10761081
pub const SSL_MODE_NO_AUTO_CHAIN: c_long = 0x8;
10771082
pub const SSL_MODE_RELEASE_BUFFERS: c_long = 0x10;
1083+
#[cfg(not(libressl))]
10781084
pub const SSL_MODE_SEND_CLIENTHELLO_TIME: c_long = 0x20;
1085+
#[cfg(not(libressl))]
10791086
pub const SSL_MODE_SEND_SERVERHELLO_TIME: c_long = 0x40;
1087+
#[cfg(not(libressl))]
10801088
pub const SSL_MODE_SEND_FALLBACK_SCSV: c_long = 0x80;
10811089

10821090
pub const SSL_ERROR_NONE: c_int = 0;
@@ -1095,26 +1103,31 @@ pub const SSL_VERIFY_FAIL_IF_NO_PEER_CERT: c_int = 2;
10951103
#[cfg(not(ossl101))]
10961104
pub const SSL_OP_TLSEXT_PADDING: c_ulong = 0x00000010;
10971105
pub const SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS: c_ulong = 0x00000800;
1106+
#[cfg(not(libressl))]
10981107
pub const SSL_OP_ALL: c_ulong = 0x80000BFF;
10991108
pub const SSL_OP_NO_QUERY_MTU: c_ulong = 0x00001000;
11001109
pub const SSL_OP_COOKIE_EXCHANGE: c_ulong = 0x00002000;
11011110
pub const SSL_OP_NO_TICKET: c_ulong = 0x00004000;
1111+
#[cfg(not(libressl))]
11021112
pub const SSL_OP_CISCO_ANYCONNECT: c_ulong = 0x00008000;
11031113
pub const SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION: c_ulong = 0x00010000;
1114+
#[cfg(not(libressl))]
11041115
pub const SSL_OP_NO_COMPRESSION: c_ulong = 0x00020000;
1116+
#[cfg(not(libressl))]
11051117
pub const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION: c_ulong = 0x00040000;
11061118
pub const SSL_OP_CIPHER_SERVER_PREFERENCE: c_ulong = 0x00400000;
11071119
pub const SSL_OP_TLS_ROLLBACK_BUG: c_ulong = 0x00800000;
1120+
#[cfg(not(libressl))]
11081121
pub const SSL_OP_NO_SSLv3: c_ulong = 0x02000000;
11091122
pub const SSL_OP_NO_TLSv1: c_ulong = 0x04000000;
11101123
pub const SSL_OP_NO_TLSv1_2: c_ulong = 0x08000000;
11111124
pub const SSL_OP_NO_TLSv1_1: c_ulong = 0x10000000;
11121125

1113-
#[cfg(not(ossl101))]
1126+
#[cfg(not(any(ossl101, libressl)))]
11141127
pub const SSL_OP_NO_DTLSv1: c_ulong = 0x04000000;
1115-
#[cfg(not(ossl101))]
1128+
#[cfg(not(any(ossl101, libressl)))]
11161129
pub const SSL_OP_NO_DTLSv1_2: c_ulong = 0x08000000;
1117-
#[cfg(not(ossl101))]
1130+
#[cfg(not(any(ossl101, libressl)))]
11181131
pub const SSL_OP_NO_SSL_MASK: c_ulong = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 |
11191132
SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_TLSv1_2;
11201133

@@ -1292,9 +1305,9 @@ extern {
12921305
pub fn BIO_new_socket(sock: c_int, close_flag: c_int) -> *mut BIO;
12931306
pub fn BIO_read(b: *mut BIO, buf: *mut c_void, len: c_int) -> c_int;
12941307
pub fn BIO_write(b: *mut BIO, buf: *const c_void, len: c_int) -> c_int;
1295-
#[cfg(ossl101)]
1308+
#[cfg(any(ossl101, libressl))]
12961309
pub fn BIO_new_mem_buf(buf: *mut c_void, len: c_int) -> *mut BIO;
1297-
#[cfg(not(ossl101))]
1310+
#[cfg(not(any(ossl101, libressl)))]
12981311
pub fn BIO_new_mem_buf(buf: *const c_void, len: c_int) -> *mut BIO;
12991312
pub fn BIO_set_flags(b: *mut BIO, flags: c_int);
13001313
pub fn BIO_clear_flags(b: *mut BIO, flags: c_int);
@@ -1375,11 +1388,11 @@ extern {
13751388

13761389
pub fn DH_new() -> *mut DH;
13771390
pub fn DH_free(dh: *mut DH);
1378-
#[cfg(not(ossl101))]
1391+
#[cfg(not(any(ossl101, libressl)))]
13791392
pub fn DH_get_1024_160() -> *mut DH;
1380-
#[cfg(not(ossl101))]
1393+
#[cfg(not(any(ossl101, libressl)))]
13811394
pub fn DH_get_2048_224() -> *mut DH;
1382-
#[cfg(not(ossl101))]
1395+
#[cfg(not(any(ossl101, libressl)))]
13831396
pub fn DH_get_2048_256() -> *mut DH;
13841397

13851398
pub fn EC_KEY_new() -> *mut EC_KEY;
@@ -1495,11 +1508,11 @@ extern {
14951508
type_: *const EVP_MD,
14961509
e: *mut ENGINE,
14971510
pkey: *mut EVP_PKEY) -> c_int;
1498-
#[cfg(ossl101)]
1511+
#[cfg(any(ossl101, libressl))]
14991512
pub fn EVP_DigestVerifyFinal(ctx: *mut EVP_MD_CTX,
15001513
sigret: *mut c_uchar,
15011514
siglen: size_t) -> c_int;
1502-
#[cfg(not(ossl101))]
1515+
#[cfg(not(any(ossl101, libressl)))]
15031516
pub fn EVP_DigestVerifyFinal(ctx: *mut EVP_MD_CTX,
15041517
sigret: *const c_uchar,
15051518
siglen: size_t) -> c_int;
@@ -1634,8 +1647,10 @@ extern {
16341647
pub fn SSL_get_ex_data_X509_STORE_CTX_idx() -> c_int;
16351648
pub fn SSL_get_SSL_CTX(ssl: *const SSL) -> *mut SSL_CTX;
16361649
pub fn SSL_set_SSL_CTX(ssl: *mut SSL, ctx: *mut SSL_CTX) -> *mut SSL_CTX;
1637-
#[cfg(not(osslconf = "OPENSSL_NO_COMP"))]
1650+
#[cfg(not(any(osslconf = "OPENSSL_NO_COMP", libressl)))]
16381651
pub fn SSL_get_current_compression(ssl: *mut SSL) -> *const COMP_METHOD;
1652+
#[cfg(libressl)]
1653+
pub fn SSL_get_current_compression(ssl: *mut SSL) -> *const libc::c_void;
16391654
pub fn SSL_get_peer_certificate(ssl: *const SSL) -> *mut X509;
16401655
pub fn SSL_get_ssl_method(ssl: *mut SSL) -> *const SSL_METHOD;
16411656
pub fn SSL_get_version(ssl: *const SSL) -> *const c_char;
@@ -1648,14 +1663,14 @@ extern {
16481663
pub fn SSL_get_ex_data(ssl: *const SSL, idx: c_int) -> *mut c_void;
16491664
pub fn SSL_get_servername(ssl: *const SSL, name_type: c_int) -> *const c_char;
16501665
pub fn SSL_get_current_cipher(ssl: *const SSL) -> *const SSL_CIPHER;
1651-
#[cfg(not(ossl101))]
1666+
#[cfg(not(any(ossl101, libressl)))]
16521667
pub fn SSL_get0_param(ssl: *mut SSL) -> *mut X509_VERIFY_PARAM;
16531668
pub fn SSL_get_verify_result(ssl: *const SSL) -> c_long;
16541669
pub fn SSL_shutdown(ssl: *mut SSL) -> c_int;
16551670
pub fn SSL_get_certificate(ssl: *const SSL) -> *mut X509;
1656-
#[cfg(ossl101)]
1671+
#[cfg(any(ossl101, libressl))]
16571672
pub fn SSL_get_privatekey(ssl: *mut SSL) -> *mut EVP_PKEY;
1658-
#[cfg(not(ossl101))]
1673+
#[cfg(not(any(ossl101, libressl)))]
16591674
pub fn SSL_get_privatekey(ssl: *const SSL) -> *mut EVP_PKEY;
16601675
pub fn SSL_load_client_CA_file(file: *const c_char) -> *mut stack_st_X509_NAME;
16611676
pub fn SSL_set_tmp_dh_callback(ctx: *mut SSL,
@@ -1664,8 +1679,10 @@ extern {
16641679
keylength: c_int)
16651680
-> *mut DH);
16661681

1667-
#[cfg(not(osslconf = "OPENSSL_NO_COMP"))]
1682+
#[cfg(not(any(osslconf = "OPENSSL_NO_COMP", libressl)))]
16681683
pub fn SSL_COMP_get_name(comp: *const COMP_METHOD) -> *const c_char;
1684+
#[cfg(libressl)]
1685+
pub fn SSL_COMP_get_name(comp: *const libc::c_void) -> *const c_char;
16691686

16701687
pub fn SSL_CIPHER_get_name(cipher: *const SSL_CIPHER) -> *const c_char;
16711688
pub fn SSL_CIPHER_get_bits(cipher: *const SSL_CIPHER, alg_bits: *mut c_int) -> c_int;
@@ -1701,9 +1718,9 @@ extern {
17011718
keylength: c_int)
17021719
-> *mut DH);
17031720

1704-
#[cfg(not(ossl101))]
1721+
#[cfg(not(any(ossl101, libressl)))]
17051722
pub fn SSL_CTX_get0_certificate(ctx: *const SSL_CTX) -> *mut X509;
1706-
#[cfg(not(ossl101))]
1723+
#[cfg(not(any(ossl101, libressl)))]
17071724
pub fn SSL_CTX_get0_privatekey(ctx: *const SSL_CTX) -> *mut EVP_PKEY;
17081725

17091726
pub fn SSL_CTX_set_cipher_list(ssl: *mut SSL_CTX, s: *const c_char) -> c_int;
@@ -1787,9 +1804,9 @@ extern {
17871804

17881805
#[cfg(not(ossl101))]
17891806
pub fn X509_VERIFY_PARAM_free(param: *mut X509_VERIFY_PARAM);
1790-
#[cfg(not(ossl101))]
1807+
#[cfg(not(any(ossl101, libressl)))]
17911808
pub fn X509_VERIFY_PARAM_set_hostflags(param: *mut X509_VERIFY_PARAM, flags: c_uint);
1792-
#[cfg(not(ossl101))]
1809+
#[cfg(not(any(ossl101, libressl)))]
17931810
pub fn X509_VERIFY_PARAM_set1_host(param: *mut X509_VERIFY_PARAM,
17941811
name: *const c_char,
17951812
namelen: size_t) -> c_int;

0 commit comments

Comments
 (0)