Пример #1
0
        public void SendTamperedTimeStampAndRecieveUnauthorizedResponse()
        {
            var data    = "AnyData";
            var payload = new MemoryStream(Encoding.UTF8.GetBytes(data));

            try
            {
                var webClient                = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS, payload);
                var headerValue              = webClient.Headers.Get(HttpRequestHeader.Authorization.ToString()).Replace("API ", "");
                var decodedHeaderValue       = Base64Decode(headerValue);
                var decodedHeaderSplitValues = decodedHeaderValue.Split(':');

                var tamperedTimeStamp      = DateTime.Now.AddHours(1).ToString("MM/dd/yyyy hh:mm:ss tt");
                var tamperedTimeStampBytes = System.Text.Encoding.UTF8.GetBytes(tamperedTimeStamp);
                var encodedTimeStamp       = Convert.ToBase64String(tamperedTimeStampBytes);

                var tamperedHeaderValue = String.Format("{0}:{1}:{2}", decodedHeaderSplitValues[0], encodedTimeStamp, decodedHeaderSplitValues[2]);
                var plainTextBytes      = System.Text.Encoding.UTF8.GetBytes(headerValue);

                webClient.Headers.Clear();
                webClient.Headers.Add(HttpRequestHeader.Authorization.ToString(), String.Format("{0} {1}", "API ", Convert.ToBase64String(plainTextBytes)));

                var dataStream = webClient.UploadString(BASE_ADDRESS.AbsoluteUri, data);
            }
            catch (WebException ex)
            {
                var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
                Assert.IsTrue(HttpStatusCode.Unauthorized.Equals(statusCode));
            }
        }
Пример #2
0
 public void PerformSuccessfulPostRequestWithShortPayload()
 {
     var data       = "AnyData";
     var payload    = new MemoryStream(Encoding.UTF8.GetBytes(data));
     var webClient  = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS, payload);
     var dataStream = webClient.UploadString(BASE_ADDRESS.AbsoluteUri, data);
 }
Пример #3
0
 /// <summary>
 /// Sends a message through the publisher asynchronously.
 /// </summary>
 /// <param name="message">
 /// The <see cref="IMessage">message</see> to be sent.
 /// </param>
 /// <returns>
 /// A <see cref="Task"/> representing the send operation.
 /// </returns>
 public async Task SendAsync(IMessage message)
 {
     using (var client = new SecureWebClient(this.Certificate))
     {
         await client.UploadStringTaskAsync(this.PublishUri, message.Message);
     }
 }
Пример #4
0
 public void SendTimedOutRequestAndRecieveUnauthorizedResponse()
 {
     try
     {
         var webClient   = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS);
         var timeToSleep = GetRequestTimeOut();
         Thread.Sleep(timeToSleep);
         var dataStream = webClient.OpenRead(BASE_ADDRESS.AbsoluteUri);
     }
     catch (WebException ex)
     {
         var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
         Assert.IsTrue(HttpStatusCode.Unauthorized.Equals(statusCode));
     }
 }
Пример #5
0
        public void TamperPayloadAndRecieveUnauthorizedResponse()
        {
            var data         = "AnyData";
            var tamperedData = String.Format("{0}{1}", data, data);
            var payload      = new MemoryStream(Encoding.UTF8.GetBytes(data));

            try
            {
                var webClient  = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS, payload);
                var dataStream = webClient.UploadString(BASE_ADDRESS.AbsoluteUri, tamperedData);
            }
            catch (WebException ex)
            {
                var statusCode = ((HttpWebResponse)ex.Response).StatusCode;
                Assert.IsTrue(HttpStatusCode.Unauthorized.Equals(statusCode));
            }
        }
