remote watchtower: initial commit
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
|
||||
#!/usr/bin/env python3
|
||||
#
|
||||
# Electrum - lightweight Bitcoin client
|
||||
@@ -48,12 +49,10 @@ class RPCAuthUnsupportedType(Exception):
|
||||
|
||||
|
||||
# based on http://acooke.org/cute/BasicHTTPA0.html by andrew cooke
|
||||
class VerifyingJSONRPCServer(SimpleJSONRPCServer, Logger):
|
||||
class AuthenticatedJSONRPCServer(SimpleJSONRPCServer, Logger):
|
||||
|
||||
def __init__(self, *args, rpc_user, rpc_password, **kargs):
|
||||
def __init__(self, *args, **kargs):
|
||||
Logger.__init__(self)
|
||||
self.rpc_user = rpc_user
|
||||
self.rpc_password = rpc_password
|
||||
|
||||
class VerifyingRequestHandler(SimpleJSONRPCRequestHandler):
|
||||
def parse_request(myself):
|
||||
@@ -73,10 +72,20 @@ class VerifyingJSONRPCServer(SimpleJSONRPCServer, Logger):
|
||||
self.logger.exception('')
|
||||
myself.send_error(500, repr(e))
|
||||
return False
|
||||
|
||||
SimpleJSONRPCServer.__init__(
|
||||
self, requestHandler=VerifyingRequestHandler, *args, **kargs)
|
||||
|
||||
def authenticate(self, headers):
|
||||
raise Exception('undefined')
|
||||
|
||||
|
||||
class PasswordProtectedJSONRPCServer(AuthenticatedJSONRPCServer):
|
||||
|
||||
def __init__(self, *args, rpc_user, rpc_password, **kargs):
|
||||
self.rpc_user = rpc_user
|
||||
self.rpc_password = rpc_password
|
||||
AuthenticatedJSONRPCServer.__init__(self, *args, **kargs)
|
||||
|
||||
def authenticate(self, headers):
|
||||
if self.rpc_password == '':
|
||||
# RPC authentication is disabled
|
||||
@@ -97,3 +106,21 @@ class VerifyingJSONRPCServer(SimpleJSONRPCServer, Logger):
|
||||
and util.constant_time_compare(password, self.rpc_password)):
|
||||
time.sleep(0.050)
|
||||
raise RPCAuthCredentialsInvalid()
|
||||
|
||||
|
||||
class AccountsJSONRPCServer(AuthenticatedJSONRPCServer):
|
||||
""" user accounts """
|
||||
|
||||
def __init__(self, *args, **kargs):
|
||||
self.users = {}
|
||||
AuthenticatedJSONRPCServer.__init__(self, *args, **kargs)
|
||||
self.register_function(self.add_user, 'add_user')
|
||||
|
||||
def authenticate(self, headers):
|
||||
# todo: verify signature
|
||||
return
|
||||
|
||||
def add_user(self, pubkey):
|
||||
user_id = len(self.users)
|
||||
self.users[user_id] = pubkey
|
||||
return user_id
|
||||
|
||||
Reference in New Issue
Block a user