Skip to content

Commit 3f8464b

Browse files
committed
Switch to OpenSSL instead of crypto API
macOS before 10.7 requires to use OpenSSL because a lot of things is simple missed.
1 parent e0045bf commit 3f8464b

File tree

13 files changed

+59
-6
lines changed

13 files changed

+59
-6
lines changed

src/tools/cargo/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,4 @@ doc = false
116116
deny-warnings = []
117117
vendored-openssl = ["openssl/vendored"]
118118
pretty-env-logger = ["pretty_env_logger"]
119+
macos_before_10_7 = []

src/tools/legacy-bootstrap/helper.rs

+9
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ pub fn insert_cargo_features() {
77
macos_feature_version();
88
}
99

10+
#[allow(dead_code)]
11+
pub fn force_openssl() -> bool {
12+
if cfg!(target_os = "macos") {
13+
macos::version() < 11
14+
} else {
15+
false
16+
}
17+
}
18+
1019
#[cfg(target_os = "macos")]
1120
fn macos_feature_version() {
1221
let version = macos::version();

vendor/commoncrypto-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "MIT"
1010

1111
[features]
1212
lint = ["clippy"]
13+
macos_before_10_7 = []
1314

1415
[dependencies]
1516
libc = "0.2"

vendor/commoncrypto-sys/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[path = "../../src/tools/legacy-bootstrap/helper.rs"]
2+
mod legacy_bootstrap_helper;
3+
4+
fn main() {
5+
legacy_bootstrap_helper::insert_cargo_features();
6+
}

vendor/commoncrypto-sys/src/lib.rs

+12
Original file line numberDiff line numberDiff line change
@@ -197,33 +197,45 @@ extern "C" {
197197
/// Generates SHA512 hash. See `man 3cc CC_SHA` for details.
198198
pub fn CC_SHA512_Final(md: *mut u8, ctx: *mut CC_SHA512_CTX) -> c_int;
199199
/// Generic digest hasher.
200+
#[cfg(not(feature = "macos_before_10_7"))]
200201
pub fn CCDigest(algorithm: CCDigestAlgorithm,
201202
data: *const u8,
202203
length: usize,
203204
output: *mut u8)
204205
-> c_int;
205206
/// Allocate and initialize a `CCDigestCtx` for a digest.
207+
#[cfg(not(feature = "macos_before_10_7"))]
206208
pub fn CCDigestCreate(algorithm: CCDigestAlgorithm) -> *mut CCDigestCtx;
207209
/// Continue to digest data. Returns `0` on success.
210+
#[cfg(not(feature = "macos_before_10_7"))]
208211
pub fn CCDigestUpdate(ctx: *mut CCDigestCtx, data: *const u8, length: usize) -> c_int;
209212
/// Conclude digest operations and produce the digest output. Returns `0` on success.
213+
#[cfg(not(feature = "macos_before_10_7"))]
210214
pub fn CCDigestFinal(ctx: *mut CCDigestCtx, output: *mut u8) -> c_int;
211215
/// Clear and free a `CCDigestCtx`.
216+
#[cfg(not(feature = "macos_before_10_7"))]
212217
pub fn CCDigestDestroy(ctx: *mut CCDigestCtx);
213218
/// Clear and re-initialize a `CCDigestCtx` for the same algorithm.
219+
#[cfg(not(feature = "macos_before_10_7"))]
214220
pub fn CCDigestReset(ctx: *mut CCDigestCtx);
215221
/// Produce the digest output result for the bytes currently processed. Returns `0` on success.
222+
#[cfg(not(feature = "macos_before_10_7"))]
216223
pub fn CCDigestGetDigest(ctx: *mut CCDigestCtx, output: *mut u8) -> c_int;
217224
/// Provides the block size of the digest algorithm. Returns `0` on failure.
225+
#[cfg(not(feature = "macos_before_10_7"))]
218226
pub fn CCDigestGetBlockSize(algorithm: CCDigestAlgorithm) -> usize;
219227
/// Provides the digest output size of the digest algorithm. Returns `0` on failure.
228+
#[cfg(not(feature = "macos_before_10_7"))]
220229
pub fn CCDigestGetOutputSize(algorithm: CCDigestAlgorithm) -> usize;
221230
/// Provides the block size of the digest algorithm. Returns `0` on failure.
231+
#[cfg(not(feature = "macos_before_10_7"))]
222232
pub fn CCDigestGetBlockSizeFromRef(ctx: *mut CCDigestCtx) -> usize;
223233
/// Provides the digest output size of the digest algorithm. Returns `0` on failure.
234+
#[cfg(not(feature = "macos_before_10_7"))]
224235
pub fn CCDigestGetOutputSizeFromRef(ctx: *mut CCDigestCtx) -> usize;
225236

226237
/// Derive a key from a user-supplied password via PBKDF2.
238+
#[cfg(not(feature = "macos_before_10_7"))]
227239
pub fn CCKeyDerivationPBKDF(algorithm: CCPBKDFAlgorithm,
228240
password: *const u8,
229241
passwordLen: usize,

vendor/commoncrypto/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ license = "MIT"
1010

1111
[features]
1212
lint = ["clippy"]
13+
macos_before_10_7 = []
1314

1415
[dependencies]
1516
commoncrypto-sys = { version = "0.2.0", path = "../commoncrypto-sys" }

vendor/commoncrypto/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[path = "../../src/tools/legacy-bootstrap/helper.rs"]
2+
mod legacy_bootstrap_helper;
3+
4+
fn main() {
5+
legacy_bootstrap_helper::insert_cargo_features();
6+
}

vendor/commoncrypto/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@
2222
2323
#![warn(missing_docs)]
2424

25+
#[cfg(not(feature = "macos_before_10_7"))]
2526
extern crate commoncrypto_sys;
2627

2728
#[warn(missing_docs)]
29+
#[cfg(not(feature = "macos_before_10_7"))]
2830
pub mod hash;
2931
#[warn(missing_docs)]
32+
#[cfg(not(feature = "macos_before_10_7"))]
3033
pub mod pbkdf2;

vendor/crypto-hash/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ readme = "README.md"
2121
keywords = ["crypto", "hash", "digest"]
2222
license = "MIT"
2323
repository = "https://github.com/malept/crypto-hash"
24+
[features]
25+
macos_before_10_7 = []
2426
[dependencies.hex]
2527
version = "0.3"
2628
[target."cfg(any(target_os = \"macos\", target_os = \"ios\"))".dependencies.commoncrypto]
2729
version = "0.2"
28-
[target."cfg(not(any(target_os = \"windows\", target_os = \"macos\", target_os = \"ios\")))".dependencies.openssl]
30+
[target."cfg(not(any(target_os = \"windows\", target_os = \"ios\")))".dependencies.openssl]
2931
version = "0.10"
3032
[target."cfg(target_os = \"windows\")".dependencies.winapi]
3133
version = "0.3"

vendor/crypto-hash/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#[path = "../../src/tools/legacy-bootstrap/helper.rs"]
2+
mod legacy_bootstrap_helper;
3+
4+
fn main() {
5+
legacy_bootstrap_helper::insert_cargo_features();
6+
}

vendor/crypto-hash/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@
4343
4444
#![warn(missing_docs)]
4545

46-
#[cfg(any(target_os = "macos", target_os = "ios"))]
46+
#[cfg(any(all(target_os = "macos", not(feature = "macos_before_10_7"))), target_os = "ios")]
4747
extern crate commoncrypto;
4848
extern crate hex;
49-
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
49+
#[cfg(not(any(all(target_os = "macos", not(feature = "macos_before_10_7")), target_os = "ios", , target_os = "windows")))]
5050
extern crate openssl;
5151
#[cfg(target_os = "windows")]
5252
extern crate winapi;
5353

5454
use std::io::Write;
5555

56-
#[cfg(any(target_os = "macos", target_os = "ios"))]
56+
#[cfg(any(all(target_os = "macos", not(feature = "macos_before_10_7"))), target_os = "ios")]
5757
#[path = "imp/commoncrypto.rs"]
5858
mod imp;
5959
#[cfg(target_os = "windows")]
6060
#[path = "imp/cryptoapi.rs"]
6161
mod imp;
62-
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "windows")))]
62+
#[cfg(not(any(all(target_os = "macos", not(feature = "macos_before_10_7")), target_os = "ios", , target_os = "windows")))]
6363
#[path = "imp/openssl.rs"]
6464
mod imp;
6565

