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

🔒 Add ssl_ctx and ssl_ctx_params attr readers #174

Merged
merged 4 commits into from
Sep 19, 2023
Merged

🔒 Add ssl_ctx and ssl_ctx_params attr readers #174

merged 4 commits into from
Sep 19, 2023

Conversation

nevans
Copy link
Collaborator

@nevans nevans commented Sep 19, 2023

Net::IMAP#ssl_ctx will return the OpenSSL::SSL::SSLContext used by the OpenSSL::SSL::SSLSocket when TLS is attempted, even when the TLS handshake is unsuccessful. The context object will be frozen. It will return nil for a plaintext connection.

Net::IMAP#ssl_ctx_params will return the parameters that were sent to OpenSSL::SSL::SSLContext#set_params when the connection tries to use TLS (even when unsuccessful). It will return false for a plaintext connection.

Additionally, error handling for the arguments to #starttls was moved before sending the command to the server. This way a simple argument error will still raise an exception, but won't result in dropping the connection. Because ssl_ctx is also created ahead of time, this will also catch invalid SSLContext params.

Tangentially:

  • #initialize was moved to the top of the public section of the class definition, to match common conventions.
  • Various other rdoc updates were made to #initialize and #startls rdoc, including examples, links to OpenSSL::SSL::SSLContext#set_params, etc.
  • #initialize was refactored into several extracted private methods, for readability.

To match the most common order in modern ruby projects:
* Moved `attr_reader`s down below class methods.
* Moved `#initialize` up above all public instance method `def`s.
* Moved an method down with other public instance method `def`s.

This commit should contain no other code changes.
Updated rdoc for #initialize:
* Various stylistic changes, mostly for options and exceptions.
* Added examples to demonstrate connecting with clear-text, TLS, and
  checking the greeting for "OK" or "PREAUTH".
* Added links to OpenSSL::SSL::SSLContext rdoc.
* Extract four methods:
  * `convert_deprecated_options`
  * `start_imap_connection`: begins IMAP protocol on connected socket
  * `get_server_greeting`: wraps `get_response` with greeting specifics
  * `start_receiver_thread`
* Various other small stylistic tweaks, e.g: grouped similar ivars.

This _should_ be the result of a series of "pure" safe refactorings.
All existing behavior should remain unchanged.
`Net::IMAP#ssl_ctx` will return the `OpenSSL::SSL::SSLContext`
used by the `OpenSSL::SSL::SSLSocket` when TLS is attempted, even when
the TLS handshake is unsuccessful.  The context object will be frozen.
It will return `nil` for a plaintext connection.

`Net::IMAP#ssl_ctx_params` will return the parameters that were sent to
`OpenSSL::SSL::SSLContext#set_params` when the connection tries to use
TLS (even when unsuccessful).  It will return `false` for a plaintext
connection.

Additionally, error handling for the arguments to `#starttls` was moved
*before* sending the command to the server.  This way a simple argument
error will still raise an exception, but won't result in dropping the
connection.  Because `ssl_ctx` is also created ahead of time, this will
also catch invalid SSLContext params.
@nevans
Copy link
Collaborator Author

nevans commented Sep 19, 2023

Note: This PR accidentally included rdoc references to DeprecatedClientOptions, which will be added by #175.

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.

1 participant