Пример #6
0
        public GuiScreenMenu() : base(0, 0, EditorWindow.Instance.ClientSize.Width, EditorWindow.Instance.ClientSize.Height)
        {
            if (File.Exists(Path.Combine(EditorWindow.Instance.LauncherDir, "background_menu.png")))
            {
                bgImg = true;
                using (Bitmap img = new Bitmap(Path.Combine(EditorWindow.Instance.LauncherDir, "background_menu.png")))
                {
                    _textureId = TextureManager.GetOrRegister("menubg", img, true);
                }
            }

            try
            {
                SecureWebClient wc = new SecureWebClient();
                ChangelogText = wc.DownloadString("https://raw.githubusercontent.com/haawwkeye/Sound-Space-Quantum-Editor/master/changelog");
                Changelog     = new GuiLabel(0, 0, ChangelogText, "main", 16);

                ScrollBar = new GuiSlider(0, 0, 20, 720)
                {
                    MaxValue = ChangelogText.Split('\n').Length,
                    Value    = ChangelogText.Split('\n').Length,
                };
            } catch {
                Changelog = new GuiLabel(0, 0, "Failed to load changelog", "main", 16);
            }

            Buttons.Add(_createMapButton);
            Buttons.Add(_loadMapButton);
            Buttons.Add(_importButton);
            Buttons.Add(_SettingsButton);
            Buttons.Add(ScrollBar);

            CHANGELOGlabel.Color        = Color.FromArgb(255, 255, 255);
            CHANGELOGlabelOutline.Color = Color.FromArgb(0, 0, 0);
            ssLabel.Color        = Color.FromArgb(255, 255, 255);
            ssLabelOutline.Color = Color.FromArgb(0, 0, 0);
            qeLabel.Color        = Color.FromArgb(255, 255, 255);
            qeLabelOutline.Color = Color.FromArgb(0, 0, 0);

            Changelog.Color = Color.FromArgb(255, 255, 255);

            OnResize(EditorWindow.Instance.ClientSize);
        }
Пример #7
0
        private bool LoadSound(long id)
        {
            try
            {
                if (!Directory.Exists(Folder))
                {
                    Directory.CreateDirectory(Folder);
                }

                if (!File.Exists(Folder + id + ".asset"))
                {
                    using (var wc = new SecureWebClient())
                    {
                        wc.DownloadFile("https://assetgame.roblox.com/asset/?id=" + id, Folder + id + ".asset");
                    }
                }

                _audioPlayer.Load(Folder + id + ".asset");

                nudTimeStamp.Maximum = (int)_audioPlayer.TotalTime.TotalMilliseconds;
                timeline1.TotalTime  = _audioPlayer.TotalTime;

                timeline1.CurrentTime = TimeSpan.Zero;

                timeline1.Invalidate();

                Settings.Default.id = id.ToString();
                Settings.Default.Save();

                Saved = true;

                return(true);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                MessageBox.Show($"Failed to download asset with id '{id}'", "Error", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }

            return(false);
        }
Пример #8
0
        static void Main(string[] args)
        {
            // End-To-End encryption example
            Encryption.StartSession();

            SecureWebClient.SendEncrypteValues("https://yourdomain.ltd", new NameValueCollection
            {
                ["example"]  = Encryption.Encrypt("data"),
                ["example2"] = Encryption.Encrypt("data")
            }, "CUSTOM_USERAGENT");

            Encryption.EndSession();

            // Grab server-sided variables
            string variable = Variables.GrabVariable("https://yourdomain.ltd", "ExampleName", "YourPassword", "CUSTOM_USERAGENT");

            // Some of the improved WebClient methods
            SecureWebClient.DownloadString("https://thirdpartydomain.ltd" /*, "useragent"*/);
            SecureWebClient.DownloadData("https://thirdpartydomain.ltd" /*, "useragent"*/);
            SecureWebClient.UploadValues("https://thirdpartydomain.ltd", new NameValueCollection {
                ["example"] = "data"
            } /*, "useragent"*/);
        }
        protected override void OnButtonClicked(int id)
        {
            switch (id)
            {
            case 0:
                EditorWindow.Instance.OpenGuiScreen(new GuiScreenCreate());
                break;

            case 1:
                using (var dialog = new OpenFileDialog
                {
                    Title = "Select Map File",
                    Filter = "Text Documents (*.txt)|*.txt"
                })
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        EditorWindow.Instance.LoadFile(dialog.FileName);
                    }
                }
                break;

            case 2:
                /*if (importmapclicked == false)
                 * {
                 *      importmapclicked = true;
                 *      _pasteDataButton.Visible = true;
                 *      _githubButton.Visible = true;
                 * }
                 * else
                 * {
                 *      importmapclicked = false;
                 *      _pasteDataButton.Visible = false;
                 *      _githubButton.Visible = false;
                 * }*/

                try
                {
                    var             clipboard = Clipboard.GetText();
                    SecureWebClient wc        = new SecureWebClient();
                    if (clipboard.Contains("gist") || clipboard.Contains("github"))
                    {
                        try
                        {
                            var reply = wc.DownloadString(clipboard);
                            EditorWindow.Instance.LoadMap(reply, false);
                        }
                        catch
                        {
                            MessageBox.Show("Error while loading map data from link.\nIs it valid?");
                        }
                    }
                    else
                    {
                        try
                        {
                            EditorWindow.Instance.LoadMap(clipboard, false);
                        }
                        catch
                        {
                            MessageBox.Show("Error while loading map data.\nIs it valid?");
                        }
                    }
                }
                catch
                {
                }

                break;

            case 3:
                EditorWindow.Instance.LoadFile(Properties.Settings.Default.LastFile);
                break;

                /*
                 * case 4:
                 *      try
                 *      {
                 *              var clipboard = Clipboard.GetText();
                 *              EditorWindow.Instance.LoadMap(clipboard, false);
                 *      }
                 *      catch
                 *      {
                 *              return;
                 *      }
                 *      break;
                 * case 5:
                 *      try
                 *      {
                 *              var gclipboard = Clipboard.GetText();
                 *              WebClient wc = new WebClient();
                 *              var reply = wc.DownloadString(gclipboard);
                 *              EditorWindow.Instance.LoadMap(reply, false);
                 *      }
                 *      catch
                 *      {
                 *              MessageBox.Show("Couldn't read map data from the link. Do you have it copied?");
                 *      }
                 *      break;
                 */
            }
            base.OnButtonClicked(id);
        }
