From 94521cdc1ae27dbfe131b8d222079bf5523db2e0 Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 11 Feb 2021 22:48:10 +0000 Subject: [PATCH] add --https-only --- copyparty/__main__.py | 1 + copyparty/httpconn.py | 14 +++++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 84e8e82b..d50f7c8a 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -205,6 +205,7 @@ def main(): ap.add_argument("--no-sendfile", action="store_true", help="disable sendfile") ap.add_argument("--urlform", type=str, default="print,get", help="how to handle url-forms") ap.add_argument("--ssl-ver", type=str, help="ssl/tls versions to allow") + ap.add_argument("--https-only", action="store_true", help="disable plaintext") al = ap.parse_args() # fmt: on diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index 3ce53ae1..e0d43219 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -75,9 +75,8 @@ class HttpConn(object): def log(self, msg): self.log_func(self.log_src, msg) - def run(self): + def _detect_https(self): method = None - self.sr = None if self.cert_path: try: method = self.s.recv(4, socket.MSG_PEEK) @@ -102,7 +101,16 @@ class HttpConn(object): 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", b"PUT ", b"OPTI"]: + return method not in [None, b"GET ", b"HEAD", b"POST", b"PUT ", b"OPTI"] + + def run(self): + self.sr = None + if self.args.https_only: + is_https = True + else: + is_https = self._detect_https() + + if is_https: if self.sr: self.log("\033[1;31mTODO: cannot do https in jython\033[0m") return