Remove bogus session, fix cipher type

This commit is contained in:
David Vennik
2023-01-14 08:54:21 +00:00
parent 83426af15a
commit 59b1dd4bdd
17 changed files with 94 additions and 348 deletions

1
go.mod
View File

@@ -18,7 +18,6 @@ require (
github.com/moby/term v0.0.0-20221205130635-1aeaba878587
github.com/multiformats/go-multiaddr v0.8.0
github.com/naoina/toml v0.1.1
github.com/stretchr/testify v1.8.1
github.com/templexxx/reedsolomon v1.1.3
go.uber.org/atomic v1.10.0
google.golang.org/grpc v1.51.0

View File

@@ -1,7 +1,6 @@
package client
import (
"fmt"
"net/netip"
"sync"
"time"
@@ -43,7 +42,7 @@ type Client struct {
ExitHooks response.Hooks
sync.Mutex
*signer.KeySet
atomic.Bool
ShuttingDown atomic.Bool
qu.C
}
@@ -114,67 +113,6 @@ func (cl *Client) FindCloaked(clk cloak.PubKey) (hdr *prv.Key, pld *prv.Key,
return
}
// SendKeys is the delivery of a ...
//
// todo: this function should be requiring input of keys, and a related prior
//
// function that generates the preimage for an LN AMP, from the hash of the
// keys.
func (cl *Client) SendKeys(nodeID []nonce.ID, hook confirm.Hook) (conf nonce.ID,
e error) {
var n []*node.Node
for i := range nodeID {
no := cl.Nodes.FindByID(nodeID[i])
if no != nil {
n = append(n, no)
}
}
if len(n) > 5 {
e = fmt.Errorf("SendKeys maximum 5 keys %d given", len(nodeID))
}
ln := len(n)
hdrPrv, pldPrv := make([]*prv.Key, ln), make([]*prv.Key, ln)
hdrPub, pldPub := make([]*pub.Key, ln), make([]*pub.Key, ln)
for i := range n {
if hdrPrv[i], e = prv.GenerateKey(); check(e) {
return
}
hdrPub[i] = pub.Derive(hdrPrv[i])
if pldPrv[i], e = prv.GenerateKey(); check(e) {
return
}
pldPub[i] = pub.Derive(pldPrv[i])
}
// selected := cl.Nodes.Select(SimpleSelector, n, 4)
// if len(selected) < 4 {
// e = fmt.Errorf("not enough nodes known to form circuit")
// return
// }
// hop := [5]*node.Node{
// selected[0], selected[1], n, selected[2], selected[3],
// }
// conf = nonce.NewID()
// os := wire.SendKeys(conf, hdrPrv, pldPrv, cl.Node, hop, cl.KeySet)
// cl.RegisterConfirmation(hook, os[len(os)-1].(*confirm.OnionSkin).ID)
// cl.Sessions.Add(&session.Session{
// ID: n.ID,
// Remaining: 1 << 16,
// IdentityPub: hdrPub,
// IdentityBytes: hdrPub.ToBytes(),
// PayloadPub: pldPub,
// PayloadBytes: pldPub.ToBytes(),
// IdentityPrv: hdrPrv,
// PayloadPrv: pldPrv,
// Deadline: time.Now().Add(DefaultDeadline),
// })
// o := os.Assemble()
// b := wire.EncodeOnion(o)
// cl.Send(hop[0].AddrPort, b)
return
}
// Cleanup closes and flushes any resources the client opened that require sync
// in order to reopen correctly.
func (cl *Client) Cleanup() {
@@ -184,13 +122,13 @@ func (cl *Client) Cleanup() {
// Shutdown triggers the shutdown of the client and the Cleanup before
// finishing.
func (cl *Client) Shutdown() {
if cl.Bool.Load() {
if cl.ShuttingDown.Load() {
return
}
log.T.C(func() string {
return "shutting down client " + cl.Node.AddrPort.String()
})
cl.Bool.Store(true)
cl.ShuttingDown.Store(true)
cl.C.Q()
}

View File

@@ -5,12 +5,11 @@ import (
"time"
"github.com/cybriq/qu"
"github.com/indra-labs/indra/pkg/key/signer"
"github.com/indra-labs/indra/pkg/node"
"github.com/indra-labs/indra/pkg/nonce"
"github.com/indra-labs/indra/pkg/sha256"
"github.com/indra-labs/indra/pkg/slice"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
"github.com/indra-labs/indra/pkg/transport"
"github.com/indra-labs/indra/pkg/wire"
"github.com/indra-labs/indra/pkg/wire/confirm"
@@ -36,7 +35,7 @@ func TestPing(t *testing.T) {
os := wire.Ping(conf, clients[0].Node, circuit, clients[0].KeySet)
quit := qu.T()
clients[0].RegisterConfirmation(func(cf nonce.ID) {
log.I.S("received ping confirmation ID", cf)
log.T.S("received ping confirmation ID", cf)
quit.Q()
}, os[len(os)-1].(*confirm.OnionSkin).ID)
o := os.Assemble()
@@ -47,10 +46,9 @@ func TestPing(t *testing.T) {
select {
case <-time.After(time.Second):
t.Error("ping got stuck")
quit.Q()
case <-quit:
}
time.Sleep(time.Second)
quit.Q()
}()
<-quit.Wait()
for _, v := range clients {
@@ -66,11 +64,6 @@ func TestSendExit(t *testing.T) {
t.Error(e)
t.FailNow()
}
var ks *signer.KeySet
if _, ks, e = signer.New(); check(e) {
t.Error(e)
t.FailNow()
}
// set up forwarding port service
const port = 3455
clients[3].Services = append(clients[3].Services, &node.Service{
@@ -85,26 +78,25 @@ func TestSendExit(t *testing.T) {
for i := range circuit {
circuit[i] = clients[0].Sessions[i+1]
}
var message slice.Bytes
var hash sha256.Hash
if message, hash, e = testutils.GenerateTestMessage(32, "request"); check(e) {
var msg slice.Bytes
var msgHash sha256.Hash
if msg, msgHash, e = tests.GenMessage(32, "request"); check(e) {
t.Error(e)
t.FailNow()
}
var responseMessage slice.Bytes
var responseHash sha256.Hash
if responseMessage, responseHash, e =
testutils.GenerateTestMessage(32, "response"); check(e) {
var respMsg slice.Bytes
var respHash sha256.Hash
if respMsg, respHash, e = tests.GenMessage(32, "response"); check(e) {
t.Error(e)
t.FailNow()
}
quit := qu.T()
os := wire.SendExit(message, port, clients[0].Node, circuit, ks)
clients[0].ExitHooks = clients[0].ExitHooks.Add(hash,
os := wire.SendExit(msg, port, clients[0].Node, circuit,
clients[0].KeySet)
clients[0].ExitHooks = clients[0].ExitHooks.Add(msgHash,
func(b slice.Bytes) {
log.T.S(b.ToBytes())
if sha256.Single(b) != responseHash {
if sha256.Single(b) != respHash {
t.Error("failed to receive expected message")
}
quit.Q()
@@ -120,7 +112,7 @@ func TestSendExit(t *testing.T) {
}()
bb := <-clients[3].Services[0].Receive()
log.T.S(bb.ToBytes())
if e = clients[3].SendTo(port, responseMessage); check(e) {
if e = clients[3].SendTo(port, respMsg); check(e) {
t.Error("fail send")
}
log.T.Ln("response sent")
@@ -130,25 +122,26 @@ func TestSendExit(t *testing.T) {
}
}
// func TestSendKeys(t *testing.T) {
// const nTotal = 6
// clients := make([]*Client, nTotal)
// var e error
// if clients, e = CreateMockCircuitClients(nTotal); check(e) {
// t.Error(e)
// t.FailNow()
// }
// // Start up the clients.
// for _, v := range clients {
// go v.Start()
// }
// quit := qu.T()
// clients[0].SendKeys(clients[0].Nodes[0].ID, func(cf nonce.ID) {
// log.I.S("received sendkeys confirmation ID", cf)
// quit.Q()
// })
// <-quit.Wait()
// for _, v := range clients {
// v.Shutdown()
// }
// }
func TestSendKeys(t *testing.T) {
var clients []*Client
var e error
if clients, e = CreateMockCircuitClients(); check(e) {
t.Error(e)
t.FailNow()
}
// Start up the clients.
for _, v := range clients {
go v.Start()
}
quit := qu.T()
go func() {
<-time.After(time.Second)
quit.Q()
// t.Error("SendKeys got stuck")
}()
<-quit.Wait()
for _, v := range clients {
v.Shutdown()
}
}

View File

@@ -20,10 +20,18 @@ import (
"github.com/indra-labs/indra/pkg/wire/noop"
"github.com/indra-labs/indra/pkg/wire/response"
"github.com/indra-labs/indra/pkg/wire/reverse"
"github.com/indra-labs/indra/pkg/wire/session"
"github.com/indra-labs/indra/pkg/wire/token"
)
func recLog(on types.Onion, b slice.Bytes, cl *Client) {
log.T.C(func() string {
return cl.AddrPort.String() +
" received " +
fmt.Sprint(reflect.TypeOf(on)) + "\n" +
spew.Sdump(b.ToBytes())
})
}
func (cl *Client) runner() (out bool) {
log.T.C(func() string {
return cl.AddrPort.String() +
@@ -44,92 +52,34 @@ func (cl *Client) runner() (out bool) {
}
switch on := onion.(type) {
case *cipher.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.cipher(on, b, c)
case *confirm.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.confirm(on, b, c)
case *delay.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.delay(on, b, c)
case *exit.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.exit(on, b, c)
case *forward.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.forward(on, b, c)
case *layer.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.layer(on, b, c)
case *noop.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.noop(on, b, c)
case *reverse.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.reverse(on, b, c)
case *response.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.response(on, b, c)
case *session.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
cl.session(on, b, c)
case *token.OnionSkin:
log.T.C(func() string {
return cl.AddrPort.String() +
" received\n" +
fmt.Sprint(reflect.TypeOf(on)) +
spew.Sdump(b.ToBytes())
})
recLog(on, b, cl)
cl.token(on, b, c)
default:
log.I.S("unrecognised packet", b)
@@ -278,27 +228,6 @@ func (cl *Client) response(on *response.OnionSkin, b slice.Bytes, cur *slice.Cur
cl.ExitHooks.Find(on.Hash, on.Bytes)
}
func (cl *Client) session(s *session.OnionSkin, b slice.Bytes,
cur *slice.Cursor) {
// Session is returned from a Purchase message in the reverse layers.
//
// Session has a nonce.ID that is given in the last layer of a LN sphinx
// Bolt 4 onion routed payment path that will cause the seller to
// activate the accounting onion the two keys it sent back with the
// nonce, so long as it has not yet expired.
for i := range cl.PendingSessions {
if cl.PendingSessions[i] == s.ID {
// we would make payment and move session to running
// sessions list.
log.I.S("session received, now to pay", s)
}
}
// So now we want to pay. For now we are just going to shut down the
// client as this finishes the test correctly.
cl.C.Q()
}
func (cl *Client) token(t *token.OnionSkin, b slice.Bytes, cur *slice.Cursor) {
// not really sure if we are using these.
return

View File

@@ -5,7 +5,7 @@ import (
"net/netip"
"testing"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
"github.com/indra-labs/indra/pkg/transport"
)
@@ -13,7 +13,7 @@ var testAddrPort, _ = netip.ParseAddrPort("1.1.1.1:20000")
func TestNodes_Add(t *testing.T) {
n := NewNodes()
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
pubKey, prvKey, e := tests.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
@@ -32,7 +32,7 @@ func TestNodes_Add(t *testing.T) {
func TestNodes_DeleteByID(t *testing.T) {
n := NewNodes()
const nNodes = 10000
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
pubKey, prvKey, e := tests.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
@@ -52,7 +52,7 @@ func TestNodes_DeleteByID(t *testing.T) {
func TestNodes_DeleteByAddrPort(t *testing.T) {
n := NewNodes()
const nNodes = 10000
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
pubKey, prvKey, e := tests.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
@@ -72,7 +72,7 @@ func TestNodes_DeleteByAddrPort(t *testing.T) {
func TestNodes_FindByID(t *testing.T) {
n := NewNodes()
const nNodes = 10000
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
pubKey, prvKey, e := tests.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()
@@ -93,7 +93,7 @@ func TestNodes_FindByID(t *testing.T) {
func TestNodes_FindByAddrPort(t *testing.T) {
n := NewNodes()
const nNodes = 10000
pubKey, prvKey, e := testutils.GenerateTestKeyPair()
pubKey, prvKey, e := tests.GenerateTestKeyPair()
if check(e) {
t.Error(e)
t.FailNow()

View File

@@ -1,12 +1,13 @@
package node
import (
"github.com/indra-labs/indra/pkg/lnwire"
"github.com/indra-labs/indra/pkg/sha256"
)
type Payment struct {
Preimage sha256.Hash
// Amount lnwire.MilliSatoshi
Amount lnwire.MilliSatoshi
}
type PaymentChan chan *Payment

View File

@@ -9,7 +9,7 @@ import (
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/sha256"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
)
func TestEncode_Decode(t *testing.T) {
@@ -24,7 +24,7 @@ func TestEncode_Decode(t *testing.T) {
pHash := sha256.Single(payload)
var sp, rp *prv.Key
var sP, rP *pub.Key
if sp, rp, sP, rP, e = testutils.GenerateTestKeyPairs(); check(e) {
if sp, rp, sP, rP, e = tests.GenerateTestKeyPairs(); check(e) {
t.FailNow()
}
addr := rP

View File

@@ -8,7 +8,7 @@ import (
"github.com/indra-labs/indra/pkg/key/prv"
"github.com/indra-labs/indra/pkg/key/pub"
"github.com/indra-labs/indra/pkg/sha256"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
)
func TestSplitJoin(t *testing.T) {
@@ -17,12 +17,12 @@ func TestSplitJoin(t *testing.T) {
var e error
var payload []byte
var pHash sha256.Hash
if payload, pHash, e = testutils.GenerateTestMessage(msgSize, ""); check(e) {
if payload, pHash, e = tests.GenMessage(msgSize, ""); check(e) {
t.FailNow()
}
var sp, rp *prv.Key
var rP *pub.Key
if sp, rp, _, rP, e = testutils.GenerateTestKeyPairs(); check(e) {
if sp, rp, _, rP, e = tests.GenerateTestKeyPairs(); check(e) {
t.FailNow()
}
addr := rP
@@ -75,12 +75,12 @@ func BenchmarkSplit(b *testing.B) {
segSize := 1382
var e error
var payload []byte
if payload, _, e = testutils.GenerateTestMessage(msgSize, ""); check(e) {
if payload, _, e = tests.GenMessage(msgSize, ""); check(e) {
b.Error(e)
}
var sp *prv.Key
var rP *pub.Key
if sp, _, _, rP, e = testutils.GenerateTestKeyPairs(); check(e) {
if sp, _, _, rP, e = tests.GenerateTestKeyPairs(); check(e) {
b.FailNow()
}
addr := rP
@@ -138,7 +138,7 @@ func TestSplitJoinFEC(t *testing.T) {
var e error
var sp, rp, Rp *prv.Key
var sP, rP, RP *pub.Key
if sp, rp, sP, rP, e = testutils.GenerateTestKeyPairs(); check(e) {
if sp, rp, sP, rP, e = tests.GenerateTestKeyPairs(); check(e) {
t.FailNow()
}
_, _, _, _ = sP, Rp, RP, rp
@@ -150,7 +150,7 @@ func TestSplitJoinFEC(t *testing.T) {
var payload []byte
var pHash sha256.Hash
if payload, pHash, e = testutils.GenerateTestMessage(msgSize, ""); check(e) {
if payload, pHash, e = tests.GenMessage(msgSize, ""); check(e) {
t.FailNow()
}

View File

@@ -5,13 +5,13 @@ import (
"testing"
"github.com/indra-labs/indra/pkg/sha256"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
)
func TestMessage_ToU64Slice(t *testing.T) {
var e error
var msg1 Bytes
if msg1, _, e = testutils.GenerateTestMessage(33, ""); check(e) {
if msg1, _, e = tests.GenMessage(33, ""); check(e) {
t.Error(e)
t.FailNow()
}
@@ -27,21 +27,21 @@ func TestU64Slice_XOR(t *testing.T) {
const ml = 1024
var e error
var msg1 Bytes
if msg1, _, e = testutils.GenerateTestMessage(ml, ""); check(e) {
if msg1, _, e = tests.GenMessage(ml, ""); check(e) {
t.Error(e)
t.FailNow()
}
hash1 := sha256.Single(msg1)
uMsg1 := msg1.ToU64Slice()
var msg2 Bytes
if msg2, _, e = testutils.GenerateTestMessage(ml, ""); check(e) {
if msg2, _, e = tests.GenMessage(ml, ""); check(e) {
t.Error(e)
t.FailNow()
}
// log.I.S(msg2)
uMsg2 := msg2.ToU64Slice()
var msg3 Bytes
if msg3, _, e = testutils.GenerateTestMessage(ml, ""); check(e) {
if msg3, _, e = tests.GenMessage(ml, ""); check(e) {
t.Error(e)
t.FailNow()
}

View File

@@ -5,7 +5,7 @@ import (
"testing"
"github.com/indra-labs/indra/pkg/sha256"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
)
func TestSize24(t *testing.T) {
@@ -24,7 +24,7 @@ func TestSegment(t *testing.T) {
var msg []byte
var hash sha256.Hash
var e error
if msg, hash, e = testutils.GenerateTestMessage(msgSize, ""); check(e) {
if msg, hash, e = tests.GenMessage(msgSize, ""); check(e) {
t.Error(e)
}
segs := Segment(msg, segSize)

View File

@@ -1,4 +1,4 @@
package testutils
package tests
import (
"crypto/rand"
@@ -15,7 +15,7 @@ var (
check = log.E.Chk
)
func GenerateTestMessage(msgSize int, hrp string) (msg []byte, hash sha256.Hash, e error) {
func GenMessage(msgSize int, hrp string) (msg []byte, hash sha256.Hash, e error) {
msg = make([]byte, msgSize)
var n int
if n, e = rand.Read(msg); check(e) && n != msgSize {

View File

@@ -40,8 +40,8 @@ func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
hdr := x.Header.ToBytes()
pld := x.Payload.ToBytes()
copy(b[*c:c.Inc(pub.KeyLen)], hdr[:])
copy(b[*c:c.Inc(pub.KeyLen)], pld[:])
copy(b[*c:c.Inc(prv.KeyLen)], hdr[:])
copy(b[*c:c.Inc(prv.KeyLen)], pld[:])
x.Onion.Encode(b, c)
}
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
@@ -49,7 +49,7 @@ func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
return magicbytes.TooShort(len(b[*c:]),
Len-magicbytes.Len, string(Magic))
}
x.Header = prv.PrivkeyFromBytes(b[*c:c.Inc(pub.KeyLen)])
x.Payload = prv.PrivkeyFromBytes(b[*c:c.Inc(pub.KeyLen)])
x.Header = prv.PrivkeyFromBytes(b[*c:c.Inc(prv.KeyLen)])
x.Payload = prv.PrivkeyFromBytes(b[*c:c.Inc(prv.KeyLen)])
return
}

View File

@@ -17,7 +17,6 @@ import (
"github.com/indra-labs/indra/pkg/wire/magicbytes"
"github.com/indra-labs/indra/pkg/wire/response"
"github.com/indra-labs/indra/pkg/wire/reverse"
"github.com/indra-labs/indra/pkg/wire/session"
"github.com/indra-labs/indra/pkg/wire/token"
)
@@ -84,12 +83,6 @@ func PeelOnion(b slice.Bytes, c *slice.Cursor) (on types.Onion, e error) {
return
}
on = o
case session.MagicString:
o := &session.OnionSkin{}
if e = o.Decode(b, c); check(e) {
return
}
on = o
case token.MagicString:
o := token.NewOnionSkin()
if e = o.Decode(b, c); check(e) {

View File

@@ -13,7 +13,7 @@ import (
"github.com/indra-labs/indra/pkg/nonce"
"github.com/indra-labs/indra/pkg/sha256"
"github.com/indra-labs/indra/pkg/slice"
"github.com/indra-labs/indra/pkg/testutils"
"github.com/indra-labs/indra/pkg/tests"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/wire/cipher"
"github.com/indra-labs/indra/pkg/wire/confirm"
@@ -23,7 +23,6 @@ import (
"github.com/indra-labs/indra/pkg/wire/layer"
"github.com/indra-labs/indra/pkg/wire/response"
"github.com/indra-labs/indra/pkg/wire/reverse"
"github.com/indra-labs/indra/pkg/wire/session"
"github.com/indra-labs/indra/pkg/wire/token"
)
@@ -114,7 +113,7 @@ func TestOnionSkins_Exit(t *testing.T) {
ciphers := GenCiphers(prvs, pubs)
var msg slice.Bytes
var hash sha256.Hash
if msg, hash, e = testutils.GenerateTestMessage(512, ""); check(e) {
if msg, hash, e = tests.GenMessage(512, ""); check(e) {
t.Error(e)
t.FailNow()
}
@@ -290,7 +289,7 @@ func TestOnionSkins_Response(t *testing.T) {
var e error
var msg slice.Bytes
var hash sha256.Hash
if msg, hash, e = testutils.GenerateTestMessage(10000, ""); check(e) {
if msg, hash, e = tests.GenMessage(10000, ""); check(e) {
t.Error(e)
t.FailNow()
}
@@ -317,37 +316,6 @@ func TestOnionSkins_Response(t *testing.T) {
}
func TestOnionSkins_Session(t *testing.T) {
var e error
hdrP, pldP := GetTwoPrvKeys(t)
hdr, pld := pub.Derive(hdrP), pub.Derive(pldP)
on := OnionSkins{}.
Session(hdr, pld).
Assemble()
onb := EncodeOnion(on)
c := slice.NewCursor()
var oncn types.Onion
if oncn, e = PeelOnion(onb, c); check(e) {
t.FailNow()
}
var cf *session.OnionSkin
var ok bool
if cf, ok = oncn.(*session.OnionSkin); !ok {
t.Error("did not unwrap expected type", reflect.TypeOf(oncn))
t.FailNow()
}
if !cf.HeaderKey.Equals(hdr) {
t.Error("header key mismatch")
t.FailNow()
}
if !cf.PayloadKey.Equals(pld) {
t.Error("payload key mismatch")
t.FailNow()
}
}
func TestOnionSkins_Token(t *testing.T) {
var e error

View File

@@ -19,7 +19,6 @@ import (
"github.com/indra-labs/indra/pkg/wire/noop"
"github.com/indra-labs/indra/pkg/wire/response"
"github.com/indra-labs/indra/pkg/wire/reverse"
"github.com/indra-labs/indra/pkg/wire/session"
"github.com/indra-labs/indra/pkg/wire/token"
)
@@ -84,14 +83,6 @@ func (o OnionSkins) Response(hash sha256.Hash, res slice.Bytes) OnionSkins {
return append(o, &rs)
}
func (o OnionSkins) Session(hdr, pld *pub.Key) OnionSkins {
return append(o, &session.OnionSkin{
HeaderKey: hdr,
PayloadKey: pld,
Onion: os,
})
}
func (o OnionSkins) Token(tok sha256.Hash) OnionSkins {
return append(o, (*token.OnionSkin)(&tok))
}

View File

@@ -1,66 +0,0 @@
package session
import (
"github.com/indra-labs/indra"
"github.com/indra-labs/indra/pkg/key/pub"
log2 "github.com/indra-labs/indra/pkg/log"
"github.com/indra-labs/indra/pkg/nonce"
"github.com/indra-labs/indra/pkg/slice"
"github.com/indra-labs/indra/pkg/types"
"github.com/indra-labs/indra/pkg/wire/magicbytes"
)
const (
MagicString = "ss"
Len = magicbytes.Len + nonce.IDLen + pub.KeyLen*2
)
var (
log = log2.GetLogger(indra.PathBase)
check = log.E.Chk
Magic = slice.Bytes(MagicString)
_ types.Onion = &OnionSkin{}
)
// OnionSkin session is a message containing two public keys which identify to a
// relay how to decrypt the header in a Reverse message, using the HeaderKey, and
// the payload, which uses the PayloadKey. There is two keys in order to prevent
// the Exit node from being able to decrypt the header, but enable it to encrypt
// the payload, and Reverse relay hops have these key pairs and identify the
// HeaderKey and then know they can unwrap their layer of the payload using the
// PayloadKey.
//
// Clients use the HeaderKey, cloaked, in their messages for the seller relay,
// in the header, and use the PayloadKey as the public key half with ECDH and
// their generated private key which produces the public key that is placed in
// the header associated with the payload, using the same nonce.IV as well.
type OnionSkin struct {
nonce.ID
HeaderKey, PayloadKey *pub.Key
types.Onion
}
func (x *OnionSkin) Inner() types.Onion { return x.Onion }
func (x *OnionSkin) Insert(o types.Onion) { x.Onion = o }
func (x *OnionSkin) Len() int { return Len + x.Onion.Len() }
func (x *OnionSkin) Encode(b slice.Bytes, c *slice.Cursor) {
hdr, pld := x.HeaderKey.ToBytes(), x.PayloadKey.ToBytes()
copy(b[*c:c.Inc(magicbytes.Len)], Magic)
copy(b[*c:c.Inc(nonce.IDLen)], x.ID[:])
copy(b[*c:c.Inc(pub.KeyLen)], hdr[:])
copy(b[*c:c.Inc(pub.KeyLen)], pld[:])
x.Onion.Encode(b, c)
}
func (x *OnionSkin) Decode(b slice.Bytes, c *slice.Cursor) (e error) {
if len(b[*c:]) < Len-magicbytes.Len {
return magicbytes.TooShort(len(b[*c:]), Len-magicbytes.Len, string(Magic))
}
copy(x.ID[:], b[*c:c.Inc(nonce.IDLen)])
if x.HeaderKey, e = pub.FromBytes(b[*c:c.Inc(pub.KeyLen)]); check(e) {
return
}
if x.PayloadKey, e = pub.FromBytes(b[*c:c.Inc(pub.KeyLen)]); check(e) {
return
}
return
}

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 = "80992332f37aa72c621fcc77fa1e87ddef9e5eda"
ParentGitCommit = "6f271556c60e5ff2a5915d48a1b4f9ed7559dff4"
// BuildTime stores the time when the current binary was built.
BuildTime = "2023-01-13T21:04:53Z"
BuildTime = "2023-01-14T08:54:21Z"
// SemVer lists the (latest) git tag on the release.
SemVer = "v0.1.7"
// PathBase is the path base returned from runtime caller.