Skip to content

feat(dpapi): WS tunneling support #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 32 commits into from
Apr 15, 2025

Conversation

TheBestTvarynka
Copy link
Collaborator

Hi,
I implemented WS tunneling support in this PR.

I tested the DPAPI on the following scenarios:

  • Direct TCP transport.
  • Tunneling over WS connection.
  • Tunneling over WSS connection.

Everything works well.

@TheBestTvarynka TheBestTvarynka self-assigned this Apr 3, 2025

fn run(data: Dpapi) -> Result<()> {
async fn run(data: Dpapi) -> Result<()> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made all codebase async, because all WS/HTTP clients for WASM are async

@TheBestTvarynka TheBestTvarynka marked this pull request as ready for review April 3, 2025 12:23
@TheBestTvarynka TheBestTvarynka requested a review from CBenoit April 3, 2025 12:26
@TheBestTvarynka
Copy link
Collaborator Author

@CBenoit When will you have a chance to review it? 🙂

@CBenoit
Copy link
Member

CBenoit commented Apr 8, 2025

@TheBestTvarynka I’ll review tomorrow! 🙂
The PR is quite big, and I think I’ll have to think over it a little bit!

@TheBestTvarynka TheBestTvarynka marked this pull request as draft April 9, 2025 12:13
@TheBestTvarynka
Copy link
Collaborator Author

@CBenoit I finished refactoring the code. Feel free to review whenever you want


/// Obtains the session token from the [tokengen server](https://github.com/Devolutions/devolutions-gateway/tree/master/tools/tokengen).
///
/// Paramers:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Suggested change
/// Paramers:
/// Parameters:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -0,0 +1,5 @@
# DPAPI cli client

This is a simple DPAPI client for using the DPAPI. It can encrypt secrets or decrupt them using DPAPI. Run `dpapi-cli-client --help` for more information and usage manual.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This is a simple DPAPI client for using the DPAPI. It can encrypt secrets or decrupt them using DPAPI. Run `dpapi-cli-client --help` for more information and usage manual.
This is a simple DPAPI client for using the DPAPI. It can encrypt secrets or decrypt them using DPAPI. Run `dpapi-cli-client --help` for more information and usage manual.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why VS code didn't highlight it 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why VS code didn't highlight it 🤔

the spell checker extension was turned off...I don't know why. Anyway, I turned it on again and fixed many other typos. See this commit: b0856be

src/rustls.rs Outdated
Comment on lines 4 to 5
pub(crate) fn install_default_crypto_provider_if_necessary() -> Result<(), ()> {
#[allow(clippy::result_unit_err)]
pub fn install_default_crypto_provider_if_necessary() -> Result<(), ()> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: This is not intended to be part of the public API of sspi.

suggestion: Not ideal, but can you add #[doc(hidden)]? Let’s at least hide it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

src/lib.rs Outdated
mod rustls;
pub mod rustls;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Let’s keep this module private. Following previous advice, re-export from lib.rs and ensure the item is properly hidden from the documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let scard_pci_info_len = unsafe { (*scard_io_request).cb_pci_length }.try_into()?;
let scard_pci_info_len = usize::try_from(unsafe { (*scard_io_request).cb_pci_length })?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: I recommend splitting on two lines instead of having the unsafe block inlined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// * session_id is an object on stack.
// * destination is created (and validated) using `CString`.
// * token_buf is a non-empty Vec.
// * token len is a local variale.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// * token len is a local variale.
// * token len is a local variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

let mut token_len = 2048;
let mut token_buf = vec![0; 2048];

// SAFETY: all function input parameters are valid because:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// SAFETY: all function input parameters are valid because:
// SAFETY:
// As per safety preconditions, the C function pointer is safe to be called with valid parameters.
// Parameters are valid:

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 12 to 13
/// This function wraps a C-function into a Rust closure which we can pass into the Rust API.
pub fn session_token_fn(get_session_token: CGetSessiontokenFn) -> Box<GetSessionTokenFn> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// This function wraps a C-function into a Rust closure which we can pass into the Rust API.
pub fn session_token_fn(get_session_token: CGetSessiontokenFn) -> Box<GetSessionTokenFn> {
/// This function wraps a C-function into a Rust closure which we can pass into the Rust API.
///
/// # Safety
///
/// The C function pointer must be safe to call provided parameters are valid.
pub unsafe fn session_token_fn(get_session_token: CGetSessiontokenFn) -> Box<GetSessionTokenFn> {

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines +2 to +4
name = "dpapi-native-transport"
version = "0.1.0"
edition = "2024"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Can you add the required meta data needed for publishing crates?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done (sorry for the delay, I had a meeting)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem! Thank you!

@@ -1,7 +1,13 @@
[package]
name = "dpapi-transport"
version = "0.1.0"
edition = "2024"
edition = "2021"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Feel free to keep edition 2024 for new code. We’ll want to update to 2024 eventually.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to be consistent. I know that crates can have different edition versions, but my inner voice says that I want it to be the same for all crates in the workspace 😄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s fair! As you prefer, anyway I don’t think you used many features from the 2024 edition yet 😉

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you!!

(Last comment can be addressed in a follow up PR.)

@CBenoit CBenoit merged commit fad2471 into feat/dpapi-wasm-support Apr 15, 2025
42 checks passed
@CBenoit CBenoit deleted the feat/ws-tunneling-support branch April 15, 2025 15:06
CBenoit pushed a commit that referenced this pull request Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants