-
Notifications
You must be signed in to change notification settings - Fork 149
Safe clone for X509Store #426
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,23 @@ foreign_type_and_impl_send_sync! { | |
| pub struct X509Store; | ||
| } | ||
|
|
||
| impl ToOwned for X509StoreRef { | ||
| type Owned = X509Store; | ||
|
|
||
| fn to_owned(&self) -> X509Store { | ||
| unsafe { | ||
| ffi::X509_STORE_up_ref(self.as_ptr()); | ||
cjpatton marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| X509Store::from_ptr(self.as_ptr()) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl Clone for X509Store { | ||
| fn clone(&self) -> X509Store { | ||
| (**self).to_owned() | ||
| } | ||
| } | ||
|
|
||
| impl X509StoreRef { | ||
| /// **Warning: this method is unsound** | ||
| /// | ||
|
|
@@ -160,12 +177,15 @@ impl X509StoreRef { | |
| } | ||
|
|
||
| #[test] | ||
| #[allow(dead_code)] | ||
| // X509Store must not implement Clone because `SslContextBuilder::cert_store_mut` lets | ||
| // you get a mutable reference to a store that could have been cloned before being | ||
| // passed to `SslContextBuilder::set_cert_store`. | ||
| fn no_clone_for_x509store() { | ||
| trait MustNotImplementClone {} | ||
| impl<T: Clone> MustNotImplementClone for T {} | ||
| impl MustNotImplementClone for X509Store {} | ||
| #[should_panic = "Shared X509Store can't be mutated"] | ||
| fn set_cert_store_pevents_mutability() { | ||
| use crate::ssl::*; | ||
|
|
||
| let mut ctx = SslContext::builder(SslMethod::tls()).unwrap(); | ||
| let store = X509StoreBuilder::new().unwrap().build(); | ||
|
|
||
| ctx.set_cert_store(store.clone()); | ||
|
|
||
| // This is bad. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bad in what way? What do we expect to happen?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is copied verbatim from #362
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough, but it would be nice to provide a more useful comment. |
||
| let _aliased_store = ctx.cert_store_mut(); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.