From 6cec75481e99a5cbcc1c39ffc7981e19aeaa6e49 Mon Sep 17 00:00:00 2001
From: David Stainton <dstainton@elixxir.io>
Date: Thu, 18 Aug 2022 15:09:02 -0400
Subject: [PATCH] WIP

---
 ud/channelIDTracking.go | 24 +++++++++++++++---------
 ud/channelLease.go      |  4 ++--
 2 files changed, 17 insertions(+), 11 deletions(-)

diff --git a/ud/channelIDTracking.go b/ud/channelIDTracking.go
index ffdbc15fd..15fa0c0bc 100644
--- a/ud/channelIDTracking.go
+++ b/ud/channelIDTracking.go
@@ -2,6 +2,7 @@ package ud
 
 import (
 	"crypto/ed25519"
+	"encoding/json"
 	"sync"
 	"time"
 
@@ -9,6 +10,7 @@ import (
 
 	"gitlab.com/elixxir/client/storage/versioned"
 	"gitlab.com/elixxir/client/xxdk"
+	"gitlab.com/elixxir/crypto/fastRNG"
 )
 
 const (
@@ -44,9 +46,9 @@ type NameService interface {
 func loadRegistrationDisk(kv *versioned.KV) (registrationDisk, error) {
 	obj, err := kv.Get(registrationDiskKey, registrationDiskVersion)
 	if err != nil {
-		return err
+		return registrationDisk{}, err
 	}
-	return UnmarshalRegistrationDisk(obj.data), nil
+	return UnmarshallRegistrationDisk(obj.Data)
 }
 
 func saveRegistrationDisk(kv *versioned.KV, reg registrationDisk) error {
@@ -56,10 +58,10 @@ func saveRegistrationDisk(kv *versioned.KV, reg registrationDisk) error {
 	}
 	obj := versioned.Object{
 		Version:   registrationDiskVersion,
-		Timestamp: now,
+		Timestamp: time.Now(),
 		Data:      regBytes,
 	}
-	kv.Set(registrationDiskKey, registrationDiskVersion, obj)
+	kv.Set(registrationDiskKey, registrationDiskVersion, &obj)
 	return nil
 }
 
@@ -79,12 +81,12 @@ func newRegistrationDisk(publicKey ed25519.PublicKey, privateKey ed25519.Private
 }
 
 func (r registrationDisk) Marshall() ([]byte, error) {
-	return json.Marshall(&r)
+	return json.Marshal(&r)
 }
 
 func UnmarshallRegistrationDisk(data []byte) (registrationDisk, error) {
 	var r registrationDisk
-	err := json.Unmarshall(&r, data)
+	err := json.Unmarshal(data, &r)
 	if err != nil {
 		return registrationDisk{}, err
 	}
@@ -108,16 +110,20 @@ type clientIDTracker struct {
 	registrationDisk  *registrationDisk
 	receptionIdentity *xxdk.ReceptionIdentity
 
+	pubKey  ed25519.PublicKey
+	privKey ed25519.PrivateKey
+
 	rngSource *fastRNG.StreamGenerator
 }
 
 var _ NameService = (*clientIDTracker)(nil)
 
 func newclientIDTracker(comms channelLeaseComms, username string, kv *versioned.KV,
-	receptionIdentity xxdk.ReceptionIdentity, rngSource *fastRNG.StreamGenerator) *clientIDTracker {
+	receptionIdentity xxdk.ReceptionIdentity, rngSource *fastRNG.StreamGenerator,
+	registrationDuration time.Duration) *clientIDTracker {
 
 	var err error
-	var reg registrationDiskKey
+	var reg registrationDisk
 
 	reg, err = loadRegistrationDisk(kv)
 	if err != nil {
@@ -143,7 +149,7 @@ func newclientIDTracker(comms channelLeaseComms, username string, kv *versioned.
 	return &clientIDTracker{
 		haltCh:               make(chan interface{}),
 		registrationDuration: registrationDuration,
-		receptionIdentity:    receptionIdentity,
+		receptionIdentity:    &receptionIdentity,
 		username:             username,
 	}
 
diff --git a/ud/channelLease.go b/ud/channelLease.go
index 64d747888..d3608f939 100644
--- a/ud/channelLease.go
+++ b/ud/channelLease.go
@@ -18,7 +18,7 @@ func requestChannelLease(userPubKey ed25519.PublicKey, username string, comms ch
 		return 0, nil, err
 	}
 	rng := rngGenerator.GetStream()
-	fSig, err := channel.SignChannelIdentityRequest(username, userPubKey, ts, privKey, rng)
+	fSig, err := channel.SignChannelIdentityRequest(userPubKey, time.Unix(0, ts), privKey, rng)
 	if err != nil {
 		return 0, nil, err
 	}
@@ -36,7 +36,7 @@ func requestChannelLease(userPubKey ed25519.PublicKey, username string, comms ch
 		return 0, nil, err
 	}
 
-	ok := channel.VerifyChannelLease(resp.UDSignedEdPubKey, userPubKey, uint64(resp.Lease), nil)
+	ok := channel.VerifyChannelLease(resp.UDLeaseEd25519Signature, resp.UDSignedEdPubKey, userPubKey, uint64(resp.Lease), nil)
 	if !ok {
 		return 0, nil, errors.New("error could not verify signature returned with channel lease")
 	}
-- 
GitLab