Socket:starttls([certificate], [password])

Enable transport level security (TLS -formerly known as SSL) on a Socket connection. The connection must have been initialized with a previous Socket:bind() or Socket:connect() call. Any further calls to Socket:send() or Socket:recv() will be encrypted/decrypted, respectively.

Parameters

[certificate]

An optional string representing the certificate to verify the identity of the other peer. If none is provided, uses the certificate from the server. The string can be :

  • A server name of a certificate already installed in the current user/Windows certificate store
  • A path to a .pfx file (PKCS #12), that contains cryptographic information (certificates and private keys). Its contents can be cryptographically protected with passwords.

[password]

An optional string representing the password that must be provided when using a .pfx file .

Return value

Returns true if TLS has been successfully enabled.
In case of error, returns false. Error message can be obtained with the net.error property.

Example

local net = require "net" -- create a socket to www.google.com on port 80 local socket = net.Socket("www.google.com", 80) if socket:connect() then print("Connected to www.google.com !") local sent = socket:send("GET / HTTP/1.1\r\nHost:www.google.com\r\n\r\n") print("Bytes sent : "..sent) end