Beispiel #1
0
        public static string TryGetPassword(string url, string username)
        {
            if (group != null)
            {
                return(InternalGetPassword(url, username));
            }

            if (failed)
            {
                return(null);
            }

            context = AzusaContext.GetInstance();
            DirectoryInfo di         = new DirectoryInfo(".");
            FileInfo      dbFileInfo = di.GetFiles("*.kdbx").FirstOrDefault(x => x.Extension.ToLower().Equals(".kdbx"));

            if (dbFileInfo == null)
            {
                dbFileInfo = di.Parent.GetFiles("*.kdbx").FirstOrDefault(x => x.Extension.ToLower().Equals(".kdbx"));
            }
            if (dbFileInfo == null)
            {
                failed = true;
                return(null);
            }

            string pw = null;

            context.Splash.Invoke((MethodInvoker) delegate
            {
                pw = TextInputForm.PromptPassword(String.Format("Passwort für {0}?", dbFileInfo.Name), context.Splash);
            });
            if (string.IsNullOrEmpty(pw))
            {
                failed = true;
                return(null);
            }

            IOConnectionInfo connectionInfo = IOConnectionInfo.FromPath(dbFileInfo.FullName);
            KcpPassword      kcpPassword    = new KcpPassword(pw);
            CompositeKey     compositeKey   = new CompositeKey();

            compositeKey.AddUserKey(kcpPassword);
            database = new PwDatabase();
            try
            {
                database.Open(connectionInfo, compositeKey, null);
                group = FindPwGroup(database.RootGroup);
                if (group == null)
                {
                    failed = true;
                    return(null);
                }
                return(InternalGetPassword(url, username));
            }
            catch (InvalidCompositeKeyException)
            {
                failed = true;
                return(null);
            }
        }
Beispiel #2
0
        public void ExecutePostConnectionTask()
        {
            if (File.Exists(lastMailTimestampFilename))
            {
                DateTime lastTime      = new DateTime(Convert.ToInt64(File.ReadAllText(lastMailTimestampFilename)));
                TimeSpan sinceLastTime = DateTime.Now - lastTime;
                if (sinceLastTime.TotalMinutes < 11)
                {
                    return;
                }
            }


            AzusaContext context = AzusaContext.GetInstance();

            if (!context.Ini.ContainsKey(iniCategoryName))
            {
                return;
            }

            if (context.Ini[iniCategoryName].ContainsKey("enabled"))
            {
                bool isEnabled = Convert.ToInt32(context.Ini[iniCategoryName]["enabled"]) > 0;
                if (!isEnabled)
                {
                    return;
                }
            }

            bool   allcerts = Convert.ToInt32(context.Ini[iniCategoryName]["acceptAllCerts"]) > 0;
            string server   = context.Ini[iniCategoryName]["server"];
            int    port     = context.Ini[iniCategoryName].ContainsKey(portName) ? Convert.ToUInt16(context.Ini[iniCategoryName][portName]) : 143;
            bool   useSsl   = Convert.ToInt32(context.Ini[iniCategoryName]["ssl"]) > 0;
            string username = context.Ini[iniCategoryName]["username"];
            string password = context.Ini[iniCategoryName].ContainsKey(passwordName) ? context.Ini[iniCategoryName][passwordName] : "";

            if (string.IsNullOrEmpty(password))
            {
                password = PasswordManagement.Boundary.PasswordManagement.TryGetPassword(server, username);
            }

            if (string.IsNullOrEmpty(password))
            {
                context.Splash.Invoke((MethodInvoker) delegate { password = TextInputForm.PromptPassword(String.Format("Passwort für {0} auf {1}?", username, server), context.Splash); });
                if (string.IsNullOrEmpty(password))
                {
                    return;
                }
            }


            ImapClient client = new ImapClient(new MailProtocolLogger());

            if (allcerts)
            {
                client.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true;
            }
            client.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
            client.Connect(server, port, useSsl);
            client.AuthenticationMechanisms.Remove("XOAUTH2");
            client.Authenticate(username, password);
            FolderNamespace     rootFolderNamespace = client.PersonalNamespaces[0];
            IList <IMailFolder> folders             = client.GetFolders(rootFolderNamespace);

            foreach (IMailFolder folder in folders)
            {
                Folder child = new Folder();
                child.id       = MakeId(folder);
                child.name     = folder.Name;
                child.parentId = MakeId(folder.ParentFolder);
                bool created = FolderService.CreateIfNotExists(child);
                CopyFolder(folder, child, !created, password);
            }
            client.Disconnect(true);

            File.WriteAllText(lastMailTimestampFilename, DateTime.Now.Ticks.ToString());
        }