blob: f61b22b1126a675967bd44b923c8bdaf8d335804 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#! /usr/bin/env python3
from http.server import *
import json
import tempfile
import base64
class HandlerClass(BaseHTTPRequestHandler):
def __init__(self, request, client_address, server):
self.timeout = 20
BaseHTTPRequestHandler.__init__(self, request, client_address, server)
def do_POST(self):
to_read = int(self.headers['Content-Length'])
data = self.rfile.read(to_read)
if len(data) > 0:
dat_str = data.decode("ascii")
body = json.loads(dat_str)
ssh_key = body['ssh']
gpg_key = body['gpg']
print("your (base64) ssh_key: " + ssh_key)
print("your (base64) gpg_key: " + gpg_key)
ssh_keypath = as_tempfile(base64.b64decode(ssh_key))
gpg_keypath = as_tempfile(base64.b64decode(gpg_key))
recv_keys(ssh_keypath, gpg_keypath)
self.send_response(200)
self.end_headers()
def as_tempfile(content):
tmpfile = tempfile.NamedTemporaryFile()
tmpfile.write(content)
return tmpfile
def main():
print("Running on port whatever")
server_address = ('', 8002)
httpd = HTTPServer(server_address, HandlerClass)
httpd.serve_forever()
main()
|