indutny / indutny/ocsp

How to enable ocsp in web socket

Open
#46 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
86
Forks
46
PR merge metrics
No merged PRs in 30d

Description

I used wb with https and express. Still I get ocsp respond from the ocsp server even I enable ocsp stapling. How to enable it. I coud not figure out it.
This is my code.

```
var WebSocket = require('ws');
var https = require('https');
var ocsp = require('ocsp');

var bodyparser = require('body-parser');
var express = require('express');
var app = express();

app.use(bodyparser.json());
var PORT = 8080;

var ocspCache = new ocsp.Cache();

var server = new https.createServer({
cert: fs.readFileSync(`${__dirname}/pki/server/certs/server.cert.pem`),
key: fs.readFileSync(`${__dirname}/pki/server/private/server.key.pem`),
ca: [
fs.readFileSync(`${__dirname}/pki/intermediate/certs/ca-chain.cert.pem`)
],
requestCert: true,
rejectUnauthorized: true
}, app);

var wss = new WebSocket.Server({
server
});

wss.on('connection', function connection(ws, req) {

var cert = req.socket.getPeerCertificate(true);
var rawCert = cert.raw;
var rawIssuer = cert.issuerCertificate.raw;

ocsp.getOCSPURI(rawCert, function(err, uri) {
if (err) console.log(err);
var req = ocsp.request.generate(rawCert, rawIssuer);
var options = {
url: uri,
ocsp: req.data
};
ocspCache.request(req.id, options, null);
});

ws.on('message', function incoming(message) {
console.log(ocspCache.cache);
ocsp.check({cert: rawCert, issuer: rawIssuer}, function(err, res) {
if(err) {
console.log(err.message);
ws.send('Failed to obtain OCSP response!');
} else {
console.log(res.type);
var status = res.type;
if(status == 'good'){
console.log('Received: %s', message);
ws.send('Hello from server!');
}else{
ws.send('Certificate is revoked!');
}
}
});
});
});

server.listen(PORT, ()=>{
console.log( (new Date()) + " Server is listening on port " + PORT);
});
```
@indutny

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the HTTPS server, WebSocket setup, and OCSP calls shown in the issue, then read the project's stapling and checking APIs. Determine whether the requested behavior is supported and document the required configuration or limitation; the issue is done when the enablement steps or limitation are clearly explained.

Written by the indexing model from the issue text.

Assessment

Tech stack
express, javascript, node.js
Domain
backend, security
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.