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.KnownFingerprints = make([]config.KnownFingerprint, len(fprs)) sort.Sort(config.ByNaturalOrder(fprs)) for ix, fpr := range fprs { ac.KnownFingerprints[ix] = *fpr } } } } sort.Sort(config.ByAccountNameAlphabetic(res.Accounts)) return res, true }
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 } } if ac.proxy != "" { res.Proxies = []string{ac.proxy} res.RequireTor = true } if strings.HasSuffix(res.Server, ".onion") { res.RequireTor = true } 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.KnownFingerprints = make([]config.KnownFingerprint, len(fprs)) sort.Sort(config.ByNaturalOrder(fprs)) for ix, fpr := range fprs { res.KnownFingerprints[ix] = *fpr } } 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 }