vendor/libgit2-sys/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ https = ["openssl-sys"]
4848
ssh = ["libssh2-sys"]
4949
ssh_key_from_memory = []
5050
zlib-ng-compat = ["libz-sys/zlib-ng", "libssh2-sys/zlib-ng-compat"]
51+
macos_before_10_7 = []
5152
[target."cfg(unix)".dependencies.openssl-sys]
5253
version = "0.9"
5354
optional = true

vendor/libgit2-sys/build.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ use std::io;
44
use std::path::{Path, PathBuf};
55
use std::process::Command;
66

7+
#[path = "../../src/tools/legacy-bootstrap/helper.rs"]
8+
mod legacy_bootstrap_helper;
9+
710
fn main() {
11+
legacy_bootstrap_helper::insert_cargo_features();
12+
813
let https = env::var("CARGO_FEATURE_HTTPS").is_ok();
914
let ssh = env::var("CARGO_FEATURE_SSH").is_ok();
1015
let zlib_ng_compat = env::var("CARGO_FEATURE_ZLIB_NG_COMPAT").is_ok();
@@ -136,7 +141,7 @@ fn main() {
136141

137142
if windows {
138143
features.push_str("#define GIT_WINHTTP 1\n");
139-
} else if target.contains("apple") {
144+
} else if !legacy_bootstrap_helper::force_openssl() && target.contains("apple") {
140145
features.push_str("#define GIT_SECURE_TRANSPORT 1\n");
141146
} else {
142147
features.push_str("#define GIT_OPENSSL 1\n");

0 commit comments

Comments
 (0)