tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ssl.js (1000B)


      1 'use strict';
      2 
      3 const https = require('https');
      4 const fs = require('fs');
      5 
      6 const { WebSocket, WebSocketServer } = require('..');
      7 
      8 const server = https.createServer({
      9  cert: fs.readFileSync('../test/fixtures/certificate.pem'),
     10  key: fs.readFileSync('../test/fixtures/key.pem')
     11 });
     12 
     13 const wss = new WebSocketServer({ server });
     14 
     15 wss.on('connection', function connection(ws) {
     16  ws.on('message', function message(msg) {
     17    console.log(msg.toString());
     18  });
     19 });
     20 
     21 server.listen(function listening() {
     22  //
     23  // If the `rejectUnauthorized` option is not `false`, the server certificate
     24  // is verified against a list of well-known CAs. An 'error' event is emitted
     25  // if verification fails.
     26  //
     27  // The certificate used in this example is self-signed so `rejectUnauthorized`
     28  // is set to `false`.
     29  //
     30  const ws = new WebSocket(`wss://localhost:${server.address().port}`, {
     31    rejectUnauthorized: false
     32  });
     33 
     34  ws.on('open', function open() {
     35    ws.send('All glory to WebSockets!');
     36  });
     37 });