From 537525411c19577f735865f80cbffe7835ba5e8e Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Tue, 5 Dec 2023 16:07:35 -0500 Subject: [PATCH 1/3] Add tvOS and watchOS support --- Cargo.toml | 4 ++-- src/imp/security_framework.rs | 30 +++++++++++++++--------------- src/lib.rs | 6 +++--- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a27b617..8960942 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ rustdoc-args = ["--cfg", "docsrs"] vendored = ["openssl/vendored"] alpn = ["security-framework/alpn"] -[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos"))'.dependencies] security-framework = "2.0.0" security-framework-sys = "2.0.0" libc = "0.2" @@ -25,7 +25,7 @@ tempfile = "3.1.0" [target.'cfg(target_os = "windows")'.dependencies] schannel = "0.1.17" -[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios")))'.dependencies] +[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos")))'.dependencies] log = "0.4.5" openssl = "0.10.29" openssl-sys = "0.9.55" diff --git a/src/imp/security_framework.rs b/src/imp/security_framework.rs index 511badf..63232b7 100644 --- a/src/imp/security_framework.rs +++ b/src/imp/security_framework.rs @@ -20,24 +20,24 @@ use std::str; use std::sync::Mutex; use std::sync::Once; -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] use self::security_framework::os::macos::certificate::{PropertyType, SecCertificateExt}; -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] use self::security_framework::os::macos::certificate_oids::CertificateOid; -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] use self::security_framework::os::macos::identity::SecIdentityExt; -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] use self::security_framework::os::macos::import_export::{ ImportOptions, Pkcs12ImportOptionsExt, SecItems, }; -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] use self::security_framework::os::macos::keychain::{self, KeychainSettings, SecKeychain}; use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder}; static SET_AT_EXIT: Once = Once::new(); -#[cfg(not(target_os = "ios"))] +#[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] static TEMP_KEYCHAIN: Mutex> = Mutex::new(None); fn convert_protocol(protocol: Protocol) -> SslProtocol { @@ -82,12 +82,12 @@ pub struct Identity { } impl Identity { - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))] pub fn from_pkcs8(_: &[u8], _: &[u8]) -> Result { panic!("Not implemented on iOS"); } - #[cfg(not(target_os = "ios"))] + #[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] pub fn from_pkcs8(pem: &[u8], key: &[u8]) -> Result { if !key.starts_with(b"-----BEGIN PRIVATE KEY-----") { return Err(Error(base::Error::from(errSecParam))); @@ -145,7 +145,7 @@ impl Identity { }) } - #[cfg(not(target_os = "ios"))] + #[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] fn import_options(buf: &[u8], pass: &str) -> Result, Error> { SET_AT_EXIT.call_once(|| { extern "C" fn atexit() { @@ -177,7 +177,7 @@ impl Identity { Ok(imports) } - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))] fn import_options(buf: &[u8], pass: &str) -> Result, Error> { let imports = Pkcs12ImportOptions::new().passphrase(pass).import(buf)?; Ok(imports) @@ -206,7 +206,7 @@ impl Certificate { Ok(Certificate(cert)) } - #[cfg(not(target_os = "ios"))] + #[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] pub fn from_pem(buf: &[u8]) -> Result { let mut items = SecItems::default(); ImportOptions::new().items(&mut items).import(buf)?; @@ -217,9 +217,9 @@ impl Certificate { } } - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))] pub fn from_pem(_: &[u8]) -> Result { - panic!("Not implemented on iOS"); + panic!("Not implemented on iOS, tvOS or watchOS"); } pub fn to_der(&self) -> Result, Error> { @@ -476,12 +476,12 @@ impl TlsStream { } } - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))] pub fn tls_server_end_point(&self) -> Result>, Error> { Ok(None) } - #[cfg(not(target_os = "ios"))] + #[cfg(not(any(target_os = "ios", target_os = "watchos", target_os = "tvos")))] pub fn tls_server_end_point(&self) -> Result>, Error> { let cert = match self.cert { Some(ref cert) => cert.clone(), diff --git a/src/lib.rs b/src/lib.rs index 267679d..b44a50a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,16 +104,16 @@ use std::fmt; use std::io; use std::result; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] +#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios", target_os = "watchos", target_os = "tvos")))] #[macro_use] extern crate log; -#[cfg(any(target_os = "macos", target_os = "ios"))] +#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos"))] #[path = "imp/security_framework.rs"] mod imp; #[cfg(target_os = "windows")] #[path = "imp/schannel.rs"] mod imp; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios")))] +#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios", target_os = "watchos", target_os = "tvos")))] #[path = "imp/openssl.rs"] mod imp; From 14ef1cefed3a5c913b48c8d03eaf3d2f78ff1a14 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 11 Dec 2023 16:14:36 -0800 Subject: [PATCH 2/3] Update ci.yml --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 73cffed..29e22df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,7 +35,7 @@ jobs: - uses: actions/checkout@v2 - uses: sfackler/actions/rustup@master with: - version: 1.63.0 + version: 1.65.0 - run: echo "::set-output name=version::$(rustc --version)" id: rust-version - uses: actions/cache@v1 From 6e462d64be61b31ec32b91f097249403c0cbdc95 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Mon, 11 Dec 2023 19:27:22 -0500 Subject: [PATCH 3/3] cargo fmt --- src/lib.rs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b44a50a..cc86502 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -104,16 +104,33 @@ use std::fmt; use std::io; use std::result; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios", target_os = "watchos", target_os = "tvos")))] +#[cfg(not(any( + target_os = "macos", + target_os = "windows", + target_os = "ios", + target_os = "watchos", + target_os = "tvos" +)))] #[macro_use] extern crate log; -#[cfg(any(target_os = "macos", target_os = "ios", target_os = "watchos", target_os = "tvos"))] +#[cfg(any( + target_os = "macos", + target_os = "ios", + target_os = "watchos", + target_os = "tvos" +))] #[path = "imp/security_framework.rs"] mod imp; #[cfg(target_os = "windows")] #[path = "imp/schannel.rs"] mod imp; -#[cfg(not(any(target_os = "macos", target_os = "windows", target_os = "ios", target_os = "watchos", target_os = "tvos")))] +#[cfg(not(any( + target_os = "macos", + target_os = "windows", + target_os = "ios", + target_os = "watchos", + target_os = "tvos" +)))] #[path = "imp/openssl.rs"] mod imp;