lundi 22 février 2016

Connection from flash v11+ to to nodejs using TLS (SSL)

I recently started creating a server for a mmorpg im building all by myself and i used node js as the server language. I've searched around on the net and figured that using TLS was the way to go for authentification and creating a secure session over TCP/IP. Everything works fine, i created a certificate and self signed it with openssl using some commands on the web i found and it gave me the key and certificate i can use with my server. I tryed connecting with openssl and everything worked fine. The certificate node js use is in PEM format.

Thats the server code i am using:

var tls = require('tls');
var fs = require('fs');

var options = {
    key: fs.readFileSync(__dirname + '/server.key'),
    cert: fs.readFileSync(__dirname + '/server.crt'),
    //requestCert: true,
   //rejectUnauthorized: false,
};

tls.createServer(options, function(sock) {
    //stuff here
}).listen(PORT, HOST);

Now, my game is made in flash. So i try to connect using SecureSocket that come in flash player version 10+ i believe. The problem is that flash use a DER X.509 certificate format. So i converted the .PEM file into a .DER file using openssl and loaded it into flash. When i try to connect to my server (which is both on localhost, wanted to mention incase it change something), i can see the connection attempt on my server but it instantly close connection.

This is the error from flash:

Secure socket supported: true
ioErrorHandler: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Erreur de socket. URL: localhost"]
securityErrorHandler: [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048: Violation de la sécurité Sandbox : file:///C|/Users/DevilCult/Desktop/Flash%20Game/tcp%20test/Untitled%2D1.swf ne peut pas charger de données à partir de localhost:8089."]

But like i said, i can see the connection server side even if the error says the host is not valid. I Do the same without TLS socket and it work like a charm.

In my flash code i used addBinaryChainBuildingCertificate like this:

secureSocket.addBinaryChainBuildingCertificate(new key(), true);
secureSocket.connect("localhost", 8089);

this is the key() class:

package
{
 import flash.utils.ByteArray;

 [Embed(source="server.der", mimeType="application/octet-stream")]
 public class key extends ByteArray
 {
 }
}

I tryed to look around node js for information about loading the same kind of certificate (in DER format) but node js documentations says it only accept PEM format. And flash only accept DER format. And i guess using diff format on each machine doesnt work well together and that could be why my connection is dropping.

Anyway from now, i dont know where to go. There must be a way to use a DER format in node js. Ive been searching around and couldnt find anything.

Anyone have encoutered this problem before?

Aucun commentaire:

Enregistrer un commentaire