You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.6 KiB

import json
import requests
from signedjson.key import generate_signing_key, get_verify_key, read_signing_keys
from signedjson.sign import (
sign_json, verify_signed_json, SignatureVerifyException
# curl
# curl ''
def authorization_headers(origin_name, origin_signing_key,
destination_name, request_method, request_target,
request_json = {
"method": request_method,
"uri": request_target,
"origin": origin_name,
"destination": destination_name,
if content is not None:
# Assuming content is already parsed as JSON
request_json["content"] = content
signed_json = sign_json(request_json, origin_name, origin_signing_key)
authorization_headers = []
for key, sig in signed_json["signatures"][origin_name].items():
"X-Matrix origin=\"%s\",destination=\"%s\",key=\"%s\",sig=\"%s\"" % (
origin_name, destination_name, key, sig),
return ("Authorization", authorization_headers[0])
sk = None
with open('homeserver.signing_key', 'r') as k:
sk = read_signing_keys(k)[0]
head_key, head_val = authorization_headers("", sk, "", "GET", "/_matrix/federation/unstable/rooms/!")
r = requests.get('!', headers = { head_key: head_val })