class BlindlySignStuffServlet(Resource): isLeaf = True def __init__(self, syd): self.server_name = syd.server_name self.tokenStore = JoinTokenStore(syd) def render_POST(self, request): send_cors(request) err, args = get_args(request, ("private_key", "token", "mxid")) if err: return json.dumps(err) private_key_base64 = args['private_key'] token = args['token'] mxid = args['mxid'] sender = self.tokenStore.getSenderForToken(token) if sender is None: request.setResponseCode(404) return json.dumps({ "errcode": "M_UNRECOGNIZED", "error": "Didn't recognize token", }) to_sign = { "mxid": mxid, "sender": sender, "token": token, } try: private_key = signedjson.key.decode_signing_key_base64( "ed25519", "0", private_key_base64 ) signed = signedjson.sign.sign_json( to_sign, self.server_name, private_key ) except: return json.dumps({ "errcode": "M_UNKNOWN", }) return json.dumps(signed) @jsonwrap def render_OPTIONS(self, request): send_cors(request) request.setResponseCode(200) return {}
class BlindlySignStuffServlet(Resource): isLeaf = True def __init__(self, syd): self.server_name = syd.server_name self.tokenStore = JoinTokenStore(syd) def render_POST(self, request): send_cors(request) err, args = get_args(request, ("private_key", "token", "mxid")) if err: return json.dumps(err) private_key_base64 = args['private_key'] token = args['token'] mxid = args['mxid'] sender = self.tokenStore.getSenderForToken(token) if sender is None: request.setResponseCode(404) return json.dumps({ "errcode": "M_UNRECOGNIZED", "error": "Didn't recognize token", }) to_sign = { "mxid": mxid, "sender": sender, "token": token, } try: private_key = signedjson.key.decode_signing_key_base64( "ed25519", "0", private_key_base64) signed = signedjson.sign.sign_json(to_sign, self.server_name, private_key) except: return json.dumps({ "errcode": "M_UNKNOWN", }) return json.dumps(signed) @jsonwrap def render_OPTIONS(self, request): send_cors(request) request.setResponseCode(200) return {}
class BlindlySignStuffServlet(Resource): isLeaf = True def __init__(self, syd: "Sydent", require_auth: bool = False) -> None: self.sydent = syd self.server_name = syd.config.general.server_name self.tokenStore = JoinTokenStore(syd) self.require_auth = require_auth @jsonwrap def render_POST(self, request: Request) -> JsonDict: send_cors(request) if self.require_auth: authV2(self.sydent, request) args = get_args(request, ("private_key", "token", "mxid")) private_key_base64 = args["private_key"] token = args["token"] mxid = args["mxid"] sender = self.tokenStore.getSenderForToken(token) if sender is None: raise MatrixRestError(404, "M_UNRECOGNIZED", "Didn't recognize token") to_sign = { "mxid": mxid, "sender": sender, "token": token, } try: private_key = signedjson.key.decode_signing_key_base64( "ed25519", "0", private_key_base64 ) signed: JsonDict = signedjson.sign.sign_json( to_sign, self.server_name, private_key ) except Exception: logger.exception("signing failed") raise MatrixRestError(500, "M_UNKNOWN", "Internal Server Error") return signed def render_OPTIONS(self, request: Request) -> bytes: send_cors(request) return b""
class BlindlySignStuffServlet(Resource): isLeaf = True def __init__(self, syd): self.sydent = syd self.server_name = syd.server_name self.tokenStore = JoinTokenStore(syd) @jsonwrap def render_POST(self, request): send_cors(request) authIfV2(self.sydent, request) args = get_args(request, ("private_key", "token", "mxid")) private_key_base64 = args['private_key'] token = args['token'] mxid = args['mxid'] sender = self.tokenStore.getSenderForToken(token) if sender is None: raise MatrixRestError(404, "M_UNRECOGNIZED", "Didn't recognize token") to_sign = { "mxid": mxid, "sender": sender, "token": token, } try: private_key = signedjson.key.decode_signing_key_base64( "ed25519", "0", private_key_base64) signed = signedjson.sign.sign_json(to_sign, self.server_name, private_key) except: logger.exception("signing failed") raise MatrixRestError(500, "M_UNKNOWN", "Internal Server Error") return signed def render_OPTIONS(self, request): send_cors(request) request.setResponseCode(200) return b''