Skip to content

feat: iOS TLS fix — defer startTLS until didConnectToHost #217

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

manoaxcend
Copy link

No description provided.

@manoaxcend
Copy link
Author

@Rapsssito , This PR fixes an issue where startTLS: is not called if the connection is established asynchronously in iOS, leading to silent TLS handshake failures.
Request to review & merge the changes.

Problem
In some edge cases—especially with secure connections and client authentication enabled—the call to startTLS: is skipped when the socket connects asynchronously. This results in:

  1. TLS never being initiated.
  2. onConnect being called prematurely.
  3. Silent failure to negotiate a secure connection.

Fix
This PR introduces two changes:

  1. Store TLS Options:
    Save the TLS options in a _tlsOptionsPending dictionary inside connect:.

  2. Invoke startTLS on Connect Completion:
    In socket:didConnectToHost:port:, check if _tlsOptionsPending is set and, if so, call startTLS: there. This ensures TLS is always started after a successful connection.

Tested On

  • iOS 15–17
  • [email protected]+
  • Mutual TLS with PEM-encoded RSA 2048-bit certs
  • Both immediate and delayed socket connection cases

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.

2 participants