Пример #10
0
        protected override void OnButtonClicked(int id)
        {
            switch (id)
            {
            case 0:
                EditorWindow.Instance.OpenGuiScreen(new GuiScreenCreate());
                break;

            case 1:
                using (var dialog = new OpenFileDialog
                {
                    Title = "Select Map File",
                    Filter = "Text Documents (*.txt)|*.txt"
                })
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        EditorWindow.Instance.LoadFile(dialog.FileName);
                    }
                }
                break;

            case 2:
                try
                {
                    var             clipboard = Clipboard.GetText();
                    SecureWebClient wc        = new SecureWebClient();
                    if (clipboard.Contains("githubusercontent") || clipboard.Contains("raw") || clipboard.Contains("gist"))
                    {
                        try
                        {
                            var reply = wc.DownloadString(clipboard);
                            EditorWindow.Instance.LoadMap(reply, false);
                        }
                        catch
                        {
                            MessageBox.Show("Error while loading map data from link.\nIs it valid?");
                        }
                    }
                    else
                    {
                        try
                        {
                            EditorWindow.Instance.LoadMap(clipboard, false);
                        }
                        catch
                        {
                            MessageBox.Show("Error while loading map data.\nIs it valid?");
                        }
                    }
                }
                catch
                {
                }

                break;

            case 3:
                EditorWindow.Instance.OpenGuiScreen(new GuiScreenSettings());
                break;
            }
            base.OnButtonClicked(id);
        }
Пример #11
0
 public void PerformASuccessfulGetRequest()
 {
     var webClient  = new SecureWebClient(SECRET_KEY, SHARED_KEY, BASE_ADDRESS);
     var dataStream = webClient.OpenRead(BASE_ADDRESS.AbsoluteUri);
 }