Skip to content

Commit

Permalink
v.2.0.0.0 exp: add Edge-based auth
Browse files Browse the repository at this point in the history
  • Loading branch information
crouvpony47 committed Jan 11, 2025
1 parent c253b1e commit 15f3c2b
Show file tree
Hide file tree
Showing 13 changed files with 255 additions and 146 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/.vs
.vs/
/src/bin
/src/obj
/packages
*.user
23 changes: 18 additions & 5 deletions src/App.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2"/>
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.2" />
</startup>
<appSettings>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true"/>
<add key="EnableWindowsFormsHighDpiAutoResizing" value="true" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
</configuration>
<system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
<providers>
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
</providers>
</membership>
<roleManager defaultProvider="ClientRoleProvider" enabled="true">
<providers>
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
</providers>
</roleManager>
</system.web>
</configuration>
35 changes: 7 additions & 28 deletions src/AppCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,20 @@ public class AppCore
#region HTTP-related members
private HttpClientHandler httph = null;
private HttpClient http = null;
#if !furdown_portable_core
[DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool InternetGetCookieEx(string pchURL, string pchCookieName, StringBuilder pchCookieData, ref uint pcchCookieData, int dwFlags, IntPtr lpReserved);
#endif
private const int INTERNET_COOKIE_HTTPONLY = 0x00002000;
#endregion

public string defaultUserId = "";

public bool isInitialized = false;

/// <summary>
/// Gets all, including http-only, cookies from WebBrowser component
/// </summary>
/// <param name="uri">URI which is used to get the cookies for</param>
/// <returns></returns>
private static string GetGlobalCookies(string uri)
private static string GetGlobalCookies(string uri) //fixme
{
string envCookies = Environment.GetEnvironmentVariable("FURDOWN_COOKIES");
if (envCookies != null) return envCookies;

#if !furdown_portable_core
uint datasize = 1024;
StringBuilder cookieData = new StringBuilder((int)datasize);
if (InternetGetCookieEx(
uri, null, cookieData, ref datasize, INTERNET_COOKIE_HTTPONLY, IntPtr.Zero
) && cookieData.Length > 0)
{
return cookieData.ToString();
}
else
{
return null;
}
#else
return null;
#endif
return CookiesStorage.GetCookieString();
}

/// <summary>
Expand Down Expand Up @@ -142,15 +121,15 @@ public void OnAppTerminate()
public async Task<bool> Init()
{
Console.WriteLine("Checking authorization...");
string cookies = GetGlobalCookies("https://www.furaffinity.net/");
string cookies = CookiesStorage.GetCookieString();
if (cookies == null) return false;
Console.WriteLine("Found some cookies.");
// Console.WriteLine("Found cookies: "+cookies);
try
{
http.DefaultRequestHeaders.Clear();
// IE's and HttpClient's UAs MUST match for Cloudflare to recognize us
http.DefaultRequestHeaders.Add("User-Agent", Utils.EmbeddedIeUtils.GetKnownUserAgentValue());
// WebView's and HttpClient's UAs MUST match for Cloudflare to recognize us
http.DefaultRequestHeaders.Add("User-Agent", CookiesStorage.GetAssociatedUserAgent());
// test: "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"
//http.DefaultRequestHeaders.Add("Accept-Language", "en-US;q=0.8,en;q=0.5,ja;q=0.3"); // not strictly neccessary
http.DefaultRequestHeaders.Add("Accept-Encoding", "gzip, deflate");
Expand Down
44 changes: 44 additions & 0 deletions src/CookiesStorage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace furdown
{
internal static class CookiesStorage
{
private static string cookieString = null;
private static string assocUserAgent = "Mozilla/5.0";

public static string GetCookieString()
{
string envCookies = Environment.GetEnvironmentVariable("FURDOWN_COOKIES");
if (envCookies != null)
{
return envCookies;
}
return cookieString;
}

public static void SetCookieString(string newCookies)
{
cookieString = newCookies;
}

public static string GetAssociatedUserAgent()
{
string envUA = Environment.GetEnvironmentVariable("FURDOWN_USERAGENT");
if (envUA != null)
{
return envUA;
}
return assocUserAgent;
}

public static void SetAssociatedUserAgent(string newUserAgent)
{
assocUserAgent = newUserAgent;
}
}
}
31 changes: 2 additions & 29 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ static void Main()
}
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
WebBrowserEmulationSet();
Utils.EmbeddedIeUtils.SetKnownUserAgent();
Application.Run(new authForm());
var af = new authForm();
Application.Run(af);
}
else
{
Expand All @@ -46,31 +45,5 @@ static void Main()
}
AppCore.Core.OnAppTerminate();
}

/// <summary>
/// Sets WebBrowser components to IE11 mode, rather than default IE7,
/// which is really not suitable for anything.
/// </summary>
static void WebBrowserEmulationSet()
{
try
{
using (
var rk = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(
@"SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_BROWSER_EMULATION", true)
)
{
if (rk == null) return;
string appname = System.IO.Path.GetFileName(Application.ExecutablePath);
dynamic value = rk.GetValue(appname);
if (value == null)
rk.SetValue(appname, (uint)11001, Microsoft.Win32.RegistryValueKind.DWord);
}
}
catch (Exception E)
{
MessageBox.Show("Something went wrong:" + Environment.NewLine + E.Message);
}
}
}
}
4 changes: 2 additions & 2 deletions src/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

[assembly: Guid("8b45577e-b5d1-4056-96e6-b2647e18b867")]

[assembly: AssemblyVersion("0.5.5.0")]
[assembly: AssemblyFileVersion("0.5.5.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
[assembly: NeutralResourcesLanguage("en")]

9 changes: 8 additions & 1 deletion src/UpdatesChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ internal static async Task<bool> CheckRemoteVersion()
var remoteVersion = tag.Split('.');
var versionComp = thisVersion.Zip(remoteVersion, (tvp, rvp) =>
{
return string.Compare(tvp, rvp, StringComparison.Ordinal);
try
{
return int.Parse(tvp) - int.Parse(rvp);
}
catch (Exception)
{
return string.Compare(tvp, rvp, StringComparison.Ordinal);
}
});

foreach (int c in versionComp)
Expand Down
24 changes: 5 additions & 19 deletions src/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,15 @@ public static string FileHash(string path)
}
}

public class EmbeddedIeUtils
public static void OpenUrl(string urlToOpen)
{
[DllImport("urlmon.dll", CharSet = CharSet.Ansi)]
private static extern int UrlMkSetSessionOption(int dwOption, string pBuffer, int dwBufferLength, int dwReserved);

const int URLMON_OPTION_USERAGENT = 0x10000001;
const string ua = "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; Touch; rv:11.0) like Gecko";

static string GetUserAgent()
{
string envUa = Environment.GetEnvironmentVariable("FURDOWN_USERAGENT");
return envUa == null ? ua : envUa;
}

public static void SetKnownUserAgent()
try
{
var userAgent = GetUserAgent();
UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, userAgent, userAgent.Length, 0);
System.Diagnostics.Process.Start(urlToOpen);
}

public static string GetKnownUserAgentValue()
catch (Exception)
{
return GetUserAgent();
Console.WriteLine("Could not open URL in the default browser:\n" + urlToOpen);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/app.manifest
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="0.5.5.0" name="Furdown.app"/>
<assemblyIdentity version="2.0.0.0" name="Furdown.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
Expand Down
47 changes: 31 additions & 16 deletions src/authForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 15f3c2b

Please sign in to comment.