Commit Graph

117 Commits

Author SHA1 Message Date
É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
Érico Nogueira 1e7d2a5517 Don't send port in Host field for HTTP header.
It's unnecessary and can confuse some servers.

I think this was initially done because I didn't fully understand how
sockets work and figured the information was necessary.
2021-12-08 23:17:38 -03:00
Érico Nogueira 3c5679872a Fix purr's default pastebin.
Per [1], it has moved to listening only on HTTPS. No other change to the
code was necessary, since we already knew how to deal with HTTPS
servers.

[1] https://github.com/PurritoBin/PurritoBin/pull/7
2021-05-21 02:27:20 -03:00
Érico Nogueira 910b69f6b2 Respect that HTTP headers are case insensitive.
So we look for them using strcasestr instead fo strstr.

If this ever becomes a bottleneck, it can probably be optimized by only
trying to match the words right after "\r\n".
2021-05-21 02:23:56 -03:00
Érico Rolim 552388db2d Use send with MSG_NOSIGNAL instead of ignoring SIGPIPE. 2021-01-06 15:56:36 -03:00
Érico Rolim ee70128300 Improve gemi's certificate handling.
It still opens certs in ~/.config/gemi, but instead of doing a big fd
dance, simply uses an openat(dirfd(), readdir()->d_name) equivalent.
This way we even save on the extra fd and fcntl() call.

Use fnmatch() to filter for file names that end with ".pem". This can be
done with string manipulation, but fnmatch is easy to extend.
2020-12-31 17:35:47 -03:00
Érico Rolim 9c83794351 Remove warning workaround from purr.c.
Let it complain if it wants.
2020-12-31 17:35:42 -03:00
Érico Rolim 80258a9a03 Create loc_init() for localization initialization.
Avoids repetition; gemi and purr are now using it.

Also use setlocale() unconditionally, since it's always good.
2020-12-31 17:21:05 -03:00
Érico Rolim 51d5882344 Update and clean up README. 2020-11-28 15:34:22 -03:00
Érico Rolim 8a6dadd57e Split platform compatibility code into compat.c.
Also use getentropy() in entropy.c, since it should be available in all
platforms.

This also cleaned up the error checking in general.
2020-11-28 15:27:03 -03:00
Érico Rolim 4678f8691b Add translation for comm.c. 2020-11-15 21:02:17 -03:00
Érico Rolim 072ac1f946 Make gettext calls a noop when building with make.
Since the Make build doesn't know how to install locale files, avoid
using any locale/libintl functions for it.
2020-11-15 21:02:12 -03:00
Érico Rolim c6ab41190a Add CI status badge to README. 2020-11-11 01:36:40 -03:00
Érico Rolim 4b3f41d0f9 Extend localization support.
Localize purr.c so both main executables are localized, plus some
library code. Refactor some message printing so localization is easier.
2020-11-11 01:36:40 -03:00
Érico Rolim 4cb82f0bff Add localization support!
Starting with gemi.c, for now.
2020-11-11 01:36:40 -03:00
Érico Rolim 1035f102c9 Improve package installation step in CI.
XBPS doesn't update itself by default.
2020-11-11 01:36:40 -03:00
Érico Rolim fa1c550090 Add meson build system. 2020-11-11 01:36:40 -03:00
Érico Rolim 158596366a Clean up CI.
- Stop using external action
- Use `container:` label
- Add clang+glibc job
2020-11-07 01:14:08 -03:00
Érico Rolim 6c76ae3724 Use action in a separate repository.
- Makes it possible to share the Dockerfile setup with other projects.
- Requires adding a ci/run.sh file.
2020-11-04 02:08:17 -03:00
Érico Rolim b6b50c9267 Add script to test final executables.
Does some simple testing with purr, for now.

Has rate limiting to avoid hitting the pastebin service too hard.
2020-11-03 23:30:56 -03:00
Érico Rolim 4d5563759e Allocate iv_throwaway on the stack.
It's pretty small and won't be used outside this function, so it's ok to
allocate it on the stack. This also has the advantage of simplifying the
error checking, since it's one less allocation that can fail.
2020-11-03 22:54:03 -03:00
Érico Rolim 37a936ffda Fix off-by-one allocation error in gemini.
Forgot to account for additional slash.
2020-11-03 22:51:58 -03:00
Érico Rolim c252ef31f4 Use abort() for situations that should never happen.
For now, that's only when purr gets back an ALPN string that it didn't
send.
2020-11-03 19:56:18 -03:00
Érico Rolim 30725ca6fc Update .gitignore. 2020-11-03 19:55:56 -03:00
Érico Rolim cab476f48d Add CI via GitHub Actions. 2020-11-03 19:18:36 -03:00
Érico Rolim 0b1a4c2fa5 Fix gemini header parsing.
Old gemini spec allowed for server responses to use tabs instead of
spaces.
2020-10-24 03:40:08 -03:00
Érico Rolim 6eb6c92c9b Add proper header dependency tracking.
Use GCC/clang's generated dependency files; avoids rebuilding the whole
project for changes in a single header.

https://stackoverflow.com/questions/39002087/about-the-gnu-make-dependency-files-d#39003791

Update the cproc script to remove those flags, which it doesn't support.
2020-10-20 20:16:04 -03:00
Érico Rolim 86f7a1575d Implement ALPN properly.
There was a misconception about how the ALPN API worked. It was actually
necessary to force a handshake so ALPN could be negotiated and
br_ssl_engine_get_selected_protocol() could possibly return any
information.

