Skip to content

Commit

Permalink
Merge remote-tracking branch 'wot/main' into fix_del_ddos
Browse files Browse the repository at this point in the history
fixed merge conflicts
  • Loading branch information
SmithSamuelM committed Sep 9, 2024
2 parents fe7ce5d + 9d9a481 commit 9f64bdf
Show file tree
Hide file tree
Showing 21 changed files with 277 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

.PHONY: build-keri

VERSION=MULTI_ARCH_TEST
VERSION=1.2.0-dev13

define DOCKER_WARNING
In order to use the multi-platform build enable the containerd image store
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
from setuptools import find_packages, setup
setup(
name='keri',
version='1.2.0-dev12', # also change in src/keri/__init__.py
version='1.2.0-dev13', # also change in src/keri/__init__.py
license='Apache Software License 2.0',
description='Key Event Receipt Infrastructure',
long_description="KERI Decentralized Key Management Infrastructure",
Expand Down
2 changes: 1 addition & 1 deletion src/keri/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -*- encoding: utf-8 -*-

__version__ = '1.2.0-dev12' # also change in setup.py
__version__ = '1.2.0-dev13' # also change in setup.py


5 changes: 3 additions & 2 deletions src/keri/app/agenting.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def msgDo(self, tymth=None, tock=1.0, **opts):

yield self.tock

def query(self, pre, r="logs", sn='0', src=None, hab=None, anchor=None, wits=None, **kwa):
def query(self, pre, r="logs", sn='0', fn='0', src=None, hab=None, anchor=None, wits=None, **kwa):
""" Create, sign and return a `qry` message against the attester for the prefix
Parameters:
Expand All @@ -534,14 +534,15 @@ def query(self, pre, r="logs", sn='0', src=None, hab=None, anchor=None, wits=Non
pre (str): qb64 identifier prefix being queried for
r (str): query route
sn (str): optional specific hex str of sequence number to query for
fn (str): optional specific hex str of sequence number to start with
anchor (Seal): anchored Seal to search for
wits (list) witnesses to query
Returns:
bytearray: signed query event
"""
qry = dict(s=sn)
qry = dict(s=sn, fn=fn)
if anchor is not None:
qry["a"] = anchor

Expand Down
84 changes: 84 additions & 0 deletions src/keri/app/cli/commands/event.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# -*- encoding: utf-8 -*-
"""
KERI
keri.kli.commands module
"""
import argparse
import json

from hio import help
from hio.base import doing

from keri.app.cli.common import existing
from keri.kering import ConfigurationError

logger = help.ogler.getLogger()

parser = argparse.ArgumentParser(description='Print an event from an AID, or specific values from an event (defaults to latest event).')
parser.set_defaults(handler=lambda args: handler(args),
transferable=True)
parser.add_argument('--name', '-n', help='keystore name and file location of KERI keystore', required=True)
parser.add_argument('--base', '-b', help='additional optional prefix to file location of KERI keystore',
required=False, default="")
parser.add_argument('--alias', '-a', help='human readable alias for the new identifier prefix', default=None,
required=True)
parser.add_argument('--passcode', '-p', help='21 character encryption passcode for keystore (is not saved)',
dest="bran", default=None) # passcode => bran
parser.add_argument('--said', '-S', help='Print the SAID of the event in question', action="store_true")
parser.add_argument('--sn', '-s', help='Print the decimal value of the sequence number of the event in question',
action="store_true")
parser.add_argument('--snh', help='Print the decimal value of the sequence number of the event in question',
action="store_true")
parser.add_argument('--raw', '-r', help='Print the raw, signed value of the event', action="store_true")
parser.add_argument('--json', '-j', help='Pretty print the JSON of the event.', action="store_true")
parser.add_argument('--seal', help='Print an anchorable seal of the event in question.', action="store_true")


def handler(args):
kwa = dict(args=args)
return [doing.doify(event, **kwa)]


def event(tymth, tock=0.0, **opts):
""" Command line status handler
"""
_ = (yield tock)
args = opts["args"]
name = args.name
alias = args.alias
base = args.base
bran = args.bran

try:
with existing.existingHby(name=name, base=base, bran=bran) as hby:
if alias is None:
alias = existing.aliasInput(hby)

hab = hby.habByName(alias)
if hab is None:
print(f"{alias} is not a valid identifier")

if args.said:
print(hab.kever.serder.said)

if args.sn:
print(hab.kever.sn)

if args.snh:
print(hab.kever.serder.snh)

if args.raw:
print(hab.kever.serder.raw.decode("utf-8"))

if args.json:
print(hab.kever.serder.pretty())

if args.seal:
seal = dict(i=hab.pre, s=hab.kever.serder.snh, d=hab.kever.serder.said)
print(json.dumps(seal))

except ConfigurationError as e:
print(f"identifier prefix for {name} does not exist, incept must be run first", )
return -1
10 changes: 7 additions & 3 deletions src/keri/app/cli/commands/incept.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,10 @@ def __init__(self, name, base, alias, bran, endpoint, proxy=None, cnfg=None, **k
reopen=True,
clear=False)
self.endpoint = endpoint
self.proxy = proxy
self.hby = existing.setupHby(name=name, base=base, bran=bran, cf=cf)
self.proxy = self.hby.habByName(proxy) if proxy is not None else None
self.hbyDoer = habbing.HaberyDoer(habery=self.hby) # setup doer
self.swain = delegating.Anchorer(hby=self.hby, proxy=self.hby.habByName(self.proxy))
self.swain = delegating.Anchorer(hby=self.hby, proxy=self.proxy)
self.postman = forwarding.Poster(hby=self.hby)
self.mbx = indirecting.MailboxDirector(hby=self.hby, topics=['/receipt', "/replay", "/reply"])
doers = [self.hbyDoer, self.postman, self.mbx, self.swain, doing.doify(self.inceptDo)]
Expand Down Expand Up @@ -185,7 +185,11 @@ def inceptDo(self, tymth, tock=0.0):
_ = yield self.tock

if hab.kever.delpre:
yield from self.postman.sendEvent(hab=hab, fn=hab.kever.sn)
if self.proxy is not None:
sender = self.proxy
else:
sender = hab
yield from self.postman.sendEventToDelegator(hab=hab, sender=sender, fn=hab.kever.sn)

print(f'Prefix {hab.pre}')
for idx, verfer in enumerate(hab.kever.verfers):
Expand Down
17 changes: 15 additions & 2 deletions src/keri/app/cli/commands/interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
dest="endpoint", action='store_true')
parser.add_argument("--authenticate", '-z', help="Prompt the controller for authentication codes for each witness",
action='store_true')
parser.add_argument('--code', help='<Witness AID>:<code> formatted witness auth codes. Can appear multiple times',
default=[], action="append", required=False)
parser.add_argument('--code-time', help='Time the witness codes were captured.', default=None, required=False)


