Пример #1
0
func verifyFingerprintDialog(account *account, uid, resource string, parent gtki.Window) gtki.ResponseType {
	accountConfig := account.session.GetConfig()
	conversation, _ := account.session.ConversationManager().EnsureConversationWith(uid, resource)
	ourFp := conversation.OurFingerprint()
	theirFp := conversation.TheirFingerprint()

	dialog := buildVerifyFingerprintDialog(accountConfig.Account, ourFp, uid, theirFp)
	defer dialog.Destroy()

	dialog.SetTransientFor(parent)
	dialog.ShowAll()

	responseType := gtki.ResponseType(dialog.Run())
	switch responseType {
	case gtki.RESPONSE_YES:
		account.executeCmd(client.AuthorizeFingerprintCmd{
			Account:     accountConfig,
			Session:     account.session,
			Peer:        uid,
			Fingerprint: theirFp,
		})
	}

	return responseType
}
Пример #2
0
func (u *gtkUI) wouldYouLikeToEncryptYourFile(k func(bool)) {
	dialogID := "AskToEncrypt"
	builder := newBuilder(dialogID)

	dialogOb := builder.getObj(dialogID)
	encryptDialog := dialogOb.(gtki.MessageDialog)
	encryptDialog.SetDefaultResponse(gtki.RESPONSE_YES)
	encryptDialog.SetTransientFor(u.window)

	responseType := gtki.ResponseType(encryptDialog.Run())
	result := responseType == gtki.RESPONSE_YES
	encryptDialog.Destroy()
	k(result)
}
Пример #3
0
func (u *gtkUI) runImporter() {
	importSettings := make(map[applicationAndAccount]bool)
	allImports := importer.TryImportAll()

	builder := newBuilder("Importer")

	win := builder.getObj("importerWindow")
	w := win.(gtki.Dialog)

	store := builder.getObj("importAccountsStore")
	s := store.(gtki.ListStore)

	for appName, v := range allImports {
		for _, vv := range v {
			for _, a := range vv.Accounts {
				it := s.Append()
				s.SetValue(it, 0, appName)
				s.SetValue(it, 1, a.Account)
				s.SetValue(it, 2, false)
			}
		}
	}

	rend := builder.getObj("import-this-account-renderer")
	rr := rend.(gtki.CellRendererToggle)

	rr.Connect("toggled", func(_ interface{}, path string) {
		iter, _ := s.GetIterFromString(path)
		current, _ := valAt(s, iter, 2).(bool)
		app, _ := valAt(s, iter, 0).(string)
		acc, _ := valAt(s, iter, 1).(string)

		importSettings[applicationAndAccount{app, acc}] = !current

		s.SetValue(iter, 2, !current)
	})

	w.Connect("response", func(_ interface{}, rid int) {
		if gtki.ResponseType(rid) == gtki.RESPONSE_OK {
			u.doActualImportOf(importSettings, allImports)
		}
		w.Destroy()
	})

	u.connectShortcutsChildWindow(w)
	doInUIThread(func() {
		w.SetTransientFor(u.window)
		w.ShowAll()
	})
}
Пример #4
0
func (u *gtkUI) confirmAccountRemoval(acc *config.Account, removeAccountFunc func(*config.Account)) {
	builder := newBuilder("ConfirmAccountRemoval")

	obj := builder.getObj("RemoveAccount")
	dialog := obj.(gtki.MessageDialog)
	dialog.SetTransientFor(u.window)
	dialog.SetProperty("text", acc.Account)

	response := dialog.Run()
	if gtki.ResponseType(response) == gtki.RESPONSE_YES {
		removeAccountFunc(acc)
	}

	dialog.Destroy()
}
Пример #5
0
func (u *gtkUI) importFingerprintsForDialog(account *config.Account, w gtki.Dialog) {
	dialog, _ := g.gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Import fingerprints"),
		w,
		gtki.FILE_CHOOSER_ACTION_OPEN,
		i18n.Local("_Cancel"),
		gtki.RESPONSE_CANCEL,
		i18n.Local("_Import"),
		gtki.RESPONSE_OK,
	)

	if gtki.ResponseType(dialog.Run()) == gtki.RESPONSE_OK {
		num, ok := u.importFingerprintsFor(account, dialog.GetFilename())
		if ok {
			u.notify(i18n.Local("Fingerprints imported"), fmt.Sprintf(i18n.Local("%d fingerprint(s) were imported correctly."), num))
		} else {
			u.notify(i18n.Local("Failure importing fingerprints"), fmt.Sprintf(i18n.Local("Couldn't import any fingerprints from %s."), dialog.GetFilename()))
		}
	}
	dialog.Destroy()
}
Пример #6
0
func (r *roster) addGroupDialog(groupList gtki.ListStore) {
	builder := newBuilder("GroupDetails")
	dialog := builder.getObj("dialog").(gtki.Dialog)

	nameEntry := builder.getObj("group-name").(gtki.Entry)

	defaultBtn := builder.getObj("btn-ok").(gtki.Button)
	defaultBtn.GrabDefault()
	dialog.SetTransientFor(r.ui.window)
	dialog.ShowAll()

	response := dialog.Run()
	defer dialog.Destroy()

	if gtki.ResponseType(response) != gtki.RESPONSE_OK {
		return
	}

	groupName, _ := nameEntry.GetText()
	groupList.SetValue(groupList.Append(), 0, groupName)
}
Пример #7
0
func (f *registrationForm) renderForm(title, instructions string, fields []interface{}) error {
	wait := make(chan error)
	doInUIThread(func() {
		f.addFields(fields)

		builder := newBuilder("RegistrationForm")

		obj := builder.getObj("dialog")
		dialog := obj.(gtki.Dialog)
		dialog.SetTitle(title)

		obj = builder.getObj("instructions")
		label := obj.(gtki.Label)
		label.SetText(instructions)
		label.SetSelectable(true)

		obj = builder.getObj("grid")
		grid := obj.(gtki.Grid)

		for i, field := range f.fields {
			grid.Attach(field.label, 0, i+1, 1, 1)
			grid.Attach(field.widget, 1, i+1, 1, 1)
		}
		grid.ShowAll()

		dialog.SetTransientFor(f.parent)

		resp := gtki.ResponseType(dialog.Run())
		switch resp {
		case gtki.RESPONSE_APPLY:
			wait <- f.accepted()
		default:
			wait <- errRegistrationAborted
		}

		dialog.Destroy()
	})

	return <-wait
}
Пример #8
0
func (u *gtkUI) exportFingerprintsForDialog(account *config.Account, w gtki.Dialog) {
	dialog, _ := g.gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Export fingerprints"),
		w,
		gtki.FILE_CHOOSER_ACTION_SAVE,
		i18n.Local("_Cancel"),
		gtki.RESPONSE_CANCEL,
		i18n.Local("_Export"),
		gtki.RESPONSE_OK,
	)

	dialog.SetCurrentName("otr.fingerprints")

	if gtki.ResponseType(dialog.Run()) == gtki.RESPONSE_OK {
		ok := u.exportFingerprintsFor(account, dialog.GetFilename())
		if ok {
			u.notify(i18n.Local("Fingerprints exported"), i18n.Local("Fingerprints were exported correctly."))
		} else {
			u.notify(i18n.Local("Failure exporting fingerprints"), fmt.Sprintf(i18n.Local("Couldn't export fingerprints to %s."), dialog.GetFilename()))
		}
	}
	dialog.Destroy()
}
Пример #9
0
func (u *gtkUI) importKeysForDialog(account *config.Account, w gtki.Dialog) {
	dialog, _ := g.gtk.FileChooserDialogNewWith2Buttons(
		i18n.Local("Import private keys"),
		w,
		gtki.FILE_CHOOSER_ACTION_OPEN,
		i18n.Local("_Cancel"),
		gtki.RESPONSE_CANCEL,
		i18n.Local("_Import"),
		gtki.RESPONSE_OK,
	)

	if gtki.ResponseType(dialog.Run()) == gtki.RESPONSE_OK {
		fname := dialog.GetFilename()
		go func() {
			_, ok := u.importKeysFor(account, fname)
			if ok {
				u.notify(i18n.Local("Keys imported"), i18n.Local("The key was imported correctly."))
			} else {
				u.notify(i18n.Local("Failure importing keys"), fmt.Sprintf(i18n.Local("Couldn't import any keys from %s."), fname))
			}
		}()
	}
	dialog.Destroy()
}
Пример #10
0
func (u *gtkUI) handlePeerEvent(ev events.Peer) {
	identityWarning := func(cv conversationView) {
		cv.updateSecurityWarning()
		cv.showIdentityVerificationWarning(u)
	}

	switch ev.Type {
	case events.IQReceived:
		//TODO
		log.Printf("received iq: %v\n", ev.From)
	case events.OTREnded:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWindowNowOrLater(account, peer, u, func(cv conversationView) {
			cv.displayNotification(i18n.Local("Private conversation has ended."))
			cv.updateSecurityWarning()
			cv.haveShownPrivateEndedNotification()
		})

	case events.OTRNewKeys:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWindowNowOrLater(account, peer, u, func(cv conversationView) {
			cv.displayNotificationVerifiedOrNot(u, i18n.Local("Private conversation started."), i18n.Local("Unverified conversation started."))
			cv.appendPendingDelayed()
			identityWarning(cv)
			cv.haveShownPrivateNotification()
		})

	case events.OTRRenewedKeys:
		peer := ev.From
		account := u.findAccountForSession(ev.Session)
		convWindowNowOrLater(account, peer, u, func(cv conversationView) {
			cv.displayNotificationVerifiedOrNot(u, i18n.Local("Successfully refreshed the private conversation."), i18n.Local("Successfully refreshed the unverified private conversation."))
			identityWarning(cv)
		})

	case events.SubscriptionRequest:
		confirmDialog := authorizePresenceSubscriptionDialog(u.window, ev.From)

		doInUIThread(func() {
			responseType := gtki.ResponseType(confirmDialog.Run())
			switch responseType {
			case gtki.RESPONSE_YES:
				ev.Session.HandleConfirmOrDeny(ev.From, true)
			case gtki.RESPONSE_NO:
				ev.Session.HandleConfirmOrDeny(ev.From, false)
			default:
				// We got a different response, such as a close of the window. In this case we want
				// to keep the subscription request open
			}
			confirmDialog.Destroy()
		})
	case events.Subscribed:
		jid := ev.Session.GetConfig().Account
		log.Printf("[%s] Subscribed to %s\n", jid, ev.From)
		u.rosterUpdated()
	case events.Unsubscribe:
		jid := ev.Session.GetConfig().Account
		log.Printf("[%s] Unsubscribed from %s\n", jid, ev.From)
		u.rosterUpdated()
	}
}
Пример #11
0
func (u *gtkUI) certificateFailedToVerifyDisplayDialog(a *account, certs []*x509.Certificate, c chan<- bool, tp, extra string) {
	doInUIThread(func() {
		builder := newBuilder("CertificateDialog")

		var md gtki.Dialog
		var message gtki.Label
		var issuedToCN, issuedToO, snis, issuedToOU, serial gtki.Label
		var issuedByCN, issuedByO, issuedByOU gtki.Label
		var issuedOn, expiresOn gtki.Label
		var sha1Fingerprint, sha256Fingerprint, sha3_256Fingerprint gtki.Label

		builder.getItems(
			"dialog", &md,
			"message", &message,
			"issuedToCnValue", &issuedToCN,
			"issuedToOValue", &issuedToO,
			"issuedToOUValue", &issuedToOU,
			"snisValue", &snis,
			"SNValue", &serial,
			"issuedByCnValue", &issuedByCN,
			"issuedByOValue", &issuedByO,
			"issuedByOUValue", &issuedByOU,
			"issuedOnValue", &issuedOn,
			"expiresOnValue", &expiresOn,
			"sha1FingerprintValue", &sha1Fingerprint,
			"sha256FingerprintValue", &sha256Fingerprint,
			"sha3_256FingerprintValue", &sha3_256Fingerprint,
		)

		issuedToCN.SetLabel(certs[0].Subject.CommonName)
		issuedToO.SetLabel(strings.Join(certs[0].Subject.Organization, ", "))
		issuedToOU.SetLabel(strings.Join(certs[0].Subject.OrganizationalUnit, ", "))
		serial.SetLabel(certs[0].SerialNumber.String())
		ss := certs[0].DNSNames[:]
		sort.Strings(ss)
		snis.SetLabel(strings.Join(ss, ", "))

		issuedByCN.SetLabel(certs[0].Issuer.CommonName)
		issuedByO.SetLabel(strings.Join(certs[0].Issuer.Organization, ", "))
		issuedByOU.SetLabel(strings.Join(certs[0].Issuer.OrganizationalUnit, ", "))

		issuedOn.SetLabel(certs[0].NotBefore.Format(time.RFC822))
		expiresOn.SetLabel(certs[0].NotAfter.Format(time.RFC822))

		sha1Fingerprint.SetLabel(displayChunked(digests.Sha1(certs[0].Raw)))
		sha256Fingerprint.SetLabel(displayChunked(digests.Sha256(certs[0].Raw)))
		sha3_256Fingerprint.SetLabel(displayChunked(digests.Sha3_256(certs[0].Raw)))

		accountName := "this account"
		if a != nil {
			accountName = a.session.GetConfig().Account
		}

		md.SetTitle(strings.Replace(md.GetTitle(), "ACCOUNT_NAME", accountName, -1))

		switch tp {
		case "verify":
			message.SetLabel(fmt.Sprintf("We couldn't verify the certificate for the connection to account %s. This can happen if the server you are connecting to doesn't use the traditional certificate hierarchies. It can also be the symptom of an attack.\n\nTry to verify that this information is correct before proceeding with the connection.", accountName))
		case "hostname":
			message.SetLabel(fmt.Sprintf("The certificate for the connection to account %s is correct, but the names for it doesn't match. We need a certificate for the name %s, but this wasn't provided. This can happen if the server is configured incorrectly or there are other reasons the proper name couldn't be used. This is very common for corporate Google accounts. It can also be the symptom of an attack.\n\nTry to verify that this information is correct before proceeding with the connection.", accountName, extra))
		case "pinning":
			message.SetLabel(fmt.Sprintf("The certificate for the connection to account %s is correct - but you have a pinning policy that requires us to ask whether you would like to continue connecting using this certificate, save it for the future, or stop connecting.\n\nTry to verify that this information is correct before proceeding with the connection.", accountName))

		}

		md.SetTransientFor(u.window)

		md.ShowAll()

		switch gtki.ResponseType(md.Run()) {
		case gtki.RESPONSE_OK:
			c <- true
		case gtki.RESPONSE_ACCEPT:
			if a != nil {
				a.session.GetConfig().SaveCert(certs[0].Subject.CommonName, certs[0].Issuer.CommonName, digests.Sha3_256(certs[0].Raw))
				u.SaveConfig()
			}
			c <- true
		case gtki.RESPONSE_CANCEL:
			if a != nil {
				a.session.SetWantToBeOnline(false)
			}
			c <- false
		default:
			a.session.SetWantToBeOnline(false)
			c <- false
		}

		md.Destroy()
	})
}
Пример #12
0
func init() {
	gtki.ACCEL_VISIBLE = gtki.AccelFlags(gtk.ACCEL_VISIBLE)
	gtki.ACCEL_LOCKED = gtki.AccelFlags(gtk.ACCEL_LOCKED)
	gtki.ACCEL_MASK = gtki.AccelFlags(gtk.ACCEL_MASK)

	gtki.ALIGN_FILL = gtki.Align(gtk.ALIGN_FILL)
	gtki.ALIGN_START = gtki.Align(gtk.ALIGN_START)
	gtki.ALIGN_END = gtki.Align(gtk.ALIGN_END)
	gtki.ALIGN_CENTER = gtki.Align(gtk.ALIGN_CENTER)

	gtki.FILE_CHOOSER_ACTION_OPEN = gtki.FileChooserAction(gtk.FILE_CHOOSER_ACTION_OPEN)
	gtki.FILE_CHOOSER_ACTION_SAVE = gtki.FileChooserAction(gtk.FILE_CHOOSER_ACTION_SAVE)
	gtki.FILE_CHOOSER_ACTION_SELECT_FOLDER = gtki.FileChooserAction(gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER)
	gtki.FILE_CHOOSER_ACTION_CREATE_FOLDER = gtki.FileChooserAction(gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER)

	gtki.PACK_START = gtki.PackType(gtk.PACK_START)
	gtki.PACK_END = gtki.PackType(gtk.PACK_END)

	gtki.RESPONSE_NONE = gtki.ResponseType(gtk.RESPONSE_NONE)
	gtki.RESPONSE_REJECT = gtki.ResponseType(gtk.RESPONSE_REJECT)
	gtki.RESPONSE_ACCEPT = gtki.ResponseType(gtk.RESPONSE_ACCEPT)
	gtki.RESPONSE_DELETE_EVENT = gtki.ResponseType(gtk.RESPONSE_DELETE_EVENT)
	gtki.RESPONSE_OK = gtki.ResponseType(gtk.RESPONSE_OK)
	gtki.RESPONSE_CANCEL = gtki.ResponseType(gtk.RESPONSE_CANCEL)
	gtki.RESPONSE_CLOSE = gtki.ResponseType(gtk.RESPONSE_CLOSE)
	gtki.RESPONSE_YES = gtki.ResponseType(gtk.RESPONSE_YES)
	gtki.RESPONSE_NO = gtki.ResponseType(gtk.RESPONSE_NO)
	gtki.RESPONSE_APPLY = gtki.ResponseType(gtk.RESPONSE_APPLY)
	gtki.RESPONSE_HELP = gtki.ResponseType(gtk.RESPONSE_HELP)

	gtki.STATE_FLAG_NORMAL = gtki.StateFlags(gtk.STATE_FLAG_NORMAL)
	gtki.STATE_FLAG_ACTIVE = gtki.StateFlags(gtk.STATE_FLAG_ACTIVE)
	gtki.STATE_FLAG_PRELIGHT = gtki.StateFlags(gtk.STATE_FLAG_PRELIGHT)
	gtki.STATE_FLAG_SELECTED = gtki.StateFlags(gtk.STATE_FLAG_SELECTED)
	gtki.STATE_FLAG_INSENSITIVE = gtki.StateFlags(gtk.STATE_FLAG_INSENSITIVE)
	gtki.STATE_FLAG_INCONSISTENT = gtki.StateFlags(gtk.STATE_FLAG_INCONSISTENT)
	gtki.STATE_FLAG_FOCUSED = gtki.StateFlags(gtk.STATE_FLAG_FOCUSED)
	gtki.STATE_FLAG_BACKDROP = gtki.StateFlags(gtk.STATE_FLAG_BACKDROP)

	gtki.STYLE_PROVIDER_PRIORITY_FALLBACK = gtki.StyleProviderPriority(gtk.STYLE_PROVIDER_PRIORITY_FALLBACK)
	gtki.STYLE_PROVIDER_PRIORITY_THEME = gtki.StyleProviderPriority(gtk.STYLE_PROVIDER_PRIORITY_THEME)
	gtki.STYLE_PROVIDER_PRIORITY_SETTINGS = gtki.StyleProviderPriority(gtk.STYLE_PROVIDER_PRIORITY_SETTINGS)
	gtki.STYLE_PROVIDER_PRIORITY_APPLICATION = gtki.StyleProviderPriority(gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)
	gtki.STYLE_PROVIDER_PRIORITY_USER = gtki.StyleProviderPriority(gtk.STYLE_PROVIDER_PRIORITY_USER)
}