Remove cloaked address from packet header, changed client onion to use message
This commit is contained in:
@@ -11,9 +11,9 @@ import (
|
||||
"github.com/Indra-Labs/indra/pkg/key/prv"
|
||||
"github.com/Indra-Labs/indra/pkg/key/pub"
|
||||
"github.com/Indra-Labs/indra/pkg/key/signer"
|
||||
"github.com/Indra-Labs/indra/pkg/message"
|
||||
"github.com/Indra-Labs/indra/pkg/node"
|
||||
"github.com/Indra-Labs/indra/pkg/nonce"
|
||||
"github.com/Indra-Labs/indra/pkg/packet"
|
||||
"github.com/Indra-Labs/indra/pkg/testutils"
|
||||
"github.com/Indra-Labs/indra/pkg/transport"
|
||||
"github.com/Indra-Labs/indra/pkg/wire"
|
||||
@@ -91,19 +91,17 @@ func TestClient_GenerateCircuit(t *testing.T) {
|
||||
Message: lastMsg,
|
||||
}
|
||||
rmm := rm.Serialize()
|
||||
ep := packet.EP{
|
||||
ep := message.EP{
|
||||
To: address.
|
||||
FromPubKey(ci.Hops[len(ci.Hops)-i-1].Key),
|
||||
From: cl.Sessions[i].KeyRoller.Next(),
|
||||
Parity: 0,
|
||||
Seq: 0,
|
||||
Length: len(rmm),
|
||||
Data: rmm,
|
||||
}
|
||||
lastMsg, e = packet.Encode(ep)
|
||||
lastMsg, e = message.Encode(ep)
|
||||
var to address.Cloaked
|
||||
var from *pub.Key
|
||||
if to, from, e = packet.GetKeys(lastMsg); check(e) {
|
||||
if to, from, e = message.GetKeys(lastMsg); check(e) {
|
||||
t.Error(e)
|
||||
t.FailNow()
|
||||
}
|
||||
@@ -116,7 +114,7 @@ func TestClient_GenerateCircuit(t *testing.T) {
|
||||
var to address.Cloaked
|
||||
var from *pub.Key
|
||||
// log.I.S("unwrapping", c, lastMsg)
|
||||
if to, from, e = packet.GetKeys(lastMsg); check(e) {
|
||||
if to, from, e = message.GetKeys(lastMsg); check(e) {
|
||||
t.Error(e)
|
||||
t.FailNow()
|
||||
}
|
||||
@@ -147,8 +145,10 @@ func TestClient_GenerateCircuit(t *testing.T) {
|
||||
log.I.Ln("did not find matching address.Receiver")
|
||||
t.FailNow()
|
||||
}
|
||||
var f *packet.Packet
|
||||
if f, e = packet.Decode(lastMsg, from, match.Key); check(e) {
|
||||
var f *message.Message
|
||||
if f, e = message.Decode(lastMsg, from,
|
||||
match.Key); check(e) {
|
||||
|
||||
t.Error(e)
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
@@ -81,11 +81,10 @@ func (ep EP) GetOverhead() int {
|
||||
}
|
||||
|
||||
const (
|
||||
CheckEnd = 4
|
||||
TypeEnd = CheckEnd + 1
|
||||
NonceEnd = TypeEnd + nonce.IVLen
|
||||
AddressEnd = NonceEnd + address.Len
|
||||
SigEnd = AddressEnd + sig.Len
|
||||
CheckEnd = 4
|
||||
TypeEnd = CheckEnd + 1
|
||||
NonceEnd = TypeEnd + nonce.IVLen
|
||||
SigEnd = NonceEnd + sig.Len
|
||||
)
|
||||
|
||||
// Encode creates a Packet, encrypts the payload using the given private from
|
||||
@@ -97,8 +96,8 @@ func Encode(ep EP) (pkt []byte, e error) {
|
||||
return
|
||||
}
|
||||
nonc := nonce.New()
|
||||
var to address.Cloaked
|
||||
to, e = ep.To.GetCloak()
|
||||
// var to address.Cloaked
|
||||
// to, e = ep.To.GetCloak()
|
||||
parity := []byte{byte(ep.Parity)}
|
||||
Seq := slice.NewUint16()
|
||||
slice.EncodeUint16(Seq, ep.Seq)
|
||||
@@ -124,8 +123,7 @@ func Encode(ep EP) (pkt []byte, e error) {
|
||||
}
|
||||
// Copy nonce, address, check and signature over top of the header.
|
||||
copy(pkt[TypeEnd:NonceEnd], nonc)
|
||||
copy(pkt[NonceEnd:AddressEnd], to)
|
||||
copy(pkt[AddressEnd:SigEnd], s)
|
||||
copy(pkt[NonceEnd:SigEnd], s)
|
||||
// last bot not least, the packet check header, which protects the
|
||||
// entire packet.
|
||||
checkBytes := sha256.Single(pkt[CheckEnd:])[:CheckEnd]
|
||||
@@ -141,7 +139,7 @@ func Encode(ep EP) (pkt []byte, e error) {
|
||||
// entire packet should then be processed with ciph.Encipher (sans signature)
|
||||
// using the block cipher thus created from the shared secret, and the Decode
|
||||
// function will then decode a Packet.
|
||||
func GetKeys(d []byte) (to address.Cloaked, from *pub.Key, e error) {
|
||||
func GetKeys(d []byte) (from *pub.Key, e error) {
|
||||
pktLen := len(d)
|
||||
if pktLen < Overhead {
|
||||
// If this isn't checked the slice operations later can
|
||||
@@ -151,12 +149,11 @@ func GetKeys(d []byte) (to address.Cloaked, from *pub.Key, e error) {
|
||||
log.E.Ln(e)
|
||||
return
|
||||
}
|
||||
to = d[NonceEnd:AddressEnd]
|
||||
// split off the signature and recover the public key
|
||||
var s sig.Bytes
|
||||
var chek []byte
|
||||
chek = d[:CheckEnd]
|
||||
s = d[AddressEnd:SigEnd]
|
||||
s = d[NonceEnd:SigEnd]
|
||||
checkHash := sha256.Single(d[CheckEnd:])[:4]
|
||||
if string(chek) != string(checkHash[:4]) {
|
||||
e = fmt.Errorf("check failed: got '%v', expected '%v'",
|
||||
|
||||
@@ -41,18 +41,13 @@ func TestEncode_Decode(t *testing.T) {
|
||||
if pkt, e = Encode(params); check(e) {
|
||||
t.Error(e)
|
||||
}
|
||||
var to address.Cloaked
|
||||
var from *pub.Key
|
||||
if to, from, e = GetKeys(pkt); check(e) {
|
||||
if from, e = GetKeys(pkt); check(e) {
|
||||
t.Error(e)
|
||||
}
|
||||
if !sP.ToBytes().Equals(from.ToBytes()) {
|
||||
t.Error(e)
|
||||
}
|
||||
rk := address.NewReceiver(rp)
|
||||
if !rk.Match(to) {
|
||||
t.Error("cloaked key incorrect")
|
||||
}
|
||||
var f *Packet
|
||||
if f, e = Decode(pkt, from, rp); check(e) {
|
||||
t.Error(e)
|
||||
|
||||
@@ -8,31 +8,31 @@ import (
|
||||
var Expected = []string{
|
||||
`
|
||||
Segments{
|
||||
Segment{ DStart: 0, DEnd: 192, PEnd: 256, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 256, DEnd: 448, PEnd: 512, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 512, DEnd: 704, PEnd: 768, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 768, DEnd: 960, PEnd: 1024, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 1024, DEnd: 1216, PEnd: 1280, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 1280, DEnd: 1472, PEnd: 1536, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 1536, DEnd: 1728, PEnd: 1792, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 1792, DEnd: 1984, PEnd: 2048, SLen: 155, Last: 155},
|
||||
Segment{ DStart: 2048, DEnd: 2204, PEnd: 2256, SLen: 155, Last: 150},
|
||||
Segment{ DStart: 0, DEnd: 192, PEnd: 256, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 256, DEnd: 448, PEnd: 512, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 512, DEnd: 704, PEnd: 768, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 768, DEnd: 960, PEnd: 1024, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 1024, DEnd: 1216, PEnd: 1280, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 1280, DEnd: 1472, PEnd: 1536, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 1536, DEnd: 1728, PEnd: 1792, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 1792, DEnd: 1984, PEnd: 2048, SLen: 163, Last: 163},
|
||||
Segment{ DStart: 2048, DEnd: 2121, PEnd: 2145, SLen: 163, Last: 151},
|
||||
}
|
||||
`,
|
||||
`
|
||||
Segments{
|
||||
Segment{ DStart: 0, DEnd: 132, PEnd: 132, SLen: 3995, Last: 943},
|
||||
Segment{ DStart: 0, DEnd: 131, PEnd: 131, SLen: 4003, Last: 3898},
|
||||
}
|
||||
`,
|
||||
`
|
||||
Segments{
|
||||
Segment{ DStart: 0, DEnd: 128, PEnd: 256, SLen: 3995, Last: 3995},
|
||||
Segment{ DStart: 256, DEnd: 260, PEnd: 264, SLen: 3995, Last: 943},
|
||||
Segment{ DStart: 0, DEnd: 128, PEnd: 256, SLen: 4003, Last: 4003},
|
||||
Segment{ DStart: 256, DEnd: 259, PEnd: 262, SLen: 4003, Last: 3898},
|
||||
}
|
||||
`,
|
||||
`
|
||||
Segments{
|
||||
Segment{ DStart: 0, DEnd: 66, PEnd: 66, SLen: 3995, Last: 2469},
|
||||
Segment{ DStart: 0, DEnd: 66, PEnd: 66, SLen: 4003, Last: 1949},
|
||||
}
|
||||
`,
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func TestSplitJoin(t *testing.T) {
|
||||
for i := range splitted {
|
||||
var pkt *Packet
|
||||
var from *pub.Key
|
||||
if _, from, e = GetKeys(splitted[i]); check(e) {
|
||||
if from, e = GetKeys(splitted[i]); check(e) {
|
||||
log.I.Ln(i)
|
||||
continue
|
||||
}
|
||||
@@ -202,7 +202,7 @@ func TestSplitJoinFEC(t *testing.T) {
|
||||
for s := range splitted {
|
||||
var pkt *Packet
|
||||
var from *pub.Key
|
||||
if _, from, e = GetKeys(
|
||||
if from, e = GetKeys(
|
||||
splitted[s]); e != nil {
|
||||
// we are puncturing, they some will
|
||||
// fail to decode
|
||||
|
||||
@@ -13,11 +13,11 @@ var (
|
||||
// GitRef is the gitref, as in refs/heads/branchname.
|
||||
GitRef = "refs/heads/main"
|
||||
// ParentGitCommit is the commit hash of the parent HEAD.
|
||||
ParentGitCommit = "94f0b3e0f8a6c2fd2ae4dd3db9c5745ab8571532"
|
||||
ParentGitCommit = "282e23f9f29ffeaddb0d498186e30b90fd34a198"
|
||||
// BuildTime stores the time when the current binary was built.
|
||||
BuildTime = "2022-12-10T10:42:15+01:00"
|
||||
BuildTime = "2022-12-10T10:57:40+01:00"
|
||||
// SemVer lists the (latest) git tag on the build.
|
||||
SemVer = "v0.0.169"
|
||||
SemVer = "v0.0.170"
|
||||
// PathBase is the path base returned from runtime caller.
|
||||
PathBase = "/home/loki/src/github.com/Indra-Labs/indra/"
|
||||
// Major is the major number from the tag.
|
||||
@@ -25,7 +25,7 @@ var (
|
||||
// Minor is the minor number from the tag.
|
||||
Minor = 0
|
||||
// Patch is the patch version number from the tag.
|
||||
Patch = 169
|
||||
Patch = 170
|
||||
)
|
||||
|
||||
// Version returns a pretty printed version information string.
|
||||
|
||||
Reference in New Issue
Block a user