tokio-native-tls-0.3.1/.cargo_vcs_info.json0000644000000001560000000000100142500ustar { "git": { "sha1": "775b6d69f42f76227c5a3c5ac5058da9ff095ca0" }, "path_in_vcs": "tokio-native-tls" }tokio-native-tls-0.3.1/CHANGELOG.md000064400000000000000000000002631046102023000146500ustar 00000000000000# 0.3.0 (December 23, 2020) - Upgrade to `tokio 1.0`. # 0.2.0 (October 16, 2020) - Upgrade to `tokio 0.3`. # 0.1.0 (January 9th, 2019) - Initial release from `tokio-tls 0.3` tokio-native-tls-0.3.1/Cargo.lock0000644000000417230000000000100122300ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "MacTypes-sys" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaf9f0d0b1cc33a4d2aee14fb4b2eac03462ef4db29c8ac4057327d8a71ad86f" dependencies = [ "libc", ] [[package]] name = "autocfg" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bytes" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" [[package]] name = "cc" version = "1.0.79" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" [[package]] name = "cfg-if" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "core-foundation" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980" dependencies = [ "core-foundation-sys 0.5.1", "libc", ] [[package]] name = "core-foundation" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" dependencies = [ "core-foundation-sys 0.8.3", "libc", ] [[package]] name = "core-foundation-sys" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa" dependencies = [ "libc", ] [[package]] name = "core-foundation-sys" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "env_logger" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aafcde04e90a5226a6443b7aabdb016ba2f8307c847d524724bd9b346dd1a2d3" dependencies = [ "log", ] [[package]] name = "fastrand" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499" dependencies = [ "instant", ] [[package]] name = "foreign-types" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ "foreign-types-shared", ] [[package]] name = "foreign-types-shared" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "futures" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13e2792b0ff0340399d58445b88fd9770e3489eff258a4cbc1523418f12abf84" dependencies = [ "futures-channel", "futures-core", "futures-executor", "futures-io", "futures-sink", "futures-task", "futures-util", ] [[package]] name = "futures-channel" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2e5317663a9089767a1ec00a487df42e0ca174b61b4483213ac24448e4664df5" dependencies = [ "futures-core", "futures-sink", ] [[package]] name = "futures-core" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec90ff4d0fe1f57d600049061dc6bb68ed03c7d2fbd697274c41805dcb3f8608" [[package]] name = "futures-executor" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8de0a35a6ab97ec8869e32a2473f4b1324459e14c29275d14b10cb1fd19b50e" dependencies = [ "futures-core", "futures-task", "futures-util", ] [[package]] name = "futures-io" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfb8371b6fb2aeb2d280374607aeabfc99d95c72edfe51692e42d3d7f0d08531" [[package]] name = "futures-macro" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95a73af87da33b5acf53acfebdc339fe592ecf5357ac7c0a7734ab9d8c876a70" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "futures-sink" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f310820bb3e8cfd46c80db4d7fb8353e15dfff853a127158425f31e0be6c8364" [[package]] name = "futures-task" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dcf79a1bf610b10f42aea489289c5a2c478a786509693b80cd39c44ccd936366" [[package]] name = "futures-util" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c1d6de3acfef38d2be4b1f543f553131788603495be83da675e180c8d6b7bd1" dependencies = [ "futures-channel", "futures-core", "futures-io", "futures-macro", "futures-sink", "futures-task", "memchr", "pin-project-lite", "pin-utils", "slab", ] [[package]] name = "hermit-abi" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" dependencies = [ "libc", ] [[package]] name = "instant" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "lazy_static" version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" version = "0.2.139" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" [[package]] name = "log" version = "0.4.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" dependencies = [ "cfg-if 1.0.0", ] [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mio" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" dependencies = [ "libc", "log", "wasi", "windows-sys", ] [[package]] name = "native-tls" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" dependencies = [ "lazy_static", "libc", "log", "openssl", "openssl-probe", "openssl-sys", "schannel", "security-framework 2.8.2", "security-framework-sys 2.8.0", "tempfile", ] [[package]] name = "num_cpus" version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" dependencies = [ "hermit-abi", "libc", ] [[package]] name = "once_cell" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" [[package]] name = "openssl" version = "0.10.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b102428fd03bc5edf97f62620f7298614c45cedf287c271e7ed450bbaf83f2e1" dependencies = [ "bitflags", "cfg-if 1.0.0", "foreign-types", "libc", "once_cell", "openssl-macros", "openssl-sys", ] [[package]] name = "openssl-macros" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b501e44f11665960c7e7fcf062c7d96a14ade4aa98116c004b2e37b5be7d736c" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "openssl-probe" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-src" version = "111.24.0+1.1.1s" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3498f259dab01178c6228c6b00dcef0ed2a2d5e20d648c017861227773ea4abd" dependencies = [ "cc", ] [[package]] name = "openssl-sys" version = "0.9.80" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "23bbbf7854cd45b83958ebe919f0e8e516793727652e27fda10a8384cfc790b7" dependencies = [ "autocfg", "cc", "libc", "openssl-src", "pkg-config", "vcpkg", ] [[package]] name = "pin-project-lite" version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" [[package]] name = "pin-utils" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkg-config" version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "proc-macro2" version = "1.0.51" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" dependencies = [ "proc-macro2", ] [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ "bitflags", ] [[package]] name = "remove_dir_all" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" dependencies = [ "winapi", ] [[package]] name = "schannel" version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ "windows-sys", ] [[package]] name = "security-framework" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bfab8dda0e7a327c696d893df9ffa19cadc4bd195797997f5223cf5831beaf05" dependencies = [ "core-foundation 0.5.1", "core-foundation-sys 0.5.1", "libc", "security-framework-sys 0.2.3", ] [[package]] name = "security-framework" version = "2.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" dependencies = [ "bitflags", "core-foundation 0.9.3", "core-foundation-sys 0.8.3", "libc", "security-framework-sys 2.8.0", ] [[package]] name = "security-framework-sys" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d6696852716b589dff9e886ff83778bb635150168e83afa8ac6b8a78cb82abc" dependencies = [ "MacTypes-sys", "core-foundation-sys 0.5.1", "libc", ] [[package]] name = "security-framework-sys" version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" dependencies = [ "core-foundation-sys 0.8.3", "libc", ] [[package]] name = "slab" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef" dependencies = [ "autocfg", ] [[package]] name = "socket2" version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", ] [[package]] name = "syn" version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f4064b5b16e03ae50984a5a8ed5d4f8803e6bc1fd170a3cda91a1be4b18e3f5" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "tempfile" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5cdb1ef4eaeeaddc8fbd371e5017057064af0911902ef36b39801f67cc6d79e4" dependencies = [ "cfg-if 1.0.0", "fastrand", "libc", "redox_syscall", "remove_dir_all", "winapi", ] [[package]] name = "tokio" version = "1.25.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c8e00990ebabbe4c14c08aca901caed183ecd5c09562a12c824bb53d3c3fd3af" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", "num_cpus", "pin-project-lite", "socket2", "tokio-macros", "windows-sys", ] [[package]] name = "tokio-macros" version = "1.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "tokio-native-tls" version = "0.3.1" dependencies = [ "cfg-if 0.1.10", "env_logger", "futures", "lazy_static", "native-tls", "openssl", "schannel", "security-framework 0.2.2", "tempfile", "tokio", "tokio-util", "winapi", ] [[package]] name = "tokio-util" version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" dependencies = [ "bytes", "futures-core", "futures-io", "futures-sink", "log", "pin-project-lite", "slab", "tokio", ] [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" [[package]] name = "windows_aarch64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" [[package]] name = "windows_i686_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" [[package]] name = "windows_i686_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" [[package]] name = "windows_x86_64_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" [[package]] name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" tokio-native-tls-0.3.1/Cargo.toml0000644000000041620000000000100122470ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" name = "tokio-native-tls" version = "0.3.1" authors = ["Tokio Contributors "] description = """ An implementation of TLS/SSL streams for Tokio using native-tls giving an implementation of TLS for nonblocking I/O streams. """ homepage = "https://tokio.rs" documentation = "https://docs.rs/tokio-native-tls" readme = "README.md" categories = [ "asynchronous", "network-programming", ] license = "MIT" repository = "https://github.com/tokio-rs/tls" [package.metadata.docs.rs] all-features = true [dependencies.native-tls] version = "0.2" [dependencies.tokio] version = "1.0" [dev-dependencies.cfg-if] version = "0.1" [dev-dependencies.env_logger] version = "0.6" default-features = false [dev-dependencies.futures] version = "0.3.0" features = ["async-await"] [dev-dependencies.lazy_static] version = "1.4.0" [dev-dependencies.tempfile] version = "3.1" [dev-dependencies.tokio] version = "1.0" features = [ "macros", "rt", "rt-multi-thread", "io-util", "net", ] [dev-dependencies.tokio-util] version = "0.6.0" features = ["full"] [features] vendored = ["native-tls/vendored"] [target."cfg(all(not(target_os = \"macos\"), not(windows), not(target_os = \"ios\")))".dev-dependencies.openssl] version = "0.10" [target."cfg(any(target_os = \"macos\", target_os = \"ios\"))".dev-dependencies.security-framework] version = "0.2" [target."cfg(windows)".dev-dependencies.schannel] version = "0.1" [target."cfg(windows)".dev-dependencies.winapi] version = "0.3" features = [ "lmcons", "basetsd", "minwinbase", "minwindef", "ntdef", "sysinfoapi", "timezoneapi", "wincrypt", "winerror", ] tokio-native-tls-0.3.1/Cargo.toml.orig000064400000000000000000000031441046102023000157270ustar 00000000000000[package] name = "tokio-native-tls" # When releasing to crates.io: # - Remove path dependencies # - Update html_root_url. # - Update doc url # - Cargo.toml # - README.md # - Update CHANGELOG.md. # - Create "v0.1.x" git tag. version = "0.3.1" edition = "2018" authors = ["Tokio Contributors "] license = "MIT" repository = "https://github.com/tokio-rs/tls" homepage = "https://tokio.rs" documentation = "https://docs.rs/tokio-native-tls" description = """ An implementation of TLS/SSL streams for Tokio using native-tls giving an implementation of TLS for nonblocking I/O streams. """ categories = ["asynchronous", "network-programming"] [dependencies] native-tls = "0.2" tokio = "1.0" [features] vendored = ["native-tls/vendored"] [dev-dependencies] tokio = { version = "1.0", features = ["macros", "rt", "rt-multi-thread", "io-util", "net"] } tokio-util = { version = "0.6.0", features = ["full"] } cfg-if = "0.1" env_logger = { version = "0.6", default-features = false } futures = { version = "0.3.0", features = ["async-await"] } tempfile = "3.1" lazy_static = "1.4.0" [target.'cfg(all(not(target_os = "macos"), not(windows), not(target_os = "ios")))'.dev-dependencies] openssl = "0.10" [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dev-dependencies] security-framework = "0.2" [target.'cfg(windows)'.dev-dependencies] schannel = "0.1" [target.'cfg(windows)'.dev-dependencies.winapi] version = "0.3" features = [ "lmcons", "basetsd", "minwinbase", "minwindef", "ntdef", "sysinfoapi", "timezoneapi", "wincrypt", "winerror", ] [package.metadata.docs.rs] all-features = true tokio-native-tls-0.3.1/LICENSE000064400000000000000000000020461046102023000140450ustar 00000000000000Copyright (c) 2019 Tokio Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tokio-native-tls-0.3.1/README.md000064400000000000000000000005671046102023000143250ustar 00000000000000# tokio-tls An implementation of TLS/SSL streams for Tokio built on top of the [`native-tls` crate] ## License This project is licensed under the [MIT license](./LICENSE). ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions. tokio-native-tls-0.3.1/examples/download-rust-lang.rs000064400000000000000000000017711046102023000207510ustar 00000000000000// #![warn(rust_2018_idioms)] use native_tls::TlsConnector; use std::error::Error; use std::net::ToSocketAddrs; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::TcpStream; #[tokio::main] async fn main() -> Result<(), Box> { let addr = "www.rust-lang.org:443" .to_socket_addrs()? .next() .ok_or("failed to resolve www.rust-lang.org")?; let socket = TcpStream::connect(&addr).await?; let cx = TlsConnector::builder().build()?; let cx = tokio_native_tls::TlsConnector::from(cx); let mut socket = cx.connect("www.rust-lang.org", socket).await?; socket .write_all( "\ GET / HTTP/1.0\r\n\ Host: www.rust-lang.org\r\n\ \r\n\ " .as_bytes(), ) .await?; let mut data = Vec::new(); socket.read_to_end(&mut data).await?; // println!("data: {:?}", &data); println!("{}", String::from_utf8_lossy(&data[..])); Ok(()) } tokio-native-tls-0.3.1/examples/echo.rs000064400000000000000000000033231046102023000161410ustar 00000000000000#![warn(rust_2018_idioms)] // A tiny async TLS echo server with Tokio use native_tls::Identity; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::net::TcpListener; /** an example to setup a tls server. how to test: wget https://127.0.0.1:12345 --no-check-certificate */ #[tokio::main] async fn main() -> Result<(), Box> { // Bind the server's socket let addr = "127.0.0.1:12345".to_string(); let tcp: TcpListener = TcpListener::bind(&addr).await?; // Create the TLS acceptor. let der = include_bytes!("identity.p12"); let cert = Identity::from_pkcs12(der, "mypass")?; let tls_acceptor = tokio_native_tls::TlsAcceptor::from(native_tls::TlsAcceptor::builder(cert).build()?); loop { // Asynchronously wait for an inbound socket. let (socket, remote_addr) = tcp.accept().await?; let tls_acceptor = tls_acceptor.clone(); println!("accept connection from {}", remote_addr); tokio::spawn(async move { // Accept the TLS connection. let mut tls_stream = tls_acceptor.accept(socket).await.expect("accept error"); // In a loop, read data from the socket and write the data back. let mut buf = [0; 1024]; let n = tls_stream .read(&mut buf) .await .expect("failed to read data from socket"); if n == 0 { return; } println!("read={}", unsafe { String::from_utf8_unchecked(buf[0..n].into()) }); tls_stream .write_all(&buf[0..n]) .await .expect("failed to write data to socket"); }); } } tokio-native-tls-0.3.1/examples/identity.p12000064400000000000000000000064721046102023000170420ustar 000000000000000 60  *H   0 0w *H h0d0] *H 0 *H  0u W70l<6- I\?ӳ]:Wh aXI3."!Dc3,[LөB':SlZuS؁! $9Bb&AHUFCew!=@2 x񘛬G"2G`DRx矱Ra}Pz6Ԥ)}`Y'BЂ)-kH̞6.K7.h͞kg9|PctGؙNchk ]ӢɛĮT:9\ =0RT{O0'23.R ' { JOVDc5V-3E _i^O* )'[䓬=d$ %vhYy<4Q\1S(|Ad)59iʅZ|ORvNyOK' HA#B$ٻ8NJB _F} T/f%.L~Z/ǹ_ ס]ǰbf@Z f4TrB!æU콆B/I$79Idz .Q^$@L*fYlx.OI;ꔛ%Raڐ㜥\Zcyx|K|>"\ձW2g_?*0SQQl F/sng^$3Ĭh'0p|.22*c K~"bgY*Tn̤zzR9r(7m૘zm Wн3-P}HԊ@_z4Di۩rpg$T#E$L =/M4 q`ИRΏ&7k'*~ݏgzcؚq@Ά)UrnXΧW,.M=9sIOXO #I͊ ȸҝ\:2S1؏_j:Purd+8p=,2ZdSMKPf|#.+";נ"$K_\>%]o LBG 5Ut!uoPfd6 ZIZeXfO^K'hpIY= 0U-uh1Gx|C["y6]C\ Nֺ OV:6bGUʶ+=,.{*2Н$6AXKS2>9RLw6Ӆn~x7*-btJ֛-rwn n u13+$)u7 XD/gZ(DY: I[N'h㾯38H |v0e4 ͍@)MZw oy=Oru7=E5_BσRYP {h%s.oY4gaɠXs)[>UdѰ 1C6qJ׽nEʹ0kVEG>,QXA*ZF4GXduȞvu[Jdʘb"MHufQPXf=7h3tᆳHr&2)TTt"^=@ӕ(G/;z-%3Xbijk&nRP 8σzHX4GC؁ʥMshՉR/uȮ ]d( N U|5u[?DSbǤVE 9G4g0f *H WS0O0K *H  00 *H  0iK[Kq=7_޼5Ue eTJc,v@D$COHpȮxM?͒i@ g*V@6>p5e OHݢfOg<`Q =S;]ZhPO@=:lpYĥe mE4oeD cMz環= 쩉q膔D"%aZG7kqv|sc"mwOŀ%ʱw3Vģ?.Z[dk;g2M5O6rdYNc;.59:7_IHR Ui9"־I+{azw}Ed||yԨZ4#.l$2l;D=;JH#Ǻ1>Z }y:֔ ;2Q Bi|KVA SCZ ^1s^Zk# ަ+>/^w;,]=^if ,Xǜ@gkWt!qЎiu4bYW&Y"Cb ;\RV) KkCp@QQ苇Zˡٿ:4z[< %}v6=O6 saBvȄ9[КQ~ (V-qϒ:Gnнҡ"M5!/Za` =&}S|m B`-H6~=$$!k[&pQxShtn+hW:f3>s26aK3}OV"poYus!㿬a5 sI;&^ݭ"g2@<]~ 9,fy!#PQ#ޛugsOe`#Cc=>ڈ1J0# *H  1foobar.com0# *H  1Y-DY'gn010!0 +d)II Z)Z#Fճ"otokio-native-tls-0.3.1/scripts/generate-certificate.sh000075500000000000000000000030551046102023000211410ustar 00000000000000#!/bin/bash set -e cd $1 # prepare config file for root CA generation cat <> root.cnf [ req ] distinguished_name = req_dn [ req_dn ] [ v3_ca ] basicConstraints = CA:TRUE keyUsage = digitalSignature, nonRepudiation, keyCertSign, cRLSign subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always EOF ROOT_CA_KEY=root-ca.key.pem ROOT_CA=root-ca.pem ROOT_CA_DER=root-ca.der echo "Generate root CA key" openssl genrsa -out $ROOT_CA_KEY 4096 echo "Generate root CA certificate" openssl req -x509 -new -key $ROOT_CA_KEY -out $ROOT_CA -days 365 -SHA256 -subj "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd" -config root.cnf -extensions v3_ca openssl x509 -outform der -in $ROOT_CA -out $ROOT_CA_DER rm root.cnf # prepare config file for server certificate generation cat <> server.cnf extendedKeyUsage=serverAuth subjectAltName = @alt_names [alt_names] DNS.1 = foobar.com EOF SERVER_KEY=server.key.pem SERVER_CERT=cert.pem SERVER_CERT_DER=cert.der IDENTITY=identity.p12 PASSPHRASE=mypass echo "Generate server key" openssl genrsa -out $SERVER_KEY 4096 echo "Generate server certificate" openssl req -out server.csr -key $SERVER_KEY -new -days 365 -SHA256 -subj "/C=AU/ST=Some-State/O=Internet Widgits Pty Ltd/CN=foobar.com" openssl x509 -req -days 365 -SHA256 -in server.csr -CA $ROOT_CA -CAkey $ROOT_CA_KEY -CAcreateserial -out $SERVER_CERT -extfile server.cnf openssl x509 -outform der -in $SERVER_CERT -out $SERVER_CERT_DER openssl pkcs12 -export -out $IDENTITY -inkey $SERVER_KEY -in $SERVER_CERT -passout pass:$PASSPHRASE rm server.csr rm server.cnf tokio-native-tls-0.3.1/src/lib.rs000064400000000000000000000265441046102023000147540ustar 00000000000000#![doc(html_root_url = "https://docs.rs/tokio-native-tls/0.3.0")] #![warn( missing_debug_implementations, missing_docs, rust_2018_idioms, unreachable_pub )] #![deny(rustdoc::broken_intra_doc_links)] #![doc(test( no_crate_inject, attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables)) ))] //! Async TLS streams //! //! This library is an implementation of TLS streams using the most appropriate //! system library by default for negotiating the connection. That is, on //! Windows this library uses SChannel, on OSX it uses SecureTransport, and on //! other platforms it uses OpenSSL. //! //! Each TLS stream implements the `Read` and `Write` traits to interact and //! interoperate with the rest of the futures I/O ecosystem. Client connections //! initiated from this crate verify hostnames automatically and by default. //! //! This crate primarily exports this ability through two newtypes, //! `TlsConnector` and `TlsAcceptor`. These newtypes augment the //! functionality provided by the `native-tls` crate, on which this crate is //! built. Configuration of TLS parameters is still primarily done through the //! `native-tls` crate. use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use crate::native_tls::{Error, HandshakeError, MidHandshakeTlsStream}; use std::fmt; use std::future::Future; use std::io::{self, Read, Write}; use std::marker::Unpin; #[cfg(unix)] use std::os::unix::io::{AsRawFd, RawFd}; #[cfg(windows)] use std::os::windows::io::{AsRawSocket, RawSocket}; use std::pin::Pin; use std::ptr::null_mut; use std::task::{Context, Poll}; /// An intermediate wrapper for the inner stream `S`. #[derive(Debug)] pub struct AllowStd { inner: S, context: *mut (), } impl AllowStd { /// Returns a shared reference to the inner stream. pub fn get_ref(&self) -> &S { &self.inner } /// Returns a mutable reference to the inner stream. pub fn get_mut(&mut self) -> &mut S { &mut self.inner } } /// A wrapper around an underlying raw stream which implements the TLS or SSL /// protocol. /// /// A `TlsStream` represents a handshake that has been completed successfully /// and both the server and the client are ready for receiving and sending /// data. Bytes read from a `TlsStream` are decrypted from `S` and bytes written /// to a `TlsStream` are encrypted when passing through to `S`. #[derive(Debug)] pub struct TlsStream(native_tls::TlsStream>); /// A wrapper around a `native_tls::TlsConnector`, providing an async `connect` /// method. #[derive(Clone)] pub struct TlsConnector(native_tls::TlsConnector); /// A wrapper around a `native_tls::TlsAcceptor`, providing an async `accept` /// method. #[derive(Clone)] pub struct TlsAcceptor(native_tls::TlsAcceptor); struct MidHandshake(Option>>); enum StartedHandshake { Done(TlsStream), Mid(MidHandshakeTlsStream>), } struct StartedHandshakeFuture(Option>); struct StartedHandshakeFutureInner { f: F, stream: S, } struct Guard<'a, S>(&'a mut TlsStream) where AllowStd: Read + Write; impl Drop for Guard<'_, S> where AllowStd: Read + Write, { fn drop(&mut self) { (self.0).0.get_mut().context = null_mut(); } } // *mut () context is neither Send nor Sync unsafe impl Send for AllowStd {} unsafe impl Sync for AllowStd {} impl AllowStd where S: Unpin, { fn with_context(&mut self, f: F) -> io::Result where F: FnOnce(&mut Context<'_>, Pin<&mut S>) -> Poll>, { unsafe { assert!(!self.context.is_null()); let waker = &mut *(self.context as *mut _); match f(waker, Pin::new(&mut self.inner)) { Poll::Ready(r) => r, Poll::Pending => Err(io::Error::from(io::ErrorKind::WouldBlock)), } } } } impl Read for AllowStd where S: AsyncRead + Unpin, { fn read(&mut self, buf: &mut [u8]) -> io::Result { let mut buf = ReadBuf::new(buf); self.with_context(|ctx, stream| stream.poll_read(ctx, &mut buf))?; Ok(buf.filled().len()) } } impl Write for AllowStd where S: AsyncWrite + Unpin, { fn write(&mut self, buf: &[u8]) -> io::Result { self.with_context(|ctx, stream| stream.poll_write(ctx, buf)) } fn flush(&mut self) -> io::Result<()> { self.with_context(|ctx, stream| stream.poll_flush(ctx)) } } impl TlsStream { fn with_context(&mut self, ctx: &mut Context<'_>, f: F) -> Poll> where F: FnOnce(&mut native_tls::TlsStream>) -> io::Result, AllowStd: Read + Write, { self.0.get_mut().context = ctx as *mut _ as *mut (); let g = Guard(self); match f(&mut (g.0).0) { Ok(v) => Poll::Ready(Ok(v)), Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => Poll::Pending, Err(e) => Poll::Ready(Err(e)), } } /// Returns a shared reference to the inner stream. pub fn get_ref(&self) -> &native_tls::TlsStream> { &self.0 } /// Returns a mutable reference to the inner stream. pub fn get_mut(&mut self) -> &mut native_tls::TlsStream> { &mut self.0 } } impl AsyncRead for TlsStream where S: AsyncRead + AsyncWrite + Unpin, { fn poll_read( mut self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: &mut ReadBuf<'_>, ) -> Poll> { self.with_context(ctx, |s| { let n = s.read(buf.initialize_unfilled())?; buf.advance(n); Ok(()) }) } } impl AsyncWrite for TlsStream where S: AsyncRead + AsyncWrite + Unpin, { fn poll_write( mut self: Pin<&mut Self>, ctx: &mut Context<'_>, buf: &[u8], ) -> Poll> { self.with_context(ctx, |s| s.write(buf)) } fn poll_flush(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll> { self.with_context(ctx, |s| s.flush()) } fn poll_shutdown(mut self: Pin<&mut Self>, ctx: &mut Context<'_>) -> Poll> { self.with_context(ctx, |s| s.shutdown()) } } #[cfg(unix)] impl AsRawFd for TlsStream where S: AsRawFd, { fn as_raw_fd(&self) -> RawFd { self.get_ref().get_ref().get_ref().as_raw_fd() } } #[cfg(windows)] impl AsRawSocket for TlsStream where S: AsRawSocket, { fn as_raw_socket(&self) -> RawSocket { self.get_ref().get_ref().get_ref().as_raw_socket() } } async fn handshake(f: F, stream: S) -> Result, Error> where F: FnOnce( AllowStd, ) -> Result>, HandshakeError>> + Unpin, S: AsyncRead + AsyncWrite + Unpin, { let start = StartedHandshakeFuture(Some(StartedHandshakeFutureInner { f, stream })); match start.await { Err(e) => Err(e), Ok(StartedHandshake::Done(s)) => Ok(s), Ok(StartedHandshake::Mid(s)) => MidHandshake(Some(s)).await, } } impl Future for StartedHandshakeFuture where F: FnOnce( AllowStd, ) -> Result>, HandshakeError>> + Unpin, S: Unpin, AllowStd: Read + Write, { type Output = Result, Error>; fn poll( mut self: Pin<&mut Self>, ctx: &mut Context<'_>, ) -> Poll, Error>> { let inner = self.0.take().expect("future polled after completion"); let stream = AllowStd { inner: inner.stream, context: ctx as *mut _ as *mut (), }; match (inner.f)(stream) { Ok(mut s) => { s.get_mut().context = null_mut(); Poll::Ready(Ok(StartedHandshake::Done(TlsStream(s)))) } Err(HandshakeError::WouldBlock(mut s)) => { s.get_mut().context = null_mut(); Poll::Ready(Ok(StartedHandshake::Mid(s))) } Err(HandshakeError::Failure(e)) => Poll::Ready(Err(e)), } } } impl TlsConnector { /// Connects the provided stream with this connector, assuming the provided /// domain. /// /// This function will internally call `TlsConnector::connect` to connect /// the stream and returns a future representing the resolution of the /// connection operation. The returned future will resolve to either /// `TlsStream` or `Error` depending if it's successful or not. /// /// This is typically used for clients who have already established, for /// example, a TCP connection to a remote server. That stream is then /// provided here to perform the client half of a connection to a /// TLS-powered server. pub async fn connect(&self, domain: &str, stream: S) -> Result, Error> where S: AsyncRead + AsyncWrite + Unpin, { handshake(move |s| self.0.connect(domain, s), stream).await } } impl fmt::Debug for TlsConnector { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TlsConnector").finish() } } impl From for TlsConnector { fn from(inner: native_tls::TlsConnector) -> TlsConnector { TlsConnector(inner) } } impl TlsAcceptor { /// Accepts a new client connection with the provided stream. /// /// This function will internally call `TlsAcceptor::accept` to connect /// the stream and returns a future representing the resolution of the /// connection operation. The returned future will resolve to either /// `TlsStream` or `Error` depending if it's successful or not. /// /// This is typically used after a new socket has been accepted from a /// `TcpListener`. That socket is then passed to this function to perform /// the server half of accepting a client connection. pub async fn accept(&self, stream: S) -> Result, Error> where S: AsyncRead + AsyncWrite + Unpin, { handshake(move |s| self.0.accept(s), stream).await } } impl fmt::Debug for TlsAcceptor { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("TlsAcceptor").finish() } } impl From for TlsAcceptor { fn from(inner: native_tls::TlsAcceptor) -> TlsAcceptor { TlsAcceptor(inner) } } impl Future for MidHandshake { type Output = Result, Error>; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut_self = self.get_mut(); let mut s = mut_self.0.take().expect("future polled after completion"); s.get_mut().context = cx as *mut _ as *mut (); match s.handshake() { Ok(mut s) => { s.get_mut().context = null_mut(); Poll::Ready(Ok(TlsStream(s))) } Err(HandshakeError::WouldBlock(mut s)) => { s.get_mut().context = null_mut(); mut_self.0 = Some(s); Poll::Pending } Err(HandshakeError::Failure(e)) => Poll::Ready(Err(e)), } } } /// re-export native_tls pub mod native_tls { pub use native_tls::*; } tokio-native-tls-0.3.1/tests/bad.rs000064400000000000000000000072531046102023000153030ustar 00000000000000#![warn(rust_2018_idioms)] use cfg_if::cfg_if; use native_tls::TlsConnector; use std::io::{self, Error}; use std::net::ToSocketAddrs; use tokio::net::TcpStream; macro_rules! t { ($e:expr) => { match $e { Ok(e) => e, Err(e) => panic!("{} failed with {:?}", stringify!($e), e), } }; } cfg_if! { if #[cfg(feature = "force-rustls")] { fn verify_failed(err: &Error, s: &str) { let err = err.to_string(); assert!(err.contains(s), "bad error: {}", err); } fn assert_expired_error(err: &Error) { verify_failed(err, "CertExpired"); } fn assert_wrong_host(err: &Error) { verify_failed(err, "CertNotValidForName"); } fn assert_self_signed(err: &Error) { verify_failed(err, "UnknownIssuer"); } fn assert_untrusted_root(err: &Error) { verify_failed(err, "UnknownIssuer"); } } else if #[cfg(any(feature = "force-openssl", all(not(target_os = "macos"), not(target_os = "windows"), not(target_os = "ios"))))] { fn verify_failed(err: &Error) { assert!(format!("{}", err).contains("certificate verify failed")) } use verify_failed as assert_expired_error; use verify_failed as assert_wrong_host; use verify_failed as assert_self_signed; use verify_failed as assert_untrusted_root; } else if #[cfg(any(target_os = "macos", target_os = "ios"))] { fn assert_invalid_cert_chain(err: &Error) { assert!(format!("{}", err).contains("was not trusted.")) } use crate::assert_invalid_cert_chain as assert_expired_error; use crate::assert_invalid_cert_chain as assert_wrong_host; use crate::assert_invalid_cert_chain as assert_self_signed; use crate::assert_invalid_cert_chain as assert_untrusted_root; } else { fn assert_expired_error(err: &Error) { let s = err.to_string(); assert!(s.contains("system clock"), "error = {:?}", s); } fn assert_wrong_host(err: &Error) { let s = err.to_string(); assert!(s.contains("CN name"), "error = {:?}", s); } fn assert_self_signed(err: &Error) { let s = err.to_string(); assert!(s.contains("root certificate which is not trusted"), "error = {:?}", s); } use assert_self_signed as assert_untrusted_root; } } async fn get_host(host: &'static str) -> Error { drop(env_logger::try_init()); let addr = format!("{}:443", host); let addr = t!(addr.to_socket_addrs()).next().unwrap(); let socket = t!(TcpStream::connect(&addr).await); let builder = TlsConnector::builder(); let cx = t!(builder.build()); let cx = tokio_native_tls::TlsConnector::from(cx); let res = cx .connect(host, socket) .await .map_err(|e| Error::new(io::ErrorKind::Other, e)); assert!(res.is_err()); res.err().unwrap() } #[tokio::test] async fn expired() { assert_expired_error(&get_host("expired.badssl.com").await) } // TODO: the OSX builders on Travis apparently fail this tests spuriously? // passes locally though? Seems... bad! #[tokio::test] #[cfg_attr(all(target_os = "macos", feature = "force-openssl"), ignore)] async fn wrong_host() { assert_wrong_host(&get_host("wrong.host.badssl.com").await) } #[tokio::test] async fn self_signed() { assert_self_signed(&get_host("self-signed.badssl.com").await) } #[tokio::test] async fn untrusted_root() { assert_untrusted_root(&get_host("untrusted-root.badssl.com").await) } tokio-native-tls-0.3.1/tests/cert.der000064400000000000000000000014371046102023000156360ustar 0000000000000000 q/0  *H  0E1 0 UAU10U Some-State1!0U Internet Widgits Pty Ltd0 160814170003Z 260812170003Z0Z1 0 UAU10U Some-State1!0U Internet Widgits Pty Ltd10U foobar.com0"0  *H 0 %DP#x6I-Gl6?7޿3eJI"do 4N?rPК6bOBt _Z%%5SR!W.xN:HexYT`^U|렑Ԓ'٫ fgړ  UሹIleFl;nvz=N׌KRV^zd3Qݔܤ߄NPY\Э;6* 50  *H  Jy CGBϥQ͸а4 )Xk>I# ք%Wn!Re-N/fqG.*< J&'Iqʦ-4f'R99H)OXϰ3~bVXv3` iP,NbG h3d߲A1 )}6u@"OHx'TAre"6؃Hk^ { match $e { Ok(e) => e, Err(e) => panic!("{} failed with {:?}", stringify!($e), e), } }; } cfg_if! { if #[cfg(feature = "force-rustls")] { fn assert_bad_hostname_error(err: &io::Error) { let err = err.to_string(); assert!(err.contains("CertNotValidForName"), "bad error: {}", err); } } else if #[cfg(any(feature = "force-openssl", all(not(target_os = "macos"), not(target_os = "windows"), not(target_os = "ios"))))] { fn assert_bad_hostname_error(err: &io::Error) { let err = err.get_ref().unwrap(); let err = err.downcast_ref::().unwrap(); assert!(format!("{}", err).contains("certificate verify failed")); } } else if #[cfg(any(target_os = "macos", target_os = "ios"))] { fn assert_bad_hostname_error(err: &io::Error) { let err = err.get_ref().unwrap(); let err = err.downcast_ref::().unwrap(); assert!(format!("{}", err).contains("was not trusted.")); } } else { fn assert_bad_hostname_error(err: &io::Error) { let err = err.get_ref().unwrap(); let err = err.downcast_ref::().unwrap(); assert!(format!("{}", err).contains("CN name")); } } } #[tokio::test] async fn fetch_google() { drop(env_logger::try_init()); // First up, resolve google.com let addr = t!("google.com:443".to_socket_addrs()).next().unwrap(); let socket = TcpStream::connect(&addr).await.unwrap(); // Send off the request by first negotiating an SSL handshake, then writing // of our request, then flushing, then finally read off the response. let builder = TlsConnector::builder(); let connector = t!(builder.build()); let connector = tokio_native_tls::TlsConnector::from(connector); let mut socket = t!(connector.connect("google.com", socket).await); t!(socket.write_all(b"GET / HTTP/1.0\r\n\r\n").await); let mut data = Vec::new(); t!(socket.read_to_end(&mut data).await); // any response code is fine assert!(data.starts_with(b"HTTP/1.0 ")); let data = String::from_utf8_lossy(&data); let data = data.trim_end(); assert!(data.ends_with("") || data.ends_with("")); } fn native2io(e: native_tls::Error) -> io::Error { io::Error::new(io::ErrorKind::Other, e) } // see comment in bad.rs for ignore reason #[cfg_attr(all(target_os = "macos", feature = "force-openssl"), ignore)] #[tokio::test] async fn wrong_hostname_error() { drop(env_logger::try_init()); let addr = t!("google.com:443".to_socket_addrs()).next().unwrap(); let socket = t!(TcpStream::connect(&addr).await); let builder = TlsConnector::builder(); let connector = t!(builder.build()); let connector = tokio_native_tls::TlsConnector::from(connector); let res = connector .connect("rust-lang.org", socket) .await .map_err(native2io); assert!(res.is_err()); assert_bad_hostname_error(&res.err().unwrap()); } tokio-native-tls-0.3.1/tests/identity.p12000064400000000000000000000064721046102023000163660ustar 000000000000000 60  *H   0 0w *H h0d0] *H 0 *H  0u W70l<6- I\?ӳ]:Wh aXI3."!Dc3,[LөB':SlZuS؁! $9Bb&AHUFCew!=@2 x񘛬G"2G`DRx矱Ra}Pz6Ԥ)}`Y'BЂ)-kH̞6.K7.h͞kg9|PctGؙNchk ]ӢɛĮT:9\ =0RT{O0'23.R ' { JOVDc5V-3E _i^O* )'[䓬=d$ %vhYy<4Q\1S(|Ad)59iʅZ|ORvNyOK' HA#B$ٻ8NJB _F} T/f%.L~Z/ǹ_ ס]ǰbf@Z f4TrB!æU콆B/I$79Idz .Q^$@L*fYlx.OI;ꔛ%Raڐ㜥\Zcyx|K|>"\ձW2g_?*0SQQl F/sng^$3Ĭh'0p|.22*c K~"bgY*Tn̤zzR9r(7m૘zm Wн3-P}HԊ@_z4Di۩rpg$T#E$L =/M4 q`ИRΏ&7k'*~ݏgzcؚq@Ά)UrnXΧW,.M=9sIOXO #I͊ ȸҝ\:2S1؏_j:Purd+8p=,2ZdSMKPf|#.+";נ"$K_\>%]o LBG 5Ut!uoPfd6 ZIZeXfO^K'hpIY= 0U-uh1Gx|C["y6]C\ Nֺ OV:6bGUʶ+=,.{*2Н$6AXKS2>9RLw6Ӆn~x7*-btJ֛-rwn n u13+$)u7 XD/gZ(DY: I[N'h㾯38H |v0e4 ͍@)MZw oy=Oru7=E5_BσRYP {h%s.oY4gaɠXs)[>UdѰ 1C6qJ׽nEʹ0kVEG>,QXA*ZF4GXduȞvu[Jdʘb"MHufQPXf=7h3tᆳHr&2)TTt"^=@ӕ(G/;z-%3Xbijk&nRP 8σzHX4GC؁ʥMshՉR/uȮ ]d( N U|5u[?DSbǤVE 9G4g0f *H WS0O0K *H  00 *H  0iK[Kq=7_޼5Ue eTJc,v@D$COHpȮxM?͒i@ g*V@6>p5e OHݢfOg<`Q =S;]ZhPO@=:lpYĥe mE4oeD cMz環= 쩉q膔D"%aZG7kqv|sc"mwOŀ%ʱw3Vģ?.Z[dk;g2M5O6rdYNc;.59:7_IHR Ui9"־I+{azw}Ed||yԨZ4#.l$2l;D=;JH#Ǻ1>Z }y:֔ ;2Q Bi|KVA SCZ ^1s^Zk# ަ+>/^w;,]=^if ,Xǜ@gkWt!qЎiu4bYW&Y"Cb ;\RV) KkCp@QQ苇Zˡٿ:4z[< %}v6=O6 saBvȄ9[КQ~ (V-qϒ:Gnнҡ"M5!/Za` =&}S|m B`-H6~=$$!k[&pQxShtn+hW:f3>s26aK3}OV"poYus!㿬a5 sI;&^ݭ"g2@<]~ 9,fy!#PQ#ޛugsOe`#Cc=>ڈ1J0# *H  1foobar.com0# *H  1Y-DY'gn010!0 +d)II Z)Z#Fճ"otokio-native-tls-0.3.1/tests/root-ca.der000064400000000000000000000015411046102023000162410ustar 000000000000000]0E /%[Ǖ0  *H  0E1 0 UAU10U Some-State1!0U Internet Widgits Pty Ltd0 160814165611Z 260812165611Z0E1 0 UAU10U Some-State1!0U Internet Widgits Pty Ltd0"0  *H 0 Q~v-u^ۙRg ا0-GAZԬf[|vT-Dz'W<~sD] WxcT/sm~Ҳιćx]z_Яf+*{R8jɪy%9y9Qe<$m|DVdUvhWJ_#h)ޥut@*ܰa,sSz\PǧWtriPң_cP0N0Ulӥ _,ɍw70U#0lӥ _,ɍw70 U00  *H  UVdQ<:M g7~ ͼ )كl6*8(BjYlb2яGG!#͠&%kUH}}M]Hw28Բ”]ȍ`hj}\c#mPG&ERվ7z",zp[Imy]^ ~ĄI3tokio-native-tls-0.3.1/tests/smoke.rs000064400000000000000000000126541046102023000156740ustar 00000000000000use futures::join; use lazy_static::lazy_static; use native_tls::{Certificate, Identity}; use std::{fs, io::Error, path::PathBuf, process::Command}; use tokio::{ io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}, net::{TcpListener, TcpStream}, }; use tokio_native_tls::{TlsAcceptor, TlsConnector}; lazy_static! { static ref CERT_DIR: PathBuf = { if cfg!(unix) { let dir = tempfile::TempDir::new().unwrap(); let path = dir.path().to_str().unwrap(); Command::new("sh") .arg("-c") .arg(format!("./scripts/generate-certificate.sh {}", path)) .output() .expect("failed to execute process"); dir.into_path() } else { PathBuf::from("tests") } }; } #[tokio::test] async fn client_to_server() { let srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = srv.local_addr().unwrap(); let (server_tls, client_tls) = context(); // Create a future to accept one socket, connect the ssl stream, and then // read all the data from it. let server = async move { let (socket, _) = srv.accept().await.unwrap(); let mut socket = server_tls.accept(socket).await.unwrap(); // Verify access to all of the nested inner streams (e.g. so that peer // certificates can be accessed). This is just a compile check. let native_tls_stream: &native_tls::TlsStream<_> = socket.get_ref(); let _peer_cert = native_tls_stream.peer_certificate().unwrap(); let allow_std_stream: &tokio_native_tls::AllowStd<_> = native_tls_stream.get_ref(); let _tokio_tcp_stream: &tokio::net::TcpStream = allow_std_stream.get_ref(); let mut data = Vec::new(); socket.read_to_end(&mut data).await.unwrap(); data }; // Create a future to connect to our server, connect the ssl stream, and // then write a bunch of data to it. let client = async move { let socket = TcpStream::connect(&addr).await.unwrap(); let socket = client_tls.connect("foobar.com", socket).await.unwrap(); copy_data(socket).await }; // Finally, run everything! let (data, _) = join!(server, client); // assert_eq!(amt, AMT); assert!(data == vec![9; AMT]); } #[tokio::test] async fn server_to_client() { // Create a server listening on a port, then figure out what that port is let srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = srv.local_addr().unwrap(); let (server_tls, client_tls) = context(); let server = async move { let (socket, _) = srv.accept().await.unwrap(); let socket = server_tls.accept(socket).await.unwrap(); copy_data(socket).await }; let client = async move { let socket = TcpStream::connect(&addr).await.unwrap(); let mut socket = client_tls.connect("foobar.com", socket).await.unwrap(); let mut data = Vec::new(); socket.read_to_end(&mut data).await.unwrap(); data }; // Finally, run everything! let (_, data) = join!(server, client); assert!(data == vec![9; AMT]); } #[tokio::test] async fn one_byte_at_a_time() { const AMT: usize = 1024; let srv = TcpListener::bind("127.0.0.1:0").await.unwrap(); let addr = srv.local_addr().unwrap(); let (server_tls, client_tls) = context(); let server = async move { let (socket, _) = srv.accept().await.unwrap(); let mut socket = server_tls.accept(socket).await.unwrap(); let mut amt = 0; for b in std::iter::repeat(9).take(AMT) { let data = [b as u8]; socket.write_all(&data).await.unwrap(); amt += 1; } amt }; let client = async move { let socket = TcpStream::connect(&addr).await.unwrap(); let mut socket = client_tls.connect("foobar.com", socket).await.unwrap(); let mut data = Vec::new(); loop { let mut buf = [0; 1]; match socket.read_exact(&mut buf).await { Ok(_) => data.extend_from_slice(&buf), Err(ref err) if err.kind() == std::io::ErrorKind::UnexpectedEof => break, Err(err) => panic!("{}", err), } } data }; let (amt, data) = join!(server, client); assert_eq!(amt, AMT); assert!(data == vec![9; AMT as usize]); } fn context() -> (TlsAcceptor, TlsConnector) { let pkcs12 = fs::read(CERT_DIR.join("identity.p12")).unwrap(); let der = fs::read(CERT_DIR.join("root-ca.der")).unwrap(); let identity = Identity::from_pkcs12(&pkcs12, "mypass").unwrap(); let acceptor = native_tls::TlsAcceptor::builder(identity).build().unwrap(); let cert = Certificate::from_der(&der).unwrap(); let connector = native_tls::TlsConnector::builder() .add_root_certificate(cert) .build() .unwrap(); (acceptor.into(), connector.into()) } const AMT: usize = 128 * 1024; async fn copy_data(mut w: W) -> Result { let mut data = vec![9; AMT as usize]; let mut amt = 0; while !data.is_empty() { let written = w.write(&data).await?; if written <= data.len() { amt += written; data.resize(data.len() - written, 0); } else { w.write_all(&data).await?; amt += data.len(); break; } println!("remaining: {}", data.len()); } Ok(amt) }