LogoPear Docs
ReferencesBareModules

bare-tls

Reference for bare-tls: Transport Layer Security (TLS) streams for Bare, layered over a duplex socket, with a server and connect helper.

stable

bare-tls provides TLS streams for Bare, wrapping an underlying duplex socket (typically bare-tcp) in an encrypted bare-stream. The shape follows the Node.js tls module. It's a native addon and requires Bare >=1.7.0.

npm i bare-tls

Usage

const tls = require('bare-tls')
const fs = require('bare-fs')

const server = tls.createServer(
  { cert: fs.readFileSync('cert.pem'), key: fs.readFileSync('key.pem') },
  (socket) => socket.end('secure hello')
)

API

Socket

const socket = new tls.Socket(stream[, options])

Wrap an existing duplex stream in TLS. Exposes socket.socket (the underlying stream), socket.encrypted, and socket.alpnProtocol; emits connect.

OptionTypeDefaultDescription
isServerbooleanfalseWhether the socket acts as a TLS server or client. If true, cert and key must be provided.
certBuffernullPEM-encoded certificate data.
keyBuffernullPEM-encoded private key data.
hoststringnullEnables hostname verification against the server certificate. For DNS names it is also sent as the SNI extension; for IP literals it is matched against the certificate's IP SANs and SNI is suppressed per RFC 6066. Required for client sockets unless rejectUnauthorized is false.
rejectUnauthorizedbooleantrueWhether the client rejects connections when certificate verification fails.
caBuffernullOne or more PEM-encoded CA certificates. When provided, only these CAs are used for verification instead of the bundled Mozilla root certificates.
alpnProtocolsstring[]nullArray of ALPN protocol name strings, ordered by preference.
eagerOpenbooleantrueWhether to open the underlying stream eagerly.
allowHalfOpenbooleantrueWhether to allow half-open TCP connections.
readBufferSizenumber65536Size in bytes of the read buffer.

Server

const server = tls.createServer([options][, onconnection])

Create a TLS server: server.listen(...args), server.address(), server.close([onclose]), server.ref() / server.unref(), and server.listening. Emits listening, connection, close, error.

Connect

const socket = tls.connect(options[, onconnect]) · tls.connect(port[, host][, onconnect])

Open a TLS client connection.

Builds on bare-net and bare-stream (see Bare modules).

See also

On this page