Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
name: rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- uses: sfackler/actions/rustup@master
- uses: sfackler/actions/rustfmt@master

Expand All @@ -32,25 +32,25 @@ jobs:
name: test-${{ matrix.os }}
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5
- uses: sfackler/actions/rustup@master
with:
version: 1.80.0
- run: echo "::set-output name=version::$(rustc --version)"
id: rust-version
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cargo/registry/index
key: index-${{ runner.os }}-${{ github.run_number }}
restore-keys: |
index-${{ runner.os }}-
- run: cargo generate-lockfile
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: ~/.cargo/registry/cache
key: registry-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- run: cargo fetch
- uses: actions/cache@v1
- uses: actions/cache@v4
with:
path: target
key: target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ description = "A wrapper over a platform's native TLS implementation"
repository = "https://github.com/sfackler/rust-native-tls"
readme = "README.md"
rust-version = "1.80.0"
edition = "2021"

[package.metadata.docs.rs]
features = ["alpn"]
Expand Down
26 changes: 12 additions & 14 deletions src/imp/openssl.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
extern crate openssl;
extern crate openssl_probe;

use self::openssl::error::ErrorStack;
use self::openssl::hash::MessageDigest;
use self::openssl::nid::Nid;
use self::openssl::pkcs12::Pkcs12;
use self::openssl::pkey::{PKey, Private};
use self::openssl::ssl::{
use openssl::error::ErrorStack;
use openssl::hash::MessageDigest;
use openssl::nid::Nid;
use openssl::pkcs12::Pkcs12;
use openssl::pkey::{PKey, Private};
use openssl::ssl::{
self, MidHandshakeSslStream, SslAcceptor, SslConnector, SslContextBuilder, SslMethod,
SslVerifyMode,
};
use self::openssl::x509::{store::X509StoreBuilder, X509VerifyResult, X509};
use self::openssl_probe::ProbeResult;
use openssl::x509::{store::X509StoreBuilder, X509VerifyResult, X509};
use openssl_probe::ProbeResult;
use std::error;
use std::fmt;
use std::io;
use std::sync::LazyLock;

use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
use crate::{Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
use log::debug;

static PROBE_RESULT: LazyLock<ProbeResult> = LazyLock::new(openssl_probe::probe);

Expand All @@ -27,7 +25,7 @@ fn supported_protocols(
max: Option<Protocol>,
ctx: &mut SslContextBuilder,
) -> Result<(), ErrorStack> {
use self::openssl::ssl::SslVersion;
use openssl::ssl::SslVersion;

fn cvt(p: Protocol) -> SslVersion {
match p {
Expand All @@ -50,7 +48,7 @@ fn supported_protocols(
max: Option<Protocol>,
ctx: &mut SslContextBuilder,
) -> Result<(), ErrorStack> {
use self::openssl::ssl::SslOptions;
use openssl::ssl::SslOptions;

let no_ssl_mask = SslOptions::NO_SSLV2
| SslOptions::NO_SSLV3
Expand Down
27 changes: 14 additions & 13 deletions src/imp/schannel.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
extern crate schannel;

use self::schannel::cert_context::{CertContext, HashAlgorithm, KeySpec};
use self::schannel::cert_store::{CertAdd, CertStore, Memory, PfxImportOptions};
use self::schannel::crypt_prov::{AcquireOptions, ProviderType};
use self::schannel::schannel_cred::{Direction, Protocol, SchannelCred};
use self::schannel::tls_stream;
use schannel::cert_context::{CertContext, HashAlgorithm, KeySpec};
use schannel::cert_store::{CertAdd, CertStore, Memory, PfxImportOptions};
use schannel::crypt_prov::{AcquireOptions, ProviderType};
use schannel::schannel_cred::{Direction, Protocol, SchannelCred};
use schannel::tls_stream;
use std::error;
use std::fmt;
use std::io;
use std::str;

use {TlsAcceptorBuilder, TlsConnectorBuilder};
use crate::{TlsAcceptorBuilder, TlsConnectorBuilder};

const SEC_E_NO_CREDENTIALS: u32 = 0x8009030E;

Expand All @@ -21,7 +19,10 @@ static PROTOCOLS: &'static [Protocol] = &[
Protocol::Tls12,
];

fn convert_protocols(min: Option<::Protocol>, max: Option<::Protocol>) -> &'static [Protocol] {
fn convert_protocols(
min: Option<crate::Protocol>,
max: Option<crate::Protocol>,
) -> &'static [Protocol] {
let mut protocols = PROTOCOLS;
if let Some(p) = max.and_then(|max| protocols.get(..=max as usize)) {
protocols = p;
Expand Down Expand Up @@ -236,8 +237,8 @@ impl<S> From<io::Error> for HandshakeError<S> {
pub struct TlsConnector {
cert: Option<CertContext>,
roots: CertStore,
min_protocol: Option<::Protocol>,
max_protocol: Option<::Protocol>,
min_protocol: Option<crate::Protocol>,
max_protocol: Option<crate::Protocol>,
use_sni: bool,
accept_invalid_hostnames: bool,
accept_invalid_certs: bool,
Expand Down Expand Up @@ -327,8 +328,8 @@ impl TlsConnector {
#[derive(Clone)]
pub struct TlsAcceptor {
cert: CertContext,
min_protocol: Option<::Protocol>,
max_protocol: Option<::Protocol>,
min_protocol: Option<crate::Protocol>,
max_protocol: Option<crate::Protocol>,
}

impl TlsAcceptor {
Expand Down
39 changes: 19 additions & 20 deletions src/imp/security_framework.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
extern crate libc;
extern crate security_framework;
extern crate security_framework_sys;

use self::security_framework::base;
use self::security_framework::certificate::SecCertificate;
use self::security_framework::identity::SecIdentity;
use self::security_framework::import_export::{ImportedIdentity, Pkcs12ImportOptions};
use self::security_framework::random::SecRandom;
use self::security_framework::secure_transport::{
use security_framework::base;
use security_framework::certificate::SecCertificate;
use security_framework::identity::SecIdentity;
use security_framework::import_export::{ImportedIdentity, Pkcs12ImportOptions};
use security_framework::random::SecRandom;
use security_framework::secure_transport::{
self, ClientBuilder, SslConnectionType, SslContext, SslProtocol, SslProtocolSide,
};
use self::security_framework_sys::base::{errSecIO, errSecParam};
use security_framework_sys::base::{errSecIO, errSecParam};
use std::error;
use std::fmt;
use std::io;
Expand All @@ -24,28 +20,28 @@ use std::sync::Once;
target_os = "tvos",
target_os = "visionos"
)))]
use self::security_framework::os::macos::certificate::{PropertyType, SecCertificateExt};
use security_framework::os::macos::certificate::{PropertyType, SecCertificateExt};
#[cfg(not(any(
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
target_os = "visionos"
)))]
use self::security_framework::os::macos::certificate_oids::CertificateOid;
use security_framework::os::macos::certificate_oids::CertificateOid;
#[cfg(not(any(
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
target_os = "visionos"
)))]
use self::security_framework::os::macos::identity::SecIdentityExt;
use security_framework::os::macos::identity::SecIdentityExt;
#[cfg(not(any(
target_os = "ios",
target_os = "watchos",
target_os = "tvos",
target_os = "visionos"
)))]
use self::security_framework::os::macos::import_export::{
use security_framework::os::macos::import_export::{
ImportOptions, Pkcs12ImportOptionsExt, SecItems,
};
#[cfg(not(any(
Expand All @@ -54,9 +50,9 @@ use self::security_framework::os::macos::import_export::{
target_os = "tvos",
target_os = "visionos"
)))]
use self::security_framework::os::macos::keychain::{self, KeychainSettings, SecKeychain};
use security_framework::os::macos::keychain::{self, KeychainSettings, SecKeychain};

