示例#1
0
func GpgDecrypt(text2decrypt string) string {
	encrypted := bytes.NewBuffer([]byte(text2decrypt))

	bin_encrypt, err := armor.Decode(encrypted)
	if err != nil {
		log.Printf("[PGP] not an armored payload: %s", err.Error())
		return ""
	}

	cleartext_md, err := openpgp.ReadMessage(bin_encrypt.Body, nil, func(keys []openpgp.Key, symmetric bool) ([]byte, error) {
		return []byte(config.GetTribeID()), nil
	}, nil)
	if err != nil {
		log.Printf("[PGP] Can't decrypt payload: %s", err.Error())
		return ""
	}

	plaintext, err := ioutil.ReadAll(cleartext_md.UnverifiedBody)
	if err != nil {
		log.Printf("[PGP] Can't read cleartext: %s", err.Error())
		return ""
	}

	return string(plaintext)
}
示例#2
0
func init() {

	var thekey string
	var metadata map[string]string
	metadata = make(map[string]string)
	log.Println("[GPG] Engine started")

	if thekey = config.GetTribeID(); len(thekey) < 32 {
		log.Println("[GPG] EEK: TribeID %d ", len(thekey))
		log.Println("[GPG] EEK: TribeID shorter than 32 bytes. Generating a random one")
		thekey = tools.RandSeq(42) // 42 because of yes.
		log.Println("[GPG] your 1-node tribe is: " + thekey)
	}

	log.Println("[GPG] TribeID is: " + thekey)
	test_cleartext := tools.RandSeq(128)
	metadata["Command"] = "NOOP"
	metadata["Group"] = "it.doesnt.exists"
	log.Println("[GPG] GPG Integrity test initiated")
	log.Println("[GPG] GPG Encrypted payload below: \n", GpgEncrypt(test_cleartext, metadata))
	log.Println("[GPG] GPG Integrity Test passed: ", test_cleartext == GpgDecrypt(GpgEncrypt(test_cleartext, metadata)))
	d_Command := GpgGetHeaders(GpgEncrypt(test_cleartext, metadata))
	log.Println("[GPG] GPG Serialization Test #1 passed: ", d_Command["Command"] == metadata["Command"])
	log.Println("[GPG] GPG Serialization Test #2 passed: ", d_Command["Group"] == metadata["Group"])
}
示例#3
0
func GpgEncrypt(text2encrypt string, headers map[string]string) string {
	var encrypted bytes.Buffer
	foo := bufio.NewWriter(&encrypted)
	w, _ := armor.Encode(foo, "TRIBES PAYLOAD", headers)
	plaintext, _ := openpgp.SymmetricallyEncrypt(w, []byte(config.GetTribeID()), nil, nil)
	fmt.Fprintf(plaintext, text2encrypt)
	plaintext.Close()
	w.Close()
	foo.Flush()
	return encrypted.String()
}
示例#4
0
func init() {

	AllNodes = make(map[wendy.NodeID]string)

	RandID := md5.Sum([]byte(config.GetTribeID())) // since it is sent in clear, we can't use TribeID in clear

	WendyID := tools.RandSeq(16)
	log.Printf("[DHT] Volatile node ID: %s", WendyID)

	id, err = wendy.NodeIDFromBytes([]byte(WendyID))
	if err != nil {
		log.Printf("[DHT] Can't create the NodeID: %s", WendyID)
	}

	mynode = wendy.NewNode(id, tools.ReadIpFromHost(), tools.ReadIpFromHost(), "Tribes", config.GetClusterPort())
	log.Printf("[DHT] Node %s created for %s", mynode.ID.String(), WendyID)

	cred = wendy.Passphrase(string(RandID[:]))

	cluster = wendy.NewCluster(mynode, cred)
	log.Printf("[DHT] Cluster initialized")

	go cluster.Listen()
	log.Printf("[DHT] Listening")

	if tmpBoot := config.GetBootStrapHost(); tmpBoot != "127.0.0.1" {
		tmpPort := config.GetBootStrapPort()
		cluster.Join(tmpBoot, tmpPort)
		log.Printf("[DHT] Trying to join cluster at %s:%d", tmpBoot, tmpPort)
	}

	app := &WendyApplication{}
	cluster.RegisterCallback(app)
	log.Printf("[DHT] Engine functional ")

	cluster.SetHeartbeatFrequency(5)
	cluster.SetNetworkTimeout(300)

}