updating to new libricochet-go log api

This commit is contained in:
Dan Ballard 2018-12-03 18:52:11 -08:00
parent d56a00842e
commit 3367f1a083
21 changed files with 112 additions and 98 deletions

View File

@ -8,8 +8,8 @@ import (
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -43,7 +43,7 @@ type Application interface {
// NewApp creates a new app with some environment awareness and initializes a Tor Manager // NewApp creates a new app with some environment awareness and initializes a Tor Manager
func NewApp(acn connectivity.ACN, appDirectory string) Application { func NewApp(acn connectivity.ACN, appDirectory string) Application {
log.Printf("NewApp(%v)\n", appDirectory) log.Debugf("NewApp(%v)\n", appDirectory)
app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, acn: acn} app := &application{peers: make(map[string]peer.CwtchPeer), storage: make(map[string]storage.ProfileStore), directory: appDirectory, acn: acn}
os.Mkdir(path.Join(app.directory, "profiles"), 0700) os.Mkdir(path.Join(app.directory, "profiles"), 0700)
return app return app
@ -64,7 +64,7 @@ func (app *application) SaveProfile(p peer.CwtchPeer) {
// NewProfile creates a new cwtchPeer with a given name. // NewProfile creates a new cwtchPeer with a given name.
func (app *application) CreatePeer(name string, password string) (peer.CwtchPeer, error) { func (app *application) CreatePeer(name string, password string) (peer.CwtchPeer, error) {
log.Printf("CreatePeer(%v)\n", name) log.Debugf("CreatePeer(%v)\n", name)
randomFileName := generateRandomFilename() randomFileName := generateRandomFilename()
fileStore := storage.CreateFileProfileStore(path.Join(app.directory, "profiles", randomFileName), password) fileStore := storage.CreateFileProfileStore(path.Join(app.directory, "profiles", randomFileName), password)
@ -105,7 +105,7 @@ func (app *application) LoadProfiles(password string) error {
_, exists := app.peers[p.GetProfile().Onion] _, exists := app.peers[p.GetProfile().Onion]
if exists { if exists {
p.Shutdown() p.Shutdown()
log.Printf("Error: profile for onion %v already exists", p.GetProfile().Onion) log.Errorf("profile for onion %v already exists", p.GetProfile().Onion)
continue continue
} }

View File

@ -6,8 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"io/ioutil"
"log"
"os" "os"
"time" "time"
) )
@ -34,7 +32,6 @@ func waitForPeerServerConnection(peer peer.CwtchPeer, server string) error {
} }
func main() { func main() {
log.SetOutput(ioutil.Discard)
if len(os.Args) != 2 { if len(os.Args) != 2 {
fmt.Printf("Usage: ./servermon SERVER_ADDRESS\n") fmt.Printf("Usage: ./servermon SERVER_ADDRESS\n")
os.Exit(1) os.Exit(1)

View File

@ -9,9 +9,9 @@ import (
"cwtch.im/cwtch/peer/connections" "cwtch.im/cwtch/peer/connections"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"github.com/c-bata/go-prompt" "github.com/c-bata/go-prompt"
"golang.org/x/crypto/ssh/terminal" "golang.org/x/crypto/ssh/terminal"
"log"
"os" "os"
"os/user" "os/user"
"path" "path"
@ -247,21 +247,23 @@ func main() {
@+''+@ '++@ ;++@ '#''@ ##'''@: +++, +++, :@ @@@@ @@@' @@@ '@@@ @+''+@ '++@ ;++@ '#''@ ##'''@: +++, +++, :@ @@@@ @@@' @@@ '@@@
:' ' '` :' ' '`
fmt.Printf("%v\n\n", cwtch) fmt.Printf("%v\n\n", cwtch)
quit := false quit := false
usr, err := user.Current() usr, err := user.Current()
if err != nil { if err != nil {
log.Fatalf("\nError: could not load current user: %v\n", err) log.Errorf("\nError: could not load current user: %v\n", err)
os.Exit(1)
} }
acn, err := connectivity.StartTor(path.Join(usr.HomeDir, ".cwtch"), "") acn, err := connectivity.StartTor(path.Join(usr.HomeDir, ".cwtch"), "")
if err != nil { if err != nil {
log.Fatalf("\nError connecting to Tor: %v\n", err) log.Errorf("\nError connecting to Tor: %v\n", err)
os.Exit(1)
} }
app = app2.NewApp(acn, path.Join(usr.HomeDir, ".cwtch")) app = app2.NewApp(acn, path.Join(usr.HomeDir, ".cwtch"))
if err != nil { if err != nil {
log.Fatalf("Error initializing application: %v", err) log.Errorf("Error initializing application: %v", err)
os.Exit(1)
} }
fmt.Printf("\nWelcome to Cwtch!\n") fmt.Printf("\nWelcome to Cwtch!\n")
fmt.Printf("If this if your first time you should create a profile by running `/new-profile`\n") fmt.Printf("If this if your first time you should create a profile by running `/new-profile`\n")

View File

@ -8,65 +8,66 @@ import (
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/utils"
"github.com/sethvargo/go-diceware/diceware" "errors"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
"io/ioutil" "io/ioutil"
"log"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
) )
func convertCwtchFile(filename string, password string) { func convertCwtchFile(filename string, password string) error {
fileStore := storage2.CreateFileProfileStore(filename, password) fileStore := storage2.CreateFileProfileStore(filename, password)
peer, err := fileStore.Load() peer, err := fileStore.Load()
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
b := []byte("== ed25519v1-secret: type0 ==") b := []byte("== ed25519v1-secret: type0 ==")
b = append(b, peer.GetProfile().Ed25519PrivateKey...) b = append(b, peer.GetProfile().Ed25519PrivateKey...)
err = ioutil.WriteFile("hs_ed25519_secret_key", b, 0600) err = ioutil.WriteFile("hs_ed25519_secret_key", b, 0600)
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
b = []byte("== ed25519v1-public: type0 ==") b = []byte("== ed25519v1-public: type0 ==")
b = append(b, peer.GetProfile().Ed25519PublicKey...) b = append(b, peer.GetProfile().Ed25519PublicKey...)
err = ioutil.WriteFile("hs_ed25519_public_key", b, 0600) err = ioutil.WriteFile("hs_ed25519_public_key", b, 0600)
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
b = []byte(peer.GetProfile().Onion + ".onion\n") b = []byte(peer.GetProfile().Onion + ".onion\n")
err = ioutil.WriteFile("hostname", b, 0600) err = ioutil.WriteFile("hostname", b, 0600)
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
fmt.Println("success!") log.Infoln("success!")
return nil
} }
func convertTorFile(filename string, password string) { func convertTorFile(filename string, password string) error {
log.Fatalf("this code doesn't work and can never work :( it's a math thing") return errors.New("this code doesn't work and can never work :( it's a math thing")
name, _ := diceware.Generate(2) /*name, _ := diceware.Generate(2)
sk, err := ioutil.ReadFile("hs_ed25519_secret_key") sk, err := ioutil.ReadFile("hs_ed25519_secret_key")
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
sk = sk[32:] sk = sk[32:]
pk, err := ioutil.ReadFile("hs_ed25519_public_key") pk, err := ioutil.ReadFile("hs_ed25519_public_key")
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
pk = pk[32:] pk = pk[32:]
onion, err := ioutil.ReadFile("hostname") onion, err := ioutil.ReadFile("hostname")
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
onion = onion[:56] onion = onion[:56]
@ -79,13 +80,14 @@ func convertTorFile(filename string, password string) {
fileStore := storage2.CreateFileProfileStore(filename, password) fileStore := storage2.CreateFileProfileStore(filename, password)
err = fileStore.Save(peer) err = fileStore.Save(peer)
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
log.Printf("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion) log.Infof("success! loaded %d byte pk and %d byte sk for %s.onion\n", len(pk), len(sk), onion)
return nil*/
} }
func vanity() { func vanity() error {
for { for {
pk, sk, err := ed25519.GenerateKey(rand.Reader) pk, sk, err := ed25519.GenerateKey(rand.Reader)
if err != nil { if err != nil {
@ -101,19 +103,20 @@ func vanity() {
fileStore := storage2.CreateFileProfileStore(os.Args[3], onion+".cwtch") fileStore := storage2.CreateFileProfileStore(os.Args[3], onion+".cwtch")
err := fileStore.Save(peer) err := fileStore.Save(peer)
if err != nil { if err != nil {
log.Fatalf("%v", err) return err
} }
log.Printf("found %s.onion\n", onion) log.Infof("found %s.onion\n", onion)
} }
} }
} }
} }
func printHelp() { func printHelp() {
log.Println("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}") log.Infoln("usage: cwtchutil {help, convert-cwtch-file, convert-tor-file, changepw, vanity}")
} }
func main() { func main() {
log.SetLevel(log.LevelInfo)
if len(os.Args) < 2 { if len(os.Args) < 2 {
printHelp() printHelp()
os.Exit(1) os.Exit(1)
@ -126,28 +129,34 @@ func main() {
printHelp() printHelp()
case "convert-cwtch-file": case "convert-cwtch-file":
if len(os.Args) != 4 { if len(os.Args) != 4 {
log.Println("example: cwtchutil convert-cwtch-file ~/.cwtch/profiles/11ddd78a9918c064e742d5e36a8b8fd4 passw0rd") fmt.Println("example: cwtchutil convert-cwtch-file ~/.cwtch/profiles/11ddd78a9918c064e742d5e36a8b8fd4 passw0rd")
os.Exit(1) os.Exit(1)
} }
convertCwtchFile(os.Args[2], os.Args[3]) err := convertCwtchFile(os.Args[2], os.Args[3])
if err != nil {
log.Errorln(err)
}
case "convert-tor-file": case "convert-tor-file":
if len(os.Args) != 4 { if len(os.Args) != 4 {
log.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd") fmt.Println("example: cwtchutil convert-tor-file /var/lib/tor/hs1 passw0rd")
os.Exit(1) os.Exit(1)
} }
convertTorFile(os.Args[2], os.Args[3]) err := convertTorFile(os.Args[2], os.Args[3])
if err != nil {
log.Errorln(err)
}
case "vanity": case "vanity":
if len(os.Args) < 5 { if len(os.Args) < 5 {
log.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv") fmt.Println("example: cwtchutil vanity 4 passw0rd erinn openpriv")
os.Exit(1) os.Exit(1)
} }
goroutines, err := strconv.Atoi(os.Args[2]) goroutines, err := strconv.Atoi(os.Args[2])
if err != nil { if err != nil {
log.Printf("first parameter after vanity should be a number\n") log.Errorf("first parameter after vanity should be a number\n")
os.Exit(1) os.Exit(1)
} }
log.Println("searching. press ctrl+c to stop") log.Infoln("searching. press ctrl+c to stop")
for i := 0; i < goroutines; i++ { for i := 0; i < goroutines; i++ {
go vanity() go vanity()
} }
@ -157,14 +166,16 @@ func main() {
} }
case "changepw": case "changepw":
if len(os.Args) != 3 { if len(os.Args) != 3 {
log.Fatalf("example: cwtch changepw ~/.cwtch/profiles/XXX") fmt.Println("example: cwtch changepw ~/.cwtch/profiles/XXX")
os.Exit(1)
} }
fmt.Printf("old password: ") fmt.Printf("old password: ")
reader := bufio.NewReader(os.Stdin) reader := bufio.NewReader(os.Stdin)
pw, err := reader.ReadString('\n') pw, err := reader.ReadString('\n')
if err != nil { if err != nil {
log.Fatalf("%v", err) log.Errorln(err)
os.Exit(1)
} }
pw = pw[:len(pw)-1] pw = pw[:len(pw)-1]
@ -172,23 +183,25 @@ func main() {
peer, err := fileStore.Load() peer, err := fileStore.Load()
if err != nil { if err != nil {
log.Fatalf("%v", err) log.Errorln(err)
os.Exit(1)
} }
fmt.Printf("new password: ") fmt.Printf("new password: ")
newpw1, err := reader.ReadString('\n') newpw1, err := reader.ReadString('\n')
if err != nil { if err != nil {
log.Fatalf("%v", err) log.Errorln(err)
os.Exit(1)
} }
newpw1 = newpw1[:len(newpw1)-1] // fuck go with this linebreak shit ^ea newpw1 = newpw1[:len(newpw1)-1] // fuck go with this linebreak shit ^ea
fileStore2 := storage2.CreateFileProfileStore(os.Args[2], newpw1) fileStore2 := storage2.CreateFileProfileStore(os.Args[2], newpw1)
err = fileStore2.Save(peer) err = fileStore2.Save(peer)
if err != nil { if err != nil {
log.Fatalf("%v", err) log.Errorln(err)
os.Exit(1)
} }
log.Println("success!") log.Infoln("success!")
} }
} }

View File

@ -2,17 +2,19 @@ package main
import ( import (
"cwtch.im/cwtch/peer" "cwtch.im/cwtch/peer"
"log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
) )
func main() { func main() {
log.AddEverythingFromPattern("peer/alice")
alice := peer.NewCwtchPeer("alice") alice := peer.NewCwtchPeer("alice")
processData := func(onion string, data []byte) []byte { processData := func(onion string, data []byte) []byte {
log.Printf("Recieved %s from %v", data, onion) log.Debugf("Recieved %s from %v", data, onion)
return data return data
} }
alice.SetPeerDataHandler(processData) alice.SetPeerDataHandler(processData)
alice.Listen() alice.Listen()
} }

View File

@ -2,23 +2,24 @@ package main
import ( import (
"cwtch.im/cwtch/peer" "cwtch.im/cwtch/peer"
"log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"strconv" "strconv"
"time" "time"
) )
func main() { func main() {
log.AddEverythingFromPattern("peer/bob")
bob := peer.NewCwtchPeer("bob") bob := peer.NewCwtchPeer("bob")
counter := 1 counter := 1
bob.SetPeerDataHandler(func(onion string, data []byte) []byte { bob.SetPeerDataHandler(func(onion string, data []byte) []byte {
log.Printf("Recieved %s from %v", data, onion) log.Infof("Recieved %s from %v", data, onion)
counter++ counter++
return []byte(strconv.Itoa(counter)) return []byte(strconv.Itoa(counter))
}) })
connection := bob.PeerWithOnion("f4b6thuwmfszsqd3fzqpr45sdem4qoazdlzr2xmnc7fq22qe746hjqqd") connection := bob.PeerWithOnion("f4b6thuwmfszsqd3fzqpr45sdem4qoazdlzr2xmnc7fq22qe746hjqqd")
log.Printf("Waiting for Bob to Connect to Alice...") log.Infof("Waiting for Bob to Connect to Alice...")
connection.SendPacket([]byte("Hello Alice!!!")) connection.SendPacket([]byte("Hello Alice!!!"))
// Wait a while... // Wait a while...

View File

@ -5,11 +5,11 @@ import (
"cwtch.im/cwtch/protocol" "cwtch.im/cwtch/protocol"
"errors" "errors"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/utils"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"golang.org/x/crypto/nacl/secretbox" "golang.org/x/crypto/nacl/secretbox"
"io" "io"
"log"
"sync" "sync"
"time" "time"
) )
@ -43,14 +43,14 @@ func NewGroup(server string) (*Group, error) {
var groupID [16]byte var groupID [16]byte
if _, err := io.ReadFull(rand.Reader, groupID[:]); err != nil { if _, err := io.ReadFull(rand.Reader, groupID[:]); err != nil {
log.Printf("Error: Cannot read from random: %v\n", err) log.Errorf("Cannot read from random: %v\n", err)
return nil, err return nil, err
} }
group.GroupID = fmt.Sprintf("%x", groupID) group.GroupID = fmt.Sprintf("%x", groupID)
var groupKey [32]byte var groupKey [32]byte
if _, err := io.ReadFull(rand.Reader, groupKey[:]); err != nil { if _, err := io.ReadFull(rand.Reader, groupKey[:]); err != nil {
log.Printf("Error: Cannot read from random: %v\n", err) log.Errorf("Error: Cannot read from random: %v\n", err)
return nil, err return nil, err
} }
copy(group.GroupKey[:], groupKey[:]) copy(group.GroupKey[:], groupKey[:])
@ -135,7 +135,7 @@ func (g *Group) GetTimeline() (t []Message) {
func (g *Group) EncryptMessage(message *protocol.DecryptedGroupMessage) ([]byte, error) { func (g *Group) EncryptMessage(message *protocol.DecryptedGroupMessage) ([]byte, error) {
var nonce [24]byte var nonce [24]byte
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil { if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
log.Printf("Error: Cannot read from random: %v\n", err) log.Errorf("Cannot read from random: %v\n", err)
return nil, err return nil, err
} }
wire, err := proto.Marshal(message) wire, err := proto.Marshal(message)

View File

@ -10,7 +10,7 @@ import (
"git.openprivacy.ca/openprivacy/libricochet-go/connection" "git.openprivacy.ca/openprivacy/libricochet-go/connection"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity" "git.openprivacy.ca/openprivacy/libricochet-go/identity"
"log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"time" "time"
) )
@ -61,7 +61,7 @@ func (ppc *PeerPeerConnection) SendPacket(data []byte) {
if channel != nil { if channel != nil {
peerchannel, ok := channel.Handler.(*peer.CwtchPeerDataChannel) peerchannel, ok := channel.Handler.(*peer.CwtchPeerDataChannel)
if ok { if ok {
log.Printf("Sending packet\n") log.Debugf("Sending packet\n")
peerchannel.SendMessage(data) peerchannel.SendMessage(data)
} }
} }
@ -89,7 +89,7 @@ func (ppc *PeerPeerConnection) SendGroupInvite(invite []byte) {
if channel != nil { if channel != nil {
peerchannel, ok := channel.Handler.(*peer.CwtchPeerChannel) peerchannel, ok := channel.Handler.(*peer.CwtchPeerChannel)
if ok { if ok {
log.Printf("Sending group invite packet\n") log.Debugf("Sending group invite packet\n")
peerchannel.SendMessage(invite) peerchannel.SendMessage(invite)
} }
} }
@ -112,7 +112,6 @@ func (ppc *PeerPeerConnection) Run() error {
ppc.state = CONNECTING ppc.state = CONNECTING
rc, err := goricochet.Open(ppc.acn, ppc.PeerHostname) rc, err := goricochet.Open(ppc.acn, ppc.PeerHostname)
if err == nil { if err == nil {
rc.TraceLog(false)
ppc.connection = rc ppc.connection = rc
ppc.state = CONNECTED ppc.state = CONNECTED
_, err := connection.HandleOutboundConnection(ppc.connection).ProcessAuthAsV3Client(identity.InitializeV3(ppc.profile.Name, &ppc.profile.Ed25519PrivateKey, &ppc.profile.Ed25519PublicKey)) _, err := connection.HandleOutboundConnection(ppc.connection).ProcessAuthAsV3Client(identity.InitializeV3(ppc.profile.Name, &ppc.profile.Ed25519PrivateKey, &ppc.profile.Ed25519PublicKey))

View File

@ -32,7 +32,6 @@ func runtestpeer(t *testing.T, tp *TestPeer, identity identity.Identity, listenC
if err != nil { if err != nil {
t.Errorf("Negotiate Version Error: %v", err) t.Errorf("Negotiate Version Error: %v", err)
} }
rc.TraceLog(true)
err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, PeerAuthValid) err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, PeerAuthValid)
if err != nil { if err != nil {
t.Errorf("ServerAuth Error: %v", err) t.Errorf("ServerAuth Error: %v", err)

View File

@ -12,8 +12,8 @@ import (
"git.openprivacy.ca/openprivacy/libricochet-go/connection" "git.openprivacy.ca/openprivacy/libricochet-go/connection"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity" "git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
"log"
"time" "time"
) )
@ -54,10 +54,9 @@ func (psc *PeerServerConnection) WaitTilAuthenticated() {
// Run manages the setup and teardown of a peer server connection // Run manages the setup and teardown of a peer server connection
func (psc *PeerServerConnection) Run() error { func (psc *PeerServerConnection) Run() error {
log.Printf("Connecting to %v", psc.Server) log.Infof("Connecting to %v", psc.Server)
rc, err := goricochet.Open(psc.acn, psc.Server) rc, err := goricochet.Open(psc.acn, psc.Server)
if err == nil { if err == nil {
rc.TraceLog(true)
psc.connection = rc psc.connection = rc
psc.state = CONNECTED psc.state = CONNECTED
pub, priv, err := ed25519.GenerateKey(rand.Reader) pub, priv, err := ed25519.GenerateKey(rand.Reader)
@ -136,6 +135,6 @@ func (psc *PeerServerConnection) Close() {
// HandleGroupMessage passes the given group message back to the profile. // HandleGroupMessage passes the given group message back to the profile.
func (psc *PeerServerConnection) HandleGroupMessage(gm *protocol.GroupMessage) { func (psc *PeerServerConnection) HandleGroupMessage(gm *protocol.GroupMessage) {
log.Printf("Received Group Message") log.Debugf("Received Group Message")
psc.GroupMessageHandler(psc.Server, gm) psc.GroupMessageHandler(psc.Server, gm)
} }

View File

@ -43,7 +43,6 @@ func runtestserver(t *testing.T, ts *TestServer, identity identity.Identity, lis
if err != nil { if err != nil {
t.Errorf("Negotiate Version Error: %v", err) t.Errorf("Negotiate Version Error: %v", err)
} }
rc.TraceLog(true)
err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, ServerAuthValid) err = connection.HandleInboundConnection(rc).ProcessAuthAsV3Server(identity, ServerAuthValid)
if err != nil { if err != nil {
t.Errorf("ServerAuth Error: %v", err) t.Errorf("ServerAuth Error: %v", err)

View File

@ -14,10 +14,10 @@ import (
"git.openprivacy.ca/openprivacy/libricochet-go/connection" "git.openprivacy.ca/openprivacy/libricochet-go/connection"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/identity" "git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/utils"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
"log"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -195,7 +195,7 @@ func (cp *cwtchPeer) InviteOnionToGroup(onion string, groupid string) error {
group := cp.Profile.GetGroupByGroupID(groupid) group := cp.Profile.GetGroupByGroupID(groupid)
if group != nil { if group != nil {
log.Printf("Constructing invite for group: %v\n", group) log.Infof("Constructing invite for group: %v\n", group)
invite, err := group.Invite(group.GetInitialMessage()) invite, err := group.Invite(group.GetInitialMessage())
if err != nil { if err != nil {
return err return err
@ -205,7 +205,7 @@ func (cp *cwtchPeer) InviteOnionToGroup(onion string, groupid string) error {
return errors.New("peer connection not setup for onion. peers must be trusted before sending") return errors.New("peer connection not setup for onion. peers must be trusted before sending")
} }
if ppc.GetState() == connections.AUTHENTICATED { if ppc.GetState() == connections.AUTHENTICATED {
log.Printf("Got connection for group: %v - Sending Invite\n", ppc) log.Infof("Got connection for group: %v - Sending Invite\n", ppc)
ppc.SendGroupInvite(invite) ppc.SendGroupInvite(invite)
} else { } else {
return errors.New("cannot send invite to onion: peer connection is not ready") return errors.New("cannot send invite to onion: peer connection is not ready")
@ -352,7 +352,7 @@ func (cp *cwtchPeer) listenFn() error {
} }
ra.Init(cp.acn, cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp) ra.Init(cp.acn, cp.Profile.Name, identity.InitializeV3(cp.Profile.Name, &cp.Profile.Ed25519PrivateKey, &cp.Profile.Ed25519PublicKey), af, cp)
log.Printf("Running cwtch peer on %v", onionService.AddressFull()) log.Infof("Running cwtch peer on %v", onionService.AddressFull())
cp.app = ra cp.app = ra
cp.started = true cp.started = true
ra.Run(onionService) ra.Run(onionService)
@ -395,7 +395,7 @@ type CwtchPeerHandler struct {
// HandleGroupInvite handles incoming GroupInvites // HandleGroupInvite handles incoming GroupInvites
func (cph *CwtchPeerHandler) HandleGroupInvite(gci *protocol.GroupChatInvite) { func (cph *CwtchPeerHandler) HandleGroupInvite(gci *protocol.GroupChatInvite) {
log.Printf("Received GroupID from %v %v\n", cph.Onion, gci.String()) log.Debugf("Received GroupID from %v %v\n", cph.Onion, gci.String())
cph.Peer.Profile.ProcessInvite(gci, cph.Onion) cph.Peer.Profile.ProcessInvite(gci, cph.Onion)
} }

View File

@ -3,10 +3,10 @@ package peer
import ( import (
"cwtch.im/cwtch/protocol" "cwtch.im/cwtch/protocol"
"git.openprivacy.ca/openprivacy/libricochet-go/channels" "git.openprivacy.ca/openprivacy/libricochet-go/channels"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/utils"
"git.openprivacy.ca/openprivacy/libricochet-go/wire/control" "git.openprivacy.ca/openprivacy/libricochet-go/wire/control"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"log"
) )
// CwtchPeerChannel implements the ChannelHandler interface for a channel of // CwtchPeerChannel implements the ChannelHandler interface for a channel of
@ -101,6 +101,6 @@ func (cpc *CwtchPeerChannel) Packet(data []byte) {
cpc.Handler.HandleGroupInvite(cpp.GetGroupChatInvite()) cpc.Handler.HandleGroupInvite(cpp.GetGroupChatInvite())
} }
} else { } else {
log.Printf("Error Receivng Packet %v\n", err) log.Errorf("Error Receivng Packet %v\n", err)
} }
} }

View File

@ -3,7 +3,7 @@ package main
import ( import (
cwtchserver "cwtch.im/cwtch/server" cwtchserver "cwtch.im/cwtch/server"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"os" "os"
"path" "path"
) )
@ -13,18 +13,21 @@ const (
) )
func main() { func main() {
log.AddEverythingFromPattern("server/app/main")
log.AddEverythingFromPattern("server/server")
configDir := os.Getenv("CWTCH_CONFIG_DIR") configDir := os.Getenv("CWTCH_CONFIG_DIR")
serverConfig := cwtchserver.LoadConfig(configDir, serverConfigFile) serverConfig := cwtchserver.LoadConfig(configDir, serverConfigFile)
acn, err := connectivity.StartTor(path.Join(configDir, "tor"), "") acn, err := connectivity.StartTor(path.Join(configDir, "tor"), "")
if err != nil { if err != nil {
log.Fatalf("\nError connecting to Tor: %v\n", err) log.Errorf("\nError connecting to Tor: %v\n", err)
os.Exit(1)
} }
defer acn.Close() defer acn.Close()
server := new(cwtchserver.Server) server := new(cwtchserver.Server)
log.Printf("starting cwtch server...") log.Infoln("starting cwtch server...")
// TODO load params from .cwtch/server.conf or command line flag // TODO load params from .cwtch/server.conf or command line flag
// TODO: respond to HUP so t.Close is gracefully called // TODO: respond to HUP so t.Close is gracefully called

View File

@ -4,8 +4,8 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/application" "git.openprivacy.ca/openprivacy/libricochet-go/application"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"github.com/struCoder/pidusage" "github.com/struCoder/pidusage"
"log"
"os" "os"
"path" "path"
"time" "time"
@ -59,7 +59,7 @@ func (mp *Monitors) run() {
func (mp *Monitors) report() { func (mp *Monitors) report() {
f, err := os.Create(path.Join(mp.configDir, reportFile)) f, err := os.Create(path.Join(mp.configDir, reportFile))
if err != nil { if err != nil {
log.Println("ERROR: Could not open monitor reporting file: ", err) log.Errorf("Could not open monitor reporting file: ", err)
return return
} }
defer f.Close() defer f.Close()

View File

@ -5,9 +5,9 @@ import (
"cwtch.im/cwtch/protocol/spam" "cwtch.im/cwtch/protocol/spam"
"errors" "errors"
"git.openprivacy.ca/openprivacy/libricochet-go/channels" "git.openprivacy.ca/openprivacy/libricochet-go/channels"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"git.openprivacy.ca/openprivacy/libricochet-go/wire/control" "git.openprivacy.ca/openprivacy/libricochet-go/wire/control"
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"log"
) )
// CwtchServerSendChannel implements the ChannelHandler interface for a channel of // CwtchServerSendChannel implements the ChannelHandler interface for a channel of
@ -89,11 +89,11 @@ func (cc *CwtchServerSendChannel) Packet(data []byte) {
if ok { if ok {
cc.Handler.HandleGroupMessage(gm) cc.Handler.HandleGroupMessage(gm)
} else { } else {
log.Printf("[ERROR] Failed to validate spamguard %v\n", gm) log.Errorf("Failed to validate spamguard %v\n", gm)
} }
} }
} else { } else {
log.Printf("[ERROR] Failed to decode packet on SEND channel %v\n", err) log.Errorf("Failed to decode packet on SEND channel %v\n", err)
} }
cc.channel.CloseChannel() cc.channel.CloseChannel()
} }

View File

@ -11,7 +11,8 @@ import (
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/utils"
"log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"os"
"strconv" "strconv"
"time" "time"
) )
@ -37,7 +38,9 @@ func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
ms := new(storage.MessageStore) ms := new(storage.MessageStore)
err := ms.Init(serverConfig.ConfigDir, s.config.MaxBufferLines, s.metricsPack.MessageCounter) err := ms.Init(serverConfig.ConfigDir, s.config.MaxBufferLines, s.metricsPack.MessageCounter)
if err != nil { if err != nil {
log.Fatal(err) log.Errorln(err)
acn.Close()
os.Exit(1)
} }
af.AddHandler("im.cwtch.server.listen", func(rai *application.ApplicationInstance) func() channels.Handler { af.AddHandler("im.cwtch.server.listen", func(rai *application.ApplicationInstance) func() channels.Handler {
return func() channels.Handler { return func() channels.Handler {
@ -69,14 +72,14 @@ func (s *Server) Run(acn connectivity.ACN, serverConfig Config) {
addressIdentity := utils.GetTorV3Hostname(s.config.PublicKey) addressIdentity := utils.GetTorV3Hostname(s.config.PublicKey)
cwtchserver.Init(acn, "cwtch server for "+addressIdentity, s.config.Identity(), af, new(application.AcceptAllContactManager)) cwtchserver.Init(acn, "cwtch server for "+addressIdentity, s.config.Identity(), af, new(application.AcceptAllContactManager))
port := strconv.Itoa(application.RicochetPort) port := strconv.Itoa(application.RicochetPort)
log.Printf("cwtch server running on cwtch:%s", addressIdentity+".onion:"+port) log.Infof("cwtch server running on cwtch:%s\n", addressIdentity+".onion:"+port)
s.app = cwtchserver s.app = cwtchserver
for true { for true {
listenService, err := acn.Listen(s.config.PrivateKey, application.RicochetPort) listenService, err := acn.Listen(s.config.PrivateKey, application.RicochetPort)
if err != nil { if err != nil {
log.Printf("Listen() error setting up onion service: %v\n", err) log.Errorf("Listen() error setting up onion service: %v\n", err)
} else { } else {
s.app.Run(listenService) s.app.Run(listenService)
} }

View File

@ -4,9 +4,9 @@ import (
"crypto/rand" "crypto/rand"
"encoding/json" "encoding/json"
"git.openprivacy.ca/openprivacy/libricochet-go/identity" "git.openprivacy.ca/openprivacy/libricochet-go/identity"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"golang.org/x/crypto/ed25519" "golang.org/x/crypto/ed25519"
"io/ioutil" "io/ioutil"
"log"
"path" "path"
) )
@ -33,14 +33,14 @@ func (config *Config) Identity() identity.Identity {
// Save dumps the latest version of the config to a json file given by filename // Save dumps the latest version of the config to a json file given by filename
func (config *Config) Save(dir, filename string) { func (config *Config) Save(dir, filename string) {
log.Printf("Saving config to %s\n", path.Join(dir, filename)) log.Infof("Saving config to %s\n", path.Join(dir, filename))
bytes, _ := json.MarshalIndent(config, "", "\t") bytes, _ := json.MarshalIndent(config, "", "\t")
ioutil.WriteFile(path.Join(dir, filename), bytes, 0600) ioutil.WriteFile(path.Join(dir, filename), bytes, 0600)
} }
// LoadConfig loads a Config from a json file specified by filename // LoadConfig loads a Config from a json file specified by filename
func LoadConfig(configDir, filename string) Config { func LoadConfig(configDir, filename string) Config {
log.Printf("Loading config from %s\n", path.Join(configDir, filename)) log.Infof("Loading config from %s\n", path.Join(configDir, filename))
config := Config{} config := Config{}
config.ConfigDir = configDir config.ConfigDir = configDir
config.MaxBufferLines = 100000 config.MaxBufferLines = 100000
@ -50,7 +50,7 @@ func LoadConfig(configDir, filename string) Config {
err = json.Unmarshal(raw, &config) err = json.Unmarshal(raw, &config)
if err != nil { if err != nil {
log.Println("Error reading config: ", err) log.Errorf("reading config: ", err)
} }
} }

View File

@ -6,12 +6,12 @@ import (
"cwtch.im/cwtch/peer" "cwtch.im/cwtch/peer"
"encoding/json" "encoding/json"
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
"golang.org/x/crypto/nacl/secretbox" "golang.org/x/crypto/nacl/secretbox"
"golang.org/x/crypto/pbkdf2" "golang.org/x/crypto/pbkdf2"
"golang.org/x/crypto/sha3" "golang.org/x/crypto/sha3"
"io" "io"
"io/ioutil" "io/ioutil"
"log"
) )
// fileProfileStore stores a cwtchPeer in an encrypted file // fileProfileStore stores a cwtchPeer in an encrypted file
@ -48,7 +48,7 @@ func (fps *fileProfileStore) Save(cwtchPeer peer.CwtchPeer) error {
func createKey(password string) ([32]byte, [128]byte, error) { func createKey(password string) ([32]byte, [128]byte, error) {
var salt [128]byte var salt [128]byte
if _, err := io.ReadFull(rand.Reader, salt[:]); err != nil { if _, err := io.ReadFull(rand.Reader, salt[:]); err != nil {
log.Printf("Error: Cannot read from random: %v\n", err) log.Errorf("Cannot read from random: %v\n", err)
return [32]byte{}, salt, err return [32]byte{}, salt, err
} }
dk := pbkdf2.Key([]byte(password), salt[:], 4096, 32, sha3.New512) dk := pbkdf2.Key([]byte(password), salt[:], 4096, 32, sha3.New512)
@ -63,7 +63,7 @@ func encryptProfile(p peer.CwtchPeer, key [32]byte) ([]byte, error) {
var nonce [24]byte var nonce [24]byte
if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil { if _, err := io.ReadFull(rand.Reader, nonce[:]); err != nil {
log.Printf("Error: Cannot read from random: %v\n", err) log.Errorf("Cannot read from random: %v\n", err)
return nil, err return nil, err
} }

View File

@ -6,7 +6,7 @@ import (
"cwtch.im/cwtch/server/metrics" "cwtch.im/cwtch/server/metrics"
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "git.openprivacy.ca/openprivacy/libricochet-go/log"
"os" "os"
"path" "path"
"sync" "sync"
@ -61,7 +61,7 @@ func (ms *MessageStore) initAndLoadFiles() error {
filename := path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, i)) filename := path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, i))
f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600) f, err := os.OpenFile(filename, os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
if err != nil { if err != nil {
log.Printf("Error: MessageStore could not open: %v: %v", filename, err) log.Errorf("MessageStore could not open: %v: %v", filename, err)
continue continue
} }
ms.activeLogFile = f ms.activeLogFile = f
@ -86,7 +86,7 @@ func (ms *MessageStore) initAndLoadFiles() error {
func (ms *MessageStore) updateFile(gm *protocol.GroupMessage) { func (ms *MessageStore) updateFile(gm *protocol.GroupMessage) {
s, err := json.Marshal(gm) s, err := json.Marshal(gm)
if err != nil { if err != nil {
log.Printf("[ERROR] Failed to unmarshal group message %v\n", err) log.Errorf("Failed to unmarshal group message %v\n", err)
} }
fmt.Fprintf(ms.activeLogFile, "%s\n", s) fmt.Fprintf(ms.activeLogFile, "%s\n", s)
ms.filePos++ ms.filePos++
@ -105,7 +105,7 @@ func (ms *MessageStore) rotateFileStore() {
f, err := os.OpenFile(path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, 0)), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600) f, err := os.OpenFile(path.Join(ms.storeDirectory, fmt.Sprintf("%s.%d", fileStoreFilename, 0)), os.O_CREATE|os.O_APPEND|os.O_RDWR, 0600)
if err != nil { if err != nil {
log.Printf("ERROR: Could not open new message store file in: %s", ms.storeDirectory) log.Errorf("Could not open new message store file in: %s", ms.storeDirectory)
} }
ms.filePos = 0 ms.filePos = 0
ms.activeLogFile = f ms.activeLogFile = f

View File

@ -8,8 +8,6 @@ import (
"fmt" "fmt"
"git.openprivacy.ca/openprivacy/libricochet-go/connectivity" "git.openprivacy.ca/openprivacy/libricochet-go/connectivity"
"golang.org/x/net/proxy" "golang.org/x/net/proxy"
"io/ioutil"
"log"
"os" "os"
"runtime" "runtime"
"testing" "testing"
@ -98,7 +96,6 @@ func waitForPeerPeerConnection(t *testing.T, peera peer.CwtchPeer, peerb peer.Cw
func TestCwtchPeerIntegration(t *testing.T) { func TestCwtchPeerIntegration(t *testing.T) {
// Hide logging "noise" // Hide logging "noise"
log.SetOutput(ioutil.Discard)
numGoRoutinesStart := runtime.NumGoroutine() numGoRoutinesStart := runtime.NumGoroutine()
acn, err := connectivity.StartTor(".", "") acn, err := connectivity.StartTor(".", "")