Skip to content

Commit

Permalink
tapfreighter: validate proof courier address before commencing send
Browse files Browse the repository at this point in the history
  • Loading branch information
ffranr committed Sep 12, 2023
1 parent c5bdbfe commit eadcf26
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
4 changes: 2 additions & 2 deletions proof/courier.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ func ParseCourierAddrUrl(addr url.URL) (CourierAddr, error) {
return NewHashMailCourierAddr(addr)
}

return nil, fmt.Errorf("unknown courier address protocol: %v",
addr.Scheme)
return nil, fmt.Errorf("unknown courier address protocol "+
"(consider updating tapd): %v", addr.Scheme)
}

// HashMailCourierAddr is a hashmail protocol specific implementation of the
Expand Down
31 changes: 31 additions & 0 deletions tapfreighter/chain_porter.go
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,15 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
return nil, fmt.Errorf("unable to cast parcel to " +
"address parcel")
}

// Perform basic validation on the address parcel before we
// continue.
err := p.validateAddrParcel(*addrParcel)
if err != nil {
return nil, fmt.Errorf("failed to validate address "+
"parcel: %w", err)
}

fundSendRes, outputIdxToAddr, err :=
p.cfg.AssetWallet.FundAddressSend(
ctx, addrParcel.destAddrs...,
Expand Down Expand Up @@ -1030,6 +1039,28 @@ func (p *ChainPorter) stateStep(currentPkg sendPackage) (*sendPackage, error) {
}
}

// validateAddrParcel validates the given address parcel.
func (p *ChainPorter) validateAddrParcel(addrParcel AddressParcel) error {
// We need at least one address to send to in an address parcel.
if len(addrParcel.destAddrs) < 1 {
return fmt.Errorf("at least one Tap address must be " +
"specified in address parcel")
}

for idx := range addrParcel.destAddrs {
tapAddr := addrParcel.destAddrs[idx]

// Validate proof courier addresses.
_, err := proof.ParseCourierAddrUrl(tapAddr.ProofCourierAddr)
if err != nil {
return fmt.Errorf("invalid proof courier address: %w",
err)
}
}

return nil
}

// RegisterSubscriber adds a new subscriber to the set of subscribers that will
// be notified of any new events that are broadcast.
//
Expand Down

0 comments on commit eadcf26

Please sign in to comment.