Fixing Linting, Vetting & Formatting Issues
This commit is contained in:
parent
90231b0be9
commit
b05567fd81
|
@ -16,7 +16,7 @@ pipeline:
|
||||||
commands:
|
commands:
|
||||||
- go list ./... | xargs go vet
|
- go list ./... | xargs go vet
|
||||||
#-set_exit_status too many lint fails for :(
|
#-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:
|
units-tests:
|
||||||
image: golang
|
image: golang
|
||||||
commands:
|
commands:
|
||||||
|
|
|
@ -2,3 +2,4 @@ go-ricochet-coverage.out
|
||||||
*~
|
*~
|
||||||
*.out
|
*.out
|
||||||
.idea
|
.idea
|
||||||
|
.reviewboardrc
|
||||||
|
|
|
@ -1,13 +1,22 @@
|
||||||
package application
|
package application
|
||||||
|
|
||||||
|
// AcceptAllContactHandler is a pass through Contact Handler. It is currently only used by the integration test.
|
||||||
|
// TODO: DEPRECATE
|
||||||
type AcceptAllContactHandler struct{}
|
type AcceptAllContactHandler struct{}
|
||||||
|
|
||||||
|
// ContactRequest returns "Pending" for everything
|
||||||
func (aach *AcceptAllContactHandler) ContactRequest(name string, message string) string {
|
func (aach *AcceptAllContactHandler) ContactRequest(name string, message string) string {
|
||||||
return "Pending"
|
return "Pending"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContactRequestRejected is a noop
|
||||||
func (aach *AcceptAllContactHandler) ContactRequestRejected() {
|
func (aach *AcceptAllContactHandler) ContactRequestRejected() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContactRequestAccepted is a noop
|
||||||
func (aach *AcceptAllContactHandler) ContactRequestAccepted() {
|
func (aach *AcceptAllContactHandler) ContactRequestAccepted() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContactRequestError is a noop
|
||||||
func (aach *AcceptAllContactHandler) ContactRequestError() {
|
func (aach *AcceptAllContactHandler) ContactRequestError() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,8 @@ import (
|
||||||
|
|
||||||
// AcceptAllContactManager implements the contact manager interface an presumes
|
// AcceptAllContactManager implements the contact manager interface an presumes
|
||||||
// all connections are allowed.
|
// all connections are allowed.
|
||||||
|
// It is currently used by the Cwtch Server.
|
||||||
|
// TODO Deprecate
|
||||||
type AcceptAllContactManager struct {
|
type AcceptAllContactManager struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,11 +17,12 @@ func (aacm *AcceptAllContactManager) LookupContact(hostname string, publicKey rs
|
||||||
return true, true
|
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) {
|
func (aacm *AcceptAllContactManager) LookupContactV3(hostname string, publicKey ed25519.PublicKey) (allowed, known bool) {
|
||||||
return true, true
|
return true, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ContactRequest accepts every single Contact Request
|
||||||
func (aacm *AcceptAllContactManager) ContactRequest(name string, message string) string {
|
func (aacm *AcceptAllContactManager) ContactRequest(name string, message string) string {
|
||||||
return "Accepted"
|
return "Accepted"
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,6 +74,7 @@ func (ra *RicochetApplication) handleConnection(conn net.Conn) {
|
||||||
ra.lock.Unlock()
|
ra.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HandleApplicationInstance delegates handling of a given ApplicationInstance to the Application.
|
||||||
func (ra *RicochetApplication) HandleApplicationInstance(rai *ApplicationInstance) {
|
func (ra *RicochetApplication) HandleApplicationInstance(rai *ApplicationInstance) {
|
||||||
ra.lock.Lock()
|
ra.lock.Lock()
|
||||||
ra.instances = append(ra.instances, rai)
|
ra.instances = append(ra.instances, rai)
|
||||||
|
@ -103,6 +104,7 @@ func (ra *RicochetApplication) Open(onionAddress string, requestMessage string)
|
||||||
return rai, nil
|
return rai, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Broadcast performs the given function do() over all application instance (all connected peers)
|
||||||
func (ra *RicochetApplication) Broadcast(do func(rai *ApplicationInstance)) {
|
func (ra *RicochetApplication) Broadcast(do func(rai *ApplicationInstance)) {
|
||||||
ra.lock.Lock()
|
ra.lock.Lock()
|
||||||
for _, rai := range ra.instances {
|
for _, rai := range ra.instances {
|
||||||
|
@ -121,6 +123,7 @@ func (ra *RicochetApplication) Shutdown() {
|
||||||
ra.lock.Unlock()
|
ra.lock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConnectionCount returns the number of concurrent connections to the application
|
||||||
func (ra *RicochetApplication) ConnectionCount() int {
|
func (ra *RicochetApplication) ConnectionCount() int {
|
||||||
return len(ra.instances)
|
return len(ra.instances)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ type ApplicationInstance struct {
|
||||||
RemoteHostname string
|
RemoteHostname string
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplicationInstanceFactory
|
// ApplicationInstanceFactory generates ApplicationInstances on a specific connection.
|
||||||
type ApplicationInstanceFactory struct {
|
type ApplicationInstanceFactory struct {
|
||||||
handlerMap map[string]func(*ApplicationInstance) func() channels.Handler
|
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
|
af.handlerMap[ctype] = chandler
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHandlers returns all handlers
|
||||||
func (af *ApplicationInstanceFactory) GetHandlers() []string {
|
func (af *ApplicationInstanceFactory) GetHandlers() []string {
|
||||||
keys := make([]string, len(af.handlerMap))
|
keys := make([]string, len(af.handlerMap))
|
||||||
|
|
||||||
|
@ -39,6 +40,7 @@ func (af *ApplicationInstanceFactory) GetHandlers() []string {
|
||||||
return keys
|
return keys
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetHandler returns a set handler for the channel type.
|
||||||
func (af *ApplicationInstanceFactory) GetHandler(ctype string) func(*ApplicationInstance) func() channels.Handler {
|
func (af *ApplicationInstanceFactory) GetHandler(ctype string) func(*ApplicationInstance) func() channels.Handler {
|
||||||
return af.handlerMap[ctype]
|
return af.handlerMap[ctype]
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,8 @@ import (
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
"git.openprivacy.ca/openprivacy/libricochet-go/utils"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/wire/auth/3edh"
|
"git.openprivacy.ca/openprivacy/libricochet-go/wire/auth/3edh"
|
||||||
"git.openprivacy.ca/openprivacy/libricochet-go/wire/control"
|
"git.openprivacy.ca/openprivacy/libricochet-go/wire/control"
|
||||||
"golang.org/x/crypto/ed25519"
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"golang.org/x/crypto/ed25519"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ func TestServer3DHAuthChannel(t *testing.T) {
|
||||||
cc := new(channels.Channel)
|
cc := new(channels.Channel)
|
||||||
cc.ID = 1
|
cc.ID = 1
|
||||||
closed := false
|
closed := false
|
||||||
cc.CloseChannel = func() {closed=true}
|
cc.CloseChannel = func() { closed = true }
|
||||||
clientChannel := new(outbound.Client3DHAuthChannel)
|
clientChannel := new(outbound.Client3DHAuthChannel)
|
||||||
pub, priv, _ := ed25519.GenerateKey(rand.Reader)
|
pub, priv, _ := ed25519.GenerateKey(rand.Reader)
|
||||||
cid := identity.InitializeV3("", &priv, &pub)
|
cid := identity.InitializeV3("", &priv, &pub)
|
||||||
|
@ -34,7 +34,7 @@ func TestServer3DHAuthChannel(t *testing.T) {
|
||||||
sid := identity.InitializeV3("", &priv, &pub)
|
sid := identity.InitializeV3("", &priv, &pub)
|
||||||
s3dhchannel.ServerIdentity = sid
|
s3dhchannel.ServerIdentity = sid
|
||||||
clientChannel.ServerHostname = utils.GetTorV3Hostname(pub)
|
clientChannel.ServerHostname = utils.GetTorV3Hostname(pub)
|
||||||
cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel())
|
cr, _ := s3dhchannel.OpenInbound(cc, packet.GetOpenChannel())
|
||||||
|
|
||||||
proto.Unmarshal(cr, packet)
|
proto.Unmarshal(cr, packet)
|
||||||
if packet.GetChannelResult() != nil {
|
if packet.GetChannelResult() != nil {
|
||||||
|
|
|
@ -27,4 +27,4 @@ type Handler interface {
|
||||||
OnOpenChannelRequest(ctype string) (channels.Handler, error)
|
OnOpenChannelRequest(ctype string) (channels.Handler, error)
|
||||||
|
|
||||||
GetSupportedChannelTypes() []string
|
GetSupportedChannelTypes() []string
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,6 +37,7 @@ func HandleInboundConnection(c *Connection) *InboundConnectionHandler {
|
||||||
// true to accept authentication and allow the connection to continue, and also returns a
|
// 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
|
// 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.
|
// 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 {
|
func (ich *InboundConnectionHandler) ProcessAuthAsServer(identity identity.Identity, sach func(hostname string, publicKey rsa.PublicKey) (allowed, known bool)) error {
|
||||||
|
|
||||||
if !identity.Initialized() {
|
if !identity.Initialized() {
|
||||||
|
@ -91,11 +92,11 @@ func (ich *InboundConnectionHandler) ProcessAuthAsServer(identity identity.Ident
|
||||||
return err
|
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
|
// connection is closed. A non-nil error is returned in all cases other than successful
|
||||||
// and accepted authentication.
|
// 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
|
// function. Another Process function must be called after this function successfully
|
||||||
// returns to continue handling connection events.
|
// returns to continue handling connection events.
|
||||||
//
|
//
|
||||||
|
|
|
@ -33,6 +33,7 @@ func HandleOutboundConnection(c *Connection) *OutboundConnectionHandler {
|
||||||
// For successful authentication, the `known` return value indicates whether the peer
|
// 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
|
// accepts us as a known contact. Unknown contacts will generally need to send a contact
|
||||||
// request before any other activity.
|
// request before any other activity.
|
||||||
|
// TODO; Deprecate
|
||||||
func (och *OutboundConnectionHandler) ProcessAuthAsClient(identity identity.Identity) (bool, error) {
|
func (och *OutboundConnectionHandler) ProcessAuthAsClient(identity identity.Identity) (bool, error) {
|
||||||
|
|
||||||
if !identity.Initialized() {
|
if !identity.Initialized() {
|
||||||
|
@ -90,11 +91,11 @@ func (och *OutboundConnectionHandler) ProcessAuthAsClient(identity identity.Iden
|
||||||
return false, utils.ServerRejectedClientConnectionError
|
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
|
// provided identity, or the connection is closed. A non-nil error is returned in all
|
||||||
// cases other than successful authentication.
|
// 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
|
// function. Another Process function must be called after this function successfully
|
||||||
// returns to continue handling connection events.
|
// returns to continue handling connection events.
|
||||||
//
|
//
|
||||||
|
|
|
@ -34,7 +34,7 @@ func Initialize(name string, pk *rsa.PrivateKey) Identity {
|
||||||
return Identity{name, pk, nil, nil}
|
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 {
|
func InitializeV3(name string, pk *ed25519.PrivateKey, pubk *ed25519.PublicKey) Identity {
|
||||||
return Identity{name, nil, pk, pubk}
|
return Identity{name, nil, pk, pubk}
|
||||||
}
|
}
|
||||||
|
@ -66,6 +66,7 @@ func (i *Identity) PublicKeyBytes() []byte {
|
||||||
return publicKeyBytes
|
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 {
|
func (i *Identity) EDH(key ed25519.PublicKey) []byte {
|
||||||
secret := utils.EDH(*i.edpk, key)
|
secret := utils.EDH(*i.edpk, key)
|
||||||
return secret[:]
|
return secret[:]
|
||||||
|
@ -73,11 +74,10 @@ func (i *Identity) EDH(key ed25519.PublicKey) []byte {
|
||||||
|
|
||||||
// Hostname provides the onion address associated with this Identity.
|
// Hostname provides the onion address associated with this Identity.
|
||||||
func (i *Identity) Hostname() string {
|
func (i *Identity) Hostname() string {
|
||||||
if i.edpk != nil {
|
if i.pk != nil {
|
||||||
return utils.GetTorV3Hostname(*i.edpubk)
|
|
||||||
} else {
|
|
||||||
return utils.GetTorHostname(i.PublicKeyBytes())
|
return utils.GetTorHostname(i.PublicKeyBytes())
|
||||||
}
|
}
|
||||||
|
return utils.GetTorV3Hostname(*i.edpubk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign produces a cryptographic signature using this Identities private key.
|
// Sign produces a cryptographic signature using this Identities private key.
|
||||||
|
|
|
@ -166,7 +166,7 @@ func Errorf(format string, v ...interface{}) {
|
||||||
std.Printf(LevelError, format, v...)
|
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{}) {
|
func Debugln(v ...interface{}) {
|
||||||
std.Println(LevelDebug, v...)
|
std.Println(LevelDebug, v...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
log.Infof("ChatMessage(from: %v, %v", bot.rai.RemoteHostname, message)
|
||||||
bot.Messages.Add(bot.rai.RemoteHostname, bot.onion, message)
|
bot.Messages.Add(bot.rai.RemoteHostname, bot.onion, message)
|
||||||
SendMessage(bot.rai, strconv.Itoa(bot.n)+" witty response")
|
SendMessage(bot.rai, strconv.Itoa(bot.n)+" witty response")
|
||||||
bot.n += 1
|
bot.n++
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func TestApplicationIntegration(t *testing.T) {
|
||||||
SendMessage(alicei, "Hello Bob!")
|
SendMessage(alicei, "Hello Bob!")
|
||||||
|
|
||||||
if err != nil {
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
echo "Checking code quality (you want to see no output here)"
|
echo "Checking code quality (you want to see no output here)"
|
||||||
echo ""
|
|
||||||
|
echo "Formatting:"
|
||||||
|
gofmt -s -w -l .
|
||||||
|
|
||||||
echo "Vetting:"
|
echo "Vetting:"
|
||||||
go list ./... | xargs go vet
|
go list ./... | xargs go vet
|
||||||
|
@ -9,4 +11,7 @@ go list ./... | xargs go vet
|
||||||
echo ""
|
echo ""
|
||||||
echo "Linting:"
|
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
|
|
@ -46,6 +46,7 @@ func EDH(privateKey ed25519.PrivateKey, remotePublicKey ed25519.PublicKey) [32]b
|
||||||
return secret
|
return secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GeneratePrivateKeyV3 cryptographically creats a new ed25519 key pair.
|
||||||
func GeneratePrivateKeyV3() (ed25519.PublicKey, ed25519.PrivateKey, error) {
|
func GeneratePrivateKeyV3() (ed25519.PublicKey, ed25519.PrivateKey, error) {
|
||||||
return ed25519.GenerateKey(rand.Reader)
|
return ed25519.GenerateKey(rand.Reader)
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,7 +101,7 @@ func (mb *MessageBuilder) Open3EDHAuthenticationChannel(channelID int32, pubkey
|
||||||
return ret
|
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 {
|
func (mb *MessageBuilder) Confirm3EDHAuthChannel(channelID int32, pubkey [32]byte, ephemeralKey [32]byte) []byte {
|
||||||
cr := &Protocol_Data_Control.ChannelResult{
|
cr := &Protocol_Data_Control.ChannelResult{
|
||||||
ChannelIdentifier: proto.Int32(channelID),
|
ChannelIdentifier: proto.Int32(channelID),
|
||||||
|
@ -122,7 +122,7 @@ func (mb *MessageBuilder) Confirm3EDHAuthChannel(channelID int32, pubkey [32]byt
|
||||||
return ret
|
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 {
|
func (mb *MessageBuilder) Proof3DH(proofBytes []byte) []byte {
|
||||||
proof := &Protocol_Data_Auth_TripleEDH.Proof{
|
proof := &Protocol_Data_Auth_TripleEDH.Proof{
|
||||||
Proof: proofBytes,
|
Proof: proofBytes,
|
||||||
|
@ -234,7 +234,7 @@ func (mb *MessageBuilder) Proof(publicKeyBytes []byte, signatureBytes []byte) []
|
||||||
return ret
|
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 {
|
func (mb *MessageBuilder) AuthResult3DH(accepted bool, isKnownContact bool) []byte {
|
||||||
// Construct a Result Message
|
// Construct a Result Message
|
||||||
result := &Protocol_Data_Auth_TripleEDH.Result{
|
result := &Protocol_Data_Auth_TripleEDH.Result{
|
||||||
|
|
|
@ -33,7 +33,8 @@ func expandKey(pri ed25519.PrivateKey) string {
|
||||||
return base64.StdEncoding.EncodeToString(h[:])
|
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
|
// Hidden service version
|
||||||
const version = byte(0x03)
|
const version = byte(0x03)
|
||||||
|
@ -65,7 +66,7 @@ func GetTorV3Hostname(pub ed25519.PublicKey) string {
|
||||||
func IsValidHostname(address string) bool {
|
func IsValidHostname(address string) bool {
|
||||||
if len(address) == V3HostnameLength {
|
if len(address) == V3HostnameLength {
|
||||||
data, err := base32.StdEncoding.DecodeString(strings.ToUpper(address))
|
data, err := base32.StdEncoding.DecodeString(strings.ToUpper(address))
|
||||||
if err ==nil {
|
if err == nil {
|
||||||
pubkey := data[0:ed25519.PublicKeySize]
|
pubkey := data[0:ed25519.PublicKeySize]
|
||||||
if GetTorV3Hostname(ed25519.PublicKey(pubkey)) == address {
|
if GetTorV3Hostname(ed25519.PublicKey(pubkey)) == address {
|
||||||
return true
|
return true
|
||||||
|
@ -73,4 +74,4 @@ func IsValidHostname(address string) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,9 +44,8 @@ func TestGetTorHostname(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestV3(t *testing.T) {
|
func TestV3(t *testing.T) {
|
||||||
pub,_,_ := ed25519.GenerateKey(rand.Reader)
|
pub, _, _ := ed25519.GenerateKey(rand.Reader)
|
||||||
hostname := GetTorV3Hostname(pub)
|
hostname := GetTorV3Hostname(pub)
|
||||||
if !IsValidHostname(hostname) {
|
if !IsValidHostname(hostname) {
|
||||||
t.Errorf("Generated V3 Hostname was invalid")
|
t.Errorf("Generated V3 Hostname was invalid")
|
||||||
|
@ -55,4 +54,4 @@ func TestV3(t *testing.T) {
|
||||||
if IsValidHostname(hostname[0:34]) {
|
if IsValidHostname(hostname[0:34]) {
|
||||||
t.Errorf("Invalid V3 Hostname was marked valid")
|
t.Errorf("Invalid V3 Hostname was marked valid")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue