diff --git a/.drone.yml b/.drone.yml index c35fb34..6548396 100644 --- a/.drone.yml +++ b/.drone.yml @@ -16,7 +16,7 @@ pipeline: commands: - go list ./... | xargs go vet #-set_exit_status too many lint fails for :( - - go list ./... | xargs golint + - go list ./... | grep -v "/wire/" | grep -v "/examples/" | grep -v "/application" | xargs golint -set_exit_status units-tests: image: golang commands: diff --git a/.gitignore b/.gitignore index 14cbaff..25c65c2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ go-ricochet-coverage.out *~ *.out .idea +.reviewboardrc diff --git a/application/acceptallcontacthandler.go b/application/acceptallcontacthandler.go index e7f757a..c244135 100644 --- a/application/acceptallcontacthandler.go +++ b/application/acceptallcontacthandler.go @@ -1,13 +1,22 @@ package application +// AcceptAllContactHandler is a pass through Contact Handler. It is currently only used by the integration test. +// TODO: DEPRECATE type AcceptAllContactHandler struct{} +// ContactRequest returns "Pending" for everything func (aach *AcceptAllContactHandler) ContactRequest(name string, message string) string { return "Pending" } + +// ContactRequestRejected is a noop func (aach *AcceptAllContactHandler) ContactRequestRejected() { } + +// ContactRequestAccepted is a noop func (aach *AcceptAllContactHandler) ContactRequestAccepted() { } + +// ContactRequestError is a noop func (aach *AcceptAllContactHandler) ContactRequestError() { } diff --git a/application/acceptallcontactmanager.go b/application/acceptallcontactmanager.go index cb136a3..5a2dac4 100644 --- a/application/acceptallcontactmanager.go +++ b/application/acceptallcontactmanager.go @@ -7,6 +7,8 @@ import ( // AcceptAllContactManager implements the contact manager interface an presumes // all connections are allowed. +// It is currently used by the Cwtch Server. +// TODO Deprecate type AcceptAllContactManager struct { } @@ -15,11 +17,12 @@ func (aacm *AcceptAllContactManager) LookupContact(hostname string, publicKey rs return true, true } -// LookupContact returns that a contact is known and allowed to communicate for all cases. +// LookupContactV3 returns that a contact is known and allowed to communicate for all cases. func (aacm *AcceptAllContactManager) LookupContactV3(hostname string, publicKey ed25519.PublicKey) (allowed, known bool) { return true, true } +// ContactRequest accepts every single Contact Request func (aacm *AcceptAllContactManager) ContactRequest(name string, message string) string { return "Accepted" } diff --git a/application/application.go b/application/application.go index 644538b..f864573 100644 --- a/application/application.go +++ b/application/application.go @@ -74,6 +74,7 @@ func (ra *RicochetApplication) handleConnection(conn net.Conn) { ra.lock.Unlock() } +// HandleApplicationInstance delegates handling of a given ApplicationInstance to the Application. func (ra *RicochetApplication) HandleApplicationInstance(rai *ApplicationInstance) { ra.lock.Lock() ra.instances = append(ra.instances, rai) @@ -103,6 +104,7 @@ func (ra *RicochetApplication) Open(onionAddress string, requestMessage string) return rai, nil } +// Broadcast performs the given function do() over all application instance (all connected peers) func (ra *RicochetApplication) Broadcast(do func(rai *ApplicationInstance)) { ra.lock.Lock() for _, rai := range ra.instances { @@ -121,6 +123,7 @@ func (ra *RicochetApplication) Shutdown() { ra.lock.Unlock() } +// ConnectionCount returns the number of concurrent connections to the application func (ra *RicochetApplication) ConnectionCount() int { return len(ra.instances) } diff --git a/application/application_factory.go b/application/application_factory.go index 1361e8e..b688b7e 100644 --- a/application/application_factory.go +++ b/application/application_factory.go @@ -12,7 +12,7 @@ type ApplicationInstance struct { RemoteHostname string } -// ApplicationInstanceFactory +// ApplicationInstanceFactory generates ApplicationInstances on a specific connection. type ApplicationInstanceFactory struct { handlerMap map[string]func(*ApplicationInstance) func() channels.Handler } @@ -27,6 +27,7 @@ func (af *ApplicationInstanceFactory) AddHandler(ctype string, chandler func(*Ap af.handlerMap[ctype] = chandler } +// GetHandlers returns all handlers func (af *ApplicationInstanceFactory) GetHandlers() []string { keys := make([]string, len(af.handlerMap)) @@ -39,6 +40,7 @@ func (af *ApplicationInstanceFactory) GetHandlers() []string { return keys } +// GetHandler returns a set handler for the channel type. func (af *ApplicationInstanceFactory) GetHandler(ctype string) func(*ApplicationInstance) func() channels.Handler { return af.handlerMap[ctype] } diff --git a/channels/v3/inbound/3dhauthchannel_test.go b/channels/v3/inbound/3dhauthchannel_test.go index 4d49c9f..f80acdd 100644 --- a/channels/v3/inbound/3dhauthchannel_test.go +++ b/channels/v3/inbound/3dhauthchannel_test.go @@ -8,8 +8,8 @@ import ( "git.openprivacy.ca/openprivacy/libricochet-go/utils" "git.openprivacy.ca/openprivacy/libricochet-go/wire/auth/3edh" "git.openprivacy.ca/openprivacy/libricochet-go/wire/control" - "golang.org/x/crypto/ed25519" "github.com/golang/protobuf/proto" + "golang.org/x/crypto/ed25519" "testing" ) @@ -18,7 +18,7 @@ func TestServer3DHAuthChannel(t *testing.T) { cc := new(channels.Channel) cc.ID = 1 closed := false - cc.CloseChannel = func() {closed=true} + cc.CloseChannel = func() { closed = true } clientChannel := new(outbound.Client3DHAuthChannel) pub, priv, _ := ed25519.GenerateKey(rand.Reader) cid := identity.InitializeV3("", &priv, &pub) @@ -34,7 +34,7 @@ func TestServer3DHAuthChannel(t *testing.T) { sid := identity.InitializeV3("", &priv, &pub) s3dhchannel.ServerIdentity = sid clientChannel.ServerHostname = utils.GetTorV3Hostname(pub) - cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel()) + cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel()) proto.Unmarshal(cr, packet) if packet.GetChannelResult() != nil { diff --git a/connection/handler.go b/connection/handler.go index f167b48..9a6c42b 100644 --- a/connection/handler.go +++ b/connection/handler.go @@ -27,4 +27,4 @@ type Handler interface { OnOpenChannelRequest(ctype string) (channels.Handler, error) GetSupportedChannelTypes() []string -} \ No newline at end of file +} diff --git a/connection/inboundconnectionhandler.go b/connection/inboundconnectionhandler.go index c359793..a58eabf 100644 --- a/connection/inboundconnectionhandler.go +++ b/connection/inboundconnectionhandler.go @@ -37,6 +37,7 @@ func HandleInboundConnection(c *Connection) *InboundConnectionHandler { // true to accept authentication and allow the connection to continue, and also returns a // boolean indicating whether the contact is known and recognized. Unknown contacts will // assume they are required to send a contact request before any other activity. +// TODO: Deprecate func (ich *InboundConnectionHandler) ProcessAuthAsServer(identity identity.Identity, sach func(hostname string, publicKey rsa.PublicKey) (allowed, known bool)) error { if !identity.Initialized() { @@ -91,11 +92,11 @@ func (ich *InboundConnectionHandler) ProcessAuthAsServer(identity identity.Ident return err } -// ProcessAuthAsServer blocks until authentication has succeeded, failed, or the +// ProcessAuthAsV3Server blocks until authentication has succeeded, failed, or the // connection is closed. A non-nil error is returned in all cases other than successful // and accepted authentication. // -// ProcessAuthAsServer cannot be called at the same time as any other call to a Process +// ProcessAuthAsV3Server cannot be called at the same time as any other call to a Process // function. Another Process function must be called after this function successfully // returns to continue handling connection events. // diff --git a/connection/outboundconnectionhandler.go b/connection/outboundconnectionhandler.go index 35d07a2..1bf1296 100644 --- a/connection/outboundconnectionhandler.go +++ b/connection/outboundconnectionhandler.go @@ -33,6 +33,7 @@ func HandleOutboundConnection(c *Connection) *OutboundConnectionHandler { // For successful authentication, the `known` return value indicates whether the peer // accepts us as a known contact. Unknown contacts will generally need to send a contact // request before any other activity. +// TODO; Deprecate func (och *OutboundConnectionHandler) ProcessAuthAsClient(identity identity.Identity) (bool, error) { if !identity.Initialized() { @@ -90,11 +91,11 @@ func (och *OutboundConnectionHandler) ProcessAuthAsClient(identity identity.Iden return false, utils.ServerRejectedClientConnectionError } -// ProcessAuthAs3DGClient blocks until authentication has succeeded or failed with the +// ProcessAuthAsV3Client blocks until authentication has succeeded or failed with the // provided identity, or the connection is closed. A non-nil error is returned in all // cases other than successful authentication. // -// ProcessAuthAsClient cannot be called at the same time as any other call to a Porcess +// ProcessAuthAsV3Client cannot be called at the same time as any other call to a Process // function. Another Process function must be called after this function successfully // returns to continue handling connection events. // diff --git a/identity/identity.go b/identity/identity.go index 5d2db3f..ec35844 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -34,7 +34,7 @@ func Initialize(name string, pk *rsa.PrivateKey) Identity { return Identity{name, pk, nil, nil} } -// Initialize is a courtesy function for initializing an Identity in-code. +// InitializeV3 is a courtesy function for initializing a V3 Identity in-code. func InitializeV3(name string, pk *ed25519.PrivateKey, pubk *ed25519.PublicKey) Identity { return Identity{name, nil, pk, pubk} } @@ -66,6 +66,7 @@ func (i *Identity) PublicKeyBytes() []byte { return publicKeyBytes } +// 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[:] @@ -73,11 +74,10 @@ func (i *Identity) EDH(key ed25519.PublicKey) []byte { // Hostname provides the onion address associated with this Identity. func (i *Identity) Hostname() string { - if i.edpk != nil { - return utils.GetTorV3Hostname(*i.edpubk) - } else { + if i.pk != nil { return utils.GetTorHostname(i.PublicKeyBytes()) } + return utils.GetTorV3Hostname(*i.edpubk) } // Sign produces a cryptographic signature using this Identities private key. diff --git a/log/log.go b/log/log.go index b53cd6b..0e9954c 100644 --- a/log/log.go +++ b/log/log.go @@ -166,7 +166,7 @@ func Errorf(format string, v ...interface{}) { std.Printf(LevelError, format, v...) } -// Degubln outputs the variables at the Debug level +// Debugln outputs the variables at the Debug level func Debugln(v ...interface{}) { std.Println(LevelDebug, v...) } diff --git a/testing/integration_test.go b/testing/integration_test.go index 9e8830d..c58458c 100644 --- a/testing/integration_test.go +++ b/testing/integration_test.go @@ -71,7 +71,7 @@ func (bot *ChatEchoBot) ChatMessage(messageID uint32, when time.Time, message st log.Infof("ChatMessage(from: %v, %v", bot.rai.RemoteHostname, message) bot.Messages.Add(bot.rai.RemoteHostname, bot.onion, message) SendMessage(bot.rai, strconv.Itoa(bot.n)+" witty response") - bot.n += 1 + bot.n++ return true } @@ -193,7 +193,7 @@ func TestApplicationIntegration(t *testing.T) { SendMessage(alicei, "Hello Bob!") if err != nil { - log.Errorf("Error dialing from Alice to Bob: ", err) + log.Errorf("Error dialing from Alice to Bob: %v", err) os.Exit(1) } diff --git a/testing/quality.sh b/testing/quality.sh index 87db32f..3539a18 100755 --- a/testing/quality.sh +++ b/testing/quality.sh @@ -1,7 +1,9 @@ #!/bin/sh echo "Checking code quality (you want to see no output here)" -echo "" + +echo "Formatting:" +gofmt -s -w -l . echo "Vetting:" go list ./... | xargs go vet @@ -9,4 +11,7 @@ go list ./... | xargs go vet echo "" echo "Linting:" -go list ./... | xargs golint +# Ignore wire packages as they are autogenerated +# Ignore examples as they are illustrative +# TODO Consider Renaming ApplicationInstance and ApplicationInstanceFactory to remove the last grep +go list ./... | grep -v "/wire/" | grep -v "/examples/" | grep -v "/application" | xargs golint \ No newline at end of file diff --git a/utils/crypto.go b/utils/crypto.go index 0bd4a18..1a60fee 100644 --- a/utils/crypto.go +++ b/utils/crypto.go @@ -46,6 +46,7 @@ func EDH(privateKey ed25519.PrivateKey, remotePublicKey ed25519.PublicKey) [32]b return secret } +// GeneratePrivateKeyV3 cryptographically creats a new ed25519 key pair. func GeneratePrivateKeyV3() (ed25519.PublicKey, ed25519.PrivateKey, error) { return ed25519.GenerateKey(rand.Reader) } diff --git a/utils/messagebuilder.go b/utils/messagebuilder.go index 34527bf..e8ec945 100644 --- a/utils/messagebuilder.go +++ b/utils/messagebuilder.go @@ -101,7 +101,7 @@ func (mb *MessageBuilder) Open3EDHAuthenticationChannel(channelID int32, pubkey return ret } -// ConfirmAuthChannel constructs a message to acknowledge a previous open channel operation. +// Confirm3EDHAuthChannel constructs a message to acknowledge a previous open channel operation. func (mb *MessageBuilder) Confirm3EDHAuthChannel(channelID int32, pubkey [32]byte, ephemeralKey [32]byte) []byte { cr := &Protocol_Data_Control.ChannelResult{ ChannelIdentifier: proto.Int32(channelID), @@ -122,7 +122,7 @@ func (mb *MessageBuilder) Confirm3EDHAuthChannel(channelID int32, pubkey [32]byt return ret } -// DHProof constructs a proof message with the given public key and signature. +// Proof3DH constructs a proof message with the given public key and signature. func (mb *MessageBuilder) Proof3DH(proofBytes []byte) []byte { proof := &Protocol_Data_Auth_TripleEDH.Proof{ Proof: proofBytes, @@ -234,7 +234,7 @@ func (mb *MessageBuilder) Proof(publicKeyBytes []byte, signatureBytes []byte) [] return ret } -// AuthResult constructs a response to a Proof +// AuthResult3DH constructs a response to a Proof func (mb *MessageBuilder) AuthResult3DH(accepted bool, isKnownContact bool) []byte { // Construct a Result Message result := &Protocol_Data_Auth_TripleEDH.Result{ diff --git a/utils/tor.go b/utils/tor.go index 9261383..b18223e 100644 --- a/utils/tor.go +++ b/utils/tor.go @@ -33,7 +33,8 @@ func expandKey(pri ed25519.PrivateKey) string { return base64.StdEncoding.EncodeToString(h[:]) } -const V3HostnameLength = 56 +// V3HostnameLength is the length of a Tor V3 Onion Address (without the .onion suffix) +const V3HostnameLength = 56 // Hidden service version const version = byte(0x03) @@ -65,7 +66,7 @@ func GetTorV3Hostname(pub ed25519.PublicKey) string { func IsValidHostname(address string) bool { if len(address) == V3HostnameLength { data, err := base32.StdEncoding.DecodeString(strings.ToUpper(address)) - if err ==nil { + if err == nil { pubkey := data[0:ed25519.PublicKeySize] if GetTorV3Hostname(ed25519.PublicKey(pubkey)) == address { return true @@ -73,4 +74,4 @@ func IsValidHostname(address string) bool { } } return false -} \ No newline at end of file +} diff --git a/utils/tor_test.go b/utils/tor_test.go index e1d9f22..30d6fbe 100644 --- a/utils/tor_test.go +++ b/utils/tor_test.go @@ -44,9 +44,8 @@ func TestGetTorHostname(t *testing.T) { } } - func TestV3(t *testing.T) { - pub,_,_ := ed25519.GenerateKey(rand.Reader) + pub, _, _ := ed25519.GenerateKey(rand.Reader) hostname := GetTorV3Hostname(pub) if !IsValidHostname(hostname) { t.Errorf("Generated V3 Hostname was invalid") @@ -55,4 +54,4 @@ func TestV3(t *testing.T) { if IsValidHostname(hostname[0:34]) { t.Errorf("Invalid V3 Hostname was marked valid") } -} \ No newline at end of file +}