Quellcode durchsuchen

Upgrading to Tapir Identity

tapir-1.8
Sarah Jamie Lewis vor 4 Monaten
Ursprung
Commit
01ec46a97c

+ 2
- 0
.gitignore Datei anzeigen

@@ -9,3 +9,5 @@ server/app/messages
.reviewboardrc
/vendor/
/testing/tor/
/storage/testing/
/testing/storage/

+ 3
- 3
app/app.go Datei anzeigen

@@ -7,9 +7,9 @@ import (
"cwtch.im/cwtch/peer"
"cwtch.im/cwtch/protocol/connections"
"cwtch.im/cwtch/storage"
"cwtch.im/tapir/primitives"
"fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"io/ioutil"
"os"
@@ -112,7 +112,7 @@ func (app *application) CreatePeer(name string, password string) {

blockedPeers := profile.BlockedPeers()
// TODO: Would be nice if ProtocolEngine did not need to explicitly be given the Private Key.
identity := identity.InitializeV3(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
identity := primitives.InitializeIdentity(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
engine := connections.NewProtocolEngine(identity, profile.Ed25519PrivateKey, app.acn, app.eventBuses[profile.Onion], blockedPeers)

app.peers[profile.Onion] = peer
@@ -167,7 +167,7 @@ func (app *application) LoadProfiles(password string) {
peer.Init(app.eventBuses[profile.Onion])

blockedPeers := profile.BlockedPeers()
identity := identity.InitializeV3(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
identity := primitives.InitializeIdentity(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
engine := connections.NewProtocolEngine(identity, profile.Ed25519PrivateKey, app.acn, app.eventBuses[profile.Onion], blockedPeers)
app.mutex.Lock()
app.peers[profile.Onion] = peer

+ 3
- 3
app/appService.go Datei anzeigen

@@ -6,8 +6,8 @@ import (
"cwtch.im/cwtch/model"
"cwtch.im/cwtch/protocol/connections"
"cwtch.im/cwtch/storage"
"cwtch.im/tapir/primitives"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"path"
"strconv"
@@ -95,7 +95,7 @@ func (as *applicationService) createPeer(name, password string) {

blockedPeers := profile.BlockedPeers()
// TODO: Would be nice if ProtocolEngine did not need to explicitly be given the Private Key.
identity := identity.InitializeV3(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
identity := primitives.InitializeIdentity(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
engine := connections.NewProtocolEngine(identity, profile.Ed25519PrivateKey, as.acn, as.eventBuses[profile.Onion], blockedPeers)

as.storage[profile.Onion] = profileStore
@@ -111,7 +111,7 @@ func (as *applicationService) loadProfiles(password string) {
as.eventBuses[profile.Onion] = event.IPCEventManagerFrom(as.bridge, profile.Onion, as.eventBuses[profile.Onion])

blockedPeers := profile.BlockedPeers()
identity := identity.InitializeV3(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
identity := primitives.InitializeIdentity(profile.Name, &profile.Ed25519PrivateKey, &profile.Ed25519PublicKey)
engine := connections.NewProtocolEngine(identity, profile.Ed25519PrivateKey, as.acn, as.eventBuses[profile.Onion], blockedPeers)
as.mutex.Lock()
as.storage[profile.Onion] = profileStore

+ 1
- 1
go.mod Datei anzeigen

@@ -1,7 +1,7 @@
module cwtch.im/cwtch

require (
cwtch.im/tapir v0.1.6
cwtch.im/tapir v0.1.9
git.openprivacy.ca/openprivacy/libricochet-go v1.0.5
github.com/c-bata/go-prompt v0.2.3
github.com/golang/protobuf v1.3.2

+ 3
- 2
go.sum Datei anzeigen

@@ -1,7 +1,8 @@
cwtch.im/tapir v0.1.6 h1:5wd0z8TOUftEBIlCosLechh5KSAo9HfiQNcqknSzRWA=
cwtch.im/tapir v0.1.6/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
cwtch.im/tapir v0.1.9 h1:TXIKN/8q2cNMlwGmu8c8i3Vq2+x61I8G9638LkBicjk=
cwtch.im/tapir v0.1.9/go.mod h1:EuRYdVrwijeaGBQ4OijDDRHf7R2MDSypqHkSl5DxI34=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4 h1:GWLMJ5jBSIC/gFXzdbbeVz7fIAn2FTgW8+wBci6/3Ek=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.4/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.5 h1:WAq54xI2xfRCtc3+Tw20MOVvOPmWmO6u0tSrCSt65G8=
git.openprivacy.ca/openprivacy/libricochet-go v1.0.5/go.mod h1:yMSG1gBaP4f1U+RMZXN85d29D39OK5s8aTpyVRoH5FY=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=

+ 5
- 10
protocol/connections/engine.go Datei anzeigen

@@ -6,9 +6,9 @@ import (
"cwtch.im/tapir"
"cwtch.im/tapir/applications"
"cwtch.im/tapir/networks/tor"
"cwtch.im/tapir/primitives"
"errors"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"github.com/golang/protobuf/proto"
"golang.org/x/crypto/ed25519"
@@ -21,7 +21,7 @@ type engine struct {
connectionsManager *Manager

// Engine Attributes
identity identity.Identity
identity primitives.Identity
acn connectivity.ACN

// Engine State
@@ -45,14 +45,13 @@ type engine struct {
// Engine (ProtocolEngine) encapsulates the logic necessary to make and receive Cwtch connections.
// Note: ProtocolEngine doesn't have access to any information necessary to encrypt or decrypt GroupMessages
type Engine interface {
Identity() identity.Identity
ACN() connectivity.ACN
EventManager() event.Manager
Shutdown()
}

// NewProtocolEngine initializes a new engine that runs Cwtch using the given parameters
func NewProtocolEngine(identity identity.Identity, privateKey ed25519.PrivateKey, acn connectivity.ACN, eventManager event.Manager, blockedPeers []string) Engine {
func NewProtocolEngine(identity primitives.Identity, privateKey ed25519.PrivateKey, acn connectivity.ACN, eventManager event.Manager, blockedPeers []string) Engine {
engine := new(engine)
engine.identity = identity
engine.privateKey = privateKey
@@ -65,7 +64,7 @@ func NewProtocolEngine(identity identity.Identity, privateKey ed25519.PrivateKey

// Init the Server running the Simple App.
engine.service = new(tor.BaseOnionService)
engine.service.Init(acn, privateKey, identity)
engine.service.Init(acn, privateKey, &identity)

engine.eventManager = eventManager

@@ -90,10 +89,6 @@ func (e *engine) ACN() connectivity.ACN {
return e.acn
}

func (e *engine) Identity() identity.Identity {
return e.identity
}

func (e *engine) EventManager() event.Manager {
return e.eventManager
}
@@ -257,7 +252,7 @@ func (e *engine) peerDisconnected(onion string) {
func (e *engine) sendMessageToPeer(eventID string, onion string, context string, message []byte) error {
conn, err := e.service.GetConnection(onion)
if err == nil {
peerApp, ok := conn.App.(*PeerApp)
peerApp, ok := (conn.App()).(*PeerApp)
if ok {
peerApp.SendMessage(PeerMessage{eventID, context, message})
return nil

+ 9
- 9
protocol/connections/peerapp.go Datei anzeigen

@@ -11,7 +11,7 @@ import (
// PeerApp encapsulates the behaviour of a Cwtch Peer
type PeerApp struct {
applications.AuthApp
connection *tapir.Connection
connection tapir.Connection
MessageHandler func(string, string, []byte)
IsBlocked func(string) bool
OnAcknowledgement func(string, string)
@@ -40,7 +40,7 @@ func (pa PeerApp) NewInstance() tapir.Application {
}

// Init is run when the connection is first started.
func (pa *PeerApp) Init(connection *tapir.Connection) {
func (pa *PeerApp) Init(connection tapir.Connection) {

// First run the Authentication App
pa.AuthApp.Init(connection)
@@ -49,15 +49,15 @@ func (pa *PeerApp) Init(connection *tapir.Connection) {

pa.connection = connection

if pa.IsBlocked(connection.Hostname) {
if pa.IsBlocked(connection.Hostname()) {
pa.connection.Close()
pa.OnClose(connection.Hostname)
pa.OnClose(connection.Hostname())
} else {
pa.OnAuth(connection.Hostname)
pa.OnAuth(connection.Hostname())
go pa.listen()
}
} else {
pa.OnClose(connection.Hostname)
pa.OnClose(connection.Hostname())
}
}

@@ -66,16 +66,16 @@ func (pa PeerApp) listen() {
message := pa.connection.Expect()
if len(message) == 0 {
log.Errorf("0 byte read, socket has likely failed. Closing the listen goroutine")
pa.OnClose(pa.connection.Hostname)
pa.OnClose(pa.connection.Hostname())
return
}
var peerMessage PeerMessage
err := json.Unmarshal(message, &peerMessage)
if err == nil {
if peerMessage.Context == event.ContextAck {
pa.OnAcknowledgement(pa.connection.Hostname, peerMessage.ID)
pa.OnAcknowledgement(pa.connection.Hostname(), peerMessage.ID)
} else {
pa.MessageHandler(pa.connection.Hostname, peerMessage.Context, peerMessage.Data)
pa.MessageHandler(pa.connection.Hostname(), peerMessage.Context, peerMessage.Data)

// Acknowledge the message
// TODO Should this be in the ui?

+ 8
- 8
protocol/connections/peerserverconnection_test.go Datei anzeigen

@@ -1,16 +1,16 @@
package connections

import (
"crypto/rand"
"cwtch.im/cwtch/event"
"cwtch.im/cwtch/protocol"
"cwtch.im/cwtch/server/fetch"
"cwtch.im/cwtch/server/send"
"cwtch.im/tapir/primitives"
"git.openprivacy.ca/openprivacy/libricochet-go"
"git.openprivacy.ca/openprivacy/libricochet-go/channels"
"git.openprivacy.ca/openprivacy/libricochet-go/connection"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity"
identityOld "git.openprivacy.ca/openprivacy/libricochet-go/identity"
"golang.org/x/crypto/ed25519"
"net"
"testing"
@@ -34,7 +34,7 @@ func (ts *TestServer) HandleFetchRequest() []*protocol.GroupMessage {
return []*protocol.GroupMessage{{Ciphertext: []byte("hello"), Signature: []byte{}, Spamguard: []byte{}}, {Ciphertext: []byte("hello"), Signature: []byte{}, Spamguard: []byte{}}}
}

func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity, listenChan chan bool) {
func runtestserver(t *testing.T, ts *TestServer, priv ed25519.PrivateKey, identity primitives.Identity, listenChan chan bool) {
ln, _ := net.Listen("tcp", "127.0.0.1:5451")
listenChan <- true
conn, _ := ln.Accept()
@@ -44,7 +44,9 @@ func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity, lis
if err != nil {
t.Errorf("Negotiate Version Error: %v", err)
}
err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, ServerAuthValid)
// TODO switch from old identity to new tapir identity.
pub := identity.PublicKey()
err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identityOld.InitializeV3("", &priv, &pub), ServerAuthValid)
if err != nil {
t.Errorf("ServerAuth Error: %v", err)
}
@@ -65,15 +67,13 @@ func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity, lis
}

func TestPeerServerConnection(t *testing.T) {
pub, priv, _ := ed25519.GenerateKey(rand.Reader)

identity := identity.InitializeV3("", &priv, &pub)
identity, priv := primitives.InitializeEphemeralIdentity()
t.Logf("Launching Server....\n")
ts := new(TestServer)
ts.Init()
ts.Received = make(chan bool)
listenChan := make(chan bool)
go runtestserver(t, ts, identity, listenChan)
go runtestserver(t, ts, priv, identity, listenChan)
<-listenChan
onionAddr := identity.Hostname()


Laden…
Abbrechen
Speichern