public void GetZipProxy(Session oS)
        {
            var data = GetRequestData(oS);

            byte[] bytes = Convert.FromBase64String(data.Get("url"));
            string url   = Encoding.UTF8.GetString(bytes);
            string content;

            using (WebClient client = new WebClient())
            {
                client.Proxy = Program.GetProxy().GetWebProxy();
                content      = client.DownloadString(url);
            }
            MemoryStream stream = new MemoryStream();

            using (ZipArchive zip = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                var entry = zip.CreateEntry("content");
                using (var entryStream = entry.Open())
                    using (var streamWriter = new StreamWriter(entryStream))
                    {
                        streamWriter.Write(content);
                    }
            }
            byte[] dataBytes = stream.ToArray();
            oS.utilCreateResponseAndBypassServer();
            oS.oResponse["Content-Length"] = dataBytes.Length.ToString();
            oS.responseBodyBytes           = dataBytes;
            Proxy.LogRequest(oS, this, "Created zip from " + url);
        }
        public void GetJson(Session oS)
        {
            var titles = new JArray();

            foreach (string filename in files)
            {
                var path     = Path.Combine(Program.GetLauncherPath(), "data", filename);
                var contents = JArray.Parse(File.ReadAllText(path));
                foreach (var title in contents)
                {
                    titles.Add(new JObject
                    {
                        ["titleID"]     = title["TitleId"].ToString().ToLower(),
                        ["name"]        = title["Name"],
                        ["region"]      = title["Region"],
                        ["titleKey"]    = "",
                        ["encTitleKey"] = ""
                    });
                }
            }

            oS.utilCreateResponseAndBypassServer();
            oS.oResponse["Content-Type"] = "application/json";
            oS.utilSetResponseBody(titles.ToString());
            Proxy.LogRequest(oS, this, "Sent custom response for request to /json");
        }
Beispiel #3
0
 public void GetJson(Session oS)
 {
     oS.utilCreateResponseAndBypassServer();
     oS.oResponse["Content-Type"] = "application/json";
     oS.utilSetResponseBody("[]");
     Proxy.LogRequest(oS, this, "Stubbed request to /json");
 }
Beispiel #4
0
 public void Get(Session oS)
 {
     oS.utilCreateResponseAndBypassServer();
     oS.oResponse.headers.SetStatus(307, "Redirect");
     oS.oResponse["Location"] = "http://ccs.cdn.c.shop.nintendowifi.net" + oS.PathAndQuery;
     Proxy.LogRequest(oS, this, "Redirecting to http://ccs.cdn.c.shop.nintendowifi.net" + oS.PathAndQuery);
 }
Beispiel #5
0
 public void GetCertificate(Session oS)
 {
     oS.utilCreateResponseAndBypassServer();
     oS.oResponse["Content-Type"] = "application/x-x509-ca-cert";
     oS.utilSetResponseBody("-----BEGIN CERTIFICATE-----\n" + Proxy.GetCertificateBase64() + "\n-----END CERTIFICATE----- ");
     Proxy.LogRequest(oS, this, "Sent certificate.");
 }
        protected void LoadResponseFromFile(Session oS, string folder)
        {
            string fileName  = Path.GetFileName(oS.PathAndQuery);
            string localPath = Path.Combine(Program.GetLauncherPath(), folder, fileName);

            oS.utilCreateResponseAndBypassServer();
            oS.LoadResponseFromFile(localPath);
            Proxy.LogRequest(oS, this, "Sending local copy of " + fileName);
        }
Beispiel #7
0
        public void GetZipProxy(Session oS)
        {
            var data = GetRequestData(oS);

            byte[] bytes = Convert.FromBase64String(data.Get("url"));
            Uri    uri   = new Uri(Encoding.UTF8.GetString(bytes));

            string content;

            using (var resp = Program.Proxy.Get(uri).GetResponse())
            {
                var contentType = new ContentType(resp.Headers["Content-Type"]);
                var encoding    = Encoding.GetEncoding(contentType.CharSet ?? "UTF-8");
                try
                {
                    using (var reader = new StreamReader(resp.GetResponseStream(), encoding))
                    {
                        content = reader.ReadToEnd();
                    }
                }
                catch (WebException e)
                {
                    Proxy.LogRequest(oS, this, "Unable to download data from " + uri.ToString() + ": " + e);
                    oS.utilCreateResponseAndBypassServer();
                    if (e.Status == WebExceptionStatus.ProtocolError)
                    {
                        var response = (HttpWebResponse)e.Response;
                        oS.oResponse.headers.SetStatus((int)response.StatusCode, response.StatusDescription);
                    }
                    else
                    {
                        oS.oResponse.headers.SetStatus(500, "Internal Server Error: " + e.Status);
                    }
                    return;
                }
            }

            MemoryStream stream = new MemoryStream();

            using (ZipArchive zip = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                var entry = zip.CreateEntry("content");
                using (var streamWriter = new StreamWriter(entry.Open()))
                {
                    streamWriter.Write(content);
                }
            }

            byte[] dataBytes = stream.ToArray();
            oS.utilCreateResponseAndBypassServer();
            oS.oResponse["Content-Length"] = dataBytes.Length.ToString();
            oS.responseBodyBytes           = dataBytes;
            Proxy.LogRequest(oS, this, "Created zip from " + uri.ToString());
        }
