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

For TLS connections, how can I set TLSSettings? #8

Closed
jbwdevries opened this issue Oct 22, 2019 · 6 comments
Closed

For TLS connections, how can I set TLSSettings? #8

jbwdevries opened this issue Oct 22, 2019 · 6 comments
Labels
enhancement New feature or request

Comments

@jbwdevries
Copy link

e.g. for setting custom CA certificates to use.

From what I can tell, this library uses tlsClientConfig, which only uses the TLSSettings default value.

@dustin
Copy link
Owner

dustin commented Oct 22, 2019

Hmm... I was wondering how this might work, but haven't needed it myself. It's definitely something I need to consider.

I may need to abstract TLS settings in such a way I can supply TLS settings for both mqtts and wss since doing it from the URI is kind of hard.

In the meantime, I did expose the lower-level conduit mechanism. mqtts translates approximately torunClientTLS which is implemented like this:

-- | Set up and run a client connected via TLS.
runClientTLS :: MQTTConfig -> IO MQTTClient
runClientTLS cfg@MQTTConfig{..} = tcpCompat (runTLSClient (tlsClientConfig _port (BCS.pack _hostname))) cfg

-- Compatibility mechanisms for TCP Conduit bits.
tcpCompat :: ((AppData -> IO ()) -> IO ()) -> MQTTConfig -> IO MQTTClient
tcpCompat mkconn = runMQTTConduit (adapt mkconn)
  where adapt mk f = mk (f . adaptor)
        adaptor ad = (appSource ad, appSink ad)

@dustin dustin added the enhancement New feature or request label Oct 22, 2019
@dustin
Copy link
Owner

dustin commented Oct 23, 2019

I filed snoyberg/conduit/issues/423 for this. I don't see how I'd actually supply this to the underlying conduit TLS connector.

@jbwdevries
Copy link
Author

I figured you could use the TLSClientConfig constructor instead of the tlsClientConfig helper method

@dustin dustin closed this as completed in 68299d9 Oct 23, 2019
@dustin
Copy link
Owner

dustin commented Oct 23, 2019

I added _tlsSettings :: TLSSettings to the MQTTConfig type and plumbed that through for both mqtts:// and wss:// connections. It's TLSSettings so you should be able to either a simple or full set of settings to configure the TLS bits of your client.

Let me know how this works!

@jbwdevries
Copy link
Author

Can confirm this works as expected. Thanks!

@AleXoundOS
Copy link

For those, inexperienced like me, you need to populate ClientHooks with appropriate onCertificateRequest and onServerCertificate functions like here: https://stackoverflow.com/a/40082394/1663197.

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

No branches or pull requests

3 participants