forked from cwtch.im/tapir
Merge branch 'identity' of cwtch.im/tapir into master
This commit is contained in:
commit
6515a4e160
|
@ -34,7 +34,7 @@ func (ea AuthApp) NewInstance() tapir.Application {
|
||||||
// or the connection is closed.
|
// or the connection is closed.
|
||||||
func (ea AuthApp) Init(connection tapir.Connection) {
|
func (ea AuthApp) Init(connection tapir.Connection) {
|
||||||
longTermPubKey := ed25519.PublicKey(connection.ID().PublicKeyBytes())
|
longTermPubKey := ed25519.PublicKey(connection.ID().PublicKeyBytes())
|
||||||
ephemeralIdentity, _ := primitives.InitializeEphemeral()
|
ephemeralIdentity, _ := primitives.InitializeEphemeralIdentity()
|
||||||
authMessage := AuthMessage{LongTermPublicKey: longTermPubKey, EphemeralPublicKey: ephemeralIdentity.PublicKey()}
|
authMessage := AuthMessage{LongTermPublicKey: longTermPubKey, EphemeralPublicKey: ephemeralIdentity.PublicKey()}
|
||||||
serialized, _ := json.Marshal(authMessage)
|
serialized, _ := json.Marshal(authMessage)
|
||||||
connection.Send(serialized)
|
connection.Send(serialized)
|
||||||
|
|
|
@ -15,7 +15,7 @@ type MockConnection struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mc *MockConnection) Init(outbound bool) {
|
func (mc *MockConnection) Init(outbound bool) {
|
||||||
mc.id, _ = primitives.InitializeEphemeral()
|
mc.id, _ = primitives.InitializeEphemeralIdentity()
|
||||||
mc.outbound = outbound
|
mc.outbound = outbound
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,17 @@ type Identity struct {
|
||||||
edpubk *ed25519.PublicKey
|
edpubk *ed25519.PublicKey
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize is a courtesy function for initializing a V3 Identity in-code.
|
// InitializeIdentity is a courtesy function for initializing a V3 Identity in-code.
|
||||||
func Initialize(name string, pk *ed25519.PrivateKey, pubk *ed25519.PublicKey) Identity {
|
func InitializeIdentity(name string, pk *ed25519.PrivateKey, pubk *ed25519.PublicKey) Identity {
|
||||||
return Identity{name, pk, pubk}
|
return Identity{name, pk, pubk}
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitializeEphemeral generates a new ephemeral identity, the private key of this identity is provided in the response.
|
// InitializeEphemeralIdentity generates a new ephemeral identity, the private key of this identity is provided in the response.
|
||||||
func InitializeEphemeral() (Identity, ed25519.PrivateKey) {
|
func InitializeEphemeralIdentity() (Identity, ed25519.PrivateKey) {
|
||||||
epk, esk, _ := ed25519.GenerateKey(rand.Reader)
|
epk, esk, _ := ed25519.GenerateKey(rand.Reader)
|
||||||
ephemeralPublicKey := ed25519.PublicKey(epk)
|
ephemeralPublicKey := ed25519.PublicKey(epk)
|
||||||
ephemeralPrivateKey := ed25519.PrivateKey(esk)
|
ephemeralPrivateKey := ed25519.PrivateKey(esk)
|
||||||
ephemeralIdentity := Initialize("", &ephemeralPrivateKey, &ephemeralPublicKey)
|
ephemeralIdentity := InitializeIdentity("", &ephemeralPrivateKey, &ephemeralPublicKey)
|
||||||
return ephemeralIdentity, ephemeralPrivateKey
|
return ephemeralIdentity, ephemeralPrivateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ func (i *Identity) PublicKey() ed25519.PublicKey {
|
||||||
return *i.edpubk
|
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 {
|
func (i *Identity) EDH(key ed25519.PublicKey) []byte {
|
||||||
secret := utils.EDH(*i.edpk, key)
|
secret := utils.EDH(*i.edpk, key)
|
||||||
return secret[:]
|
return secret[:]
|
||||||
|
|
|
@ -65,7 +65,7 @@ func TestTapir(t *testing.T) {
|
||||||
acn.WaitTillBootstrapped()
|
acn.WaitTillBootstrapped()
|
||||||
|
|
||||||
// Generate Server Keys
|
// Generate Server Keys
|
||||||
id, sk := primitives.InitializeEphemeral()
|
id, sk := primitives.InitializeEphemeralIdentity()
|
||||||
|
|
||||||
// Init the Server running the Simple App.
|
// Init the Server running the Simple App.
|
||||||
var service tapir.Service
|
var service tapir.Service
|
||||||
|
@ -105,7 +105,7 @@ func TestTapir(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func genclient(acn connectivity.ACN) (tapir.Service, string) {
|
func genclient(acn connectivity.ACN) (tapir.Service, string) {
|
||||||
id, sk := primitives.InitializeEphemeral()
|
id, sk := primitives.InitializeEphemeralIdentity()
|
||||||
var client tapir.Service
|
var client tapir.Service
|
||||||
client = new(tor.BaseOnionService)
|
client = new(tor.BaseOnionService)
|
||||||
client.Init(acn, sk, &id)
|
client.Init(acn, sk, &id)
|
||||||
|
|
Loading…
Reference in New Issue