migrate to stand alone log, port over required lib ricochet util functions
This commit is contained in:
parent
a7cb23036b
commit
52ef350514
|
@ -1 +1,2 @@
|
||||||
tor/
|
tor/
|
||||||
|
.idea/
|
||||||
|
|
5
go.mod
5
go.mod
|
@ -1,9 +1,10 @@
|
||||||
module git.openprivacy.ca/connectivity
|
module git.openprivacy.ca/openprivacy/connectivity
|
||||||
|
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.10
|
git.openprivacy.ca/openprivacy/log v0.0.0-20200206193118-3093e3fae448
|
||||||
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca
|
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca
|
||||||
|
github.com/stretchr/testify v1.3.0 // indirect
|
||||||
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72
|
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72
|
||||||
)
|
)
|
||||||
|
|
16
go.sum
16
go.sum
|
@ -1,25 +1,19 @@
|
||||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.10 h1:yxEqFJH4EdacPwGuOXx+QieYqIPDyzWP50H27EI7fxI=
|
git.openprivacy.ca/openprivacy/log v0.0.0-20200206193118-3093e3fae448 h1:Tzy38uHvRCT/v6fiG/456myCjRk6RASH6XIX9yXhcpQ=
|
||||||
git.openprivacy.ca/openprivacy/libricochet-go v1.0.10/go.mod h1:jJdxIwYDCcM4w4HAydeHuksPRTirUnyERAloPL0qtic=
|
git.openprivacy.ca/openprivacy/log v0.0.0-20200206193118-3093e3fae448/go.mod h1:gGYK8xHtndRLDymFtmjkG26GaMQNgyhioNS82m812Iw=
|
||||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 h1:w1UutsfOrms1J05zt7ISrnJIXKzwaspym5BTKGx93EI=
|
|
||||||
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412/go.mod h1:WPjqKcmVOxf0XSf3YxCJs6N6AOSrOx3obionmG7T0y0=
|
|
||||||
github.com/cretz/bine v0.1.0 h1:1/fvhLE+fk0bPzjdO5Ci+0ComYxEMuB1JhM4X5skT3g=
|
|
||||||
github.com/cretz/bine v0.1.0/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
|
|
||||||
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca h1:Q2r7AxHdJwWfLtBZwvW621M3sPqxPc6ITv2j1FGsYpw=
|
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca h1:Q2r7AxHdJwWfLtBZwvW621M3sPqxPc6ITv2j1FGsYpw=
|
||||||
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
|
github.com/cretz/bine v0.1.1-0.20200124154328-f9f678b84cca/go.mod h1:6PF6fWAvYtwjRGkAuDEJeWNOv3a2hUouSP/yRYXmvHw=
|
||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
golang.org/x/crypto v0.0.0-20190128193316-c7b33c32a30b/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
|
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
|
||||||
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
|
||||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|
|
@ -3,8 +3,7 @@ package connectivity
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
"git.openprivacy.ca/openprivacy/log"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
|
||||||
"github.com/cretz/bine/control"
|
"github.com/cretz/bine/control"
|
||||||
"github.com/cretz/bine/process"
|
"github.com/cretz/bine/process"
|
||||||
"github.com/cretz/bine/tor"
|
"github.com/cretz/bine/tor"
|
||||||
|
@ -23,13 +22,18 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Error captures various common ricochet errors
|
||||||
|
type Error string
|
||||||
|
|
||||||
|
func (e Error) Error() string { return string(e) }
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// CannotResolveLocalTCPAddressError is thrown when a local ricochet connection has the wrong format.
|
// CannotResolveLocalTCPAddressError is thrown when a local ricochet connection has the wrong format.
|
||||||
CannotResolveLocalTCPAddressError = utils.Error("CannotResolveLocalTCPAddressError")
|
CannotResolveLocalTCPAddressError = Error("CannotResolveLocalTCPAddressError")
|
||||||
// CannotDialLocalTCPAddressError is thrown when a connection to a local ricochet address fails.
|
// CannotDialLocalTCPAddressError is thrown when a connection to a local ricochet address fails.
|
||||||
CannotDialLocalTCPAddressError = utils.Error("CannotDialLocalTCPAddressError")
|
CannotDialLocalTCPAddressError = Error("CannotDialLocalTCPAddressError")
|
||||||
// CannotDialRicochetAddressError is thrown when a connection to a ricochet address fails.
|
// CannotDialRicochetAddressError is thrown when a connection to a ricochet address fails.
|
||||||
CannotDialRicochetAddressError = utils.Error("CannotDialRicochetAddressError")
|
CannotDialRicochetAddressError = Error("CannotDialRicochetAddressError")
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -125,7 +129,7 @@ func (tp *torProvider) Listen(identity PrivateKey, port int) (ListenService, err
|
||||||
gpubk := pk.Public()
|
gpubk := pk.Public()
|
||||||
switch pubk := gpubk.(type) {
|
switch pubk := gpubk.(type) {
|
||||||
case ed25519.PublicKey:
|
case ed25519.PublicKey:
|
||||||
onion = utils.GetTorV3Hostname(pubk)
|
onion = GetTorV3Hostname(pubk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
package connectivity
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/base32"
|
||||||
|
"strings"
|
||||||
|
"golang.org/x/crypto/ed25519"
|
||||||
|
"golang.org/x/crypto/sha3"
|
||||||
|
)
|
||||||
|
|
||||||
|
// V3HostnameLength is the length of a Tor V3 Onion Address (without the .onion suffix)
|
||||||
|
const V3HostnameLength = 56
|
||||||
|
|
||||||
|
// Hidden service version
|
||||||
|
const version = byte(0x03)
|
||||||
|
|
||||||
|
// Salt used to create checkdigits
|
||||||
|
const salt = ".onion checksum"
|
||||||
|
|
||||||
|
func getCheckdigits(pub ed25519.PublicKey) []byte {
|
||||||
|
// Calculate checksum sha3(".onion checksum" || publicKey || version)
|
||||||
|
checkstr := []byte(salt)
|
||||||
|
checkstr = append(checkstr, pub...)
|
||||||
|
checkstr = append(checkstr, version)
|
||||||
|
checksum := sha3.Sum256(checkstr)
|
||||||
|
return checksum[:2]
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTorV3Hostname converts an ed25519 public key to a valid tor onion hostname
|
||||||
|
func GetTorV3Hostname(pub ed25519.PublicKey) string {
|
||||||
|
// Construct onion address base32(publicKey || checkdigits || version)
|
||||||
|
checkdigits := getCheckdigits(pub)
|
||||||
|
combined := pub[:]
|
||||||
|
combined = append(combined, checkdigits...)
|
||||||
|
combined = append(combined, version)
|
||||||
|
serviceID := base32.StdEncoding.EncodeToString(combined)
|
||||||
|
return strings.ToLower(serviceID)
|
||||||
|
}
|
Loading…
Reference in New Issue