Tanganelli / CoAPthon

CoAPthon is a python library to the CoAP protocol aligned with the RFC
MIT License
224 stars 131 forks source link

Coap DTLS Client and Server #80

Open jyotirajsharma opened 7 years ago

jyotirajsharma commented 7 years ago

Hi,

I am planning to use Coap DTLS client from this library "test_secure.py". But i am using javascript webserver as my Coap Server. So, my question- will following piece of code will work to validate the key that has been used from the test_secure,py ?

const coap = require('../') // or coap const path = require('path');

var SegfaultHandler = require('segfault-handler');

SegfaultHandler.registerHandler("crash.log"); // With no argument, SegfaultHandler will generate a generic log file name

const dtls_opts = { key: path.join(__dirname, '/test/server.pem'), debug: 1, handshakeTimeoutMin: 3000 };

const server = coap.createServer( { dtls: dtls_opts, port: 5684, } );

server.on('request', function(req, res) { console.log('request arrives:\n'+JSON.stringify(req)); res.end('Hello ' + req.url.split('/')[1] + '\n') })

server.listen(function() { console.log('server started') });

Thanks, Jyoti Raj

mcfreis commented 7 years ago

Well just copy the key KEY_CERT_VALID form test_secure.py to a pem file and that should do the job. About the javascript server I can't say anything.

BUT you should generate your own certs. Take a look at the scripts supplied with pyDTLS.