All Projects → derhuerst → gemini

derhuerst / gemini

Licence: ISC license
Gemini protocol server & client.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gemini

enzyme-subgraph
The official subgraph the Enzyme protocol.
Stars: ✭ 20 (-48.72%)
Mutual labels:  protocol
loco.rs
Loco Protocol Wrapper for Rust
Stars: ✭ 38 (-2.56%)
Mutual labels:  protocol
RDMnet
Implementation of ANSI E1.33
Stars: ✭ 29 (-25.64%)
Mutual labels:  protocol
encrypted-smiley-secure-protocol
Node.JS library Encrypted Smiley ® Secure Protocol (eSSP, SSP)
Stars: ✭ 22 (-43.59%)
Mutual labels:  protocol
spec
Tox Protocol Specification
Stars: ✭ 29 (-25.64%)
Mutual labels:  protocol
ampleforth-contracts
Smart contracts for Ampleforth Protocol (working name uFragments)
Stars: ✭ 238 (+510.26%)
Mutual labels:  protocol
opensimmpls
OpenSimMPLS is an MPLS network simulator, multiplatform and mutilanguage. It is easy-to-use and is intended for teaching activities. It can be used as well to test new protocols, techniques and methods related to MPLS and/or GoS.
Stars: ✭ 21 (-46.15%)
Mutual labels:  protocol
ucp
UCP protocol in Go
Stars: ✭ 40 (+2.56%)
Mutual labels:  protocol
Computer-Networks
GBN and SR simulation, Distance Vector Algorithm Simulation
Stars: ✭ 21 (-46.15%)
Mutual labels:  protocol
gmid
a Gemini server
Stars: ✭ 54 (+38.46%)
Mutual labels:  gemini
FreeRADIUS-Server-Configuration-Tool
🎯 FreeRADIUS Server Configuration Tool 🖥️
Stars: ✭ 33 (-15.38%)
Mutual labels:  protocol
md2gemini
File converter from Markdown to Gemini.
Stars: ✭ 128 (+228.21%)
Mutual labels:  gemini
yahdlc
yahdlc - Yet Another HDLC implementation
Stars: ✭ 47 (+20.51%)
Mutual labels:  protocol
OverlayViewController
A simple way to present your child view controller on top of another one
Stars: ✭ 17 (-56.41%)
Mutual labels:  protocol
librelp
OFFICIAL librelp repository on github
Stars: ✭ 25 (-35.9%)
Mutual labels:  protocol
node-ads
NodeJS Twincat ADS protocol implementation
Stars: ✭ 49 (+25.64%)
Mutual labels:  protocol
dystopia
Anonymity on the Internet by Transparent way.
Stars: ✭ 97 (+148.72%)
Mutual labels:  protocol
gopher
A simple server for the Gopher protocol written in Go.
Stars: ✭ 17 (-56.41%)
Mutual labels:  protocol
elvisp
Virtual ISP / IP tunnel daemon for cjdns.
Stars: ✭ 19 (-51.28%)
Mutual labels:  protocol
FullProxy
Bind and reverse connection based, SOCKS5, HTTP and PortForward based portable proxy
Stars: ✭ 22 (-43.59%)
Mutual labels:  protocol

gemini

Gemini protocol server & client.

npm version build status ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

Installation

npm install @derhuerst/gemini

Usage

Server

The following code assumes that you have a valid SSL certificate & key.

const {createServer, DEFAULT_PORT} = require('@derhuerst/gemini')

const handleRequest = (req, res) => {
	if (req.path === '/foo') {
		if (!req.clientFingerprint) {
			return res.requestTransientClientCert('/foo is secret!')
		}
		res.write('foo')
		res.end('!')
	} else if (req.path === '/bar') {
		res.redirect('/foo')
	} else {
		res.gone()
	}
}

const server = createServer({
	cert: , // certificate (+ chain)
	key: , // private key
	passphrase: , // passphrase, if the key is encrypted
}, handleRequest)

server.listen(DEFAULT_PORT)
server.on('error', console.error)

Client

const request = require('@derhuerst/gemini/client')

request('/bar', (err, res) => {
	if (err) {
		console.error(err)
		process.exit(1)
	}

	console.log(res.statusCode, res.statusMessage)
	if (res.meta) console.log(res.meta)
	res.pipe(process.stdout)
})

TOFU-style client certificates

Interactive clients for human users MUST inform users that such a session has been requested and require the user to approve generation of such a certificate. Transient certificates MUST NOT be generated automatically. – Gemini spec, section 1.4.3

This library leaves it up to you how to ask the user for approval. As an example, we're going to build a simple CLI prompt:

const {createInterface} = require('readline')

const letUserConfirmClientCertUsage = ({host, reason}, cb) => {
	const prompt = createInterface({
		input: process.stdin,
		output: process.stdout,
		history: 0,
	})
	prompt.question(`Send client cert to ${host}? Server says: "${reason}". y/n > `, (confirmed) => {
		prompt.close()
		cb(confirmed === 'y' || confirmed === 'Y')
	})
}

request('/foo', {
	// opt into client certificates
	useClientCerts: true,
	letUserConfirmClientCertUsage,
}, cb)

API

createServer

const createServer = require('@derhuerst/gemini/server')
createServer(opt = {}, onRequest)

opt extends the following defaults:

{
	// SSL certificate & key
	cert: null, key: null, passphrase: null,
	// additional options to be passed into `tls.createServer`
	tlsOpt: {},
	// verify the ALPN ID requested by the client
	// see https://de.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation
	verifyAlpnId: alpnId => alpnId ? alpnId === ALPN_ID : true,
}

request

const request = require('@derhuerst/gemini/client')
request(pathOrUrl, opt = {}, cb)

opt extends the following defaults:

{
	// follow redirects automatically
	// Can also be a function `(nrOfRedirects, response) => boolean`.
	followRedirects: false,
	// client certificates
	useClientCerts: false,
	letUserConfirmClientCertUsage: null,
	clientCertStore: defaultClientCertStore,
	// time to wait for socket connection & TLS handshake
	connectTimeout: 60 * 1000, // 60s
	// additional options to be passed into `tls.connect`
	tlsOpt: {},
	// verify the ALPN ID chosen by the server
	// see https://de.wikipedia.org/wiki/Application-Layer_Protocol_Negotiation
	verifyAlpnId: alpnId => alpnId ? (alpnId === ALPN_ID) : true,
}

connect

const connect = require('@derhuerst/gemini/connect')
connect(opt = {}, cb)

opt extends the following defaults:

{
	hostname: '127.0.0.1',
	port: 1965,
	// client certificate
	cert: null, key: null, passphrase: null,
	// time to wait for socket connection & TLS handshake
	connectTimeout: 60 * 1000, // 60s
	// additional options to be passed into `tls.connect`
	tlsOpt: {},
}

Related

  • gemini-fetch – Load data from the Gemini protocol the way you would fetch from HTTP in JavaScript
  • dioscuri – A gemtext (text/gemini) parser with support for streaming, ASTs, and CSTs

Contributing

If you have a question or need support using gemini, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use the issues page.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].