Skip to content

Commit 4f5440e

Browse files
feat: TSSSP module (#95)
1 parent e8944a9 commit 4f5440e

15 files changed

+1700
-183
lines changed

.github/workflows/ci.yml

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,60 @@ jobs:
2626
}
2727
2828
lints:
29-
name: Lints
30-
runs-on: ubuntu-latest
29+
name: Lints [${{ matrix.os }}]
30+
runs-on: ${{ matrix.runner }}
3131
needs: formatting
32+
strategy:
33+
fail-fast: true
34+
matrix:
35+
os: [ win, osx, linux ]
36+
include:
37+
- os: win
38+
runner: windows-2022
39+
features: tsssp,debug_mode
40+
- os: osx
41+
runner: macos-12
42+
features: debug_mode
43+
- os: linux
44+
runner: ubuntu-20.04
45+
features: debug_mode
3246

3347
steps:
3448
- uses: actions/checkout@v3
3549

50+
# Compiling the ffi module is enough to lint the whole sspi workspace
3651
- name: Check clippy
37-
run: cargo clippy --workspace --all-features -- -D warnings
52+
run: cargo clippy --manifest-path ffi/Cargo.toml --features ${{ matrix.features }} -- -D warnings
3853

3954
tests:
40-
name: Tests
41-
runs-on: ubuntu-latest
55+
name: Tests [${{ matrix.os }}] [${{ matrix.crate-name }}]
56+
runs-on: ${{ matrix.runner }}
4257
needs: formatting
58+
strategy:
59+
fail-fast: true
60+
matrix:
61+
os: [ win, osx, linux ]
62+
manifest: [ Cargo.toml, ffi/Cargo.toml ]
63+
include:
64+
- manifest: Cargo.toml
65+
crate-name: sspi
66+
- manifest: ffi/Cargo.toml
67+
crate-name: sspi-ffi
68+
- os: win
69+
runner: windows-2022
70+
features: tsssp
71+
- os: osx
72+
runner: macos-12
73+
features: default
74+
- os: linux
75+
runner: ubuntu-20.04
76+
features: default
4377

4478
steps:
4579
- uses: actions/checkout@v3
4680

4781
- name: Test
48-
run: cargo test --workspace --all-features
82+
run: cargo test --manifest-path ${{ matrix.manifest }} --features ${{ matrix.features }}
4983

5084
wasm:
5185
name: WASM target

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ exclude = [
2424
default = []
2525
network_client = ["dep:reqwest", "dep:portpicker"]
2626
dns_resolver = ["dep:trust-dns-resolver"]
27+
# TSSSP should be used only on Windows as a native CREDSSP replacement
28+
tsssp = ["dep:rustls"]
2729

2830
[dependencies]
2931
byteorder = "1.2.7"
@@ -55,6 +57,7 @@ trust-dns-resolver = { version = "0.21.2", optional = true }
5557
portpicker = { version = "0.1.1", optional = true }
5658
num-bigint-dig = "0.8.1"
5759
tracing = { version = "0.1.37" }
60+
rustls = { version = "0.20.7", features = ["dangerous_configuration"], optional = true }
5861

5962
[target.'cfg(windows)'.dependencies]
6063
winreg = "0.10"

ffi/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,22 @@ name = "sspi"
1313
crate-type = ["cdylib"]
1414

1515
[features]
16+
default = []
1617
debug_mode = ["dep:tracing", "dep:tracing-subscriber"]
18+
tsssp = ["sspi/tsssp"]
1719

1820
[dependencies]
1921
cfg-if = "0.1"
20-
sspi = { path = "..", features = ["network_client", "dns_resolver"] }
2122
libc = "0.2"
2223
num-traits = "0.2"
2324
whoami = "1.2.3"
25+
sspi = { path = "..", features = ["network_client", "dns_resolver"] }
2426

2527
# For debugging only
2628
tracing = { version = "0.1.37", optional = true }
2729
tracing-subscriber = { version = "0.3.16", features = ["std", "fmt", "local-time", "env-filter"], optional = true }
2830

2931
[target.'cfg(windows)'.dependencies]
3032
symbol-rename-macro = { path = "./symbol-rename-macro" }
33+
winapi = "0.3.9"
34+
windows-sys = { version = "0.42.0", features = ["Win32_Security_Authentication_Identity", "Win32_Security_Credentials", "Win32_Foundation"] }

ffi/src/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ pub unsafe extern "system" fn DecryptMessage(
308308
catch_panic! {
309309
check_null!(ph_context);
310310
check_null!(p_message);
311-
check_null!(pf_qop);
312311

313312
let sspi_context = try_execute!(p_ctxt_handle_to_sspi_context(
314313
&mut ph_context,
@@ -329,7 +328,10 @@ pub unsafe extern "system" fn DecryptMessage(
329328
};
330329

331330
copy_to_c_sec_buffer((*p_message).p_buffers, &message, false);
332-
*pf_qop = decryption_flags.bits().try_into().unwrap();
331+
// `pf_qop` can be null if this library is used as a CredSsp security package
332+
if !pf_qop.is_null() {
333+
*pf_qop = decryption_flags.bits().try_into().unwrap();
334+
}
333335

334336
try_execute!(result_status);
335337

ffi/src/sec_buffer.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use libc::c_char;
66
use libc::c_uint;
77
#[cfg(target_os = "windows")]
88
use libc::c_ulong;
9-
use num_traits::FromPrimitive;
9+
use num_traits::{FromPrimitive, ToPrimitive};
1010
use sspi::{SecurityBuffer, SecurityBufferType};
1111

1212
#[cfg(target_os = "windows")]
@@ -18,6 +18,7 @@ pub struct SecBuffer {
1818
}
1919

2020
#[cfg(not(target_os = "windows"))]
21+
#[derive(Debug)]
2122
#[repr(C)]
2223
pub struct SecBuffer {
2324
pub cb_buffer: c_uint,
@@ -66,7 +67,8 @@ pub(crate) unsafe fn copy_to_c_sec_buffer(to_buffers: PSecBuffer, from_buffers:
6667
let buffer = &from_buffers[i];
6768
let buffer_size = buffer.buffer.len();
6869
to_buffers[i].cb_buffer = buffer_size.try_into().unwrap();
69-
if allocate {
70+
to_buffers[i].buffer_type = buffer.buffer_type.to_u32().unwrap();
71+
if allocate || to_buffers[i].pv_buffer.is_null() {
7072
let memory_layout = Layout::from_size_align_unchecked(buffer_size, 8);
7173
to_buffers[i].pv_buffer = alloc(memory_layout) as *mut c_char;
7274
}

0 commit comments

Comments
 (0)