send_and_receive() now has a small diagnostics output for ALPN
and purr itself now forces the handshake before assembling the HTTP
requests, so it can use the ALPN results for that. The requests were
also reworked a bit.
2020-10-19 03:52:33 -03:00
Érico Rolim bdc4461a45 Remove libbaseencode.
Move base64 decoding to BearSSL's PEM decoder/encoder, using some simple
hacks for inserting and removing the PEM headers as well as the added
newlines.

Also added some fixes around the usage of mmap_file objects in purr.c,
and checked that the object size passed to cbcdec is actually the right
size.
2020-10-19 03:49:49 -03:00
Érico Rolim a78061e6db Simplify reallocation loops in read_certs.
realloc(NULL, size) works the same as malloc(size), so there's no need
to have one path for each.
2020-10-19 03:28:30 -03:00
Érico Rolim 3ac895d75d Remove some errors from gemi's non debug output.
The config directory isn't required to exist, so there's no need to
print an error about it in regular usage.
2020-10-19 03:26:31 -03:00
Érico Rolim 36d9312beb Add mode to accept public key in gemi.
This allows the client to connect to and get content from servers whose
certificates aren't accepted by the client's trust anchors. It isn't
exactly TOFU, since the cert isn't stored locally, but it's a start.

Also update README.
2020-10-19 00:14:45 -03:00
Érico Rolim 8435f3b695 Use opendir and readdir instead of scandir.
Slightly better portability, makes scandirat unnecessary.

Also fix small resource leakage with config_fd.
2020-10-18 03:17:54 -03:00
Érico Rolim 7cd4a58ab1 Add scandirat verification to configure script.
Tested on glibc, correctly detects the function. Added for a future use
case, if such appears.
2020-10-16 01:16:59 -03:00
Érico Rolim d710666486 Use nanosleep instead of sleep in pager.
This allows for delays shorter than 1s. The additional functionality of
nanosleep isn't used.
2020-10-16 01:13:33 -03:00
Érico Rolim 367fbc823f Fix read_certs to receive FILE instead of a path.
This change lead to completely overhauling the bearssl_read_certs()
function, which now deals directly with FILES, instead of depending on
mmap_file. There is some slight added complexity for dealing with the
file reads.

The idea for this came from the idea of implementing path resolution
using openat() instead of path concatenation, so there was a need to
pass either fds or file streams to functions instead of specific paths.
2020-10-16 01:13:09 -03:00
Érico Rolim 8100addb24 Use PATH_MAX in gemi.c.
Remove asprintf dependency and move to snprintf. Not so clean and can
probably be improved with openat(2), but it's enough for now.
2020-10-15 22:45:30 -03:00
Érico Rolim f249f7301b Make gemi.c read config dir for cert files.
Allow it to read files in ~/.config/gemi/ to pick up certs, instead of
being limited to the ones in CA_CERT_SSL_FILE.

Also uses the new bearssl_read_certs() "API", and was in fact the
motivation for the changes there.
2020-10-15 22:34:32 -03:00
Érico Rolim 4dab3ebdc3 Make it possible to read certs from multiple files
The previous impl clobbered most of the ta array if it was reutilized.
Add proper bookkeeping to solve this and enable reading from multiple
files.

The necessary changes in gemi.c are in the next commit, due to being
more involved and adding unrelated features.
2020-10-15 22:31:38 -03:00
Érico Rolim 5dc696466e Make request stack allocated.
Simplifies memory management.
2020-10-15 22:30:14 -03:00
Érico Rolim b85aaae164 Fix memory leak with redirect_link.
It should be duplicated by who's going to use it, otherwise the
duplicated string will simply leak. Add function to free it, because why
not.

This also fixes a compiler warning about losing the const qualifier.
2020-10-15 22:29:48 -03:00
Érico Rolim 9096022f18 Improve connection error messages.
connect() can fail due to server side issues, so printing error messages
when the next attempt (in the same loop) might work leads to weird user
experience.
2020-10-15 20:49:11 -03:00
Érico Rolim a8ded0e76f Build system fixes.
- Use CFLAGS and LDFLAGS from the environment in configure.
- Install meowd correctly.
2020-10-15 20:48:24 -03:00
Érico Rolim 751ab7dbdd Clean up gemini_link_node size and handling. 2020-10-15 20:47:51 -03:00
Érico Rolim b39b302785 Add option to skip server name checking in gemi. 2020-10-15 20:47:17 -03:00
Érico Rolim 7da7454a7d Improve file descriptor handling.
- Add close-on-exec flags where applicable, either with arguments when
opening the file or with fcntl calls. The possibility of applying the
flags atomically, when opening the file, is tested by the configure
script.
- Close the duplicated socket_write fd if fdopen in comm.c fails.
2020-10-15 20:45:05 -03:00
Érico Rolim f7270d1640 Add parameter to bearssl_read_certs for certs file
Still has the option of looking at the env var, but can also be
controlled directly. Will be useful when certificates are stored in
custom locations.
2020-10-15 20:45:05 -03:00
Érico Rolim 3566ed2690 Add help output for cert env var to all utilities.
Also redirect help output to stderr when it's supposed to fail and to
stdout otherwise.
2020-10-15 20:44:46 -03:00
Érico Rolim ce76c12f7a Hide gemini redirect link from gemi.c.
Use a static variable for better encapsulation.
2020-10-15 20:43:18 -03:00
Érico Rolim 00459ad59b Simplify test.c error counting.
Use a global variable instead of copy pasting the rv logic multiple
times. Added advantage of counting the amount of errors.
2020-10-06 19:11:40 -03:00