Handle onion based nodeinfo

main
Bob Mottram 2020-03-27 12:18:11 +00:00
parent 279f6ece20
commit b8b0d962e2
1 changed files with 20 additions and 7 deletions

View File

@ -618,7 +618,7 @@ class PubServer(BaseHTTPRequestHandler):
self._404() self._404()
return True return True
def _webfinger(self) -> bool: def _webfinger(self,callingDomain: str) -> bool:
if not self.path.startswith('/.well-known'): if not self.path.startswith('/.well-known'):
return False return False
if self.server.debug: if self.server.debug:
@ -627,7 +627,13 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug: if self.server.debug:
print('DEBUG: WEBFINGER host-meta') print('DEBUG: WEBFINGER host-meta')
if self.path.startswith('/.well-known/host-meta'): if self.path.startswith('/.well-known/host-meta'):
wfResult=webfingerMeta(self.server.httpPrefix,self.server.domainFull) if not callingDomain.endswith('.onion'):
wfResult= \
webfingerMeta(self.server.httpPrefix, \
self.server.domainFull)
else:
wfResult= \
webfingerMeta('http',self.server.onionDomain)
if wfResult: if wfResult:
msg=wfResult.encode('utf-8') msg=wfResult.encode('utf-8')
self._set_headers('application/xrd+xml',len(msg),None) self._set_headers('application/xrd+xml',len(msg),None)
@ -636,7 +642,13 @@ class PubServer(BaseHTTPRequestHandler):
self._404() self._404()
return True return True
if self.path.startswith('/.well-known/nodeinfo'): if self.path.startswith('/.well-known/nodeinfo'):
wfResult=webfingerNodeInfo(self.server.httpPrefix,self.server.domainFull) if not callingDomain.endswith('.onion'):
wfResult= \
webfingerNodeInfo(self.server.httpPrefix, \
self.server.domainFull)
else:
wfResult= \
webfingerNodeInfo('http',self.server.onionDomain)
if wfResult: if wfResult:
msg=json.dumps(wfResult).encode('utf-8') msg=json.dumps(wfResult).encode('utf-8')
if self.headers.get('Accept'): if self.headers.get('Accept'):
@ -653,9 +665,10 @@ class PubServer(BaseHTTPRequestHandler):
if self.server.debug: if self.server.debug:
print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir)) print('DEBUG: WEBFINGER lookup '+self.path+' '+str(self.server.baseDir))
wfResult=webfingerLookup(self.path,self.server.baseDir, \ wfResult= \
self.server.domain,self.server.onionDomain, \ webfingerLookup(self.path,self.server.baseDir, \
self.server.port,self.server.debug) self.server.domain,self.server.onionDomain, \
self.server.port,self.server.debug)
if wfResult: if wfResult:
msg=json.dumps(wfResult).encode('utf-8') msg=json.dumps(wfResult).encode('utf-8')
self._set_headers('application/jrd+json',len(msg),None) self._set_headers('application/jrd+json',len(msg),None)
@ -1608,7 +1621,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.GETbusy=False self.server.GETbusy=False
return return
# get webfinger endpoint for a person # get webfinger endpoint for a person
if self._webfinger(): if self._webfinger(callingDomain):
self.server.GETbusy=False self.server.GETbusy=False
return return