Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 35 additions & 6 deletions doc/api/tls.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,35 +468,64 @@ to set the security level to 0 while using the default OpenSSL cipher list, you

```mjs
import { createServer, connect } from 'node:tls';
const port = 443;
import { readFileSync } from 'node:fs';
const port = 8000;

createServer({ ciphers: 'DEFAULT@SECLEVEL=0', minVersion: 'TLSv1' }, function(socket) {
createServer({
key: readFileSync('server-key.pem'),
cert: readFileSync('server-cert.pem'),
ciphers: 'DEFAULT@SECLEVEL=0',
minVersion: 'TLSv1',
}, function(socket) {
console.log('Client connected with protocol:', socket.getProtocol());
socket.end();
this.close();
})
.listen(port, () => {
connect(port, { ciphers: 'DEFAULT@SECLEVEL=0', maxVersion: 'TLSv1' });
connect(port, {
ciphers: 'DEFAULT@SECLEVEL=0',
minVersion: 'TLSv1',
maxVersion: 'TLSv1',
ca: [ readFileSync('server-cert.pem') ],
});
});
```

```cjs
const { createServer, connect } = require('node:tls');
const port = 443;
const { readFileSync } = require('node:fs');
const port = 8000;

createServer({ ciphers: 'DEFAULT@SECLEVEL=0', minVersion: 'TLSv1' }, function(socket) {
createServer({
key: readFileSync('server-key.pem'),
cert: readFileSync('server-cert.pem'),
ciphers: 'DEFAULT@SECLEVEL=0',
minVersion: 'TLSv1',
}, function(socket) {
console.log('Client connected with protocol:', socket.getProtocol());
socket.end();
this.close();
})
.listen(port, () => {
connect(port, { ciphers: 'DEFAULT@SECLEVEL=0', maxVersion: 'TLSv1' });
connect(port, {
ciphers: 'DEFAULT@SECLEVEL=0',
minVersion: 'TLSv1',
maxVersion: 'TLSv1',
ca: [ readFileSync('server-cert.pem') ],
});
});
```

This approach sets the security level to 0, allowing the use of legacy features while still
leveraging the default OpenSSL ciphers.

To generate the certificate and key for this example, run:

```bash
openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \
-keyout server-key.pem -out server-cert.pem
```

### Using [`--tls-cipher-list`][]

You can also set the security level and ciphers from the command line using the
Expand Down
Loading