Fixed Return message to be same as forward, Exit drafted
still need to add the key generation
This commit is contained in:
@@ -27,8 +27,8 @@ func (o OnionSkins) Exit(port uint16, ciphers [3]sha256.Hash,
|
||||
|
||||
return append(o, &Exit{Port: port, Cipher: ciphers, Bytes: payload})
|
||||
}
|
||||
func (o OnionSkins) Return(ip net.IP, rtn *pub.Key) OnionSkins {
|
||||
return append(o, &Return{IP: ip, Key: rtn})
|
||||
func (o OnionSkins) Return(ip net.IP) OnionSkins {
|
||||
return append(o, &Return{IP: ip})
|
||||
}
|
||||
func (o OnionSkins) Cipher(hdr, pld *prv.Key) OnionSkins {
|
||||
return append(o, &Cipher{Header: hdr, Payload: pld})
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"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"
|
||||
)
|
||||
|
||||
// Ping is a message which checks the liveness of relays by ensuring they are
|
||||
@@ -47,11 +48,7 @@ func Ping(id nonce.ID, client node.Node, hop [3]node.Node,
|
||||
// This message's last layer is a Confirmation, which allows the client to know
|
||||
// that the key was successfully delivered to the Return relays that will be
|
||||
// used in the Purchase.
|
||||
//
|
||||
// The first hop (0) is the destination of the first layer, 1 is second, 2 is
|
||||
// the return relay, 3 is the first return, 4 is the second return, and client
|
||||
// is the client.
|
||||
func SendReturn(idCipher sha256.Hash, id nonce.ID, hdr, pld *prv.Key,
|
||||
func SendReturn(id nonce.ID, hdr, pld *prv.Key,
|
||||
client node.Node, hop [5]node.Node, set signer.KeySet) Onion {
|
||||
|
||||
return OnionSkins{}.
|
||||
@@ -70,3 +67,32 @@ func SendReturn(idCipher sha256.Hash, id nonce.ID, hdr, pld *prv.Key,
|
||||
Confirmation(id).
|
||||
Assemble()
|
||||
}
|
||||
|
||||
// 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
|
||||
// hops that are layered progressively after the Exit message.
|
||||
//
|
||||
// The Exit node forwards the packet it receives to the local port specified in
|
||||
// the Exit message, and then uses the ciphers to encrypt the return with the
|
||||
// three ciphers provided, which don't enable it to decrypt the header, only to
|
||||
// encrypt the payload.
|
||||
//
|
||||
// TODO: we can create the ciphers based on hop 3, 4 and client Nodes.
|
||||
func SendExit(payload slice.Bytes, port uint16, ciphers [3]sha256.Hash,
|
||||
client node.Node, hop [5]node.Node, set signer.KeySet) Onion {
|
||||
|
||||
return OnionSkins{}.
|
||||
Message(address.FromPubKey(hop[0].HeaderKey), set.Next()).
|
||||
Forward(hop[1].IP).
|
||||
Message(address.FromPubKey(hop[1].HeaderKey), set.Next()).
|
||||
Forward(hop[2].IP).
|
||||
Message(address.FromPubKey(hop[2].HeaderKey), set.Next()).
|
||||
Exit(port, ciphers, payload).
|
||||
Return(hop[3].IP).
|
||||
Message(address.FromPubKey(hop[3].PayloadKey), set.Next()).
|
||||
Return(hop[4].IP).
|
||||
Message(address.FromPubKey(hop[4].PayloadKey), set.Next()).
|
||||
Return(client.IP).
|
||||
Message(address.FromPubKey(client.PayloadKey), set.Next()).
|
||||
Assemble()
|
||||
}
|
||||
|
||||
@@ -151,6 +151,31 @@ func (fw *Forward) Encode(o slice.Bytes, c *slice.Cursor) {
|
||||
fw.Onion.Encode(o, c)
|
||||
}
|
||||
|
||||
// Return messages are distinct from Forward messages in that the header
|
||||
// encryption uses a different secret than the payload. The magic bytes signal
|
||||
// this to the relay that receives this, which then looks up the Return key
|
||||
// matching the To address in the message header.
|
||||
type Return struct {
|
||||
// IP is the address of the next relay in the return leg of a circuit.
|
||||
net.IP
|
||||
Onion
|
||||
}
|
||||
|
||||
var _ Onion = &Return{}
|
||||
|
||||
func (rt *Return) Inner() Onion { return rt.Onion }
|
||||
func (rt *Return) Insert(o Onion) { rt.Onion = o }
|
||||
func (rt *Return) Len() int {
|
||||
return MagicLen + len(rt.IP) + 1 + rt.Onion.Len()
|
||||
}
|
||||
|
||||
func (rt *Return) Encode(o slice.Bytes, c *slice.Cursor) {
|
||||
copy(o[*c:c.Inc(MagicLen)], ReturnMagic)
|
||||
o[*c] = byte(len(rt.IP))
|
||||
copy(o[c.Inc(1):c.Inc(len(rt.IP))], rt.IP)
|
||||
rt.Onion.Encode(o, c)
|
||||
}
|
||||
|
||||
// Exit messages are the layer of a message after two Forward packets that
|
||||
// provides an exit address and
|
||||
type Exit struct {
|
||||
@@ -195,36 +220,6 @@ func (ex *Exit) Encode(o slice.Bytes, c *slice.Cursor) {
|
||||
|
||||
}
|
||||
|
||||
// Return messages are distinct from Forward messages in that the header
|
||||
// encryption uses a different secret than the payload. The magic bytes signal
|
||||
// this to the relay that receives this, which then looks up the Return key
|
||||
// matching the To address in the message header.
|
||||
type Return struct {
|
||||
// IP is the address of the next relay in the return leg of a circuit.
|
||||
net.IP
|
||||
// The Key here should be the Return key matching the IP of the relay.
|
||||
// The header provided in a previous Exit message uses the Forward key
|
||||
// so that the Exit node cannot decrypt the header and discover the
|
||||
// return path.
|
||||
*pub.Key
|
||||
Onion
|
||||
}
|
||||
|
||||
var _ Onion = &Return{}
|
||||
|
||||
func (rt *Return) Inner() Onion { return rt.Onion }
|
||||
func (rt *Return) Insert(o Onion) { rt.Onion = o }
|
||||
func (rt *Return) Len() int {
|
||||
return MagicLen + len(rt.IP) + 1 + rt.Onion.Len()
|
||||
}
|
||||
|
||||
func (rt *Return) Encode(o slice.Bytes, c *slice.Cursor) {
|
||||
copy(o[*c:c.Inc(MagicLen)], ReturnMagic)
|
||||
o[*c] = byte(len(rt.IP))
|
||||
copy(o[c.Inc(1):c.Inc(len(rt.IP))], rt.IP)
|
||||
rt.Onion.Encode(o, c)
|
||||
}
|
||||
|
||||
// Cipher delivers a public key to be used in association with a Return
|
||||
// specifically in the situation of a node bootstrapping that doesn't have
|
||||
// sessions yet. The Forward key will appear in the pre-formed header, but the
|
||||
|
||||
@@ -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 = "28935667e84947dd065d8afe5eda166c5708a1c8"
|
||||
ParentGitCommit = "6ae27fc4353fe8399f83acfe7639f9168643023a"
|
||||
// BuildTime stores the time when the current binary was built.
|
||||
BuildTime = "2022-12-20T14:25:24Z"
|
||||
BuildTime = "2022-12-20T16:42:32Z"
|
||||
// SemVer lists the (latest) git tag on the build.
|
||||
SemVer = "v0.0.195"
|
||||
SemVer = "v0.0.196"
|
||||
// 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 = 195
|
||||
Patch = 196
|
||||
)
|
||||
|
||||
// Version returns a pretty printed version information string.
|
||||
|
||||
Reference in New Issue
Block a user