mirror of https://gitlab.com/bashrc2/epicyon
Merge branch 'main' of gitlab.com:bashrc2/epicyon
commit
fe6c0e9098
7
cache.py
7
cache.py
|
@ -147,7 +147,12 @@ def get_person_pub_key(base_dir: str, session, person_url: str,
|
||||||
"""
|
"""
|
||||||
if not person_url:
|
if not person_url:
|
||||||
return None
|
return None
|
||||||
person_url = person_url.replace('#main-key', '')
|
if '#/publicKey' in person_url:
|
||||||
|
person_url = person_url.replace('#/publicKey', '')
|
||||||
|
elif '/main-key' in person_url:
|
||||||
|
person_url = person_url.replace('/main-key', '')
|
||||||
|
else:
|
||||||
|
person_url = person_url.replace('#main-key', '')
|
||||||
users_paths = get_user_paths()
|
users_paths = get_user_paths()
|
||||||
for possible_users_path in users_paths:
|
for possible_users_path in users_paths:
|
||||||
if person_url.endswith(possible_users_path + 'inbox'):
|
if person_url.endswith(possible_users_path + 'inbox'):
|
||||||
|
|
58
daemon.py
58
daemon.py
|
@ -709,7 +709,7 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
if signature_item.startswith('keyId='):
|
if signature_item.startswith('keyId='):
|
||||||
if '"' in signature_item:
|
if '"' in signature_item:
|
||||||
key_id = signature_item.split('"')[1]
|
key_id = signature_item.split('"')[1]
|
||||||
# remove #main-key
|
# remove #/main-key or #main-key
|
||||||
if '#' in key_id:
|
if '#' in key_id:
|
||||||
key_id = key_id.split('#')[0]
|
key_id = key_id.split('#')[0]
|
||||||
return key_id
|
return key_id
|
||||||
|
@ -795,6 +795,44 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
print('AUTH: secure mode authorization failed for ' + key_id)
|
print('AUTH: secure mode authorization failed for ' + key_id)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def _get_account_pub_key(self, path: str, person_cache: {},
|
||||||
|
base_dir: str, http_prefix: str,
|
||||||
|
domain: str, onion_domain: str,
|
||||||
|
i2p_domain: str,
|
||||||
|
calling_domain: str) -> str:
|
||||||
|
"""Returns the public key for an account
|
||||||
|
"""
|
||||||
|
if '/users/' not in path:
|
||||||
|
return None
|
||||||
|
nickname = path.split('/users/')[1]
|
||||||
|
if '#main-key' in nickname:
|
||||||
|
nickname = nickname.split('#main-key')[0]
|
||||||
|
elif '/main-key' in nickname:
|
||||||
|
nickname = nickname.split('/main-key')[0]
|
||||||
|
elif '#/publicKey' in nickname:
|
||||||
|
nickname = nickname.split('#/publicKey')[0]
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
if calling_domain.endswith('.onion'):
|
||||||
|
actor = 'http://' + onion_domain + '/users/' + nickname
|
||||||
|
elif calling_domain.endswith('.i2p'):
|
||||||
|
actor = 'http://' + i2p_domain + '/users/' + nickname
|
||||||
|
else:
|
||||||
|
actor = http_prefix + '://' + domain + '/users/' + nickname
|
||||||
|
actor_json = get_person_from_cache(base_dir, actor, person_cache)
|
||||||
|
if not actor_json:
|
||||||
|
actor_filename = acct_dir(base_dir, nickname, domain) + '.json'
|
||||||
|
if not os.path.isfile(actor_filename):
|
||||||
|
return None
|
||||||
|
actor_json = load_json(actor_filename, 1, 1)
|
||||||
|
if not actor_json:
|
||||||
|
return None
|
||||||
|
store_person_in_cache(base_dir, actor, actor_json,
|
||||||
|
person_cache, False)
|
||||||
|
if not actor_json.get('publicKey'):
|
||||||
|
return None
|
||||||
|
return actor_json['publicKey']
|
||||||
|
|
||||||
def _login_headers(self, file_format: str, length: int,
|
def _login_headers(self, file_format: str, length: int,
|
||||||
calling_domain: str) -> None:
|
calling_domain: str) -> None:
|
||||||
self.send_response(200)
|
self.send_response(200)
|
||||||
|
@ -15212,6 +15250,24 @@ class PubServer(BaseHTTPRequestHandler):
|
||||||
self.server.domain):
|
self.server.domain):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# getting the public key for an account
|
||||||
|
acct_pub_key_json = \
|
||||||
|
self._get_account_pub_key(self.path, self.server.person_cache,
|
||||||
|
self.server.base_dir,
|
||||||
|
self.server.http_prefix,
|
||||||
|
self.server.domain,
|
||||||
|
self.server.onion_domain,
|
||||||
|
self.server.i2p_domain,
|
||||||
|
calling_domain)
|
||||||
|
if acct_pub_key_json:
|
||||||
|
msg_str = json.dumps(acct_pub_key_json, ensure_ascii=False)
|
||||||
|
msg = msg_str.encode('utf-8')
|
||||||
|
msglen = len(msg)
|
||||||
|
self._set_headers('application/json',
|
||||||
|
msglen, None, calling_domain, False)
|
||||||
|
self._write(msg)
|
||||||
|
return
|
||||||
|
|
||||||
# Since fediverse crawlers are quite active,
|
# Since fediverse crawlers are quite active,
|
||||||
# make returning info to them high priority
|
# make returning info to them high priority
|
||||||
# get nodeinfo endpoint
|
# get nodeinfo endpoint
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -921,7 +921,11 @@ def add_alternate_domains(actor_json: {}, domain: str,
|
||||||
def person_lookup(domain: str, path: str, base_dir: str) -> {}:
|
def person_lookup(domain: str, path: str, base_dir: str) -> {}:
|
||||||
"""Lookup the person for an given nickname
|
"""Lookup the person for an given nickname
|
||||||
"""
|
"""
|
||||||
if path.endswith('#main-key'):
|
if path.endswith('#/publicKey'):
|
||||||
|
path = path.replace('#/publicKey', '')
|
||||||
|
elif path.endswith('/main-key'):
|
||||||
|
path = path.replace('/main-key', '')
|
||||||
|
elif path.endswith('#main-key'):
|
||||||
path = path.replace('#main-key', '')
|
path = path.replace('#main-key', '')
|
||||||
# is this a shared inbox lookup?
|
# is this a shared inbox lookup?
|
||||||
is_shared_inbox = False
|
is_shared_inbox = False
|
||||||
|
|
Loading…
Reference in New Issue