Skip to content

Commit 6b81ff1

Browse files
authored
Wincrypto Implementation for Str0m (algesten#589)
Implement new Str0m feature 'wincrypto'. When enabled, this cause Str0m to use Windows Cryptographic APIs for crypto. This feature cannot be used in conjunction with 'sha1' not 'openssl' features, as it provides the same functionality. Windows APIs are accessed via the windows-rs crate. These calls are `unsafe`, so in order to isolate them from `safe` str0m code, all `unsafe` code is in a separate `str0m_wincrypto` crate. The code in the core `str0m/crypto/wincrypto` is the glue code between Str0m and this str0m_wincrypto crate. The `str0m_wincrypto` crate is not intended to be a generic crypto crate, and is very much tailored to match str0m's crypto APIs.
1 parent c8bf98f commit 6b81ff1

24 files changed

+2091
-28
lines changed

.github/workflows/cargo.yml

+26-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,31 @@ jobs:
3535
with:
3636
command: test
3737

38+
test_wincrypto:
39+
strategy:
40+
matrix:
41+
os: [windows-latest]
42+
rust: [stable, beta, 1.70.0]
43+
44+
runs-on: ${{ matrix.os }}
45+
46+
steps:
47+
- uses: actions/checkout@v2
48+
- uses: actions-rs/toolchain@v1
49+
with:
50+
profile: minimal
51+
toolchain: ${{ matrix.rust }}
52+
override: true
53+
- uses: Swatinem/rust-cache@v1
54+
- uses: actions-rs/cargo@v1
55+
with:
56+
command: build
57+
args: --no-default-features --features wincrypto
58+
- uses: actions-rs/cargo@v1
59+
with:
60+
command: test
61+
args: --no-default-features --features wincrypto
62+
3863
lint:
3964
runs-on: ubuntu-latest
4065
steps:
@@ -57,7 +82,7 @@ jobs:
5782
- uses: actions-rs/cargo@v1
5883
with:
5984
command: clippy
60-
args: --all-targets --no-default-features -- -D warnings
85+
args: --all-targets --no-default-features --features openssl,vendored,sha1 -- -D warnings
6186
- uses: actions-rs/toolchain@v1
6287
with:
6388
profile: minimal

Cargo.lock

+86-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+16-3
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ rust-version = "1.65"
2525

2626
[features]
2727
default = ["openssl", "vendored", "sha1"]
28-
openssl = ["dep:openssl", "dep:openssl-sys", "dep:libc"]
28+
openssl = ["dep:openssl", "dep:openssl-sys", "dep:libc", "rouille/ssl"]
2929
vendored = ["openssl?/vendored"]
3030

3131
# Without the sha1 feature, str0m uses the openssl sha1 impl which is slower.
3232
sha1 = ["dep:sha1"]
3333

34+
# Uses native Windows API to implement cryptographic features, use instead on openssl and sha1.
35+
wincrypto = ["dep:str0m-wincrypto"]
36+
3437
_internal_dont_use_log_stats = []
3538
_internal_test_exports = []
3639

@@ -55,13 +58,15 @@ serde = { version = "1.0.152", features = ["derive"] }
5558
[target.'cfg(unix)'.dependencies]
5659
sha1 = { version = "0.10.6", features = ["asm"], optional = true }
5760

61+
[target.'cfg(windows)'.dependencies]
5862
# The ASM feature is broken on windows. Unclear where in the rust-crypto project
5963
# we're supposed to check when it gets sorted out.
60-
[target.'cfg(windows)'.dependencies]
6164
sha1 = { version = "0.10.6", optional = true }
65+
# Windows Crypto (CNG + SChannel)
66+
str0m-wincrypto = { path = "wincrypto", optional = true }
6267

6368
[dev-dependencies]
64-
rouille = { version = "3.5.0", features = ["ssl"] }
69+
rouille = { version = "3.5.0", features = [] }
6570
serde_json = "1.0"
6671
tracing-subscriber = { version = "0.3.16", features = ["env-filter", "std"] }
6772
systemstat = "0.2.2"
@@ -74,3 +79,11 @@ _str0m_test = { path = "_str0m_test" }
7479
time = "=0.3.23"
7580
pcap-file = "2.0.0"
7681
url = "=2.5.0"
82+
83+
[[example]]
84+
name = "chat"
85+
required-features = ["openssl"]
86+
87+
[[example]]
88+
name = "http-post"
89+
required-features = ["openssl"]

_str0m_test/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ version = "0.1.0"
88
edition = "2021"
99

1010
[dependencies]
11-
str0m = { path = "..", features = ["_internal_test_exports"] }
11+
str0m = { path = "..", default-features = false, features = ["_internal_test_exports"] }

0 commit comments

Comments
 (0)