damlib

package
v0.0.0-...-b67131d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 12, 2020 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const DirPort = 49371

DirPort is the port where dam-dir will be listening.

View Source
const PostMsg = "I am a DAM node!"

PostMsg holds the message we are signing with our private key.

View Source
const PrivKeyPath = "dam-private.key"

PrivKeyPath holds the name of where our private key is.

View Source
const ProxyAddr = "127.0.0.1:9050"

ProxyAddr is the address of our Tor SOCKS port.

View Source
const PubSubChan = "tordam"

PubSubChan is the name of the pub/sub channel we're publishing to in Redis.

View Source
const RedisAddress = "127.0.0.1:6379"

RedisAddress points us to our Redis instance.

View Source
const SeedPath = "dam-private.seed"

SeedPath holds the name of where our private key seed is.

View Source
const WelcomeMsg = "Welcome to the DAM network!"

WelcomeMsg holds the message we return when welcoming a node.

Variables

Rctx is the context for Redis

View Source
var RedisCli = redis.NewClient(&redis.Options{
	Addr:     RedisAddress,
	Password: "",
	DB:       0,
})

RedisCli is our global Redis client

View Source
var Testnet = false

Testnet is flipped with a flag in dam-dir and represents if all new nodes are initially marked valid or not.

View Source
var TorPortMap = "80:49371,13010:13010,13011:13011,5000:5000"

TorPortMap is a comma-separated string holding the mapping of ports to be opened by the Tor Hidden Service. Format is "remote:local".

View Source
var Workdir = os.Getenv("HOME") + "/.dam"

Workdir holds the path to the directory where we will Chdir on startup.

Functions

func CheckError

func CheckError(err error)

CheckError is a handler for errors. It takes an error type as an argument, and issues a log.Fatalln, printing the error and exiting with os.Exit(1).

func GenEd25519

func GenEd25519() (ed25519.PublicKey, ed25519.PrivateKey, error)

GenEd25519 generates an ed25519 keypair. Returns error on failure.

func GenRandomASCII

func GenRandomASCII(length int) (string, error)

GenRandomASCII generates a random ASCII string of a given length. Takes length int as argument, and returns a string of that length on success and error on failure.

func GzipEncode

func GzipEncode(data []byte) (string, error)

GzipEncode compresses a given slice of bytes using gzip, and returns it as a base64 encoded string. Returns error upon failure.

func HTTPDownload

func HTTPDownload(uri string) ([]byte, error)

HTTPDownload tries to download a given uri and return it as a slice of bytes. On failure it will return an error.

func HTTPPost

func HTTPPost(host string, data []byte) (*http.Response, error)

HTTPPost sends an HTTP POST request to the given host. Takes the host to request and the data to post as arguments. If the host ends with ".onion", it will enable the request to be performed over a SOCKS proxy, defined in ProxyAddr. On success, it will return the http.Response. Otherwise, it returns an error.

func LoadEd25519KeyFromSeed

func LoadEd25519KeyFromSeed(filename string) (ed25519.PrivateKey, error)

LoadEd25519KeyFromSeed loads a key from a given seed file and returns ed25519.PrivateKey. Otherwise, on failure, it returns error.

func OnionFromPubkeyEd25519

func OnionFromPubkeyEd25519(pubkey ed25519.PublicKey) []byte

OnionFromPubkeyEd25519 generates a valid onion address from a given ed25519 public key. Returns the onion address as a slice of bytes.

Tor Spec excerpt from https://gitweb.torproject.org/torspec.git/tree/rend-spec-v3.txt --- 6. Encoding onion addresses [ONIONADDRESS] The onion address of a hidden service includes its identity public key, a version field and a basic checksum. All this information is then base32 encoded as shown below:

onion_address = base32(PUBKEY | CHECKSUM | VERSION) + ".onion"
CHECKSUM = H(".onion checksum" | PUBKEY | VERSION)[:2]

where:
	- PUBKEY is the 32 bytes ed25519 master pubkey of the hidden service.
	- VERSION is an one byte version field (default value '\x03')
	- ".onion checksum" is a constant string
	- CHECKSUM is truncated to two bytes before inserting it in onion_address

func ParseDirs

func ParseDirs(sl []string, data []byte) []string

ParseDirs parses and appends a given slice of bytes and returns an appended slice of strings with new contents.

func PublishToRedis

func PublishToRedis(mt, address string)

PublishToRedis is a function that publishes a node's status to Redis. This is used for Gource visualization.

func SavePrivEd25519

func SavePrivEd25519(filename string, key ed25519.PrivateKey) error

SavePrivEd25519 writes a ed25519.PrivateKey type to a given string filename. Expands ed25519.PrivateKey to (a || RH) form, writing base64. Returns error upon failure.

func SaveSeedEd25519

func SaveSeedEd25519(filename string, key ed25519.PrivateKey) error

SaveSeedEd25519 saves the ed25519 private key seed to a given string filename for later reuse. Returns error upon failure.

func SignMsgEd25519

func SignMsgEd25519(message []byte, key ed25519.PrivateKey) ([]byte, error)

SignMsgEd25519 signs a message using ed25519. Returns the signature in the form of []byte, or returns an error if it fails.

func StartRedis

func StartRedis(conf string) (*exec.Cmd, error)

StartRedis is the function that will start up the Redis server. Takes the path to a configuration file as an argument and returns error upon failure.

func StringInSlice

func StringInSlice(str string, slice []string) bool

StringInSlice loops over a slice of strings and checks if a given string is already an existing element. Returns true if so, and false if not.

func ValidateFirstHandshake

func ValidateFirstHandshake(req map[string]string) (bool, string)

ValidateFirstHandshake validates the first incoming handshake. It first calls sanityCheck to validate it's actually working with proper data. Next, it will look if the node is already found in redis. If so, it will fetch its public hey from redis, otherwise it will take it from the initial request from the incoming node. Once the public key is retrieved, it will validate the received message signature against that key. If all is well, we consider the request valid. Continuing, a random ASCII string will be generated and encrypted with the retrieved public key. All this data will be written into redis, and finally the encrypted (and base64 encoded) secret will be returned along with a true boolean value. On any failure, the function will return false, and produce an according string which is to be considered as an error message.

func ValidateOnionAddress

func ValidateOnionAddress(addr string) bool

ValidateOnionAddress matches a string against a regular expression matching a Tor hidden service address. Returns true on success and false on failure.

func ValidateSecondHandshake

func ValidateSecondHandshake(req map[string]string) (bool, string)

ValidateSecondHandshake validates the second part of the handshake. First basic sanity checks are performed to ensure we are working with valid data. Next, the according public key will be retrieved from redis. If no key is found, we will consider the handshake invalid. Now the decrypted secret that was sent to us will be compared with what we have saved before. Upon proving they are the same, the signature will now be validated. If all is well, we consider the request valid. Further on, we will generate a new random ASCII string and save it in redis to prevent further reuse of the already known string. Upon success, the function will return true, and a welcome message. Upon failure, the function will return false, and an according string which is to be considered an error message.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL