Search code examples
csslwinapiwinsock2

Is there a way to connect to an encrypted TCP server using Winsock?


Winsock docs mentions IPsec secure extension for sockets but it does not mention SSL anywhere, Is there a way to use SSL with the created socket without using third party libraries such as OpenSSL or WolfSSL?

The closest thing I found was official MS examples on github but there is no mention of SSL and public and private keys.

Can anyone provide an insight on how to achieve such goal, what functions to use?


Solution

  • Winsock itself does not offer SSL/TLS, but you can accomplish this security by using SSPI on top of Winsock via the SChannel provider, which does offer SSL/TLS. Look up AcquireCredentialsHandle() and InitializeSecurityContext().

    If you are planning on porting this to other platforms, I would seriously suggest use of OpenSSL instead, simply so that you don't have to implement your glue logic more than once.