-
Notifications
You must be signed in to change notification settings - Fork 149
Add set_ticket_key_callback (SSL_CTX_set_tlsext_ticket_key_cb) #330
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
Add set_ticket_key_callback (SSL_CTX_set_tlsext_ticket_key_cb) #330
Conversation
5a54a4d to
28f7678
Compare
28f7678 to
9a6e166
Compare
kornelski
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key_name is uninitialized, so it can't be &mut [u8; 16]
Add a wrapper for the `SSL_CTX_set_tlsext_ticket_key_cb`, which allows consumers to configure the EVP_CIPHER_CTX and HMAC_CTX used for encrypting/decrypting session tickets. See https://docs.openssl.org/1.0.2/man3/SSL_CTX_set_tlsext_ticket_key_cb/ for more details.
d5ecffd to
91c95bb
Compare
|
I've changed the code to use |
| assert!(!ptr.is_null()); | ||
| unsafe { &mut *ptr.cast::<MaybeUninit<T>>() } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirming my understanding: panic on assert seems appropriate because otherwise we have UB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
References must never be null, so they can't be made from a null pointer.
This assert isn't strictly necessary as long as the function is always given non-null pointers.
I thought it's better to be extra careful about this, I don't feel strongly about this choice. It could have been a Result (assuming null is a real possibility), or downgraded to debug_assert if we trust that we'll never get a null pointer in these functions.
6d711ac to
e395c52
Compare
fbf9dff to
8c3bca2
Compare
boring/src/hmac.rs
Outdated
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must ensure HMAC_CTX has been initalized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this safety requirement. It's not clear what "initialized" here refers to, since this is an init function doing initialization.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was conflating documentation between this and session resumption. Removed and removed the unsafe.
boring/src/symm.rs
Outdated
| /// | ||
| /// # Safety | ||
| /// | ||
| /// The caller must ensure EVP_CIPHER_CTX has been initalized. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again not clear what "initialized" is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was conflating documentation between this and session resumption. Removed and removed the unsafe.
boring/src/symm.rs
Outdated
| /// | ||
| /// The caller must ensure EVP_CIPHER_CTX has been initalized. | ||
| /// | ||
| /// The caller is responsible for ensuring the length of `key` and `iv` are appropriate for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only length of the key needs to be checked, right? The iv is an array of max len.
Is there a cheap way to check key length against the Cipher to make it a safe function?
In raw_ticket_key the key is assumed to be 16 bytes long. Why is one place fixed, and another is flexible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 2d5be20
Only length of the key needs to be checked, right? The iv is an array of max len.
Is there a cheap way to check key length against the Cipher to make it a safe function?
Yea good point. We can do a key.len() != cipher.key_len() and return early. But not sure if ErrorStack::get() is correct error to return here.
In raw_ticket_key the key is assumed to be 16 bytes long. Why is one place fixed, and another is flexible?
raw_ticket_key is dealing with key_name, which is guaranteed to be 16 bytes (docs).
Here, the application is calling EVP_EncryptInit_ex with the correct key and iv, the sizes of which depend on the chosen cipher.
I also expanded the tests to use the iv and key_name values from the callback.
b4c73ab to
93270a6
Compare
|
It's nicer with safe wrapper types. I've changed to use Generally looks good. |
Yea, much nicer not to use the ffi functions, I was sold when I got rid of the
Sweet. I actually had to debug a panic in tests before adding the ManuallyDrop so this seems like the correct choice. |
2d5be20 to
20f91cb
Compare
|
ErrorStack::get() is for cases when FFI reports an error. I'll fix it in a separate PR. |
Add a wrapper for the
SSL_CTX_set_tlsext_ticket_key_cb, which allows consumers to configure the EVP_CIPHER_CTX and HMAC_CTX used for encrypting/decrypting session tickets.See https://docs.openssl.org/1.0.2/man3/SSL_CTX_set_tlsext_ticket_key_cb/ for more details.