From 0bfb77844652a400796a1400edd689c2caa3d9cb Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 25 Jun 2019 23:21:15 +0000 Subject: [PATCH] TLS error handling --- README.md | 12 ++++++++++++ copyparty/httpconn.py | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 93cab981..bc55b17b 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ * http file sharing hub (py2/py3) * MIT-Licensed, 2019-05-26, ed @ irc.rizon.net + ## summary turn your phone or raspi into a portable file server with resumable uploads/downloads using IE6 or any other browser @@ -11,6 +12,7 @@ turn your phone or raspi into a portable file server with resumable uploads/down * *resumable* uploads need `firefox 12+` / `chrome 6+` / `safari 6+` / `IE 10+` * code standard: `black` + ## status * [x] sanic multipart parser @@ -49,6 +51,7 @@ after the initial setup (and restarting bash), you can launch copyparty at any t # dev env setup + ```sh python3 -m venv .env . .env/bin/activate @@ -58,6 +61,15 @@ pip install black bandit pylint flake8 # vscode tooling ``` +# how to release + +in the `scripts` folder: + +* run `make -C deps-docker` to build all dependencies +* create github release with `make-tgz-release.sh` +* upload to pypi with `make-pypi-release.(sh|bat)` + + # immediate todo roughly sorted by priority diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index 27ab28a7..790aaa35 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -46,11 +46,11 @@ class HttpConn(object): if self.cert_path: method = self.s.recv(4, socket.MSG_PEEK) if len(method) != 4: - err = b"need at least 4 bytes in the first packet; got {}".format( + err = "need at least 4 bytes in the first packet; got {}".format( len(method) ) self.log(err) - self.s.send(b"HTTP/1.1 400 Bad Request\r\n\r\n" + err) + self.s.send(b"HTTP/1.1 400 Bad Request\r\n\r\n" + err.encode("utf-8")) return if method not in [None, b"GET ", b"HEAD", b"POST"]: @@ -60,10 +60,18 @@ class HttpConn(object): self.s, server_side=True, certfile=self.cert_path ) except Exception as ex: - if "ALERT_BAD_CERTIFICATE" in str(ex): + em = str(ex) + + if "ALERT_BAD_CERTIFICATE" in em: + # firefox-linux if there is no exception yet self.log("client rejected our certificate (nice)") + + elif "ALERT_CERTIFICATE_UNKNOWN" in em: + # chrome-android keeps doing this + pass + else: - self.log("\033[35mhandshake\033[0m " + str(ex)) + self.log("\033[35mhandshake\033[0m " + em) return