Skip to content

Commit ca8eda6

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 400fc90 commit ca8eda6

File tree

13 files changed

+63
-6
lines changed

13 files changed

+63
-6
lines changed

src/tools/cargo/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,4 @@ doc = false
115115
deny-warnings = []
116116
vendored-openssl = ['openssl/vendored']
117117
pretty-env-logger = ['pretty_env_logger']
118+
macos_before_10_7 = []

src/tools/legacy-bootstrap/helper.rs

+8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ pub fn insert_cargo_features() {
66
macos_feature_version();
77
}
88

9+
pub fn force_openssl() -> bool {
10+
if cfg!(target_os = "macos") {
11+
macos::version() < 11
12+
} else {
13+
false
14+
}
15+
}
16+
917
#[cfg(target_os = "macos")]
1018
fn macos_feature_version() {
1119
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,9 +21,11 @@ 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"
26-
[target."cfg(not(any(target_os = \"windows\", target_os = \"macos\")))".dependencies.openssl]
28+
[target."cfg(not(any(target_os = \"windows\")))".dependencies.openssl]
2729
version = "0.10"
2830
[target."cfg(target_os = \"macos\")".dependencies.commoncrypto]
2931
version = "0.2"

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(target_os = "macos")]
46+
#[cfg(all(target_os = "macos", not(feature = "macos_before_10_7")))]
4747
extern crate commoncrypto;
4848
extern crate hex;
49-
#[cfg(not(any(target_os = "macos", target_os = "windows")))]
49+
#[cfg(not(any(all(target_os = "macos", not(feature = "macos_before_10_7")), 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(target_os = "macos")]
56+
#[cfg(all(target_os = "macos", not(feature = "macos_before_10_7")))]
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 = "windows")))]
62+
#[cfg(not(any(all(target_os = "macos", not(feature = "macos_before_10_7")), 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
@@ -44,6 +44,7 @@ version = "0.3.7"
4444
https = ["openssl-sys"]
4545
ssh = ["libssh2-sys"]
4646
ssh_key_from_memory = []
47+
macos_before_10_7 = []
4748
[target."cfg(unix)".dependencies.openssl-sys]
4849
version = "0.9"
4950
optional = true

vendor/libgit2-sys/build.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ use std::fs;
33
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

6+
#[path = "../../src/tools/legacy-bootstrap/helper.rs"]
7+
mod legacy_bootstrap_helper;
8+
69
fn main() {
10+
legacy_bootstrap_helper::insert_cargo_features();
11+
712
let https = env::var("CARGO_FEATURE_HTTPS").is_ok();
813
let ssh = env::var("CARGO_FEATURE_SSH").is_ok();
914

@@ -130,9 +135,14 @@ fn main() {
130135
if https {
131136
features.push_str("#define GIT_HTTPS 1\n");
132137

138+
#[cfg(feature = "macos_before_10_7")]
139+
let macos_before_10_7 = true;
140+
#[cfg(not(feature = "macos_before_10_7"))]
141+
let macos_before_10_7 = false;
142+
133143
if windows {
134144
features.push_str("#define GIT_WINHTTP 1\n");
135-
} else if target.contains("apple") {
145+
} else if !legacy_bootstrap_helper::force_openssl() && target.contains("apple") {
136146
features.push_str("#define GIT_SECURE_TRANSPORT 1\n");
137147
} else {
138148
features.push_str("#define GIT_OPENSSL 1\n");

0 commit comments

Comments
 (0)