Exemple #1
0
func (u *gtkUI) chooseKeyToImport(keys map[string][]byte) ([]byte, bool) {
	result := make(chan int)
	parsedKeys := make(map[string]otr3.PrivateKey)
	for v, vv := range keys {
		_, ok, parsedKey := otr3.ParsePrivateKey(vv)
		if ok {
			parsedKeys[v] = parsedKey
		}
	}
	sortedKeys := sortKeys(parsedKeys)

	doInUIThread(func() {
		builder := newBuilder("ChooseKeyToImport")
		d := builder.getObj("dialog").(gtki.Dialog)
		d.SetTransientFor(u.window)
		keyBox := builder.getObj("keys").(gtki.ComboBoxText)

		for _, s := range sortedKeys {
			kval := parsedKeys[s]
			keyBox.AppendText(fmt.Sprintf("%s -- %s", s, config.FormatFingerprint(kval.PublicKey().Fingerprint())))
		}

		keyBox.SetActive(0)

		builder.ConnectSignals(map[string]interface{}{
			"on_import_signal": func() {
				ix := keyBox.GetActive()
				if ix != -1 {
					result <- ix
					close(result)
					d.Destroy()
				}
			},

			"on_cancel_signal": func() {
				close(result)
				d.Destroy()
			},
		})

		d.ShowAll()
	})

	res, ok := <-result
	if ok {
		return keys[sortedKeys[res]], true
	}
	return nil, false
}
Exemple #2
0
func parseFromConfig(cu *config.Account) []otr3.PrivateKey {
	var result []otr3.PrivateKey

	allKeys := cu.AllPrivateKeys()

	log.Printf("Loading %d configured keys", len(allKeys))
	for _, pp := range allKeys {
		_, ok, parsedKey := otr3.ParsePrivateKey(pp)
		if ok {
			result = append(result, parsedKey)
			log.Printf("Loaded key: %s", config.FormatFingerprint(parsedKey.PublicKey().Fingerprint()))
		}
	}

	return result
}
Exemple #3
0
func (u *gtkUI) exportKeysFor(account *config.Account, file string) bool {
	var result []*otr3.Account

	allKeys := account.AllPrivateKeys()

	for _, pp := range allKeys {
		_, ok, parsedKey := otr3.ParsePrivateKey(pp)
		if ok {
			result = append(result, &otr3.Account{
				Name:     account.Account,
				Protocol: "prpl-jabber",
				Key:      parsedKey,
			})
		}
	}

	err := otr3.ExportKeysToFile(result, file)
	return err == nil
}