Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for https endpoints in witnesses and controllers #555

Merged
merged 3 commits into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/keri/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ def get(self, pre, sn=None):
return

wit = random.choice(hab.kever.wits)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http) or hab.fetchUrls(eid=wit, scheme=kering.Schemes.https)
if not urls:
raise kering.MissingEntryError(f"unable to query witness {wit}, no http endpoint")

base = urls[kering.Schemes.http]
base = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
url = urljoin(base, f"/receipts?pre={pre}&sn={sn}")

client = self.clienter.request("GET", url)
Expand Down Expand Up @@ -731,10 +731,10 @@ def __init__(self, hab, wit, url, msgs=None, sent=None, doers=None, **kwa):
doers.extend([doing.doify(self.msgDo), doing.doify(self.responseDo)])

up = urlparse(url)
if up.scheme != kering.Schemes.http:
if up.scheme != kering.Schemes.http and up.scheme != kering.Schemes.https:
raise ValueError(f"invalid scheme {up.scheme} for HTTPMessenger")

self.client = http.clienting.Client(hostname=up.hostname, port=up.port)
self.client = http.clienting.Client(scheme=up.scheme, hostname=up.hostname, port=up.port)
clientDoer = http.clienting.ClientDoer(client=self.client)

doers.extend([clientDoer])
Expand Down Expand Up @@ -825,8 +825,8 @@ def messengerFrom(hab, pre, urls):
Returns:
Optional(TcpWitnesser, HTTPMessenger): witnesser for ensuring full reciepts
"""
if kering.Schemes.http in urls:
url = urls[kering.Schemes.http]
if kering.Schemes.http in urls or kering.Schemes.https in urls:
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
witer = HTTPMessenger(hab=hab, wit=pre, url=url)
elif kering.Schemes.tcp in urls:
url = urls[kering.Schemes.tcp]
Expand All @@ -849,12 +849,13 @@ def httpClient(hab, wit):
ClientDoer: Doer for client

"""
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http) or hab.fetchUrls(eid=wit, scheme=kering.Schemes.https)
if not urls:
raise kering.MissingEntryError(f"unable to query witness {wit}, no http endpoint")

up = urlparse(urls[kering.Schemes.http])
client = http.clienting.Client(hostname=up.hostname, port=up.port)
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
client = http.clienting.Client(scheme=up.scheme, hostname=up.hostname, port=up.port)
clientDoer = http.clienting.ClientDoer(client=client)

return client, clientDoer
Expand Down
14 changes: 8 additions & 6 deletions src/keri/app/cli/commands/did/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,20 @@ def generate(tymth, tock=0.0, **opts):
sys.exit(-1)

wit = random.choice(hab.kever.wits)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http) or hab.fetchUrls(eid=wit, scheme=kering.Schemes.https)
if not urls:
raise kering.ConfigurationError(f"unable to query witness {wit}, no http endpoint")

up = urlparse(urls[kering.Schemes.http])
enc = urllib.parse.quote_plus(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/witness")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
enc = urllib.parse.quote_plus(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/witness")
print(f"did:keri:{hab.pre}?oobi={enc}")
elif role in (kering.Roles.controller,):
urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http) or hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.https)
if not urls:
print(f"{alias} identifier {hab.pre} does not have any controller endpoints")
return
up = urlparse(urls[kering.Schemes.http])
enc = urllib.parse.quote_plus(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
enc = urllib.parse.quote_plus(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
print(f"did:keri:{hab.pre}?oobi={enc}")
14 changes: 8 additions & 6 deletions src/keri/app/cli/commands/oobi/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,18 @@ def generate(tymth, tock=0.0, **opts):
sys.exit(-1)

for wit in hab.kever.wits:
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http) or hab.fetchUrls(eid=wit, scheme=kering.Schemes.https)
if not urls:
raise kering.ConfigurationError(f"unable to query witness {wit}, no http endpoint")

up = urlparse(urls[kering.Schemes.http])
print(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/witness")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
print(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/witness")
elif role in (kering.Roles.controller,):
urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http) or hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.https)
if not urls:
print(f"{alias} identifier {hab.pre} does not have any controller endpoints")
return
up = urlparse(urls[kering.Schemes.http])
print(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
print(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
14 changes: 8 additions & 6 deletions src/keri/app/oobiing.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,24 +122,26 @@ def on_get_alias(self, req, rep, alias=None):
if role in (kering.Roles.witness,): # Fetch URL OOBIs for all witnesses
oobis = []
for wit in hab.kever.wits:
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=wit, scheme=kering.Schemes.http) or hab.fetchUrls(eid=wit, scheme=kering.Schemes.https)
if not urls:
rep.status = falcon.HTTP_404
rep.text = f"unable to query witness {wit}, no http endpoint"
return

up = urlparse(urls[kering.Schemes.http])
oobis.append(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/witness/{wit}")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/witness/{wit}")
res["oobis"] = oobis
elif role in (kering.Roles.controller,): # Fetch any controller URL OOBIs
oobis = []
urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http)
urls = hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.http) or hab.fetchUrls(eid=hab.pre, scheme=kering.Schemes.https)
if not urls:
rep.status = falcon.HTTP_404
rep.text = f"unable to query controller {hab.pre}, no http endpoint"
return
up = urlparse(urls[kering.Schemes.http])
oobis.append(f"http://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
url = urls[kering.Schemes.http] if kering.Schemes.http in urls else urls[kering.Schemes.https]
up = urlparse(url)
oobis.append(f"{up.scheme}://{up.hostname}:{up.port}/oobi/{hab.pre}/controller")
res["oobis"] = oobis
else:
rep.status = falcon.HTTP_404
Expand Down
Loading