public IContentResponse HandlePasswordSet(NameValueCollection headers, Stream inputStream)
        {
            INameValueStore store = new RegistryStorage(Settings.RegistryPath);
                
            int contentLen = int.Parse(headers["Content-Length"]);
            if (contentLen == 0)
            {
                using (RSAPrivateKey _temporaryKey = new RSAPrivateKey(2048))
                {
                    store.Write("Transfers", "temp-key", Convert.ToBase64String(_temporaryKey.ToArray()));
                    return new DynamicResponse("application/public-key", _temporaryKey.PublicKey.ToArray());
                }
            }

            string tempkey;
            if (contentLen <= 2048 && store.Read("Transfers", "temp-key", out tempkey))
            {
                byte[] bytes = IOStream.Read(inputStream, contentLen);
                using (RSAPrivateKey _temporaryKey = RSAPrivateKey.FromBytes(Convert.FromBase64String(tempkey)))
                    bytes = _temporaryKey.Decrypt(bytes);

                _content.KeyPair.SetServerPassword(bytes);
            }
            return DynamicResponse.Empty;
        }
Example #2
0
        private void SaveSettings(string userId, string uri, string password)
        {
            INameValueStore storage = new RegistryStorage();

            try
            {
                if (String.IsNullOrEmpty(password))
                {
                    storage.Delete(uri, "UserName");
                    storage.Delete(uri, "Password");
                }
                else
                {
                    storage.Write(uri, "UserName", userId);
                    storage.Write(uri, "Password", Encryption.CurrentUser.Encrypt(password));
                }
            }
            catch
            {
            }
        }
Example #3
0
        private string ReadSettings(IntPtr hParentWnd, string serviceUri, ref string userId)
        {
            Log.Verbose("Acquiring username and password");
            INameValueStore storage = new RegistryStorage();
            try
            {
                Log.Verbose("Trying to read username and password from the cache");
                string password;
                storage.Read(serviceUri, "UserName", out userId);
                if (storage.Read(serviceUri, "Password", out password))
                {
                    string pass = Encryption.CurrentUser.Decrypt(password);
                    Log.Verbose("Successfully read Username and password from the cache");
                    return pass;
                }
            }
            catch
            {
            }

            Log.Verbose("Failed reading username and password from the cache. Prompting user");
            var pwdDlg = new PasswordEntry(userId, serviceUri);
            if (pwdDlg.ShowDialog(Win32Window.FromHandle(hParentWnd)) == DialogResult.OK)
            {
                userId = pwdDlg.UserName.Text;
                SaveSettings(userId, serviceUri, pwdDlg.Password.Text);
                return pwdDlg.Password.Text;
            }

            return null;
        }