Skip to content

Commit 943a297

Browse files
TheBestTvarynkaCBenoit
authored andcommitted
feat(sspi): server-side Kebreros implementation (#440)
1 parent 8508601 commit 943a297

File tree

30 files changed

+1739
-539
lines changed

30 files changed

+1739
-539
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ picky = { version = "7.0.0-rc.12", default-features = false }
4848
picky-asn1 = "0.10"
4949
picky-asn1-der = "0.5"
5050
picky-asn1-x509 = "0.14"
51+
picky-krb = "0.10"
5152
tokio = "1.45"
5253
ffi-types = { path = "crates/ffi-types" }
5354
winscard = { version = "0.2", path = "crates/winscard" }

examples/server.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::net::{TcpListener, TcpStream};
99
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
1010
use sspi::{
1111
AuthIdentity, BufferType, CredentialUse, DataRepresentation, EncryptionFlags, Ntlm, SecurityBuffer,
12-
SecurityBufferRef, SecurityStatus, ServerRequestFlags, Sspi, Username,
12+
SecurityBufferRef, SecurityStatus, ServerRequestFlags, Sspi, SspiImpl, Username,
1313
};
1414

1515
const IP: &str = "127.0.0.1:8080";
@@ -84,14 +84,14 @@ fn do_authentication(ntlm: &mut Ntlm, identity: &AuthIdentity, mut stream: &mut
8484
loop {
8585
read_message(&mut stream, &mut input_buffer[0].buffer)?;
8686

87-
let result = ntlm
87+
let builder = ntlm
8888
.accept_security_context()
8989
.with_credentials_handle(&mut acq_cred_result.credentials_handle)
9090
.with_context_requirements(ServerRequestFlags::ALLOCATE_MEMORY)
9191
.with_target_data_representation(DataRepresentation::Native)
9292
.with_input(&mut input_buffer)
93-
.with_output(&mut output_buffer)
94-
.execute(ntlm)?;
93+
.with_output(&mut output_buffer);
94+
let result = ntlm.accept_security_context_impl(builder)?.resolve_to_result()?;
9595

9696
if [SecurityStatus::CompleteAndContinue, SecurityStatus::CompleteNeeded].contains(&result.status) {
9797
println!("Completing the token...");

ffi/src/sspi/common.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use libc::{c_ulonglong, c_void};
44
use num_traits::cast::{FromPrimitive, ToPrimitive};
55
use sspi::{
66
BufferType, DataRepresentation, DecryptionFlags, EncryptionFlags, Error, ErrorKind, SecurityBuffer,
7-
SecurityBufferRef, SecurityBufferType, ServerRequestFlags, Sspi,
7+
SecurityBufferRef, SecurityBufferType, ServerRequestFlags, Sspi, SspiImpl,
88
};
99
#[cfg(windows)]
1010
use symbol_rename_macro::rename_symbol;
@@ -100,13 +100,14 @@ pub unsafe extern "system" fn AcceptSecurityContext(
100100

101101
let mut output_tokens = vec![SecurityBuffer::new(Vec::with_capacity(1024), BufferType::Token)];
102102

103-
let result_status = sspi_context.accept_security_context()
104-
.with_credentials_handle(&mut Some(auth_data))
103+
let mut auth_data = Some(auth_data);
104+
let builder = sspi_context.accept_security_context()
105+
.with_credentials_handle(&mut auth_data)
105106
.with_context_requirements(ServerRequestFlags::from_bits(f_context_req.try_into().unwrap()).unwrap())
106107
.with_target_data_representation(DataRepresentation::from_u32(target_data_rep.try_into().unwrap()).unwrap())
107108
.with_input(&mut input_tokens)
108-
.with_output(&mut output_tokens)
109-
.execute(sspi_context);
109+
.with_output(&mut output_tokens);
110+
let result_status = try_execute!(sspi_context.accept_security_context_impl(builder)).resolve_with_default_network_client();
110111

111112
// SAFETY: `p_output` is not null. We've checked this above.
112113
try_execute!(unsafe { copy_to_c_sec_buffer((*p_output).p_buffers, &output_tokens, false) });

ffi/src/sspi/sec_handle.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,10 @@ impl SspiImpl for SspiHandle {
126126

127127
fn accept_security_context_impl(
128128
&mut self,
129-
builder: sspi::builders::FilledAcceptSecurityContext<'_, Self::CredentialsHandle>,
130-
) -> Result<sspi::AcceptSecurityContextResult> {
131-
self.sspi_context.lock()?.accept_security_context_impl(builder)
129+
builder: sspi::builders::FilledAcceptSecurityContext<Self::CredentialsHandle>,
130+
) -> Result<sspi::generator::GeneratorAcceptSecurityContext> {
131+
let mut context = self.sspi_context.lock()?;
132+
Ok(context.accept_security_context_sync(builder).into())
132133
}
133134
}
134135

src/builders/accept_sec_context.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::{
66
ToAssign, WithContextRequirements, WithCredentialsHandle, WithOutput, WithTargetDataRepresentation,
77
WithoutContextRequirements, WithoutCredentialsHandle, WithoutOutput, WithoutTargetDataRepresentation,
88
};
9+
use crate::generator::GeneratorAcceptSecurityContext;
910
use crate::{DataRepresentation, SecurityBuffer, SecurityStatus, ServerRequestFlags, ServerResponseFlags, SspiPackage};
1011

1112
pub type EmptyAcceptSecurityContext<'a, C> = AcceptSecurityContext<
@@ -252,24 +253,8 @@ impl<'a, CredsHandle> FilledAcceptSecurityContext<'a, CredsHandle> {
252253
/// Executes the SSPI function that the builder represents.
253254
pub fn execute<AuthData>(
254255
self,
255-
inner: SspiPackage<'_, CredsHandle, AuthData>,
256-
) -> crate::Result<AcceptSecurityContextResult> {
256+
inner: SspiPackage<'a, CredsHandle, AuthData>,
257+
) -> crate::Result<GeneratorAcceptSecurityContext<'a>> {
257258
inner.accept_security_context_impl(self)
258259
}
259-
260-
pub(crate) fn transform(self) -> FilledAcceptSecurityContext<'a, CredsHandle> {
261-
AcceptSecurityContext {
262-
phantom_creds_use_set: PhantomData,
263-
phantom_context_req_set: PhantomData,
264-
phantom_data_repr_set: PhantomData,
265-
phantom_output_set: PhantomData,
266-
267-
credentials_handle: self.credentials_handle,
268-
context_requirements: self.context_requirements,
269-
target_data_representation: self.target_data_representation,
270-
271-
output: self.output,
272-
input: self.input,
273-
}
274-
}
275260
}

0 commit comments

Comments
 (0)