use {Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};
use crate::{Protocol, TlsAcceptorBuilder, TlsConnectorBuilder};

static SET_AT_EXIT: Once = Once::new();

Expand Down Expand Up @@ -199,9 +195,12 @@ impl Identity {
}
});

let keychain = match *TEMP_KEYCHAIN.lock().unwrap() {
Some((ref keychain, _)) => keychain.clone(),
ref mut lock @ None => {
// keep it locked during import()
let keychain = &mut *TEMP_KEYCHAIN.lock().unwrap();

let keychain = match keychain {
Some((keychain, _)) => keychain.clone(),
lock @ None => {
let dir =
tempfile::TempDir::new().map_err(|_| Error(base::Error::from(errSecIO)))?;

Expand Down
17 changes: 6 additions & 11 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,12 @@ use std::fmt;
use std::io;
use std::result;

#[cfg(not(any(target_os = "windows", target_vendor = "apple")))]
#[macro_use]
extern crate log;
#[cfg(target_vendor = "apple")]
#[path = "imp/security_framework.rs"]
mod imp;
#[cfg(target_os = "windows")]
#[path = "imp/schannel.rs"]
mod imp;
#[cfg(not(any(target_vendor = "apple", target_os = "windows")))]
#[path = "imp/openssl.rs"]
#[cfg_attr(target_vendor = "apple", path = "imp/security_framework.rs")]
#[cfg_attr(target_os = "windows", path = "imp/schannel.rs")]
#[cfg_attr(
not(any(target_vendor = "apple", target_os = "windows")),
path = "imp/openssl.rs"
)]
mod imp;

#[cfg(test)]
Expand Down
Loading