Skip to content

Commit 7523e75

Browse files
committed
kli mailbox start impl with authed fwd handler
Signed-off-by: Kent Bull <kent@kentbull.com>
1 parent 9ca0064 commit 7523e75

8 files changed

Lines changed: 901 additions & 10 deletions

File tree

src/keri/app/__init__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .configing import openCF, Configer, ConfigerDoer
1515
from .delegating import Anchorer, DelegateRequestHandler, delegateRequestExn
1616
from .directing import Director, Reactor, Directant, Reactant, runController
17-
from .forwarding import Poster, StreamPoster, ForwardHandler, introduce
17+
from .forwarding import Poster, StreamPoster, ForwardHandler, AuthorizedForwardHandler, introduce
1818
from .grouping import (Counselor, MultisigNotificationHandler, multisigInceptExn,
1919
multisigRotateExn, multisigInteractExn, multisigRegistryInceptExn,
2020
multisigIssueExn, multisigRevokeExn, multisigRpyExn,
@@ -24,10 +24,11 @@
2424
from .httping import (SignatureValidationComponent, CesrRequest, CESR_CONTENT_TYPE,
2525
parseCesrHttpRequest, createCESRRequest, streamCESRRequests,
2626
Clienter, CESR_DESTINATION_HEADER)
27-
from .indirecting import (setupWitness, createHttpServer, WitnessStart,
28-
Indirector, MailboxDirector, Poller, HttpEnd,
29-
QryRpyMailboxIterable, MailboxIterable, ReceiptEnd,
30-
QueryEnd)
27+
from .indirecting import (setupWitness, createHttpServer,
28+
WitnessStart, Indirector, MailboxDirector, Poller,
29+
HttpEnd, QryRpyMailboxIterable, MailboxIterable,
30+
ReceiptEnd, QueryEnd)
31+
from .mailboxing import setupMailbox, MailboxStart, MailboxAddRemoveEnd, HealthEnd
3132
from .keeping import (PubLot, PreSit, PrePrm, PubSet, riKey, openKS, Keeper,
3233
KeeperDoer, Creator, RandyCreator, SaltyCreator,
3334
Creatory, Initage, Manager, ManagerDoer, Algos)

src/keri/app/forwarding.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,39 @@ def handle(self, serder, attachments=None):
513513
self.mbx.storeMsg(topic=resource, msg=pevt)
514514

515515

516+
class AuthorizedForwardHandler(ForwardHandler):
517+
"""Mailbox `/fwd` handler that enforces recipient mailbox authorization.
518+
519+
Decoupling mailbox hosting from witness hosting removes the old implicit
520+
trust boundary. A standalone mailbox host must not become an open storage
521+
surface for unsolicited or malicious `/fwd` traffic.
522+
523+
This handler stores the embedded payload only when accepted ``ends.`` state
524+
currently authorizes ``(recipient, Roles.mailbox, mailboxAid)``.
525+
"""
526+
527+
def __init__(self, hby, mbx, mailboxAid):
528+
"""Create a mailbox-specific forward handler.
529+
530+
Parameters:
531+
hby (Habery): database environment
532+
mbx (Mailboxer): provider-side mailbox storage
533+
mailboxAid (str): hosted mailbox AID that this handler represents
534+
"""
535+
super().__init__(hby=hby, mbx=mbx)
536+
self.mailboxAid = mailboxAid
537+
538+
def handle(self, serder, attachments=None):
539+
"""Store the forwarded payload only when the hosted mailbox is allowed."""
540+
modifiers = serder.ked.get("q", {})
541+
recipient = modifiers["pre"]
542+
end = self.hby.db.ends.get(keys=(recipient, Roles.mailbox, self.mailboxAid))
543+
if not end or not (end.allowed or end.enabled):
544+
return
545+
546+
super().handle(serder, attachments=attachments)
547+
548+
516549
def introduce(hab, wit):
517550
""" Clone and return hab KEL if lastest event has not been receipted by wit
518551

0 commit comments

Comments
 (0)