From 875690aff24a31fd81fa067f984d7077f75e3a13 Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Thu, 8 Aug 2019 12:07:13 -0700 Subject: [PATCH] Updating Initialize Identity Interface --- applications/auth.go | 2 +- applications/auth_test.go | 2 +- primitives/identity.go | 12 ++++++------ testing/tapir_integration_test.go | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/applications/auth.go b/applications/auth.go index f7af141..238aaf2 100644 --- a/applications/auth.go +++ b/applications/auth.go @@ -34,7 +34,7 @@ func (ea AuthApp) NewInstance() tapir.Application { // or the connection is closed. func (ea AuthApp) Init(connection tapir.Connection) { longTermPubKey := ed25519.PublicKey(connection.ID().PublicKeyBytes()) - ephemeralIdentity, _ := primitives.InitializeEphemeral() + ephemeralIdentity, _ := primitives.InitializeEphemeralIdentity() authMessage := AuthMessage{LongTermPublicKey: longTermPubKey, EphemeralPublicKey: ephemeralIdentity.PublicKey()} serialized, _ := json.Marshal(authMessage) connection.Send(serialized) diff --git a/applications/auth_test.go b/applications/auth_test.go index 5c71c8f..26c7884 100644 --- a/applications/auth_test.go +++ b/applications/auth_test.go @@ -15,7 +15,7 @@ type MockConnection struct { } func (mc *MockConnection) Init(outbound bool) { - mc.id, _ = primitives.InitializeEphemeral() + mc.id, _ = primitives.InitializeEphemeralIdentity() mc.outbound = outbound return } diff --git a/primitives/identity.go b/primitives/identity.go index 6bf53d5..9307510 100644 --- a/primitives/identity.go +++ b/primitives/identity.go @@ -16,17 +16,17 @@ type Identity struct { edpubk *ed25519.PublicKey } -// Initialize is a courtesy function for initializing a V3 Identity in-code. -func Initialize(name string, pk *ed25519.PrivateKey, pubk *ed25519.PublicKey) Identity { +// InitializeIdentity is a courtesy function for initializing a V3 Identity in-code. +func InitializeIdentity(name string, pk *ed25519.PrivateKey, pubk *ed25519.PublicKey) Identity { return Identity{name, pk, pubk} } -// InitializeEphemeral generates a new ephemeral identity, the private key of this identity is provided in the response. -func InitializeEphemeral() (Identity, ed25519.PrivateKey) { +// InitializeEphemeralIdentity generates a new ephemeral identity, the private key of this identity is provided in the response. +func InitializeEphemeralIdentity() (Identity, ed25519.PrivateKey) { epk, esk, _ := ed25519.GenerateKey(rand.Reader) ephemeralPublicKey := ed25519.PublicKey(epk) ephemeralPrivateKey := ed25519.PrivateKey(esk) - ephemeralIdentity := Initialize("", &ephemeralPrivateKey, &ephemeralPublicKey) + ephemeralIdentity := InitializeIdentity("", &ephemeralPrivateKey, &ephemeralPublicKey) return ephemeralIdentity, ephemeralPrivateKey } @@ -41,7 +41,7 @@ func (i *Identity) PublicKey() ed25519.PublicKey { return *i.edpubk } -// EDH performs a diffie helman operation on this identities private key with the given public key. +// EDH performs a diffie-helman operation on this identities private key with the given public key. func (i *Identity) EDH(key ed25519.PublicKey) []byte { secret := utils.EDH(*i.edpk, key) return secret[:] diff --git a/testing/tapir_integration_test.go b/testing/tapir_integration_test.go index db3e6df..65eae06 100644 --- a/testing/tapir_integration_test.go +++ b/testing/tapir_integration_test.go @@ -65,7 +65,7 @@ func TestTapir(t *testing.T) { acn.WaitTillBootstrapped() // Generate Server Keys - id, sk := primitives.InitializeEphemeral() + id, sk := primitives.InitializeEphemeralIdentity() // Init the Server running the Simple App. var service tapir.Service @@ -105,7 +105,7 @@ func TestTapir(t *testing.T) { } func genclient(acn connectivity.ACN) (tapir.Service, string) { - id, sk := primitives.InitializeEphemeral() + id, sk := primitives.InitializeEphemeralIdentity() var client tapir.Service client = new(tor.BaseOnionService) client.Init(acn, sk, &id)