Logic Machine Forum
SSL communication - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: SSL communication (/showthread.php?tid=206)



SSL communication - hrebik - 03.02.2016

Hello,
My LogicMachine communicates with second device via TCP (outgoing from LogicMachine) and HTTP (incoming to LogicMachine) protocols , I want to secure them with SSL. I can ensure SSL certificate with JavaScript in second device.




When I create socket it runs this code:

 
  local host, port = "IP address", portNO.
  local socket = require("socket")
  local tcp = assert(socket.tcp())

  tcp:connect(host, port)

--some code here

  tcp:send(value)
  tcp:close()


this is SSL unsecured, when I want to send value to server, 

and when I receive data I create socket and send feedback data via

socket:send(value);   


Is there some simple way to secure this communication with SSL in LogicMachine's Lua script? 

Thank you!

Marek H.


RE: SSL communication - admin - 03.02.2016

Have a look here for HTTPS requests:
http://openrb.com/docs/lua.htm#ssl.https.request

If you need SSL for raw sockets, I can provide an example later.


RE: SSL communication - hrebik - 04.02.2016

(03.02.2016, 16:12)admin Wrote: Have a look here for HTTPS requests:
http://openrb.com/docs/lua.htm#ssl.https.request

If you need SSL for raw sockets, I can provide an example later.

Thank you!

And I need also SSL for raw socket and copas. 

Thanks alot Smile


RE: SSL communication - admin - 04.02.2016

For now we only have support for SSL/TLS in client mode, here's a short example. If handshake fails, try setting proto to tlsv1.

Code:
require('socket')
require('ssl')

host = '127.0.0.1'
port = '443'
proto = 'tlsv12' -- can also be 'tlsv1' or 'tlsv11'

sock = socket.tcp()
res, err = sock:connect(host, port)
if res then
  sock = ssl.wrap(sock, proto)
  res, err = sock:dohandshake()

  if res then
    ...
  else
    log('Handshake failed', err)
  end
else
  log('Connect failed', err)
end

sock:close()



RE: SSL communication - hrebik - 05.02.2016

(04.02.2016, 09:42)admin Wrote: For now we only have support for SSL/TLS in client mode, here's a short example. If handshake fails, try setting proto to tlsv1.

Code:
require('socket')
require('ssl')

host = '127.0.0.1'
port = '443'
proto = 'tlsv12' -- can also be 'tlsv1' or 'tlsv11'

sock = socket.tcp()
res, err = sock:connect(host, port)
if res then
 sock = ssl.wrap(sock, proto)
 res, err = sock:dohandshake()

 if res then
   ...
 else
   log('Handshake failed', err)
 end
else
 log('Connect failed', err)
end

sock:close()

Thank you, 

Is it possible to make it also for server mode (copas)? 

Marek H.


RE: SSL communication - admin - 05.02.2016

Give us some time to finish the next FW release, then we'll update the SSL library with server part Smile