Pure C client for PurritoBin and other networking projects
Go to file
Érico Nogueira cd14bff782 Add support for pastebin.stratumzero.date.
- use -s flag to enable it
- required support for Content-Type: multipart/form-data
2021-12-09 03:19:22 -03:00
.github/workflows Improve package installation step in CI. 2020-11-11 01:36:40 -03:00
ci Add meson build system. 2020-11-11 01:36:40 -03:00
po Add support for pastebin.stratumzero.date. 2021-12-09 03:19:22 -03:00
.gitignore Add meson build system. 2020-11-11 01:36:40 -03:00
LICENSE Add README and LICENSE. 2020-09-13 21:40:15 -03:00
README.md Add support for pastebin.stratumzero.date. 2021-12-09 03:19:22 -03:00
comm.c Add support for pastebin.stratumzero.date. 2021-12-09 03:19:22 -03:00
compat.c Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
compat.h Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
configure Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
cproc-make Add proper header dependency tracking. 2020-10-20 20:16:04 -03:00
encrypt.c Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
files.c Respect that HTTP headers are case insensitive. 2021-05-21 02:23:56 -03:00
formats.c General cleanup: comments and test cases. 2020-10-04 01:31:43 -03:00
gemi.c Use send with MSG_NOSIGNAL instead of ignoring SIGPIPE. 2021-01-06 15:56:36 -03:00
gemini.c Fix off-by-one allocation error in gemini. 2020-11-03 22:51:58 -03:00
gemini.h Fix memory leak with redirect_link. 2020-10-15 22:29:48 -03:00
makefile Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
meson.build Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
mmap_file.c Clear up input file code in purr. 2020-10-01 19:09:27 -03:00
mmap_file.h Fix compilation under glibc. 2020-09-24 20:48:22 -03:00
pager.c Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00
pager.h Add pager implementation, use in gemi. 2020-10-01 03:19:02 -03:00
purr.c Add support for pastebin.stratumzero.date. 2021-12-09 03:19:22 -03:00
purr.h Add support for pastebin.stratumzero.date. 2021-12-09 03:19:22 -03:00
read_certs.c Extend localization support. 2020-11-11 01:36:40 -03:00
read_certs.h Fix read_certs to receive FILE instead of a path. 2020-10-16 01:13:09 -03:00
socket.c Use send with MSG_NOSIGNAL instead of ignoring SIGPIPE. 2021-01-06 15:56:36 -03:00
test.sh Add meson build system. 2020-11-11 01:36:40 -03:00
tests.c Simplify test.c error counting. 2020-10-06 19:11:40 -03:00
translation.h Create loc_init() for localization initialization. 2020-12-31 17:21:05 -03:00
urls.c Split platform compatibility code into compat.c. 2020-11-28 15:27:03 -03:00

README.md

purr-c

Tests

This repository holds some loosely related networking projects. This is mainly a learning exercise for network and TLS programming, with a dash of crypto, and all of the programs contained here should be treated as such.

The BearSSL library was chosen as the TLS and crypto implementation.

All pieces of code should be either self explanatory or well commented. If you find any part of the code lacking in those, feel free to open an issue.

Building

The only non-optional external dependency is the BearSSL library - on Void Linux, it can be obtained via the bearssl-devel package.

This project can be built with two different build systems.

GNU Make

GNU Make and a C99 compiler, such as cproc, are required for building.

You can build and install the project with the commands below:

$ ./configure # creates config.mk
$ make
$ make install PREFIX=$HOME/.local

Meson

Alternatively, you can use the Meson build system, which requires the Meson tool itself, Ninja, a C99 compiler that Meson knows about (GCC or Clang will do the trick), and the msgfmt tool from GNU Gettext or a compatible implementation. Note that only the Meson builds support localization, and it isn't optional.

You can build and install the project with the commands below:

$ meson build --prefix $HOME/.local
$ ninja -C build/
$ ninja -C build/ install

Instead of using Ninja, you can use samurai.

Programs

purr

This is a pure C client for the PurritoBin pastebin server, and uses PurritoBin's author's instance at https://bsd.ac by default. It also supports zdykstra's pastebin.

It supports symmetric paste encryption (as supported by PurritoBin's online interface and its suggested clients). This makes it possible to share paste links that can only be decrypted by someone who has the keys to them. The key and IV are stored in the url's hash property, and are never sent to the server.

It can also work as a very limited curl alternative, due to its support of both HTTP and HTTPS. It can use HTTP/1.0 or HTTP/1.1 for requests, and always requires the Content-Length field in the response header (no chunked transfer here!) - this is done because I have found servers that don't send notify_close when their transmission is done, instead relying on the Content-Length field to provide enough information for the client to determine if the transmission was sucessful or if the connection was terminated before it should have been.

This program uses getentropy(3) for key and IV generation.

Usage

Usage information can be viewed with purr -h. There are two symlinks to the purr executable, meow and meowd, which are used as shortcuts to send and receive encrypted pastes, respectively.

gemi

This is a (not so dumb anymore) Gemini client. It doesn't support TOFU (Trust On First Use) yet, so it isn't fully compliant with the Gemini spec, but it can talk to (almost) any server, not being limited to those whose certificates can be verified by the local trust anchors.

It has a built-in "navigation" mechanism via the -b command line flag, which parses the received page, finds links, asks the user to select one, and finally execs into itself with the new link.

It can parse server responses with status headers, including redirects, and can deal with "complex" links, such as ../../docs. However, it doesn't pass the gemini browser torture test.

Usage

Usage information can be viewed with gemi -h.

Localization

The Meson build system has been added mainly due to its capabilities for dealing with translation via GNU gettext. Documentation for these features can be found in their official docs and module manual.

For reference, some useful commands:

$ ninja -C build/ purr-c-pot # generate pot file
$ ninja -C build/ purr-c-update-po # update po files
$ ninja -C build/ purr-c-gmo # builds translations without installing

Contributing translations

Simply add the locale name (usually in the form ll or ll_CC, where ll refers to the language and CC to the country - see the GNU Gettext manual section on Locale Names) to the po/LINGUAS file and run the command for updating po files, shown above. After that, you will be ready to start working on the new po/ll[_CC].po file!

Acknowledgements

  • Thomas Pornin for BearSSL
  • Laurent Bercot for s6-networking (even though it's no longer in use here)
  • epsilon-0 for PurritoBin (and the valuable help while I was testing this program)
  • paolostivanin for libbaseencode (also no longer used here)