def interact(args):
Expand Down Expand Up @@ -57,7 +60,7 @@ def interact(args):
data = None

ixnDoer = InteractDoer(name=name, base=base, alias=alias, bran=bran, data=data, authenticate=args.authenticate,
endpoint=args.endpoint)
endpoint=args.endpoint, codes=args.code, codeTime=args.code_time)

return [ixnDoer]

Expand All @@ -68,7 +71,8 @@ class InteractDoer(doing.DoDoer):
to all appropriate witnesses
"""

def __init__(self, name, base, bran, alias, data: list = None, endpoint=False, authenticate=False):
def __init__(self, name, base, bran, alias, data: list = None, endpoint=False, authenticate=False,
codes=None, codeTime=None):
"""
Returns DoDoer with all registered Doers needed to perform interaction event.
Expand All @@ -82,6 +86,8 @@ def __init__(self, name, base, bran, alias, data: list = None, endpoint=False, a
self.data = data
self.endpoint = endpoint
self.authenticate = authenticate
self.codes = codes if codes is not None else []
self.codeTime = codeTime

self.hby = existing.setupHby(name=name, base=base, bran=bran)
self.hbyDoer = habbing.HaberyDoer(habery=self.hby) # setup doer
Expand All @@ -105,7 +111,14 @@ def interactDo(self, tymth, tock=0.0, **opts):

auths = {}
if self.authenticate:
codeTime = helping.fromIso8601(self.codeTime) if self.codeTime is not None else helping.nowIso8601()
for arg in self.codes:
(wit, code) = arg.split(":")
auths[wit] = f"{code}#{codeTime}"

for wit in hab.kever.wits:
if wit in auths:
continue
code = input(f"Entire code for {wit}: ")
auths[wit] = f"{code}#{helping.nowIso8601()}"

Expand Down
2 changes: 1 addition & 1 deletion src/keri/app/cli/commands/multisig/incept.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def inceptDo(self, tymth, tock=0.0):
yield self.tock

if ghab.kever.delpre:
yield from self.postman.sendEvent(hab=ghab, fn=ghab.kever.sn)
yield from self.postman.sendEventToDelegator(hab=ghab, sender=ghab.mhab, fn=ghab.kever.sn)

print()
displaying.printIdentifier(self.hby, ghab.pre)
Expand Down
2 changes: 1 addition & 1 deletion src/keri/app/cli/commands/multisig/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def rotateDo(self, tymth, tock=0.0, **opts):
yield self.tock

if ghab.kever.delpre:
yield from self.postman.sendEvent(hab=ghab, fn=ghab.kever.sn)
yield from self.postman.sendEventToDelegator(hab=ghab, sender=ghab.mhab, fn=ghab.kever.sn)

print()
displaying.printIdentifier(self.hby, ghab.pre)
Expand Down
15 changes: 10 additions & 5 deletions src/keri/app/cli/commands/rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
default=[], action="append", required=False)
parser.add_argument('--code-time', help='Time the witness codes were captured.', default=None, required=False)

