Skip to content

Commit

Permalink
Improve https examples
Browse files Browse the repository at this point in the history
  • Loading branch information
tniessen committed Dec 1, 2019
1 parent 9dd3f40 commit 5de17ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/https-server/server.js
Expand Up @@ -11,19 +11,19 @@ const { kem, computeKeyId } = require('../../protocol');
const httpsServerDebug = require('debug')('https:server');

const httpsOptions = {
key: fs.readFileSync('../key.pem', 'ascii'),
cert: fs.readFileSync('../cert.pem', 'ascii')
key: fs.readFileSync(`${__dirname}/../key.pem`, 'ascii'),
cert: fs.readFileSync(`${__dirname}/../cert.pem`, 'ascii')
};

// Generate the server key pair.
httpsServerDebug('generating keypair');
const { publicKey, privateKey } = kem.keypair();
const publicKeyId = computeKeyId(publicKey);
httpsServerDebug('generated public key');

// Sign the public key id.
const publicKeySignature = sign('sha256', publicKeyId, httpsOptions.key);

const render = pug.compileFile('view.pug');
const render = pug.compileFile(`${__dirname}/view.pug`);

// Create the HTTPS server.
const httpsServer = https.createServer(httpsOptions, (req, res) => {
Expand Down
10 changes: 7 additions & 3 deletions examples/https-test.js
Expand Up @@ -11,11 +11,12 @@ const httpsServerDebug = require('debug')('https:server');
const httpsClientDebug = require('debug')('https:client');

const httpsOptions = {
key: fs.readFileSync('key.pem', 'ascii'),
cert: fs.readFileSync('cert.pem', 'ascii')
key: fs.readFileSync(`${__dirname}/key.pem`, 'ascii'),
cert: fs.readFileSync(`${__dirname}/cert.pem`, 'ascii')
};

// Generate the server key pair.
httpsServerDebug('generating keypair');
const { publicKey, privateKey } = kem.keypair();
const publicKeyId = computeKeyId(publicKey);

Expand Down Expand Up @@ -71,7 +72,10 @@ server.listen(8124, () => {
});
conn.on('error', err => console.error(err));

const req = https.request('https://localhost:8124/foo', { socket: conn });
const req = https.request('https://localhost:8124/foo', {
socket: conn,
rejectUnauthorized: false
});
req.on('error', (err) => console.error(err));

req.on('socket', (socket) => {
Expand Down

0 comments on commit 5de17ea

Please sign in to comment.