Merge branch 'main' into ind-bootstrap

# Conflicts:
#	version.go
This commit is contained in:
Colin Lyons
2022-12-28 09:14:52 +00:00
7 changed files with 97 additions and 122 deletions

View File

@@ -20,31 +20,25 @@ var (
type Client struct {
*netip.AddrPort
Prv *prv.Key
Pub *pub.Key
*node.Node
node.Nodes
*address.SendCache
*address.ReceiveCache
Circuits
Sessions
ifc.Transport
qu.C
}
func New(tpt ifc.Transport, no *node.Node, nodes node.Nodes) (c *Client, e error) {
var p *prv.Key
if p, e = prv.GenerateKey(); check(e) {
return
}
pubKey := pub.Derive(p)
func New(tpt ifc.Transport, hdrPrv *prv.Key, no *node.Node,
nodes node.Nodes) (c *Client, e error) {
hdrPub := pub.Derive(hdrPrv)
var n *node.Node
n, _ = node.New(no.AddrPort, pubKey, nil, p, nil, tpt)
n, _ = node.New(no.AddrPort, hdrPub, nil, hdrPrv, nil, tpt)
c = &Client{
Node: n,
Nodes: nodes,
Transport: tpt,
C: qu.T(),
Node: n,
Nodes: nodes,
C: qu.T(),
}
return
}
@@ -59,6 +53,7 @@ out:
case msg := <-c.Node.Receive():
// process received message
_ = msg
}
}
}

View File

@@ -68,7 +68,7 @@ package client
// // log.I.Ln(len(ci.Hops))
// for i := range ci.Hops {
// // progress through the hops in reverse
// rm := &wire.HeaderKey{
// rm := &wire.HeaderPub{
// IP: ci.Hops[len(ci.Hops)-i-1].IP,
// OnionSkin: lastMsg,
// }
@@ -134,7 +134,7 @@ package client
// t.Error(e)
// t.FailNow()
// }
// var rm *wire.HeaderKey
// var rm *wire.HeaderPub
// var msg wire.OnionSkin
// if msg, e = wire.Deserialize(f.Data); check(e) {
// t.Error(e)

View File

