Commit Graph

17 Commits

Author SHA1 Message Date
É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 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 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 c10edd5180 General cleanup: comments and test cases.
Also removed unused function.
2020-10-04 01:31:43 -03:00
Érico Rolim 98e956b31a Fix bug in decrypt_mmap.
allocate_mmap return was being used wrong.
2020-09-17 16:21:27 -03:00
Érico Rolim 5226c3b534 Use (more) functions for mmap management.
Add free_mmap and allocate_mmap, which allow for easier changes to the
codebase, if desired, since it's now modularized.
2020-09-17 15:35:44 -03:00
Érico Rolim 6503fb31b7 Use PKCS7 padding instead of all zeros. 2020-09-17 13:54:15 -03:00
Érico Rolim a99b5380a1 Add configure script to make it work on BSD.
We could use `extern const char *__progname` to work on musl/glibc and
BSDs, but it's not a recommended interface, and they prefer
getprogname(). In the interest of proper platform usage, use
getprogname() on BSD and program_invocation_short_name on musl/glibc.

Supporting arc4random_buf and getrandom is pretty simple.

Hasn't been tested on an actual BSD platform.
2020-09-14 10:20:48 -03:00
Érico Rolim 06eb9d4222 Split mmap_file implementation.
Also add some useful definitions.
2020-09-14 00:32:16 -03:00
Érico Rolim 52f7829b48 Fix some compiler warnings. 2020-09-14 00:09:09 -03:00
Érico Rolim a80f082b48 Remove padding bytes (uglily) from encrypted recv. 2020-09-13 20:32:37 -03:00
Érico Rolim f13c0c2e3e Add decryption for recv.
A few fixes and hacks all around, but can now do:

  ./purr -e recv (./purr -e send makefile)

And output the original page.
2020-09-13 20:17:58 -03:00
Érico Rolim b70d741b03 Enable IV randomization. 2020-09-13 18:08:52 -03:00
Érico Rolim 94f8f4f61d Enable encrypted pastes properly.
Add base64 encoding per the pattern expected by the web interface.

Fix some pointers and file size things in purr/files.

TODO: files are cut off at random points, despite the efforts to remove
verification of null characters in libbaseencode.
2020-09-13 18:05:43 -03:00
Érico Rolim baa013afae Move to mmap implementation.
Using FILE* is error prone and limited.
2020-09-13 13:32:28 -03:00
Érico Rolim 32f9910ece Fix encryption function.
Fix pointer parameters as function returns.
Add file clean-up as an atexit functionality.
2020-09-13 01:06:39 -03:00
Érico Rolim dd30aa72a8 Split encrypt.c and fix use-after-free.
UAF from genalloc and stralloc frees.

Also remove randomization of IV, not used in bsd.ac.
2020-09-12 23:28:49 -03:00