Commit graph

153 commits

Author SHA1 Message Date
Albert Larsan
75424b57fc
Replace bare status codes with consts (#163)
* Replace bare status codes with consts
* Put the new consts in their own mod
2022-04-06 16:25:09 +02:00
j-k
f1e6a2e0d6
fix port collisions in tests (#143)
Co-authored-by: Johann150 <johann.galle@protonmail.com>
2022-02-08 23:04:41 +01:00
Johann150
b6ff8f7758
fix IRI error handling 2022-02-04 18:23:10 +01:00
Johann150
675309f4aa
normalize hostnames before comparing 2021-11-23 09:56:28 +01:00
Johann150
99494e148b
always shut down connection properly 2021-11-10 14:29:17 +01:00
Johann150
d10c512253
add ability for preamble to directory list 2021-11-07 15:23:29 +01:00
Johann150
6af5efbf67
make process of starting listeners synchronous
Alternatively, a semaphore could have been used which might be a bit faster,
but since the start up process is only used once this simpler solution is
not at a significant disadvantage while being much simpler.
2021-10-22 14:21:40 +02:00
Johann150
b5a416fc35
update rustls and related dependencies (#72)
* chore(deps): bump rustls from 0.19.1 to 0.20.0
* chore(deps): bump webpki from 0.21.4 to 0.22.0
* chore(deps): bump tokio-rustls from 0.22.0 to 0.23.0
* update rustls calls
* update webpki naming
* update tests
2021-10-19 00:30:38 +02:00
Johann150
9556579de0
try to detect dual stack address in use error
If multiple unspecified addresses are used, issue a warning if listening to
it after the first time fails because the system probably already listens in
dual stack mode. Assumes that IPv6 and IPv4 are used. If such addresses are
passed in manually, thats the admins problem for setting up something stupid
in case it goes wrong.
2021-10-14 23:14:46 +02:00
Johann150
b0d0f64be0
actually bind to multiple addresses
resolves #63

This now causes an error message with the default bindings because on Linux
binding to both IPv6's [::] and IPv4's 0.0.0.0 results in a "port in use" error
2021-07-18 11:30:17 +02:00
dece
2f52157c73 add an option to disable the port check 2021-06-11 02:24:17 +02:00
Matthew Ingwersen
3c38dae599
Fix directory traversal vulnerability
When computing the filesystem path to serve, each URL path segment
appended to the content directory path must be checked to ensure that it
consists only of normal filesystem path components (and not the root
directory, .., drive labels, or other special components). Otherwise,
the following directory traversal attacks are possible:

- When an absolute path is pushed onto a PathBuf, the PathBuf will be
  overwritten. If we don't check for absolute paths, Agate can be
  tricked into serving an arbitrary absolute filesystem path via a URL
  like gemini://example.com/%2Fetc/passwd

- The url crate eliminates all .. segments from the URL when parsing,
  even when these are percent-encoded. However, .. can be injected
  into the computed filesystem path by using a URL path segment that,
  when decoded, contains more than one filesystem path component, like
  gemini://example.com/subdir%2F..%2F../outside_content_dir

Furthermore, path separators appearing within a single URL path segment,
like escaped / (%2F), should probably not be considered structural [0].
That is, "a%2Fb" refers to a resource literally named "a/b", not "b" in
subdirectory "a". Thus we also check that a URL path segment represents
no more than one filesystem path segment.

[0] https://www.w3.org/Addressing/URL/4_URI_Recommentations.html
2021-06-08 08:22:00 +02:00
Johann150
2bc7d6e63a
better error messages when directory listing is disabled
This is possibly also related to #60.

Instead of showing a generic not found error, this shows both the admin and
the user that the directory exists, but directory listing is disabled.
2021-06-06 13:00:24 +02:00
Johann150
a4bafa2c4e
carefully check unwrap and expect usage
closes #59
I did not find any other cases where the unwrap or expect usage does not depend
on an internal invariant.
2021-05-24 12:36:48 +02:00
Johann150
f85585155e
switch default cert signing algorithm to ECDSA
resolves #42
resolves #49

I did not expect support for Ed25519 to be so bad as to receive multiple
complaints about it. I did expect some problems, hence why I provided the
--ecdsa flag. I had hoped support would be better to drive those who still
do not support it (while again there is no reason to not support this
algorithm!) to use it.
2021-04-08 00:13:18 +02:00
Johann150
ba9297eabf
implement stricter requirements for request URLs
Addresses changes in the specification, namely these stricter requirements:
0235100151/specification.gmi (L153-155)
2021-04-07 23:54:44 +02:00
Johann150
16d05c73a0
resolve clippy warning 2021-03-27 20:31:06 +01:00
Johann150
1a537d630f
automatically create certificate directory
resolves #44
2021-03-27 20:31:06 +01:00
Johann150
2213b055dc
add automatic certificate generation 2021-03-27 00:52:50 +01:00
Johann150
d24db63583
remove silent flag in favour of RUST_LOG 2021-03-26 20:33:45 +01:00
Johann150
2934350485
add function to check for cert of a domain 2021-03-26 12:49:31 +01:00
Johann150
e6f70722de
improve help texts 2021-03-25 21:42:24 +01:00
Johann150
eec057515d
finish up for merge 2021-03-23 23:25:04 +01:00
Johann150
2ed6d2886e
Merge branch 'master' into multi-certs 2021-03-09 21:11:34 +01:00
Johann150
3ffe89b775
make all log lines uniform
Now also if the connection is never established. Use the nonexistent status
code 00 for that.
2021-03-07 00:04:22 +01:00
Johann150
d4324233c7
make log lines more uniform
Ensure there is something logged for the request if reading it actually failed.
Instead just write an empty quoted string.
2021-03-07 00:04:21 +01:00
Johann150
c6b34055e9
suppress log messages from other modules
resolves #30
2021-03-07 00:04:02 +01:00
Johann150
afd30c386c
implement clippy reccomendation 2021-03-03 23:17:35 +01:00
Johann150
5dbb4be864
improve comments 2021-03-03 23:09:29 +01:00
Johann150
424bed7861
add instructions for multiple certificates
also adjusted the certificate creation example to contain a subject alt name
with a DNS entry. This is strictly speaking not required for the top level
certificate, but it doesn't hurt to include it and makes the example reusable
for all certificates.
2021-03-03 19:41:36 +01:00
Johann150
635f7bc1e7
better error messages 2021-03-03 18:46:41 +01:00
Johann150
06819eeabd
add loading fallback certificates 2021-02-28 15:12:20 +01:00
Johann150
5a4907292f
use certificate store 2021-02-28 10:42:56 +01:00
Johann150
f374598fd3
add module to store multiple certificates 2021-02-28 10:42:51 +01:00
Johann150
e00f8e5026
add version info flag 2021-02-27 20:46:08 +01:00
Johann150
b7ffece867
correct help text 2021-02-27 20:43:47 +01:00
Johann150
1059f8b94a
never log remote port
This information is basically useless anyway and fills logs needlessly.
Because this is not necessarily true for the local port because multiple ports
may be selected for hosting, logging for the local socket address is unchanged.
2021-02-25 14:14:08 +01:00
Johann150
bc501ebcc5
update CHANGELOG and CONTRIBUTING
Moved updating the changelog from the quality standards up to the workflow
section so it should not be missed, since it is not really a quality standard
but an action to be performed.
2021-02-19 12:08:19 +01:00
Johann150
b5fa24cb5b
resolve TODO comment for Url 2021-02-19 12:01:59 +01:00
06kellyjac
4e130dc89e have help exit with code 0 2021-02-19 08:33:00 +00:00
Johann150
7af42a9bd5
make semicolon not a comment
This causes issues with MIME media type parameters.
2021-02-12 20:34:03 +01:00
Johann150
197e4592b9
use configparser crate
This parser can correctly read globs from configuration keys which allows
their use not just in theory in the server logic but in the config file too.
2021-02-12 16:51:42 +01:00
Johann150
fdca530591
allow globs in config file paths
The configuration parser will have to be changed again because YAML does not
support asterisks in its key names.
2021-02-12 15:00:29 +01:00
Johann150
49813d0c68
serve hidden files if there is a .meta config for them 2021-02-11 18:46:20 +01:00
Johann150
bd9ed3255a
add central configuration mode
also slight correction of the documentation because we are now using YAML
(a space is now required behind the colon)
2021-02-11 09:04:38 +01:00
Johann150
8fd9ca15c3
better error message for missing keys (again)
adresses comments from #33
Loading the certificate and key file is done at startup because:
1. We can detect the incorrect file faster and fail the whole server and not
   just a worker thread. All subsequent worker threads would fail for the same
   reason anyway.
2. We do not have to read the same unchanged files over and over again. This
   is good because file I/O is slower than in-memory cloning instead.
2021-02-10 23:39:11 +01:00
Johann150
fb0a30e5fc
better error message for incorrect keys 2021-02-10 22:41:39 +01:00
Johann150
544f577b59
use YAML parser for sidecar files
The syntax so far is (compatible with) YAML.
2021-02-10 21:25:22 +01:00
Johann150
9d9fb3d31b
resolve merge conflicts 2021-02-09 19:52:29 +01:00
Johann150
a9588350a0
format using cargo fmt 2021-02-09 15:01:26 +01:00