Beispiel #8
0
        public void GetZipProxy(Session oS)
        {
            var data = GetRequestData(oS);

            byte[] bytes = Convert.FromBase64String(data.Get("url"));
            string url   = Encoding.UTF8.GetString(bytes);

            string content;

            using (WebClient client = new WebClient())
            {
                client.Proxy = Program.Proxy.GetWebProxy();
                byte[] responseBytes;
                try
                {
                    responseBytes = client.DownloadData(url);
                }
                catch (WebException webEx)
                {
                    Proxy.LogRequest(oS, this, "Unable to download data from " + url + ": " + webEx);
                    oS.utilCreateResponseAndBypassServer();
                    if (webEx.Status == WebExceptionStatus.ProtocolError)
                    {
                        var response = (HttpWebResponse)webEx.Response;
                        oS.oResponse.headers.SetStatus((int)response.StatusCode, response.StatusDescription);
                    }
                    else
                    {
                        oS.oResponse.headers.SetStatus(500, "Internal Server Error: " + webEx.Status);
                    }
                    return;
                }

                var contentType = new ContentType(client.ResponseHeaders["Content-Type"]);
                content = Encoding.GetEncoding(contentType.CharSet ?? "UTF-8").GetString(responseBytes);
            }

            MemoryStream stream = new MemoryStream();

            using (ZipArchive zip = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                var entry = zip.CreateEntry("content");
                using (var streamWriter = new StreamWriter(entry.Open()))
                {
                    streamWriter.Write(content);
                }
            }

            byte[] dataBytes = stream.ToArray();
            oS.utilCreateResponseAndBypassServer();
            oS.oResponse["Content-Length"] = dataBytes.Length.ToString();
            oS.responseBodyBytes           = dataBytes;
            Proxy.LogRequest(oS, this, "Created zip from " + url);
        }
        public void GetProxy(Session oS)
        {
            var data = GetRequestData(oS);

            oS.utilCreateResponseAndBypassServer();
            oS.oResponse.headers.SetStatus(307, "Redirect");
            byte[] bytes = Convert.FromBase64String(data.Get("url"));
            String url   = Encoding.UTF8.GetString(bytes);

            oS.oResponse["Location"] = url;
            Proxy.LogRequest(oS, this, "Redirecting to " + url);
        }
        public void GetZipHash(Session oS)
        {
            string data = Path.GetFileName(oS.PathAndQuery);

            if (data == "requestZipHash.php")
            {
                data = GetRequestData(oS).Get("url");
            }

            byte[] bytes = Convert.FromBase64String(data);
            string url   = Encoding.UTF8.GetString(bytes);

            oS.utilCreateResponseAndBypassServer();
            Proxy.LogRequest(oS, this, "Sent empty zip hash for " + url);
        }
        public void GetVerificationResponse(Session oS)
        {
            var data = GetRequestData(oS);

            oS.utilCreateResponseAndBypassServer();
            string  key  = data.Get("key");
            JObject resp = new JObject(
                new JProperty("Accepted", true),
                new JProperty("Message", "This key can be used."),
                new JProperty("DonationDate", DateTime.Now.ToString("yyyy-MM-dd")),
                new JProperty("Email", WindowsIdentity.GetCurrent().Name.Split('\\').Last() + "@localhost"),
                new JProperty("DonatorKey", key));

            oS.utilSetResponseBody(resp.ToString());
            Proxy.LogRequest(oS, this, "Sent key validation.");
        }
        private void LoadResponseFromDatabase(Session oS, Database.EncryptionVersion?version = null)
        {
            string message = "Sending database contents {0} encryption.";

            byte[] bytes;
            if (version.HasValue)
            {
                bytes   = database.Encrypt(version.Value).ToArray();
                message = string.Format(message, "with " + version.Value.ToString());
            }
            else
            {
                bytes   = database.ToArray();
                message = string.Format(message, "without");
            }
            LoadResponseFromByteArray(oS, bytes);
            Proxy.LogRequest(oS, this, message);
        }
Beispiel #13
0
        protected void LoadResponseFromFile(Session oS, string folder)
        {
            string fileName  = Path.GetFileName(oS.PathAndQuery);
            string localPath = Path.Combine(Program.GetLauncherPath(), folder, fileName);

            oS.utilCreateResponseAndBypassServer();

            // Treat request as GET to keep response body
            string temp = oS.RequestMethod;

            oS.RequestMethod = "GET";
            oS.LoadResponseFromFile(localPath);
            oS.RequestMethod     = temp;
            oS.oResponse["ETag"] = oS.GetResponseBodyHashAsBase64("md5");
            if (oS.HTTPMethodIs("HEAD"))
            {
                oS.responseBodyBytes = Utilities.emptyByteArray;
            }

            Proxy.LogRequest(oS, this, "Sending local copy of " + fileName);
        }
 public void GetContributors(Session oS)
 {
     oS.utilCreateResponseAndBypassServer();
     oS.utilSetResponseBody(Resources.Credits);
     Proxy.LogRequest(oS, this, "Sent credits.");
 }
Beispiel #15
0
 public void GetContributors(Session oS)
 {
     oS.utilCreateResponseAndBypassServer();
     oS.utilSetResponseBody("USBHelperLauncher made by\n!FailedShack\n© 2018");
     Proxy.LogRequest(oS, this, "Sent credits.");
 }
Beispiel #16
0
 public void GetSession(Session oS)
 {
     oS.utilCreateResponseAndBypassServer();
     oS.utilSetResponseBody(Program.Session.ToString());
     Proxy.LogRequest(oS, this, "Sent session guid.");
 }