parser.add_argument("--proxy", help="alias for delegation communication proxy", default="")
parser.add_argument("--proxy", help="alias for delegation communication proxy", default=None)

rotating.addRotationArgs(parser)

Expand Down Expand Up @@ -148,7 +148,6 @@ def __init__(self, name, base, bran, alias, endpoint=False, isith=None, nsith=No
self.toad = toad
self.data = data
self.endpoint = endpoint
self.proxy = proxy
self.authenticate = authenticate
self.codes = codes if codes is not None else []
self.codeTime = codeTime
Expand All @@ -159,7 +158,9 @@ def __init__(self, name, base, bran, alias, endpoint=False, isith=None, nsith=No

self.hby = existing.setupHby(name=name, base=base, bran=bran)
self.hbyDoer = habbing.HaberyDoer(habery=self.hby) # setup doer
self.swain = delegating.Anchorer(hby=self.hby, proxy=self.hby.habByName(self.proxy))

self.proxy = self.hby.habByName(proxy) if proxy is not None else None
self.swain = delegating.Anchorer(hby=self.hby, proxy=self.proxy)
self.postman = forwarding.Poster(hby=self.hby)
self.mbx = indirecting.MailboxDirector(hby=self.hby, topics=['/receipt', "/replay", "/reply"])
doers = [self.hbyDoer, self.mbx, self.swain, self.postman, doing.doify(self.rotateDo)]
Expand Down Expand Up @@ -213,7 +214,7 @@ def rotateDo(self, tymth, tock=0.0):
auths[wit] = f"{code}#{helping.nowIso8601()}"

if hab.kever.delpre:
self.swain.delegation(pre=hab.pre, sn=hab.kever.sn, auths=auths)
self.swain.delegation(pre=hab.pre, sn=hab.kever.sn, auths=auths, proxy=self.proxy)
print("Waiting for delegation approval...")
while not self.swain.complete(hab.kever.prefixer, coring.Seqner(sn=hab.kever.sn)):
yield self.tock
Expand All @@ -237,7 +238,11 @@ def rotateDo(self, tymth, tock=0.0):
self.remove([witDoer])

if hab.kever.delpre:
yield from self.postman.sendEvent(hab=hab, fn=hab.kever.sn)
if self.proxy is not None:
sender = self.proxy
else:
sender = hab
yield from self.postman.sendEventToDelegator(hab=hab, sender=sender, fn=hab.kever.sn)

print(f'Prefix {hab.pre}')
print(f'New Sequence No. {hab.kever.sn}')
Expand Down
12 changes: 11 additions & 1 deletion src/keri/app/delegating.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,14 @@ def processPartialWitnessEscrow(self):
if not witnessed:
continue
logger.info(f"Witness receipts complete, waiting for delegation approval.")
if pre not in self.hby.habs:
continue

hab = self.hby.habs[pre]
delpre = hab.kever.delpre # get the delegator identifier
dkever = hab.kevers[delpre] # and the delegator's kever
smids = []

if isinstance(hab, GroupHab):
phab = hab.mhab
smids = hab.smids
Expand Down Expand Up @@ -208,6 +212,9 @@ def processWitnessPublication(self):
"""
for (pre, said), serder in self.hby.db.dpub.getItemIter(): # group partial witness escrow
if pre not in self.publishers:
continue

publisher = self.publishers[pre]

if not publisher.idle:
Expand All @@ -220,8 +227,11 @@ def processWitnessPublication(self):
self.hby.db.cdel.put(keys=(pre, coring.Seqner(sn=serder.sn).qb64), val=coring.Saider(qb64=serder.said))

def publishDelegator(self, pre):
hab = self.hby.habs[pre]
if pre not in self.publishers:
return

publisher = self.publishers[pre]
hab = self.hby.habs[pre]
self.extend([publisher])
for msg in hab.db.cloneDelegation(hab.kever):
publisher.msgs.append(dict(pre=hab.pre, msg=bytes(msg)))
Expand Down
5 changes: 2 additions & 3 deletions src/keri/app/forwarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,14 @@ def sent(self, said):

return False

def sendEvent(self, hab, fn=0):
def sendEventToDelegator(self, sender, hab, fn=0):
""" Returns generator for sending event and waiting until send is complete """
# Send KEL event for processing
icp = self.hby.db.cloneEvtMsg(pre=hab.pre, fn=fn, dig=hab.kever.serder.saidb)
ser = serdering.SerderKERI(raw=icp)
del icp[:ser.size]

sender = hab.mhab.pre if isinstance(hab, GroupHab) else hab.pre
self.send(src=sender, dest=hab.kever.delpre, topic="delegate", serder=ser, attachment=icp)
self.send(src=sender.pre, dest=hab.kever.delpre, topic="delegate", serder=ser, attachment=icp)
while True:
if self.cues:
cue = self.cues.popleft()
Expand Down
1 change: 0 additions & 1 deletion src/keri/app/httping.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ def process_request(self, req, resp):
req: Http request object
resp: Http response object
"""
sig = req.headers.get("SIGNATURE")
ked = req.media
Expand Down
8 changes: 6 additions & 2 deletions src/keri/app/querying.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,17 @@ def recur(self, tyme, deeds=None):

class SeqNoQuerier(doing.DoDoer):

def __init__(self, hby, hab, pre, sn, wits=None, **opts):
def __init__(self, hby, hab, pre, sn, fn=None, wits=None, **opts):
self.hby = hby
self.hab = hab
self.pre = pre
self.sn = sn
self.fn = fn if fn is not None else 0
self.witq = agenting.WitnessInquisitor(hby=self.hby)
self.witq.query(src=self.hab.pre, pre=self.pre, sn="{:x}".format(self.sn), wits=wits)
self.witq.query(src=self.hab.pre, pre=self.pre,
sn="{:x}".format(self.sn),
fn="{:x}".format(self.fn),
wits=wits)
super(SeqNoQuerier, self).__init__(doers=[self.witq], **opts)

def recur(self, tyme, deeds=None):
Expand Down
2 changes: 1 addition & 1 deletion src/keri/app/watching.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def adjudicate(self, watched, toad=None):
for watcher in watchers:
saider = self.hab.db.knas.get(keys=(watched, watcher))
if saider is None:
print(f"No key state from watcher {watcher} for {watched}")
logger.info(f"No key state from watcher {watcher} for {watched}")
continue

ksn = self.hab.db.ksns.get(keys=(saider.qb64,))
Expand Down
Loading

0 comments on commit 9f64bdf

Please sign in to comment.