@@ -3,6 +3,7 @@ package client
import (
"github.com/Indra-Labs/indra/pkg/key/address"
"github.com/Indra-Labs/indra/pkg/key/signer"
"github.com/Indra-Labs/indra/pkg/node"
"github.com/Indra-Labs/indra/pkg/nonce"
)
@@ -11,6 +12,7 @@ import (
// with new credit, and the current state of the encryption.
type Session struct {
nonce.ID
*node.Node
Remaining uint64
HeaderKey, PayloadKey *address.SendEntry
*signer.KeySet

View File

@@ -22,17 +22,17 @@ var (
// Node is a representation of a messaging counterparty. The net.IP can be nil
// for the case of a client node that is not in a direct open connection. For
// this reason all nodes are assigned an ID and will normally be handled by this
// except when the net.IP is known via the packet sender address.
// except when the netip.AddrPort is known via the packet sender address.
type Node struct {
nonce.ID
*netip.AddrPort
HeaderKey, PayloadKey *pub.Key
HeaderPub, PayloadPub *pub.Key
HeaderPriv, PayloadPriv *prv.Key
ifc.Transport
}
// New creates a new Node. net.IP is optional if the counterparty is not in
// direct connection.
// New creates a new Node. netip.AddrPort is optional if the counterparty is not
// in direct connection.
func New(ip *netip.AddrPort, hdr, pld *pub.Key, hdrPriv, pldPriv *prv.Key,
tpt ifc.Transport) (n *Node, id nonce.ID) {
@@ -41,8 +41,8 @@ func New(ip *netip.AddrPort, hdr, pld *pub.Key, hdrPriv, pldPriv *prv.Key,
ID: id,
AddrPort: ip,
Transport: tpt,
HeaderKey: hdr,
PayloadKey: pld,
HeaderPub: hdr,
PayloadPub: pld,
HeaderPriv: hdrPriv,
PayloadPriv: pldPriv,
}

View File

@@ -6,14 +6,6 @@ import (
type Sim chan slice.Bytes
func (d Sim) Send(b slice.Bytes) {
d <- b
}
func (d Sim) Receive() <-chan slice.Bytes {
return d
}
func NewSim(bufs int) Dispatcher {
return make(Dispatcher, bufs)
}
func NewSim(bufs int) Sim { return make(Sim, bufs) }
func (d Sim) Send(b slice.Bytes) { d <- b }
func (d Sim) Receive() <-chan slice.Bytes { return d }

View File

@@ -8,7 +8,6 @@ import (
"github.com/Indra-Labs/indra/pkg/node"
"github.com/Indra-Labs/indra/pkg/nonce"
"github.com/Indra-Labs/indra/pkg/slice"
"github.com/Indra-Labs/indra/pkg/types"
)
// Ping is a message which checks the liveness of relays by ensuring they are
@@ -22,19 +21,18 @@ import (
// offline their scores will fall to zero after a time whereas live nodes will
// have steadily increasing scores from successful pings.
func Ping(id nonce.ID, client *node.Node, hop [3]*node.Node,
set *signer.KeySet) types.Onion {
set *signer.KeySet) OnionSkins {
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
Forward(client.AddrPort).
OnionSkin(address.FromPubKey(client.HeaderKey), set.Next()).
Confirmation(id).
Assemble()
OnionSkin(address.FromPubKey(client.HeaderPub), set.Next()).
Confirmation(id)
}
// SendKeys provides a pair of private keys that will be used to generate the
@@ -51,24 +49,23 @@ func Ping(id nonce.ID, client *node.Node, hop [3]*node.Node,
// that the key was successfully delivered to the Reply relays that will be
// used in the Purchase.
func SendKeys(id nonce.ID, hdr, pld *pub.Key,
client *node.Node, hop [5]*node.Node, set *signer.KeySet) types.Onion {
client *node.Node, hop [5]*node.Node, set *signer.KeySet) OnionSkins {
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
Cipher(hdr, pld).
Forward(hop[3].AddrPort).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[3].HeaderPub), set.Next()).
Forward(hop[4].AddrPort).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[4].HeaderPub), set.Next()).
Forward(client.AddrPort).
OnionSkin(address.FromPubKey(client.HeaderKey), set.Next()).
Confirmation(id).
Assemble()
OnionSkin(address.FromPubKey(client.HeaderPub), set.Next()).
Confirmation(id)
}
// SendPurchase delivers a request for keys for a relaying session with a given
@@ -78,7 +75,7 @@ func SendKeys(id nonce.ID, hdr, pld *pub.Key,
// The response, which will be two public keys that identify the session and
// form the basis of the cloaked "To" keys, is encrypted with the given layers,
// the ciphers are already given in reverse order, so they are decoded in given
// order to create the correct payload encryption to match the PayloadKey
// order to create the correct payload encryption to match the PayloadPub
// combined with the header's given public From key.
//
// The header remains a constant size and each node in the Reply trims off
@@ -86,39 +83,34 @@ func SendKeys(id nonce.ID, hdr, pld *pub.Key,
// remainder with noise, so it always looks like the first hop,
// indistinguishable.
func SendPurchase(nBytes uint64, client *node.Node,
hop [5]*node.Node, set *signer.KeySet) types.Onion {
hop [5]*node.Node, set *signer.KeySet) OnionSkins {
var replies [3]*prv.Key
for i := range replies {
replies[i] = set.Next()
}
var prvs [3]*prv.Key
for i := range prvs {
prvs[i] = set.Next()
}
var pubs [3]*pub.Key
prvs[0] = replies[2]
prvs[1] = replies[1]
prvs[2] = replies[0]
pubs[0] = client.PayloadKey
pubs[1] = hop[4].PayloadKey
pubs[2] = hop[3].PayloadKey
pubs[0] = client.PayloadPub
pubs[1] = hop[4].PayloadPub
pubs[2] = hop[3].PayloadPub
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
Purchase(nBytes, prvs, pubs).
Reply(hop[3].AddrPort).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), replies[0]).
OnionSkin(address.FromPubKey(hop[3].HeaderPub), prvs[0]).
Reply(hop[4].AddrPort).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), replies[1]).
OnionSkin(address.FromPubKey(hop[4].HeaderPub), prvs[1]).
Reply(client.AddrPort).
OnionSkin(address.FromPubKey(client.HeaderKey), replies[2]).
Assemble()
OnionSkin(address.FromPubKey(client.HeaderPub), prvs[2])
}
// SendExit constructs a message containing an arbitrary payload to a node (3rd
// hop) with a set of 3 ciphers derived from the hidden PayloadKey of the return
// hop) with a set of 3 ciphers derived from the hidden PayloadPub of the return
// hops that are layered progressively after the Exit message.
//
// The Exit node forwards the packet it receives to the local port specified in
@@ -128,42 +120,36 @@ func SendPurchase(nBytes uint64, client *node.Node,
//
// The response is encrypted with the given layers, the ciphers are already
// given in reverse order, so they are decoded in given order to create the
// correct payload encryption to match the PayloadKey combined with the header's
// correct payload encryption to match the PayloadPub combined with the header's
// given public From key.
//
// The header remains a constant size and each node in the Reply trims off
// their section at the top, moves the next layer header to the top and pads the
// remainder with noise, so it always looks like the first hop,
// indistinguishable.
// remainder with noise, so it always looks like the first hop.
func SendExit(payload slice.Bytes, port uint16, client *node.Node,
hop [5]*node.Node, set *signer.KeySet) types.Onion {
var replies [3]*prv.Key
for i := range replies {
replies[i] = set.Next()
}
hop [5]*node.Node, set *signer.KeySet) OnionSkins {
var prvs [3]*prv.Key
for i := range prvs {
prvs[i] = set.Next()
}
var pubs [3]*pub.Key
prvs[0] = replies[2]
prvs[1] = replies[1]
prvs[2] = replies[0]
pubs[0] = client.PayloadKey
pubs[1] = hop[4].PayloadKey
pubs[2] = hop[3].PayloadKey
pubs[0] = client.PayloadPub
pubs[1] = hop[4].PayloadPub
pubs[2] = hop[3].PayloadPub
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
Exit(port, prvs, pubs, payload).
Reply(hop[3].AddrPort).
OnionSkin(address.FromPubKey(hop[3].HeaderKey), replies[0]).
OnionSkin(address.FromPubKey(hop[3].HeaderPub), prvs[0]).
Reply(hop[4].AddrPort).
OnionSkin(address.FromPubKey(hop[4].HeaderKey), replies[1]).
OnionSkin(address.FromPubKey(hop[4].HeaderPub), prvs[1]).
Reply(client.AddrPort).
OnionSkin(address.FromPubKey(client.HeaderKey), replies[2]).
Assemble()
OnionSkin(address.FromPubKey(client.HeaderPub), prvs[2])
}

View File

@@ -139,7 +139,7 @@ func TestPing(t *testing.T) {
cpub1, cpub2, cprv1, cprv2, nil)
on := Ping(n, client, hop, ks)
b := EncodeOnion(on)
b := EncodeOnion(on.Assemble())
c := slice.NewCursor()
// Forward(hop[0].AddrPort).
@@ -150,7 +150,7 @@ func TestPing(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[0].HeaderPriv, b, c)
// Forward(hop[1].AddrPort).
@@ -161,7 +161,7 @@ func TestPing(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[1].HeaderPriv, b, c)
// Forward(hop[2].AddrPort).
@@ -172,7 +172,7 @@ func TestPing(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[2].HeaderPriv, b, c)
// Forward(client.AddrPort).
@@ -183,7 +183,7 @@ func TestPing(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(client.HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(client.HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(client.HeaderPriv, b, c)
// Confirmation(id).
@@ -219,7 +219,7 @@ func TestSendKeys(t *testing.T) {
cipub1, cipub2 := pub.Derive(ciprv1), pub.Derive(ciprv2)
on := SendKeys(n, cipub1, cipub2, client, hop, ks)
b := EncodeOnion(on)
b := EncodeOnion(on.Assemble())
c := slice.NewCursor()
var ok bool
@@ -231,7 +231,7 @@ func TestSendKeys(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[0].HeaderPriv, b, c)
// Forward(hop[1].AddrPort).
@@ -242,7 +242,7 @@ func TestSendKeys(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[1].HeaderPriv, b, c)
// Forward(hop[2].AddrPort).
@@ -253,7 +253,7 @@ func TestSendKeys(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[2].HeaderPriv, b, c)
// Cipher(hdr, pld).
@@ -284,7 +284,7 @@ func TestSendKeys(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[3].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[3].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[3].HeaderPriv, b, c)
// Forward(hop[4].AddrPort).
@@ -295,7 +295,7 @@ func TestSendKeys(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[4].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[4].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[4].HeaderPriv, b, c)
// Forward(client.AddrPort).
@@ -306,7 +306,7 @@ func TestSendKeys(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(client.HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(client.HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(client.HeaderPriv, b, c)
// Confirmation(id).
@@ -342,7 +342,7 @@ func TestSendPurchase(t *testing.T) {
// cipub1, cipub2 := pub.Derive(ciprv1), pub.Derive(ciprv2)
nBytes := rand.Uint64()
on := SendPurchase(nBytes, client, hop, ks)
b := EncodeOnion(on)
b := EncodeOnion(on.Assemble())
c := slice.NewCursor()
// var ok bool
@@ -354,7 +354,7 @@ func TestSendPurchase(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[0].HeaderPriv, b, c)
// Forward(hop[1].AddrPort).
@@ -365,7 +365,7 @@ func TestSendPurchase(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[1].HeaderPriv, b, c)
// Forward(hop[2].AddrPort).
@@ -376,7 +376,7 @@ func TestSendPurchase(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[2].HeaderPriv, b, c)
// Purchase(nBytes, prvs, pubs).
@@ -393,27 +393,27 @@ func TestSendPurchase(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[3].HeaderKey), replies[0]).
// OnionSkin(address.FromPubKey(hop[3].HeaderPub), replies[0]).
PeelOnionSkin(t, b, c).Decrypt(hop[3].HeaderPriv, b, c)
// Reply(hop[4].AddrPort).
rp2 := PeelReply(t, b, c)
if rp2.AddrPort.String() != hop[4].AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve second reply hop")
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[4].HeaderKey), replies[1]).
// OnionSkin(address.FromPubKey(hop[4].HeaderPub), replies[1]).
PeelOnionSkin(t, b, c).Decrypt(hop[4].HeaderPriv, b, c)
// Reply(client.AddrPort).
rp3 := PeelReply(t, b, c)
if rp3.AddrPort.String() != client.AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve third reply hop")
t.FailNow()
}
// OnionSkin(address.FromPubKey(client.HeaderKey), replies[2]).
// OnionSkin(address.FromPubKey(client.HeaderPub), replies[2]).
PeelOnionSkin(t, b, c).Decrypt(client.HeaderPriv, b, c)
}
@@ -442,7 +442,7 @@ func TestSendExit(t *testing.T) {
var hash sha256.Hash
message, hash, e = testutils.GenerateTestMessage(2502)
on := SendExit(message, port, client, hop, ks)
b := EncodeOnion(on)
b := EncodeOnion(on.Assemble())
c := slice.NewCursor()
// Forward(hop[0].AddrPort).
@@ -453,7 +453,7 @@ func TestSendExit(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[0].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[0].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[0].HeaderPriv, b, c)
// Forward(hop[1].AddrPort).
@@ -464,7 +464,7 @@ func TestSendExit(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[1].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[1].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[1].HeaderPriv, b, c)
// Forward(hop[2].AddrPort).
@@ -475,7 +475,7 @@ func TestSendExit(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[2].HeaderKey), set.Next()).
// OnionSkin(address.FromPubKey(hop[2].HeaderPub), set.Next()).
PeelOnionSkin(t, b, c).Decrypt(hop[2].HeaderPriv, b, c)
// Exit(port, prvs, pubs, payload).
@@ -497,27 +497,27 @@ func TestSendExit(t *testing.T) {
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[3].HeaderKey), replies[0]).
// OnionSkin(address.FromPubKey(hop[3].HeaderPub), replies[0]).
PeelOnionSkin(t, b, c).Decrypt(hop[3].HeaderPriv, b, c)
// Reply(hop[4].AddrPort).
rp2 := PeelReply(t, b, c)
if rp2.AddrPort.String() != hop[4].AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve second reply hop")
t.FailNow()
}
// OnionSkin(address.FromPubKey(hop[4].HeaderKey), replies[1]).
// OnionSkin(address.FromPubKey(hop[4].HeaderPub), replies[1]).
PeelOnionSkin(t, b, c).Decrypt(hop[4].HeaderPriv, b, c)
// Reply(client.AddrPort).
rp3 := PeelReply(t, b, c)
if rp3.AddrPort.String() != client.AddrPort.String() {
t.Errorf("failed to retrieve first reply hop")
t.Errorf("failed to retrieve third reply hop")
t.FailNow()
}
// OnionSkin(address.FromPubKey(client.HeaderKey), replies[2]).
// OnionSkin(address.FromPubKey(client.HeaderPub), replies[2]).
PeelOnionSkin(t, b, c).Decrypt(client.HeaderPriv, b, c)
}