handle empty paths in request

This commit is contained in:
Jan Wolff 2020-05-24 19:08:07 +02:00
parent 458b25247d
commit aa041cc4a6
4 changed files with 16 additions and 89 deletions

View file

@ -39,15 +39,24 @@ to create a release build.
Starting
--------
Sheldon Director look for a config file in `/etc/sheldond.conf`. If you want to
change this, pass an alternative path on startup using the `-c` parameter.
Sheldon Director looks for a config file in `/etc/sheldond.conf`. If you want
to change this, pass an alternative path on startup using the `-c` parameter.
Use `-h` to get a list of all supported command line arguments.
You'll need a TLS certificate, I've chosen not to include an example in this
repository. Use OpenSSL to quickly generate one:
```sh
openssl req -x509 -newkey rsa:4096 -keyout doc/key.pem -out doc/cert.pem -days 365 -nodes
```
An example config file can be found in this repository in `doc/sheldond.conf`.
Use it to serve the content of the `doc/` directory on localhost:
```
```sh
sudo ./target/debug/sheldond -c ./doc/sheldond.conf
```
Try connecting to `gemini://localhost` via your favorite Gemini client!
Note: This sets the user to `nobody` and the group to `nobody` as well. This

View file

@ -1,32 +0,0 @@
-----BEGIN CERTIFICATE-----
MIIFlTCCA32gAwIBAgIUPqRiFp5Gc1b2Frbab/WcQ4Xdg74wDQYJKoZIhvcNAQEL
BQAwWTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDESMBAGA1UEAwwJbG9jYWxob3N0MCAX
DTIwMDUxNDE4NDI0NVoYDzIxMjAwNDIwMTg0MjQ1WjBZMQswCQYDVQQGEwJBVTET
MBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQ
dHkgTHRkMRIwEAYDVQQDDAlsb2NhbGhvc3QwggIiMA0GCSqGSIb3DQEBAQUAA4IC
DwAwggIKAoICAQCqDaso0s8+Rt9fILlF7koLcYJCjs+MjB0kpS7itdJj1YXW6a5l
zIRP9bMSSftVmHGR1qFo6suKbVEayCkTrw3PU6w7iW7CMiRK6XL1Ix4B5BY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uxGplqqEAGo7YQmQPb6uVmcnEPF1zkUI/t
mmkCggEAGgNF6D0eSSb9muKwxzoYH6SeFsP6gXDJcLGRvD6nLdO70tK8R5H3EWAj
68FTlYhn5n4ljbPcHfOI8yxNgeQj/G4w9LX5MvqzxIgphiYk9D/NH99aaxX/JFuM
X6ZlpZLoNKpYJPWYoDxuGWhp3k66W/Rnfby7k5L/wh5c/zt4Q8OCW1mFwRXBXcS9
I6Z9jK72M8L7jp6hZELRTDfuMNv2Wj9BLoHu5wF66LsK5bw9zhcIgRUWUF+M1FqD
DafTiG+aLvDTNor/PDirYsLpHNW0j0uN4NC4jcIFiKXsgks8v3pgOJylnkxtgsRn
Qdcfj82isy1JR/mZp2t+sasS1DGxNg==
-----END PRIVATE KEY-----

View file

@ -24,11 +24,13 @@ pub fn handle_request(config: &ServerConfig, mut stream: SslStream<TcpStream>) {
match stream.ssl_read(&mut buffer) {
Ok(s) => {
if s == 0 {
println!("received empty request buffer");
send_header(&mut stream, &response::bad_request());
return;
}
}
Err(_) => {
println!("received broken request");
send_header(&mut stream, &response::bad_request());
return;
}
@ -37,6 +39,7 @@ pub fn handle_request(config: &ServerConfig, mut stream: SslStream<TcpStream>) {
let request = match String::from_utf8(buffer.to_vec()) {
Ok(request) => request,
Err(_) => {
println!("received empty request string");
send_header(&mut stream, &response::bad_request());
return;
}
@ -79,8 +82,7 @@ fn handle_response(config: &ServerConfig, url: Url, mut stream: &mut SslStream<T
let rel_path = match Path::new(url.path()).strip_prefix("/") {
Ok(path) => path,
Err(_) => {
send_header(&mut stream, &response::bad_request());
return;
Path::new("")
}
};