46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
|
|
from .config import Config
|
|
from .files import read_public_key, make_submission_address_file, make_policy_file
|
|
from .util import hash_user_id
|
|
|
|
from bottle import get, run, abort, response, request
|
|
|
|
|
|
@get('/.well-known/openpgpkey/<domain>/submission-address')
|
|
def submission_address(domain: str):
|
|
if domain not in Config.domains:
|
|
abort(404, 'Not Found')
|
|
response.add_header('Content-Type', 'text/plain')
|
|
return make_submission_address_file(domain)
|
|
|
|
|
|
@get('/.well-known/openpgpkey/<domain>/policy')
|
|
def policy(domain: str):
|
|
if domain not in Config.domains:
|
|
abort(404, 'Not Found')
|
|
response.add_header('Content-Type', 'text/plain')
|
|
return make_policy_file(domain)
|
|
|
|
|
|
@get('/.well-known/openpgpkey/<domain>/hu/<userhash>')
|
|
def hu(domain: str, userhash: str):
|
|
if domain not in Config.domains:
|
|
abort(404, 'Not Found')
|
|
userid = request.query.l
|
|
print(userid, userhash, hash_user_id(userid))
|
|
if not userid or hash_user_id(userid) != userhash:
|
|
abort(404, 'Not Found')
|
|
try:
|
|
pubkey = read_public_key(domain, userid)
|
|
response.add_header('Content-Type', 'application/octet-stream')
|
|
return bytes(pubkey)
|
|
except FileNotFoundError:
|
|
abort(404, 'Not Found')
|
|
|
|
|
|
def run_server():
|
|
run(host=Config.host, port=Config.port)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
run_server()
|