func mergeAccountInformation(ac gajimAccountInfo, s gajimOTRSettings, s2 map[string]gajimOTRSettings, fprs []*config.KnownFingerprint, key []byte) *config.Account { res := &config.Account{} res.Password = ac.password // This is incorrect, since Gajim uses SHA-1 fingerprints, not SHA-256... // res.ServerCertificateSHA256 = ac.sslFingerprint res.Account = ac.name + "@" + ac.hostname if ac.server != "" { res.Server = ac.server } else { res.Server = ac.hostname } if ac.port != "" { i, err := strconv.Atoi(ac.port) if err == nil { res.Port = i } } res.Proxies = make([]string, 0) if ac.proxy != "" { res.Proxies = append(res.Proxies, ac.proxy) } res.AlwaysEncrypt = s.requireEncryption res.OTRAutoAppendTag = s.sendTag res.OTRAutoStartSession = s.whitespaceStartAke res.OTRAutoTearDown = true if key != nil { res.PrivateKeys = [][]byte{key} } if fprs != nil { res.Peers = nil sort.Sort(config.LegacyByNaturalOrder(fprs)) for _, kfpr := range fprs { fpr := res.EnsurePeer(kfpr.UserID).EnsureHasFingerprint(kfpr.Fingerprint) if !kfpr.Untrusted { fpr.Trusted = true } } } res.AlwaysEncryptWith = make([]string, 0) res.DontEncryptWith = make([]string, 0) for peer, settings := range s2 { if settings.requireEncryption { res.AlwaysEncryptWith = append(res.AlwaysEncryptWith, peer) } else { if !s.requireEncryption { res.DontEncryptWith = append(res.DontEncryptWith, peer) } } } sort.Sort(byAlpha(res.AlwaysEncryptWith)) sort.Sort(byAlpha(res.DontEncryptWith)) return res }
func (p *pidginImporter) importAllFrom(accountsFile, prefsFile, blistFile, keyFile, fprFile string) (*config.ApplicationConfig, bool) { accounts, ok1 := p.importAccounts(accountsFile) globalPrefs, ok2 := p.importGlobalPrefs(prefsFile) peerPrefs, ok3 := p.importPeerPrefs(blistFile) keys, ok4 := p.importKeysFrom(keyFile) fprs, ok5 := p.importFingerprintsFrom(fprFile) if !ok1 { return nil, false } res := &config.ApplicationConfig{} for name, ac := range accounts { res.Add(ac) if ok2 { if globalPrefs.enabled { if globalPrefs.onlyPrivate { ac.AlwaysEncrypt = true ac.OTRAutoStartSession = true } else if globalPrefs.automatic { ac.OTRAutoStartSession = true ac.OTRAutoAppendTag = true } } else { ac.AlwaysEncrypt = false } } if ok3 { if ss, ok := peerPrefs[name]; ok { for p, sp := range ss { if sp.enabled { if sp.onlyPrivate { ac.AlwaysEncryptWith = append(ac.AlwaysEncryptWith, p) } } else { ac.DontEncryptWith = append(ac.DontEncryptWith, p) } } } } if ok4 { if kk, ok := keys[name]; ok { ac.PrivateKeys = [][]byte{kk} } } if ok5 { if fprs, ok := fprs[name]; ok { ac.Peers = nil sort.Sort(config.LegacyByNaturalOrder(fprs)) for _, kfpr := range fprs { fpr, _ := ac.EnsurePeer(kfpr.UserID).EnsureHasFingerprint(kfpr.Fingerprint) if !kfpr.Untrusted { fpr.Trusted = true } } } } } sort.Sort(config.ByAccountNameAlphabetic(res.Accounts)) return res, true }