Skip to content
Snippets Groups Projects
Commit 4fe61cbe authored by Benjamin Wenger's avatar Benjamin Wenger
Browse files

Merge remote-tracking branch 'origin/project/Channels' into project/Channels

parents 6c2e9ab7 d26728b4
No related branches found
No related tags found
3 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!340Project/channels
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
package channels package channels
import ( import (
"crypto/ed25519" "crypto/ed25519"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/crypto/channel" "gitlab.com/elixxir/crypto/channel"
"gitlab.com/xx_network/primitives/netTime"
"io" "io"
"time" "time"
) )
// NewDummyNameService returns a dummy object adhering to the name service // NewDummyNameService returns a dummy object adhering to the name service
// This neither produces valid signatures or validates passed signature // This neither produces valid signatures nor validates passed signatures.
// is is for Development and Debugging purposes only //
// THIS IS FOR DEVELOPMENT AND DEBUGGING PURPOSES ONLY.
func NewDummyNameService(username string, rng io.Reader) (NameService, error) { func NewDummyNameService(username string, rng io.Reader) (NameService, error) {
jww.WARN.Printf("Creating a Dummy Name Service. This is for " + jww.WARN.Printf("Creating a Dummy Name Service. This is for " +
"development and debugging only. It does not produce valid " + "development and debugging only. It does not produce valid " +
...@@ -19,7 +28,7 @@ func NewDummyNameService(username string, rng io.Reader) (NameService, error) { ...@@ -19,7 +28,7 @@ func NewDummyNameService(username string, rng io.Reader) (NameService, error) {
dns := &dummyNameService{ dns := &dummyNameService{
username: username, username: username,
lease: time.Now().Add(35 * 24 * time.Hour), lease: netTime.Now().Add(35 * 24 * time.Hour),
} }
//generate the private key //generate the private key
...@@ -37,6 +46,8 @@ func NewDummyNameService(username string, rng io.Reader) (NameService, error) { ...@@ -37,6 +46,8 @@ func NewDummyNameService(username string, rng io.Reader) (NameService, error) {
return dns, nil return dns, nil
} }
// dummyNameService is a dummy NameService implementation. This is NOT meant
// for use in production
type dummyNameService struct { type dummyNameService struct {
private ed25519.PrivateKey private ed25519.PrivateKey
public ed25519.PublicKey public ed25519.PublicKey
...@@ -45,10 +56,18 @@ type dummyNameService struct { ...@@ -45,10 +56,18 @@ type dummyNameService struct {
lease time.Time lease time.Time
} }
// GetUsername returns the username for the dummyNameService. This is what was
// passed in through NewDummyNameService.
//
// THIS IS FOR DEVELOPMENT AND DEBUGGING PURPOSES ONLY.
func (dns *dummyNameService) GetUsername() string { func (dns *dummyNameService) GetUsername() string {
return dns.username return dns.username
} }
// GetChannelValidationSignature will return the dummy validation signature
// generated in through the constructor, NewDummyNameService.
//
// THIS IS FOR DEVELOPMENT AND DEBUGGING PURPOSES ONLY.
func (dns *dummyNameService) GetChannelValidationSignature() ([]byte, time.Time) { func (dns *dummyNameService) GetChannelValidationSignature() ([]byte, time.Time) {
jww.WARN.Printf("GetChannelValidationSignature called on Dummy Name " + jww.WARN.Printf("GetChannelValidationSignature called on Dummy Name " +
"Service, dummy signature from a random key returned - identity not " + "Service, dummy signature from a random key returned - identity not " +
...@@ -56,11 +75,18 @@ func (dns *dummyNameService) GetChannelValidationSignature() ([]byte, time.Time) ...@@ -56,11 +75,18 @@ func (dns *dummyNameService) GetChannelValidationSignature() ([]byte, time.Time)
return dns.validationSig, dns.lease return dns.validationSig, dns.lease
} }
// GetChannelPubkey returns the ed25519.PublicKey generates in the constructor,
// NewDummyNameService.
func (dns *dummyNameService) GetChannelPubkey() ed25519.PublicKey { func (dns *dummyNameService) GetChannelPubkey() ed25519.PublicKey {
return dns.public return dns.public
} }
func (dns *dummyNameService) SignChannelMessage(message []byte) (signature []byte, err error) { // SignChannelMessage will sign the passed in message using the
// dummyNameService's private key.
//
// THIS IS FOR DEVELOPMENT AND DEBUGGING PURPOSES ONLY.
func (dns *dummyNameService) SignChannelMessage(message []byte) (
signature []byte, err error) {
jww.WARN.Printf("SignChannelMessage called on Dummy Name Service, " + jww.WARN.Printf("SignChannelMessage called on Dummy Name Service, " +
"signature from a random key - identity not proven. YOU SHOULD " + "signature from a random key - identity not proven. YOU SHOULD " +
"NEVER SEE THIS MESSAGE IN PRODUCTION") "NEVER SEE THIS MESSAGE IN PRODUCTION")
...@@ -68,6 +94,11 @@ func (dns *dummyNameService) SignChannelMessage(message []byte) (signature []byt ...@@ -68,6 +94,11 @@ func (dns *dummyNameService) SignChannelMessage(message []byte) (signature []byt
return sig, nil return sig, nil
} }
// ValidateChannelMessage will always return true, indicating the the channel
// message is valid. This will ignore the passed in arguments. As a result,
// these values may be dummy or precanned.
//
// THIS IS FOR DEVELOPMENT AND DEBUGGING PURPOSES ONLY.
func (dns *dummyNameService) ValidateChannelMessage(username string, lease time.Time, func (dns *dummyNameService) ValidateChannelMessage(username string, lease time.Time,
pubKey ed25519.PublicKey, authorIDSignature []byte) bool { pubKey ed25519.PublicKey, authorIDSignature []byte) bool {
//ignore the authorIDSignature //ignore the authorIDSignature
......
////////////////////////////////////////////////////////////////////////////////
// Copyright © 2022 xx foundation //
// //
// Use of this source code is governed by a license that can be found in the //
// LICENSE file. //
////////////////////////////////////////////////////////////////////////////////
package channels
import (
"crypto/ed25519"
"gitlab.com/xx_network/crypto/csprng"
"testing"
"time"
)
const numTests = 10
// Smoke test.
func TestNewDummyNameService(t *testing.T) {
rng := csprng.NewSystemRNG()
username := "floridaMan"
_, err := NewDummyNameService(username, rng)
if err != nil {
t.Fatalf("NewDummyNameService error: %+v", err)
}
}
// Smoke test.
func TestDummyNameService_GetUsername(t *testing.T) {
rng := csprng.NewSystemRNG()
username := "floridaMan"
ns, err := NewDummyNameService(username, rng)
if err != nil {
t.Fatalf("NewDummyNameService error: %+v", err)
}
if username != ns.GetUsername() {
t.Fatalf("GetUsername did not return expected value."+
"\nExpected: %s"+
"\nReceived: %s", username, ns.GetUsername())
}
}
// Smoke test.
func TestDummyNameService_SignChannelMessage(t *testing.T) {
rng := csprng.NewSystemRNG()
username := "floridaMan"
ns, err := NewDummyNameService(username, rng)
if err != nil {
t.Fatalf("NewDummyNameService error: %+v", err)
}
message := []byte("the secret is in the sauce.")
signature, err := ns.SignChannelMessage(message)
if err != nil {
t.Fatalf("SignChannelMessage error: %v", err)
}
if len(signature) != ed25519.SignatureSize {
t.Errorf("DummyNameService's SignChannelMessage did not return a "+
"signature of expected size, according to ed25519 specifications."+
"\nExpected: %d"+
"\nReceived: %d", ed25519.SignatureSize, len(signature))
}
}
// Smoke test.
func TestDummyNameService_GetChannelValidationSignature(t *testing.T) {
rng := csprng.NewSystemRNG()
username := "floridaMan"
ns, err := NewDummyNameService(username, rng)
if err != nil {
t.Fatalf("NewDummyNameService error: %+v", err)
}
validationSig, _ := ns.GetChannelValidationSignature()
if len(validationSig) != ed25519.SignatureSize {
t.Errorf("DummyNameService's GetChannelValidationSignature did not "+
"return a validation signature of expected size, according to "+
"ed25519 specifications."+
"\nExpected: %d"+
"\nReceived: %d", ed25519.SignatureSize, len(validationSig))
}
}
// Smoke test.
func TestDummyNameService_ValidateChannelMessage(t *testing.T) {
rng := csprng.NewSystemRNG()
username := "floridaMan"
ns, err := NewDummyNameService(username, rng)
if err != nil {
t.Fatalf("NewDummyNameService error: %+v", err)
}
for i := 0; i < numTests; i++ {
if !ns.ValidateChannelMessage(username, time.Now(), nil, nil) {
t.Errorf("ValidateChannelMessage returned false. This should " +
"only ever return true.")
}
}
}
// Smoke test.
func TestDummyNameService_GetChannelPubkey(t *testing.T) {
rng := csprng.NewSystemRNG()
username := "floridaMan"
ns, err := NewDummyNameService(username, rng)
if err != nil {
t.Fatalf("NewDummyNameService error: %+v", err)
}
if len(ns.GetChannelPubkey()) != ed25519.PublicKeySize {
t.Errorf("DummyNameService's GetChannelPubkey did not "+
"return a validation signature of expected size, according to "+
"ed25519 specifications."+
"\nExpected: %d"+
"\nReceived: %d", ed25519.PublicKeySize, ns.GetChannelPubkey())
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment