diff --git a/onionshare.py b/onionshare.py index 9c2cd758..8568c4e4 100755 --- a/onionshare.py +++ b/onionshare.py @@ -13,44 +13,18 @@ from stem import SocketError from flask import Flask, Markup, Response, request, make_response, send_from_directory app = Flask(__name__) -auth_username = auth_password = filename = filehash = filesize = '' +# generate an unguessable string +slug = os.urandom(16).encode('hex') -def check_auth(username, password): - global auth_username, auth_password +# file information +filename = filehash = filesize = '' - if len(username) != 16 or len(password) != 16: - return False - - # constant time string comparison, to prevent timing attacks - valid = True - for i in range(16): - if username[i] != auth_username[i] or password[i] != auth_password[i]: - valid = False - return valid - -def authenticate(): - return Response( - 'Could not verify your access level for that URL.\n' - 'You have to login with proper credentials', 401, - {'WWW-Authenticate': 'Basic realm="Login Required"'}) - -def requires_auth(f): - @wraps(f) - def decorated(*args, **kwargs): - auth = request.authorization - if not auth or not check_auth(auth.username, auth.password): - return authenticate() - return f(*args, **kwargs) - return decorated - -@app.route("/") -@requires_auth +@app.route("/{0}".format(slug)) def index(): - global filename, filesize, filehash - return "
SHA1 checksum: {1}
File size: {2} bytes
SHA1 checksum: {2}
File size: {3} bytes