Skip to content

Commit

Permalink
Non deterministic prefixes in witnesses (WebOfTrust#701)
Browse files Browse the repository at this point in the history
* Added ctags

* Fix to remove hardcoded salts as default behavior.

Removed hardcoded salts as default behavior of openHby and openHab.

Also fixed a bug that hadn't been caught yet wherein whatever was passed
to openHby was always used and a default salt was never created.
Adjusted to match the intention of the code and no tests seemed to break
from it so it must have been getting caught further down the stack.

* Removed erroneous print statement

* Removed a deleted space that had entered the diff
  • Loading branch information
daidoji authored Mar 8, 2024
1 parent 8243509 commit a6e3a88
Show file tree
Hide file tree
Showing 21 changed files with 97 additions and 84 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,7 @@ klid.log
config/

# keripy virtualenv
keripy/
keripy/

# ctags
.tags
6 changes: 3 additions & 3 deletions src/keri/app/habbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def openHby(*, name="test", base="", temp=True, salt=None, **kwa):
"""
habery = None
salt = salt if not None else coring.Salter(raw=b'0123456789abcdef').qb64
salt = salt if salt is not None else coring.Salter().qb64
try:
habery = Habery(name=name, base=base, temp=temp, salt=salt, **kwa)
yield habery
Expand All @@ -79,7 +79,7 @@ def openHby(*, name="test", base="", temp=True, salt=None, **kwa):


@contextmanager
def openHab(name="test", base="", salt=b'0123456789abcdef', temp=True, cf=None, **kwa):
def openHab(name="test", base="", salt=None, temp=True, cf=None, **kwa):
"""
Context manager wrapper for Hab instance.
Defaults to temporary resources
Expand Down Expand Up @@ -297,7 +297,7 @@ def setup(self, *, seed=None, aeid=None, bran=None, pidx=None, algo=None,
aeid = signer.verfer.qb64 # lest it remove encryption

if salt is None: # salt for signing keys not aeid seed
salt = coring.Salter(raw=b'0123456789abcdef').qb64
salt = coring.Salter().qb64
else:
salt = coring.Salter(qb64=salt).qb64

Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_delegating.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def sealer_test_do(tymth=None, tock=0.0, **opts):


def test_delegation_request(mockHelpingNowUTC):
with habbing.openHab(name="test", temp=True) as (hby, hab):
with habbing.openHab(name="test", temp=True, salt=b'0123456789abcdef') as (hby, hab):

delpre = "EArzbTSWjccrTdNRsFUUfwaJ2dpYxu9_5jI2PJ-TRri0"
serder = eventing.delcept(keys=["DUEFuPeaDH2TySI-wX7CY_uW5FF41LRu3a59jxg1_pMs"], delpre=delpre,
Expand Down
4 changes: 2 additions & 2 deletions tests/app/test_grouping.py
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ def openMultiSig(prefix="test", salt=b'0123456789abcdef', temp=True, **kwa):


def test_multisig_incept(mockHelpingNowUTC):
with habbing.openHab(name="test", temp=True) as (hby, hab):
with habbing.openHab(name="test", temp=True, salt=b'0123456789abcdef') as (hby, hab):
aids = [hab.pre, "EfrzbTSWjccrTdNRsFUUfwaJ2dpYxu9_5jI2PJ-TRri0"]
exn, atc = grouping.multisigInceptExn(hab=hab, smids=aids, rmids=aids,
icp=hab.makeOwnEvent(sn=hab.kever.sn))
Expand Down Expand Up @@ -715,7 +715,7 @@ def test_multisig_registry_incept(mockHelpingNowUTC, mockCoringRandomNonce):


def test_multisig_incept_handler(mockHelpingNowUTC):
with habbing.openHab(name="test0", temp=True) as (hby, hab):
with habbing.openHab(name="test0", temp=True, salt=b'0123456789abcdef') as (hby, hab):
aids = [hab.pre, "EfrzbTSWjccrTdNRsFUUfwaJ2dpYxu9_5jI2PJ-TRri0"]
exn, atc = grouping.multisigInceptExn(hab=hab, smids=aids, rmids=aids,
icp=hab.makeOwnEvent(sn=hab.kever.sn))
Expand Down
28 changes: 14 additions & 14 deletions tests/app/test_habbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_habery():
"""
# test default
default_salt = coring.Salter(raw=b'0123456789abcdef').qb64
hby = habbing.Habery(temp=True)
hby = habbing.Habery(temp=True, salt=default_salt)
assert hby.name == "test"
assert hby.base == ""
assert hby.temp
Expand Down Expand Up @@ -76,7 +76,7 @@ def test_habery():
seed4bran = 'ALQVu9AjGW3JrIzX0UHm2awGCbDXcsLzy-vAE649Fz1j'
aeid4seed = 'BHRYV_5a1AlibCrXFG_KDD9rC6aXx9cb0sR968NL80VI'

hby = habbing.Habery(bran=bran, temp=True)
hby = habbing.Habery(bran=bran, temp=True, salt=default_salt)
assert hby.name == "test"
assert hby.base == ""
assert hby.temp
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_habery():

# setup habery
hby = habbing.Habery(name=name, base=base, ks=ks, db=db, cf=cf, temp=temp,
bran=bran)
bran=bran, salt=default_salt)
hbyDoer = habbing.HaberyDoer(habery=hby) # setup doer

assert hby.name == "main"
Expand Down Expand Up @@ -180,7 +180,7 @@ def test_habery():
temp = True

# setup habery with resources
hby = habbing.Habery(name=name, base=base, temp=temp, bran=bran, free=True)
hby = habbing.Habery(name=name, base=base, temp=temp, bran=bran, free=True, salt=default_salt)
hbyDoer = habbing.HaberyDoer(habery=hby) # setup doer

conf = hby.cf.get()
Expand Down Expand Up @@ -234,7 +234,7 @@ def test_habery():
assert not os.path.exists(hby.db.path)
assert not os.path.exists(hby.ks.path)

with habbing.openHby() as hby:
with habbing.openHby(salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby:
assert hby.name == "test"
assert hby.base == ""
assert hby.temp
Expand Down Expand Up @@ -281,7 +281,7 @@ def test_habery():
assert not os.path.exists(hby.ks.path)

bran = "MyPasscodeARealSecret"
with habbing.openHby(bran=bran) as hby:
with habbing.openHby(bran=bran, salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby:
assert hby.name == "test"
assert hby.base == ""
assert hby.temp
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_make_load_hab_with_habery():
name = "sue"
suePre = 'ELF1S0jZkyQx8YtHaPLu-qyFmrkcykAiEW8twS-KPSO1' # with temp=True

with habbing.openHby() as hby: # default is temp=True on openHab
with habbing.openHby(salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby: # default is temp=True on openHab
hab = hby.makeHab(name=name)
assert isinstance(hab, habbing.Hab)
assert hab.pre in hby.habs
Expand Down Expand Up @@ -386,7 +386,7 @@ def test_make_load_hab_with_habery():
suePre = 'EAxe215BJ4Iy9r0mfoMEGVmHW8A4Avk3RYBC1A1_DZam' # with temp=False
bobPre = 'ENya5E5pvc6MVCe75huDK0QQhE4_64J55vCn4aKdXhR9' # with temp=False

with habbing.openHby(base=base, temp=False) as hby: # default is temp=True
with habbing.openHby(base=base, temp=False, salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby: # default is temp=True
assert hby.cf.path.endswith("keri/cf/hold/test.json")
assert hby.db.path.endswith("keri/db/hold/test")
assert hby.ks.path.endswith('keri/ks/hold/test')
Expand Down Expand Up @@ -560,7 +560,7 @@ def test_habery_reinitialization():


def test_habery_signatory():
with habbing.openHby() as hby:
with habbing.openHby(salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby:
signer = hby.signator

assert signer is not None
Expand Down Expand Up @@ -714,7 +714,7 @@ def test_habery_reconfigure(mockHelpingNowUTC):


def test_namespaced_habs():
with habbing.openHby() as hby:
with habbing.openHby(salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby:
hab = hby.makeHab(name="test")
assert hab.pre == "EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3"

Expand Down Expand Up @@ -797,7 +797,7 @@ def test_namespaced_habs():


def test_make_other_event():
with habbing.openHby() as hby:
with habbing.openHby(salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby:
hab = hby.makeHab(name="test")
assert hab.pre == "EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3"

Expand Down Expand Up @@ -867,9 +867,9 @@ def test_hab_by_pre():


def test_postman_endsfor():
with habbing.openHby(name="test", temp=True) as hby, \
habbing.openHby(name="wes", salt=coring.Salter(raw=b'wess-the-witness').qb64, temp=True) as wesHby, \
habbing.openHab(name="agent", temp=True) as (agentHby, agentHab):
with habbing.openHby(name="test", temp=True, salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby, \
habbing.openHby(name="wes", temp=True, salt=coring.Salter(raw=b'wess-the-witness').qb64) as wesHby, \
habbing.openHab(name="agent", temp=True, salt=b'0123456789abcdef') as (agentHby, agentHab):

wesHab = wesHby.makeHab(name='wes', isith="1", icount=1, transferable=False)
assert not wesHab.kever.prefixer.transferable
Expand Down
4 changes: 2 additions & 2 deletions tests/app/test_httping.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def request(self, **kwargs):


def test_create_cesr_request(mockHelpingNowUTC):
with habbing.openHab(name="test", transferable=True, temp=True) as (hby, hab):
with habbing.openHab(name="test", transferable=True, temp=True, salt=b'0123456789abcdef') as (hby, hab):
wit = "BGKVzj4ve0VSd8z_AmvhLg4lqcC_9WYX90k03q-R_Ydo"
regery = credentialing.Regery(hby=hby, name="test", temp=True)
issuer = regery.makeRegistry(prefix=hab.pre, name="test")
Expand Down Expand Up @@ -114,7 +114,7 @@ def test_create_cesr_request(mockHelpingNowUTC):


def test_stream_cesr_request(mockHelpingNowUTC):
with habbing.openHab(name="test", transferable=True, temp=True) as (hby, hab):
with habbing.openHab(name="test", transferable=True, temp=True, salt=b'0123456789abcdef') as (hby, hab):
wit = "BGKVzj4ve0VSd8z_AmvhLg4lqcC_9WYX90k03q-R_Ydo"
regery = credentialing.Regery(hby=hby, name="test", temp=True)
issuer = regery.makeRegistry(prefix=hab.pre, name="test")
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_indirecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def test_mailbox_multiple_iter():


def test_qrymailbox_iter():
with habbing.openHab(name="test", transferable=True, temp=True) as (hby, hab):
with habbing.openHab(name="test", transferable=True, temp=True, salt=b'0123456789abcdef') as (hby, hab):
assert hab.pre == 'EIaGMMWJFPmtXznY1IIiKDIrg-vIyge6mBl2QV8dDjI3'
icp = hab.makeOwnInception()
icpSrdr = serdering.SerderKERI(raw=icp)
Expand Down
2 changes: 1 addition & 1 deletion tests/app/test_oobiing.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
def test_oobi_share(mockHelpingNowUTC):
oobi = "http://127.0.0.1:5642/oobi/Egw3N07Ajdkjvv4LB2Mhx2qxl6TOCFdWNJU6cYR_ImFg/witness" \
"/BGKVzj4ve0VSd8z_AmvhLg4lqcC_9WYX90k03q-R_Ydo?name=Phil"
with habbing.openHab(name="test", temp=True) as (hby, hab):
with habbing.openHab(name="test", temp=True, salt=b'0123456789abcdef') as (hby, hab):
exc = exchanging.Exchanger(hby=hby, handlers=[])
notifier = notifying.Notifier(hby=hby)

Expand Down
10 changes: 5 additions & 5 deletions tests/core/test_eventing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4726,7 +4726,7 @@ def test_reload_kever(mockHelpingNowUTC):
Test reload Kever from keystate state message
"""

with habbing.openHby(name="nat", base="test") as natHby:
with habbing.openHby(name="nat", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as natHby:
# setup Nat's habitat using default salt multisig already incepts
natHab = natHby.makeHab(name="nat", isith='2', icount=3)
assert natHab.name == 'nat'
Expand Down Expand Up @@ -4795,10 +4795,10 @@ def test_reload_kever(mockHelpingNowUTC):


def test_load_event(mockHelpingNowUTC):
with habbing.openHby(name="tor", base="test") as torHby, \
habbing.openHby(name="wil", base="test") as wilHby, \
habbing.openHby(name="wan", base="test") as wanHby, \
habbing.openHby(name="tee", base="test") as teeHby:
with habbing.openHby(name="tor", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as torHby, \
habbing.openHby(name="wil", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as wilHby, \
habbing.openHby(name="wan", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as wanHby, \
habbing.openHby(name="tee", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as teeHby:

wanKvy = Kevery(db=wanHby.db, lax=False, local=False)
torKvy = Kevery(db=torHby.db, lax=False, local=False)
Expand Down
12 changes: 6 additions & 6 deletions tests/core/test_kevery.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_witness_state():
"""

# with basing.openDB(name="controller") as bobDB, keeping.openKS(name="controller") as bobKS:
with habbing.openHby(name="controller", base="test") as hby:
with habbing.openHby(name="controller", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby:

wits = [
"BAMUu4hpUYY4FKd4LtsvpMN6claZKF2AUmXIgXiAI9ZQ",
Expand Down Expand Up @@ -336,11 +336,11 @@ def test_stale_event_receipts():
Bam is verifying the key events with receipts from Bob
"""
# openHby default temp=True
with (habbing.openHby(name="bob", base="test") as bobHby,
habbing.openHby(name="bam", base="test") as bamHby,
habbing.openHby(name="wes", base="test") as wesHby,
habbing.openHby(name="wan", base="test") as wanHby,
habbing.openHby(name="wil", base="test") as wilHby):
with (habbing.openHby(name="bob", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as bobHby,
habbing.openHby(name="bam", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as bamHby,
habbing.openHby(name="wes", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as wesHby,
habbing.openHby(name="wan", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as wanHby,
habbing.openHby(name="wil", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as wilHby):

# setup Wes's habitat nontrans
wesHab = wesHby.makeHab(name="wes", isith='1', icount=1, transferable=False,)
Expand Down
18 changes: 10 additions & 8 deletions tests/core/test_keystate.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ def test_keystate(mockHelpingNowUTC):
salt = salter.qb64
assert salt == '0AAFqo8tU5rp-lWcApybCEh1'

default_salt = coring.Salter(raw=b'0123456789abcdef').qb64

# Bob is the controller
# Wes is his witness
# Bam is verifying the key state for Bob from Wes

# default for openHby temp = True
with (habbing.openHby(name="bob", base="test") as bobHby,
habbing.openHby(name="bam", base="test") as bamHby,
with (habbing.openHby(name="bob", base="test", salt=default_salt) as bobHby,
habbing.openHby(name="bam", base="test", salt=default_salt) as bamHby,
habbing.openHby(name="wes", base="test", salt=salt) as wesHby):

# setup Wes's habitat nontrans
Expand Down Expand Up @@ -124,8 +126,8 @@ def test_keystate(mockHelpingNowUTC):
# Bam is verifying the key state for Bob from Wes
# Wes is Bam's watcher

with (habbing.openHby(name="bob", base="test") as bobHby,
habbing.openHby(name="bam", base="test") as bamHby,
with (habbing.openHby(name="bob", base="test", salt=default_salt) as bobHby,
habbing.openHby(name="bam", base="test", salt=default_salt) as bamHby,
habbing.openHby(name="wes", base="test", salt=salt) as wesHby):

# setup Wes's habitat nontrans
Expand Down Expand Up @@ -192,8 +194,8 @@ def test_keystate(mockHelpingNowUTC):
# Bam is verifying the key state for Bob from Wes
# Wes is no one

with (habbing.openHby(name="bob", base="test") as bobHby,
habbing.openHby(name="bam", base="test") as bamHby,
with (habbing.openHby(name="bob", base="test", salt=default_salt) as bobHby,
habbing.openHby(name="bam", base="test", salt=default_salt) as bamHby,
habbing.openHby(name="wes", base="test", salt=salt) as wesHby):

# setup Wes's habitat nontrans
Expand Down Expand Up @@ -234,8 +236,8 @@ def test_keystate(mockHelpingNowUTC):
# Bob is the controller
# Bam is verifying the key state for Bob with a stale key state in the way

with (habbing.openHby(name="bob", base="test") as bobHby,
habbing.openHby(name="bam", base="test") as bamHby):
with (habbing.openHby(name="bob", base="test", salt=default_salt) as bobHby,
habbing.openHby(name="bam", base="test", salt=default_salt) as bamHby):

bobHab = bobHby.makeHab(name="bob", isith='1', icount=1, transferable=True)
assert bobHab.pre == bobpre
Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_parsing_pathed.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def handle(self, serder, attachments=None):
self.atcs.append(attachments)

with (habbing.openHby(name="pal", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby,
habbing.openHby(name="deb", base="test") as debHby):
habbing.openHby(name="deb", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as debHby):
sith = ["1/2", "1/2", "1/2"] # weighted signing threshold
palHab = hby.makeHab(name="pal")
debHab = debHby.makeHab(name="deb", isith=sith, icount=3)
Expand Down
15 changes: 8 additions & 7 deletions tests/core/test_replay.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def test_replay():
Compare replay of Deb's events with receipts by both Deb and Cam to confirm identical
"""
artSalt = coring.Salter(raw=b'abcdef0123456789').qb64
default_salt = coring.Salter(raw=b'0123456789abcdef').qb64

with (habbing.openHby(name="deb", base="test") as debHby,
habbing.openHby(name="cam", base="test") as camHby,
habbing.openHby(name="bev", base="test") as bevHby,
with (habbing.openHby(name="deb", base="test", salt=default_salt) as debHby,
habbing.openHby(name="cam", base="test", salt=default_salt) as camHby,
habbing.openHby(name="bev", base="test", salt=default_salt) as bevHby,
habbing.openHby(name="art", base="test", salt=artSalt) as artHby):

# setup Deb's habitat using default salt multisig already incepts
Expand Down Expand Up @@ -493,11 +494,11 @@ def test_replay_all():
"""
artSalt = coring.Salter(raw=b'abcdef0123456789').qb64
default_salt = coring.Salter(raw=b'0123456789abcdef').qb64


with (habbing.openHby(name="deb", base="test") as debHby,
habbing.openHby(name="cam", base="test") as camHby,
habbing.openHby(name="bev", base="test") as bevHby,
with (habbing.openHby(name="deb", base="test", salt=default_salt) as debHby,
habbing.openHby(name="cam", base="test", salt=default_salt) as camHby,
habbing.openHby(name="bev", base="test", salt=default_salt) as bevHby,
habbing.openHby(name="art", base="test", salt=artSalt) as artHby):

# setup Deb's habitat using default salt multisig already incepts
Expand Down
7 changes: 4 additions & 3 deletions tests/core/test_witness.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,10 @@ def test_out_of_order_witnessed_events():
# Wes is his witness
# Bam is verifying the key state for Bob from Wes

with habbing.openHby(name="wes", base="test") as wesHby, \
habbing.openHby(name="bob", base="test") as bobHby, \
habbing.openHby(name="bam", base="test") as bamHby:
default_salt = coring.Salter(raw=b'0123456789abcdef').qb64
with habbing.openHby(name="wes", base="test", salt=default_salt) as wesHby, \
habbing.openHby(name="bob", base="test", salt=default_salt) as bobHby, \
habbing.openHby(name="bam", base="test", salt=default_salt) as bamHby:

# setup Wes's habitat nontrans
wesHab = wesHby.makeHab(name='wes', isith='1', icount=1, transferable=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/db/test_basing.py
Original file line number Diff line number Diff line change
Expand Up @@ -1707,7 +1707,7 @@ def test_clean_baser():
"""
name = "nat"
# with basing.openDB(name="nat") as natDB, keeping.openKS(name="nat") as natKS:
with habbing.openHby(name=name) as hby: # default is temp=True
with habbing.openHby(name=name, salt=coring.Salter(raw=b'0123456789abcdef').qb64) as hby: # default is temp=True
natHab = hby.makeHab(name=name, isith='2', icount=3) # default Hab
# setup Nat's habitat using default salt multisig already incepts
#natHab = habbing.Habitat(name='nat', ks=natKS, db=natDB,
Expand Down
8 changes: 4 additions & 4 deletions tests/demo/test_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,12 +417,12 @@ def test_indirect_mode_sam_cam_wit_demo():
camSigners = coring.Salter(raw=raw).signers(count=8, path="cam", temp=True)
camSecrecies = [[signer.qb64] for signer in camSigners]

with (habbing.openHby(name="cam", base="test") as camHby,
habbing.openHby(name="sam", base="test") as samHby,
habbing.openHby(name="wit", base="test") as witHby):
with (habbing.openHby(name="cam", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as camHby,
habbing.openHby(name="sam", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as samHby,
habbing.openHby(name="wit", base="test", salt=coring.Salter(raw=b'0123456789abcdef').qb64) as witHby):

samPort = 5620 # sam's TCP listening port for server
witPort = 5621 # wit' TCP listneing port for server
witPort = 5621 # wit' TCP listening port for server

# setup the witness
witHab = witHby.makeHab(name="Wit",
Expand Down
Loading

0 comments on commit a6e3a88

Please sign in to comment.