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

Support for secure connection wss:// #14

Closed
bridger opened this issue Apr 28, 2019 · 5 comments
Closed

Support for secure connection wss:// #14

bridger opened this issue Apr 28, 2019 · 5 comments
Assignees

Comments

@bridger
Copy link
Contributor

bridger commented Apr 28, 2019

Kitura-NIO has a "todo" to support the wss upgrade. Does this mean secure websocket connections are not yet supported in this version of Kitura-Websocket?

@pushkarnk pushkarnk self-assigned this Apr 29, 2019
@pushkarnk
Copy link
Contributor

Presuming that a Kitura server, on which a WebSocket upgrade is requested for, has a configured SSLContext, we need to make sure that the subsequently configured NIOSSLServerHandler, which is the first InboundHandler and the last OutboundHandler is retained in the same position after a successful WebSocket upgrade. But I wonder how we are going to differentiate between a ws request and a wss request that are received on an HTTP server configured with SSL/TLS. Possibly here.

@pushkarnk
Copy link
Contributor

OK, I figured out that we DO support WSS.

I set up a simple WebSocket echo service with a Kitura server like this:

let sslConfig: SSLConfig = {
    let sslConfigDir = URL(fileURLWithPath: #file).deletingLastPathComponent().appendingPathComponent("../SSLConfig")
    let chainFilePath = sslConfigDir.appendingPathComponent("certificateChain.pfx").standardized.path
    return SSLConfig(withChainFilePath: chainFilePath, withPassword: "kitura",
                     usingSelfSignedCerts: true)
}()

// Using an implementation for a Logger
HeliumLogger.use(.info)
let router = Router()
WebSocket.register(service: EchoService(), onPath: "/")
let port = 9001
Kitura.addHTTPServer(onPort: port, with: router, withSSL: sslConfig)
Kitura.run()

I then accessed the HTTPS URL: https://localhost:9001/ and added the certificate as prompted by the browser. After that I was able to make a wss connection to this echo service using the Simple WebSocket Client extension on Firefox/Chrome.

@pushkarnk
Copy link
Contributor

I have changed all our client-server tests to use secure web socket connections: #19

@bridger
Copy link
Contributor Author

bridger commented May 2, 2019

Thank you for checking that it is supported!

@bridger
Copy link
Contributor Author

bridger commented May 2, 2019

Maybe the TODO should be removed from the code?

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

No branches or pull requests

2 participants