2019-08-24 05:36:24 +02:00
|
|
|
# Jetforce
|
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
An experimental TCP server for the new, under development
|
|
|
|
[Gemini Protocol](https://gopher.commons.host/gopher://zaibatsu.circumlunar.space/1/~solderpunk/gemini).
|
2019-08-24 05:36:24 +02:00
|
|
|
|
|
|
|
![Rocket Launch](resources/rocket.jpg)
|
2019-08-09 03:45:26 +02:00
|
|
|
|
2019-08-05 04:57:34 +02:00
|
|
|
## Features
|
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
- A built-in static file server with support for gemini directories and
|
|
|
|
CGI scripts.
|
|
|
|
- Lightweight, single-file framework with zero external dependencies.
|
|
|
|
- Modern python codebase with type hinting and black style formatting.
|
2019-08-05 04:57:34 +02:00
|
|
|
- Supports concurrent connections using an asynchronous event loop.
|
2019-08-28 04:52:38 +02:00
|
|
|
- Extendable components that loosely implement the [WSGI](https://en.wikipedia.org/wiki/Web_Server_Gateway_Interface)
|
2019-08-24 06:34:05 +02:00
|
|
|
server/application pattern.
|
2019-08-05 04:57:34 +02:00
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
Requires Python 3.7+
|
2019-08-05 04:57:34 +02:00
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
The latest release can be installed from [PyPI](https://pypi.org/project/Jetforce/):
|
2019-08-24 06:34:05 +02:00
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
```bash
|
2019-08-05 04:57:34 +02:00
|
|
|
$ pip install jetforce
|
|
|
|
```
|
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
Or, clone the repository and run the script directly:
|
2019-08-05 04:57:34 +02:00
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
```bash
|
2019-08-05 04:57:34 +02:00
|
|
|
$ git clone https://github.com/michael-lazar/jetforce
|
|
|
|
$ cd jetforce
|
2019-08-28 04:52:38 +02:00
|
|
|
$ python3 jetforce.py
|
2019-08-05 04:57:34 +02:00
|
|
|
```
|
2019-08-24 06:34:05 +02:00
|
|
|
|
|
|
|
## Usage
|
|
|
|
|
|
|
|
Use the ``--help`` flag to view command-line options:
|
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
```bash
|
2019-08-24 06:34:05 +02:00
|
|
|
$ jetforce --help
|
|
|
|
usage: jetforce [-h] [--host HOST] [--port PORT] [--tls-certfile FILE]
|
|
|
|
[--tls-keyfile FILE] [--hostname HOSTNAME] [--dir DIR]
|
2019-08-28 04:52:38 +02:00
|
|
|
[--cgi-dir DIR] [--index-file FILE]
|
2019-08-24 06:34:05 +02:00
|
|
|
|
|
|
|
An Experimental Gemini Protocol Server
|
|
|
|
|
|
|
|
optional arguments:
|
2019-08-28 04:52:38 +02:00
|
|
|
-h, --help show this help message and exit
|
|
|
|
--host HOST Server address to bind to (default: 127.0.0.1)
|
|
|
|
--port PORT Server port to bind to (default: 1965)
|
|
|
|
--tls-certfile FILE Server TLS certificate file (default: None)
|
|
|
|
--tls-keyfile FILE Server TLS private key file (default: None)
|
|
|
|
--hostname HOSTNAME Server hostname (default: localhost)
|
|
|
|
--dir DIR Local directory to serve (default: /var/gemini)
|
|
|
|
--cgi-dir DIR CGI script directory, relative to the server's root
|
|
|
|
directory (default: cgi-bin)
|
|
|
|
--index-file FILE If a directory contains a file with this name, that
|
|
|
|
file will be served instead of auto-generating an index
|
|
|
|
page (default: index.gmi)
|
2019-08-24 06:34:05 +02:00
|
|
|
|
|
|
|
If the TLS cert/keyfile is not provided, a self-signed certificate will
|
2019-08-24 06:54:53 +02:00
|
|
|
automatically be generated and saved to your temporary directory.
|
2019-08-24 06:34:05 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
### TLS Certificates
|
|
|
|
|
|
|
|
The gemini specification *requires* that all connections be sent over TLS.
|
|
|
|
Before you deploy jetforce, you should either generate your own self-signed
|
|
|
|
certificate, or obtain one from a Certificate Authority like
|
|
|
|
[Let's Encrypt](https://letsencrypt.org).
|
|
|
|
|
|
|
|
In order to make local development easier, if you do not specify the certificate
|
|
|
|
arguments, jetforce will automatically generate a temporary ad-hoc TLS certificate
|
2019-08-24 06:58:00 +02:00
|
|
|
to use. Here's the OpenSSL command that jetforce uses internally:
|
2019-08-24 06:34:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
$ openssl req -newkey rsa:2048 -nodes -keyout {hostname}.key \
|
|
|
|
-nodes -x509 -out {hostname}.crt -subj "/CN={hostname}"
|
|
|
|
```
|
|
|
|
|
2019-08-24 20:38:57 +02:00
|
|
|
There are currently no plans to support transient self-signed client certificates.
|
2019-08-26 16:37:28 +02:00
|
|
|
This is due to a techinical limitation of the python standard library's ``ssl``
|
2019-08-24 20:38:57 +02:00
|
|
|
module, which is described in detail
|
|
|
|
[here](https://portal.mozz.us/?url=gemini%3A%2F%2Fmozz.us%2Fjournal%2F2019-08-21.txt).
|
|
|
|
|
2019-08-24 20:39:19 +02:00
|
|
|
Support for verified client certificates will be added in a future version.
|
2019-08-24 20:38:57 +02:00
|
|
|
|
2019-08-24 06:34:05 +02:00
|
|
|
### Hostname
|
|
|
|
|
2019-08-24 06:34:38 +02:00
|
|
|
Because the gemini protocol sends the *whole* URL in the request, it's required
|
2019-08-28 04:52:38 +02:00
|
|
|
that you declare the hostname that your server is expecting to receive traffic
|
|
|
|
under. Jetforce will reject any request that doesn't match your hostname with a
|
|
|
|
status of ``Proxy Request Refused``.
|
2019-08-24 06:34:05 +02:00
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
Using python, you can modify this behavior to do fancy things like building a
|
|
|
|
proxy server for HTTP requests. See [http_proxy.py](examples/http_proxy.py) for
|
|
|
|
an example of how this is done.
|
2019-08-24 06:54:53 +02:00
|
|
|
|
2019-08-24 07:05:45 +02:00
|
|
|
### Serving Files
|
2019-08-24 06:54:53 +02:00
|
|
|
|
|
|
|
Jetforce serves files from the ``/var/gemini/`` directory by default:
|
|
|
|
|
|
|
|
- Files with the **.gmi** extension will be interpreted as *text/gemini*.
|
2019-08-24 07:05:45 +02:00
|
|
|
- Other files will have their *mimetype* guessed based on their file extension.
|
2019-08-24 19:58:11 +02:00
|
|
|
- Directories will look for a file with the name **index.gmi**.
|
2019-08-24 20:11:17 +02:00
|
|
|
- If an index file does not exist, a directory listing will be generated.
|
2019-08-24 06:54:53 +02:00
|
|
|
|
2019-08-28 04:52:38 +02:00
|
|
|
### CGI Scripts
|
|
|
|
|
|
|
|
Jetforce implements a slightly modified version of the official CGI
|
|
|
|
specification. Because Gemini is a less complex than HTTP, the CGI interface is
|
|
|
|
also inherently easier and more straightforward to use.
|
|
|
|
|
|
|
|
The main difference in this implementation is that the CGI script is expected
|
|
|
|
to write the entire gemini response *verbetim* to stdout:
|
|
|
|
|
|
|
|
1. The status code and meta on the first line
|
|
|
|
2. Any additional response body on subsequent lines
|
|
|
|
|
|
|
|
Unlike HTTP's CGI, there are no request/response headers or other special
|
|
|
|
fields to perform actions like redirects.
|
2019-08-24 07:05:45 +02:00
|
|
|
|
|
|
|
## License
|
|
|
|
|
|
|
|
This project is licensed under the [Floodgap Free Software License](https://www.floodgap.com/software/ffsl/license.html).
|
|
|
|
|
|
|
|
> The Floodgap Free Software License (FFSL) has one overriding mandate: that software
|
|
|
|
> using it, or derivative works based on software that uses it, must be free. By free
|
|
|
|
> we mean simply "free as in beer" -- you may put your work into open or closed source
|
|
|
|
> packages as you see fit, whether or not you choose to release your changes or updates
|
|
|
|
> publicly, but you must not ask any fee for it.
|