Skip to content

Commit

Permalink
Merge pull request #285 from simlay/add-tvos-and-watchos-target-flags
Browse files Browse the repository at this point in the history
Add tvOS and watchOS support
  • Loading branch information
sfackler authored Dec 12, 2023
2 parents 5db1b77 + 6e462d6 commit 0b69ce6
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
30 changes: 15 additions & 15 deletions src/imp/security_framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Option<(SecKeychain, TempDir)>> = Mutex::new(None);

fn convert_protocol(protocol: Protocol) -> SslProtocol {
Expand Down Expand Up @@ -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<Identity, Error> {
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<Identity, Error> {
if !key.starts_with(b"-----BEGIN PRIVATE KEY-----") {
return Err(Error(base::Error::from(errSecParam)));
Expand Down Expand Up @@ -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<Vec<ImportedIdentity>, Error> {
SET_AT_EXIT.call_once(|| {
extern "C" fn atexit() {
Expand Down Expand Up @@ -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<Vec<ImportedIdentity>, Error> {
let imports = Pkcs12ImportOptions::new().passphrase(pass).import(buf)?;
Ok(imports)
Expand Down Expand Up @@ -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<Certificate, Error> {
let mut items = SecItems::default();
ImportOptions::new().items(&mut items).import(buf)?;
Expand All @@ -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<Certificate, Error> {
panic!("Not implemented on iOS");
panic!("Not implemented on iOS, tvOS or watchOS");
}

pub fn to_der(&self) -> Result<Vec<u8>, Error> {
Expand Down Expand Up @@ -476,12 +476,12 @@ impl<S: io::Read + io::Write> TlsStream<S> {
}
}

#[cfg(target_os = "ios")]
#[cfg(any(target_os = "ios", target_os = "watchos", target_os = "tvos"))]
pub fn tls_server_end_point(&self) -> Result<Option<Vec<u8>>, 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<Option<Vec<u8>>, Error> {
let cert = match self.cert {
Some(ref cert) => cert.clone(),
Expand Down
23 changes: 20 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")))]
#[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;

Expand Down

0 comments on commit 0b69ce6

Please sign in to comment.