Skip to content
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

Support using mbedtls #142

Closed
wants to merge 1 commit into from

Conversation

jack-fortanix
Copy link

Mbedtls is somewhat easier to use in certain situations where no OS facilities are present, such as bare metal or in SGX enclaves. This PR allows building native-tls with mbedtls as an alternative to OpenSSL.

@jack-fortanix
Copy link
Author

macOS build failed, seems unrelated to this change

@@ -20,7 +24,10 @@ tempfile = "3.0"
[target.'cfg(target_os = "windows")'.dependencies]
schannel = "0.1.16"

[target.'cfg(not(any(target_os = "windows", target_os = "macos", target_os = "ios")))'.dependencies]
[target.'cfg(feature = "mbedtls")'.dependencies]
Copy link
Owner

Choose a reason for hiding this comment

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

You can't cfg on features in the dependency section.

If this is designed for SGX, should it just be filtered to that target_os?

where
S: io::Read + io::Write
{
// If any of the ? fail then memory leaks ...
Copy link
Owner

Choose a reason for hiding this comment

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

That seems bad...

None
};

unsafe {
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not sure I'm on board with this much unsafe code for just establishing a TLS connection. Why can't the mbedtls crate provide a safe interface?

Copy link

Choose a reason for hiding this comment

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

The current Rust API for MbedTLS doesn't take ownership of anything. So if you run your entire server on a single stack, no unsafe is needed. However, if you want to do something else, you need self-referential structs.

if self.session != ::std::ptr::null_mut() {
Box::from_raw(self.session);
}
Box::from_raw(self.socket);
Copy link
Owner

Choose a reason for hiding this comment

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

Why do these all need to be raw pointers if they're treated as owned data?

@jethrogb
Copy link

jethrogb commented May 9, 2023

For reference #211 #261

1 similar comment
@jethrogb
Copy link

jethrogb commented May 9, 2023

For reference #211 #261

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants