Completed removal of keychain nonsense

This commit is contained in:
David Vennik
2023-01-07 17:43:47 +00:00
parent 86c10c4f51
commit c8803c18ff
21 changed files with 218 additions and 183 deletions

View File

@@ -39,8 +39,8 @@ var (
type Client struct {
*node.Node
node.Nodes
*address.SendCache
*address.ReceiveCache
// *address.SendCache
// *address.ReceiveCache
session.Sessions
PendingSessions []nonce.ID
*confirm.Confirms
@@ -62,14 +62,14 @@ func New(tpt ifc.Transport, hdrPrv *prv.Key, no *node.Node,
return
}
c = &Client{
Confirms: confirm.NewConfirms(),
Node: no,
Nodes: nodes,
ReceiveCache: address.NewReceiveCache(),
KeySet: ks,
C: qu.T(),
Confirms: confirm.NewConfirms(),
Node: no,
Nodes: nodes,
// ReceiveCache: address.NewReceiveCache(),
KeySet: ks,
C: qu.T(),
}
c.ReceiveCache.Add(address.NewReceiver(hdrPrv))
// c.ReceiveCache.Add(address.NewReceiver(hdrPrv))
return
}
@@ -93,6 +93,27 @@ func (cl *Client) RegisterConfirmation(hook confirm.Hook,
})
}
// FindCloaked searches the client identity key and the Sessions for a match.
func (cl *Client) FindCloaked(clk address.Cloaked) (hdr *prv.Key, pld *prv.Key) {
var b address.Blinder
copy(b[:], clk[:address.BlindLen])
hash := address.Cloak(b, cl.Node.HeaderBytes)
if hash == clk {
hdr = cl.Node.HeaderPrv
// there is no payload key for the node, only in sessions.
return
}
for i := range cl.Sessions {
hash = address.Cloak(b, cl.Sessions[i].HeaderBytes)
if hash == clk {
hdr = cl.Sessions[i].HeaderPrv
pld = cl.Sessions[i].PayloadPrv
return
}
}
return
}
func (cl *Client) SendKeys(nodeID nonce.ID,
hook func(cf nonce.ID)) (confirmation nonce.ID, hdr, pld *prv.Key,
e error) {

View File

@@ -5,7 +5,6 @@ import (
"time"
"github.com/cybriq/qu"
"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"
@@ -99,12 +98,11 @@ func TestSendPurchase(t *testing.T) {
}
var sess [3]*session.Session
for i := range sess {
sess[i] = session.NewSession(nonce.NewID(), 203230230,
time.Hour, ks)
sess[i] = session.NewSession(nonce.NewID(), 203230230, time.Hour)
}
clients[4].ReceiveCache.Add(address.NewReceiver(sess[0].HeaderPrv))
clients[5].ReceiveCache.Add(address.NewReceiver(sess[1].HeaderPrv))
clients[0].ReceiveCache.Add(address.NewReceiver(sess[2].HeaderPrv))
// clients[4].ReceiveCache.Add(address.NewReceiver(sess[0].HeaderPrv))
// clients[5].ReceiveCache.Add(address.NewReceiver(sess[1].HeaderPrv))
// clients[0].ReceiveCache.Add(address.NewReceiver(sess[2].HeaderPrv))
clients[4].Sessions = clients[4].Sessions.Add(sess[0])
clients[5].Sessions = clients[5].Sessions.Add(sess[1])
clients[0].Sessions = clients[0].Sessions.Add(sess[2])
@@ -145,12 +143,11 @@ func TestSendExit(t *testing.T) {
}
var sess [3]*session.Session
for i := range sess {
sess[i] = session.NewSession(nonce.NewID(), 203230230,
time.Hour, ks)
sess[i] = session.NewSession(nonce.NewID(), 203230230, time.Hour)
}
clients[4].ReceiveCache.Add(address.NewReceiver(sess[0].HeaderPrv))
clients[5].ReceiveCache.Add(address.NewReceiver(sess[1].HeaderPrv))
clients[0].ReceiveCache.Add(address.NewReceiver(sess[2].HeaderPrv))
// clients[4].ReceiveCache.Add(address.NewReceiver(sess[0].HeaderPrv))
// clients[5].ReceiveCache.Add(address.NewReceiver(sess[1].HeaderPrv))
// clients[0].ReceiveCache.Add(address.NewReceiver(sess[2].HeaderPrv))
clients[4].Sessions = clients[4].Sessions.Add(sess[0])
clients[5].Sessions = clients[5].Sessions.Add(sess[1])
clients[0].Sessions = clients[0].Sessions.Add(sess[2])

View File

@@ -42,6 +42,8 @@ func TestPurchaseFlow(t *testing.T) {
}
log.I.S(confirmation)
wait.Wait()
// now to do the purchase
for _, v := range clients {
v.Shutdown()
}

View File

@@ -139,12 +139,12 @@ func (cl *Client) forward(on *forward.OnionSkin, b slice.Bytes,
func (cl *Client) layer(on *layer.OnionSkin, b slice.Bytes, c *slice.Cursor) {
// this is probably an encrypted layer for us.
rcv := cl.ReceiveCache.FindCloaked(on.Cloak)
if rcv == nil {
hdr, _ := cl.FindCloaked(on.Cloak)
if hdr == nil {
log.I.Ln("no matching key found from cloaked key")
return
}
on.Decrypt(rcv.Key, b, c)
on.Decrypt(hdr, b, c)
b = append(b[*c:], slice.NoisePad(int(*c))...)
cl.Node.Send(b)
}
@@ -155,11 +155,11 @@ func (cl *Client) noop(on *noop.OnionSkin, b slice.Bytes, c *slice.Cursor) {
func (cl *Client) purchase(on *purchase.OnionSkin, b slice.Bytes, c *slice.Cursor) {
// Create a new Session.
s := session2.NewSession(on.ID, on.NBytes, DefaultDeadline, cl.KeySet)
s := session2.NewSession(on.ID, on.NBytes, DefaultDeadline)
se := &session.OnionSkin{
ID: s.ID,
HeaderKey: s.HeaderKey.Key,
PayloadKey: s.PayloadKey.Key,
HeaderKey: s.HeaderPub,
PayloadKey: s.PayloadPub,
Onion: &noop.OnionSkin{},
}
cl.Mutex.Lock()
@@ -193,16 +193,16 @@ func (cl *Client) reverse(on *reverse.OnionSkin, b slice.Bytes,
first := *c
second := first + ReverseLayerLen
last := second + ReverseLayerLen
rcv := cl.ReceiveCache.FindCloaked(on1.Cloak)
// We need to find the PayloadKey to match.
ses := cl.Sessions.FindPub(rcv.Pub)
hdrPrv := ses.HeaderPrv
hdr, pld := cl.FindCloaked(on1.Cloak)
// We need to find the PayloadPub to match.
// ses := cl.Sessions.FindPub(hdr.Pub)
hdrPrv := hdr
hdrPub := on1.FromPub
blk := ciph.GetBlock(hdrPrv, hdrPub)
// Decrypt using the Payload key and header nonce.
ciph.Encipher(blk, on1.Nonce,
b[*c:c.Inc(2*ReverseLayerLen)])
blk = ciph.GetBlock(ses.PayloadPrv, hdrPub)
blk = ciph.GetBlock(pld, hdrPub)
ciph.Encipher(blk, on1.Nonce, b[*c:])
// shift the header segment upwards and pad the
// remainder.

View File

@@ -15,7 +15,6 @@ import (
"crypto/rand"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
log2 "github.com/indra-labs/indra/pkg/log"
"github.com/indra-labs/indra/pkg/sha256"
@@ -42,26 +41,6 @@ type Cloaked [Len]byte
type Blinder [BlindLen]byte
type Hash [HashLen]byte
// Sender is the raw bytes of a public key received in the metadata of a
// message.
type Sender struct {
*pub.Key
}
// FromPub creates a Sender from a public key.
func FromPub(k *pub.Key) (s *Sender) {
s = &Sender{Key: k}
return
}
// FromBytes creates a Sender from a received public key bytes.
func FromBytes(pkb pub.Bytes) (s *Sender, e error) {
var pk *pub.Key
pk, e = pub.FromBytes(pkb[:])
s = &Sender{Key: pk}
return
}
// GetCloak returns a value which a receiver with the private key can
// identify the association of a message with the peer in order to retrieve the
// private key to generate the message cipher.
@@ -70,14 +49,14 @@ func FromBytes(pkb pub.Bytes) (s *Sender, e error) {
// generates the 5 bytes at the end of the Cloaked code. In this way the
// source public key it relates to is hidden to any who don't have this public
// key, which only the parties know.
func (s Sender) GetCloak() (c Cloaked) {
func GetCloak(s *pub.Key) (c Cloaked) {
var blinder Blinder
var n int
var e error
if n, e = rand.Read(blinder[:]); check(e) && n != BlindLen {
panic("no entropy")
}
c = Cloak(blinder, s.Key.ToBytes())
c = Cloak(blinder, s.ToBytes())
return
}
@@ -88,33 +67,54 @@ func Cloak(b Blinder, key pub.Bytes) (c Cloaked) {
return
}
// Receiver wraps a private key with pre-generated public key used to recognise
// and associate messages from a specific peer, the public key is sent in a
// previous message inside the encrypted payload and this structure is cached to
// identify the correct key to decrypt the message.
type Receiver struct {
*prv.Key
Pub *pub.Key
pub.Bytes
}
// NewReceiver takes a private key and generates a Receiver for the address
// cache.
func NewReceiver(k *prv.Key) (a *Receiver) {
a = &Receiver{
Key: k,
Pub: pub.Derive(k),
}
a.Bytes = a.Pub.ToBytes()
return
}
// Match uses the cached public key and the provided blinding factor to
// match the source public key so the packet address field is only recognisable
// to the intended recipient.
func (a *Receiver) Match(r Cloaked) bool {
func Match(r Cloaked, k pub.Bytes) bool {
var b Blinder
copy(b[:], r[:BlindLen])
hash := Cloak(b, a.Bytes)
hash := Cloak(b, k)
return r == hash
}
// // Receiver wraps a private key with pre-generated public key used to recognise
// // and associate messages from a specific peer, the public key is sent in a
// // previous message inside the encrypted payload and this structure is cached to
// // identify the correct key to decrypt the message.
// type Receiver struct {
// *prv.Key
// Pub *pub.Key
// pub.Bytes
// }
//
// // NewReceiver takes a private key and generates a Receiver for the address
// // cache.
// func NewReceiver(k *prv.Key) (a *Receiver) {
// a = &Receiver{
// Key: k,
// Pub: pub.Derive(k),
// }
// a.Bytes = a.Pub.ToBytes()
// return
// }
//
// // Sender is the raw bytes of a public key received in the metadata of a
// // message.
// type Sender struct {
// *pub.Key
// }
//
// // FromPub creates a Sender from a public key.
// func FromPub(k *pub.Key) (s *Sender) {
// s = &Sender{Key: k}
// return
// }
//
// // FromBytes creates a Sender from a received public key bytes.
// func FromBytes(pkb pub.Bytes) (s *Sender, e error) {
// var pk *pub.Key
// pk, e = pub.FromBytes(pkb[:])
// s = &Sender{Key: pk}
// return
// }

View File

@@ -6,6 +6,7 @@ import (
"time"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
)
func TestAddress(t *testing.T) {
@@ -14,11 +15,11 @@ func TestAddress(t *testing.T) {
if sendPriv, e = prv.GenerateKey(); check(e) {
return
}
r := NewReceiver(sendPriv)
s := FromPub(r.Pub)
sendPub := pub.Derive(sendPriv)
sendBytes := sendPub.ToBytes()
var cloaked Cloaked
cloaked = s.GetCloak()
if !r.Match(cloaked) {
cloaked = GetCloak(sendPub)
if !Match(cloaked, sendBytes) {
t.Error("failed to recognise cloaked address")
}
rand.Seed(time.Now().Unix())
@@ -26,7 +27,7 @@ func TestAddress(t *testing.T) {
var broken Cloaked
copy(broken[:], cloaked[:])
broken[flip] = ^broken[flip]
if r.Match(broken) {
if Match(broken, sendBytes) {
t.Error("recognised incorrectly broken cloaked address")
}
}

View File

@@ -26,10 +26,11 @@ var (
// this except when the netip.AddrPort is known via the packet sender address.
type Node struct {
nonce.ID
Addr string
AddrPort *netip.AddrPort
HeaderPub *pub.Key
HeaderPrv *prv.Key
Addr string
AddrPort *netip.AddrPort
HeaderPub *pub.Key
HeaderBytes pub.Bytes
HeaderPrv *prv.Key
Services
ifc.Transport
}
@@ -41,12 +42,13 @@ func New(addr *netip.AddrPort, hdr *pub.Key, hdrPrv *prv.Key,
id = nonce.NewID()
n = &Node{
ID: id,
Addr: addr.String(),
AddrPort: addr,
Transport: tpt,
HeaderPub: hdr,
HeaderPrv: hdrPrv,
ID: id,
Addr: addr.String(),
AddrPort: addr,
Transport: tpt,
HeaderPub: hdr,
HeaderBytes: hdr.ToBytes(),
HeaderPrv: hdrPrv,
}
return
}

View File

@@ -5,6 +5,7 @@ import (
"net/netip"
"testing"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/transport"
)
@@ -12,10 +13,15 @@ var testAddrPort, _ = netip.ParseAddrPort("1.1.1.1:20000")
func TestNodes_Add(t *testing.T) {
n := NewNodes()
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
}
const nNodes = 10000
for i := 0; i < nNodes; i++ {
var nn *Node
nn, _ = New(&testAddrPort, nil, nil, transport.NewSim(0))
nn, _ = New(&testAddrPort, prvKey, pubKey, transport.NewSim(0))
n = n.Add(nn)
}
if n.Len() != nNodes {
@@ -26,10 +32,14 @@ func TestNodes_Add(t *testing.T) {
func TestNodes_DeleteByID(t *testing.T) {
n := NewNodes()
const nNodes = 10000
var e error
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
}
for i := 0; i < nNodes; i++ {
var nn *Node
nn, _ = New(&testAddrPort, nil, nil, transport.NewSim(0))
nn, _ = New(&testAddrPort, prvKey, pubKey, transport.NewSim(0))
n.Add(nn)
}
for i := range n {
@@ -42,10 +52,14 @@ func TestNodes_DeleteByID(t *testing.T) {
func TestNodes_DeleteByAddrPort(t *testing.T) {
n := NewNodes()
const nNodes = 10000
var e error
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
}
for i := 0; i < nNodes; i++ {
var nn *Node
nn, _ = New(&testAddrPort, nil, nil, transport.NewSim(0))
nn, _ = New(&testAddrPort, prvKey, pubKey, transport.NewSim(0))
n.Add(nn)
}
for i := range n {
@@ -58,9 +72,14 @@ func TestNodes_DeleteByAddrPort(t *testing.T) {
func TestNodes_FindByID(t *testing.T) {
n := NewNodes()
const nNodes = 10000
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
}
for i := 0; i < nNodes; i++ {
var nn *Node
nn, _ = New(&testAddrPort, nil, nil, transport.NewSim(0))
nn, _ = New(&testAddrPort, prvKey, pubKey, transport.NewSim(0))
n.Add(nn)
}
for i := range n {
@@ -74,9 +93,14 @@ func TestNodes_FindByID(t *testing.T) {
func TestNodes_FindByAddrPort(t *testing.T) {
n := NewNodes()
const nNodes = 10000
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
}
for i := 0; i < nNodes; i++ {
var nn *Node
nn, _ = New(&testAddrPort, nil, nil, transport.NewSim(0))
nn, _ = New(&testAddrPort, prvKey, pubKey, transport.NewSim(0))
n.Add(nn)
}
for i := range n {

View File

@@ -11,7 +11,6 @@ import (
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/ciph"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
log2 "github.com/indra-labs/indra/pkg/log"
@@ -76,7 +75,7 @@ func (p Packets) Swap(i, j int) { p[i], p[j] = p[j], p[i] }
// is 32 bits in size as precision to the second is sufficient, and low latency
// messages will potentially beat the deadline at one second.
type EP struct {
To *address.Sender
To *pub.Key
From *prv.Key
Parity int
Seq int
@@ -96,7 +95,7 @@ func (ep EP) GetOverhead() int {
// the signature to the end.
func Encode(ep EP) (pkt []byte, e error) {
var blk cipher.Block
if blk = ciph.GetBlock(ep.From, ep.To.Key); check(e) {
if blk = ciph.GetBlock(ep.From, ep.To); check(e) {
return
}
nonc := nonce.New()

View File

@@ -6,7 +6,6 @@ import (
"testing"
"time"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/sha256"
@@ -28,7 +27,7 @@ func TestEncode_Decode(t *testing.T) {
if sp, rp, sP, rP, e = testutils.GenerateTestKeyPairs(); check(e) {
t.FailNow()
}
addr := address.FromPub(rP)
addr := rP
var pkt []byte
params := EP{
To: addr,

View File

@@ -5,7 +5,6 @@ import (
"math/rand"
"testing"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/sha256"
@@ -28,7 +27,7 @@ func TestSplitJoin(t *testing.T) {
t.FailNow()
}
_, _, _, _ = sP, Rp, RP, rp
addr := address.FromPub(rP)
addr := rP
params := EP{
To: addr,
From: sp,
@@ -89,7 +88,7 @@ func BenchmarkSplit(b *testing.B) {
b.FailNow()
}
_, _, _ = sP, Rp, rp
addr := address.FromPub(rP)
addr := rP
for n := 0; n < b.N; n++ {
params := EP{
To: addr,
@@ -160,7 +159,7 @@ func TestSplitJoinFEC(t *testing.T) {
punctures[p], punctures[len(punctures)-p-1] =
punctures[len(punctures)-p-1], punctures[p]
}
addr := address.FromPub(rP)
addr := rP
for p := range punctures {
var splitted [][]byte
ep := EP{

View File

@@ -4,10 +4,8 @@ import (
"time"
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/key/signer"
log2 "github.com/indra-labs/indra/pkg/log"
"github.com/indra-labs/indra/pkg/node"
"github.com/indra-labs/indra/pkg/nonce"
@@ -24,22 +22,18 @@ var (
type Session struct {
nonce.ID
*node.Node
Remaining uint64
HeaderKey, PayloadKey *address.SendEntry
HeaderPrv, PayloadPrv *prv.Key
Deadline time.Time
*signer.KeySet
Remaining uint64
HeaderPub, PayloadPub *pub.Key
HeaderBytes, PayloadBytes pub.Bytes
HeaderPrv, PayloadPrv *prv.Key
Deadline time.Time
}
type Sessions []*Session
func (s Sessions) Len() int {
return len(s)
}
func (s Sessions) Len() int { return len(s) }
func (s Sessions) Add(se *Session) Sessions {
return append(s, se)
}
func (s Sessions) Add(se *Session) Sessions { return append(s, se) }
func (s Sessions) Delete(se *Session) Sessions {
for i := range s {
@@ -62,7 +56,7 @@ func (s Sessions) Find(t nonce.ID) (se *Session) {
func (s Sessions) FindPub(pubKey *pub.Key) (se *Session) {
for i := range s {
if s[i].HeaderKey.Key.Equals(pubKey) {
if s[i].HeaderPub.Equals(pubKey) {
se = s[i]
return
}
@@ -74,38 +68,36 @@ func (s Sessions) FindPub(pubKey *pub.Key) (se *Session) {
//
// Purchasing a session the seller returns a token, based on a requested data
// allocation.
func NewSession(id nonce.ID, rem uint64, deadline time.Duration,
kr *signer.KeySet) (s *Session) {
func NewSession(id nonce.ID, rem uint64, deadline time.Duration) (s *Session) {
var e error
var hdrPrv, pldPrv *prv.Key
if hdrPrv, e = prv.GenerateKey(); check(e) {
}
hdrPub := pub.Derive(hdrPrv)
hdrSend := address.NewSendEntry(hdrPub)
// hdrSend := address.NewSendEntry(hdrPub)
if pldPrv, e = prv.GenerateKey(); check(e) {
}
pldPub := pub.Derive(pldPrv)
pldSend := address.NewSendEntry(pldPub)
// pldSend := address.NewSendEntry(pldPub)
s = &Session{
ID: id,
Remaining: rem,
HeaderKey: hdrSend,
PayloadKey: pldSend,
HeaderPrv: hdrPrv,
PayloadPrv: pldPrv,
KeySet: kr,
Deadline: time.Now().Add(deadline),
ID: id,
Remaining: rem,
HeaderPub: hdrPub,
HeaderBytes: hdrPub.ToBytes(),
PayloadPub: pldPub,
PayloadBytes: pldPub.ToBytes(),
HeaderPrv: hdrPrv,
PayloadPrv: pldPrv,
Deadline: time.Now().Add(deadline),
}
return
}
// AddBytes adds to the Remaining counter, used when new data allowance has been
// purchased.
func (s *Session) AddBytes(b uint64) {
s.Remaining += b
}
func (s *Session) AddBytes(b uint64) { s.Remaining += b }
// SubtractBytes reduces the amount Remaining, if the requested amount would put
// the total below zero it returns false, signalling that new data allowance

View File

@@ -27,13 +27,15 @@ func GenerateTestMessage(msgSize int) (msg []byte, hash sha256.Hash, e error) {
}
func GenerateTestKeyPairs() (sp, rp *prv.Key, sP, rP *pub.Key, e error) {
sp, sP, e = GenerateTestKeyPair()
rp, rP, e = GenerateTestKeyPair()
return
}
func GenerateTestKeyPair() (sp *prv.Key, sP *pub.Key, e error) {
if sp, e = prv.GenerateKey(); check(e) {
return
}
sP = pub.Derive(sp)
if rp, e = prv.GenerateKey(); check(e) {
return
}
rP = pub.Derive(rp)
return
}

View File

@@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
log2 "github.com/indra-labs/indra/pkg/log"
@@ -212,7 +211,7 @@ func TestOnionSkins_Layer(t *testing.T) {
prv1, prv2 := GetTwoPrvKeys(t)
pub1 := pub.Derive(prv1)
on := OnionSkins{}.
OnionSkin(address.FromPub(pub1), prv2, n1).
OnionSkin(pub1, prv2, n1).
Confirmation(n).
Assemble()
onb := EncodeOnion(on)

View File

@@ -33,7 +33,7 @@ var (
// for each layer, and a header which a relay uses to determine what cipher to
// use.
type OnionSkin struct {
To *address.Sender
To *pub.Key
From *prv.Key
// The remainder here are for Decode.
Nonce nonce.IV
@@ -63,7 +63,7 @@ func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
copy(b[*c:c.Inc(nonce.IVLen)], x.Nonce[:])
// Derive the cloaked key and copy it in.
to := x.To.GetCloak()
to := address.GetCloak(x.To)
copy(b[*c:c.Inc(address.Len)], to[:])
// Derive the public key from the From key and copy in.
pubKey := pub.Derive(x.From).ToBytes()
@@ -74,7 +74,7 @@ func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
// Then we can encrypt the message segment
var e error
var blk cipher.Block
if blk = ciph.GetBlock(x.From, x.To.Key); check(e) {
if blk = ciph.GetBlock(x.From, x.To); check(e) {
panic(e)
}
ciph.Encipher(blk, x.Nonce, b[start:])

View File

@@ -4,7 +4,6 @@ import (
"net/netip"
"time"
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/ecdh"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
@@ -83,7 +82,9 @@ func (o OnionSkins) Forward(addr *netip.AddrPort) OnionSkins {
return append(o, &forward.OnionSkin{AddrPort: addr, Onion: &noop.OnionSkin{}})
}
func (o OnionSkins) OnionSkin(to *address.Sender, from *prv.Key, n nonce.IV) OnionSkins {
func (o OnionSkins) OnionSkin(to *pub.Key, from *prv.Key,
n nonce.IV) OnionSkins {
return append(o, &layer.OnionSkin{
To: to,
From: from,

View File

@@ -1,7 +1,6 @@
package wire
import (
"github.com/indra-labs/indra/pkg/key/address"
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/key/signer"
@@ -27,13 +26,13 @@ func Ping(id nonce.ID, client *node.Node, hop [3]*node.Node,
n := GenPingNonces()
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPub(hop[0].HeaderPub), set.Next(), n[0]).
OnionSkin(hop[0].HeaderPub, set.Next(), n[0]).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPub(hop[1].HeaderPub), set.Next(), n[1]).
OnionSkin(hop[1].HeaderPub, set.Next(), n[1]).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPub(hop[2].HeaderPub), set.Next(), n[2]).
OnionSkin(hop[2].HeaderPub, set.Next(), n[2]).
Forward(client.AddrPort).
OnionSkin(address.FromPub(client.HeaderPub), set.Next(), n[3]).
OnionSkin(client.HeaderPub, set.Next(), n[3]).
Confirmation(id)
}
@@ -57,18 +56,18 @@ func SendKeys(id nonce.ID, hdr, pld *prv.Key,
n1 := Gen3Nonces()
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPub(hop[0].HeaderPub), set.Next(), n0[0]).
OnionSkin(hop[0].HeaderPub, set.Next(), n0[0]).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPub(hop[1].HeaderPub), set.Next(), n0[1]).
OnionSkin(hop[1].HeaderPub, set.Next(), n0[1]).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPub(hop[2].HeaderPub), set.Next(), n0[2]).
OnionSkin(hop[2].HeaderPub, set.Next(), n0[2]).
Cipher(hdr, pld).
Forward(hop[3].AddrPort).
OnionSkin(address.FromPub(hop[3].HeaderPub), set.Next(), n1[0]).
OnionSkin(hop[3].HeaderPub, set.Next(), n1[0]).
Forward(hop[4].AddrPort).
OnionSkin(address.FromPub(hop[4].HeaderPub), set.Next(), n1[1]).
OnionSkin(hop[4].HeaderPub, set.Next(), n1[1]).
Forward(client.AddrPort).
OnionSkin(address.FromPub(client.HeaderPub), set.Next(), n1[2]).
OnionSkin(client.HeaderPub, set.Next(), n1[2]).
Confirmation(id)
}
@@ -96,23 +95,23 @@ func SendPurchase(n nonce.ID, nBytes uint64, client *node.Node,
}
n0, n1 := Gen3Nonces(), Gen3Nonces()
var pubs [3]*pub.Key
pubs[0] = sess[0].PayloadKey.Key
pubs[1] = sess[1].PayloadKey.Key
pubs[2] = sess[2].PayloadKey.Key
pubs[0] = sess[0].PayloadPub
pubs[1] = sess[1].PayloadPub
pubs[2] = sess[2].PayloadPub
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPub(hop[0].HeaderPub), set.Next(), n0[0]).
OnionSkin(hop[0].HeaderPub, set.Next(), n0[0]).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPub(hop[1].HeaderPub), set.Next(), n0[1]).
OnionSkin(hop[1].HeaderPub, set.Next(), n0[1]).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPub(hop[2].HeaderPub), set.Next(), n0[2]).
OnionSkin(hop[2].HeaderPub, set.Next(), n0[2]).
Purchase(n, nBytes, prvs, pubs, n1).
Reverse(hop[3].AddrPort).
OnionSkin(address.FromPub(sess[0].HeaderKey.Key), prvs[0], n1[0]).
OnionSkin(sess[0].HeaderPub, prvs[0], n1[0]).
Reverse(hop[4].AddrPort).
OnionSkin(address.FromPub(sess[1].HeaderKey.Key), prvs[1], n1[1]).
OnionSkin(sess[1].HeaderPub, prvs[1], n1[1]).
Reverse(client.AddrPort).
OnionSkin(address.FromPub(sess[2].HeaderKey.Key), prvs[2], n1[2])
OnionSkin(sess[2].HeaderPub, prvs[2], n1[2])
}
// SendExit constructs a message containing an arbitrary payload to a node (3rd
@@ -141,21 +140,21 @@ func SendExit(payload slice.Bytes, port uint16, client *node.Node,
}
n0, n1 := Gen3Nonces(), Gen3Nonces()
var pubs [3]*pub.Key
pubs[0] = sess[0].PayloadKey.Key
pubs[1] = sess[1].PayloadKey.Key
pubs[2] = sess[2].PayloadKey.Key
pubs[0] = sess[0].PayloadPub
pubs[1] = sess[1].PayloadPub
pubs[2] = sess[2].PayloadPub
return OnionSkins{}.
Forward(hop[0].AddrPort).
OnionSkin(address.FromPub(hop[0].HeaderPub), set.Next(), n0[0]).
OnionSkin(hop[0].HeaderPub, set.Next(), n0[0]).
Forward(hop[1].AddrPort).
OnionSkin(address.FromPub(hop[1].HeaderPub), set.Next(), n0[1]).
OnionSkin(hop[1].HeaderPub, set.Next(), n0[1]).
Forward(hop[2].AddrPort).
OnionSkin(address.FromPub(hop[2].HeaderPub), set.Next(), n0[2]).
OnionSkin(hop[2].HeaderPub, set.Next(), n0[2]).
Exit(port, prvs, pubs, n1, payload).
Reverse(hop[3].AddrPort).
OnionSkin(address.FromPub(sess[0].HeaderKey.Key), prvs[0], n1[0]).
OnionSkin(sess[0].HeaderPub, prvs[0], n1[0]).
Reverse(hop[4].AddrPort).
OnionSkin(address.FromPub(sess[1].HeaderKey.Key), prvs[1], n1[1]).
OnionSkin(sess[1].HeaderPub, prvs[1], n1[1]).
Reverse(client.AddrPort).
OnionSkin(address.FromPub(sess[2].HeaderKey.Key), prvs[2], n1[2])
OnionSkin(sess[2].HeaderPub, prvs[2], n1[2])
}

View File

@@ -343,8 +343,7 @@ func TestSendPurchase(t *testing.T) {
cpub1, cprv1, nil)
var sess [3]*session.Session
for i := range sess {
sess[i] = session.NewSession(nonce.NewID(), 203230230,
time.Hour, ks)
sess[i] = session.NewSession(nonce.NewID(), 203230230, time.Hour)
}
nBytes := rand.Uint64()
n := nonce.NewID()
@@ -449,8 +448,7 @@ func TestSendExit(t *testing.T) {
message, hash, e = testutils.GenerateTestMessage(2502)
var sess [3]*session.Session
for i := range sess {
sess[i] = session.NewSession(nonce.NewID(), 203230230,
time.Hour, ks)
sess[i] = session.NewSession(nonce.NewID(), 203230230, time.Hour)
}
on := SendExit(message, port, client, hop, sess, ks)
b := EncodeOnion(on.Assemble())

View File

@@ -10,9 +10,9 @@ var (
// GitRef is the gitref, as in refs/heads/branchname.
GitRef = "refs/heads/protocol"
// ParentGitCommit is the commit hash of the parent HEAD.
ParentGitCommit = "6f68679b7cfa8a4d0a47aa9b1598037bbb18844a"
ParentGitCommit = "0c1d790011c29f145d8e0f04e2ec00701819e793"
// BuildTime stores the time when the current binary was built.
BuildTime = "2023-01-07T15:30:48Z"
BuildTime = "2023-01-07T17:43:47Z"
// SemVer lists the (latest) git tag on the release.
SemVer = "v0.1.4"
// PathBase is the path base returned from runtime caller.