Skip to content

Tarun200897 winauth import #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "lib/SteamAuth"]
path = lib/SteamAuth
url = git://github.com/geel9/SteamAuth
ignore = dirty
1,030 changes: 1,030 additions & 0 deletions Steam Desktop Authenticator/.vs/config/applicationhost.config

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Steam Desktop Authenticator/ImportAccountForm.Designer.cs

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

207 changes: 207 additions & 0 deletions Steam Desktop Authenticator/ImportWinAuthForm.Designer.cs

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

221 changes: 221 additions & 0 deletions Steam Desktop Authenticator/ImportWinAuthForm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
using ICSharpCode.SharpZipLib.Core;
using ICSharpCode.SharpZipLib.Zip;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Steam_Desktop_Authenticator
{
public partial class ImportWinAuthForm : Form
{
SteamAuth.SteamGuardAccount[] steamAccounts;
SteamAuth.SteamGuardAccount selectedAccount;
public ImportWinAuthForm()
{
InitializeComponent();
}

private void btnCancel_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnBrowse_Click(object sender, EventArgs e)
{
// File Dialog options
openFileDialog1.Filter = "WinAuth Protected Export (.zip)|*.zip|WinAuth Export (.txt)|*.txt|All Files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.Multiselect = false;

if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
var path = openFileDialog1.FileName;
txtPassword.Enabled = Path.GetExtension(path) == ".zip";
txtPath.Text = path;
}
}

// Similar to PhoneExtractForm's LoginAccount method since both have the same data at this stage.
private void LoginAccount()
{
MessageBox.Show("Account extracted succesfully! Please login to it.");
LoginForm login = new LoginForm(LoginForm.LoginType.Android, selectedAccount);
login.ShowDialog();
this.Close();
}

private void btnLoad_Click(object sender, EventArgs e)
{
var path = txtPath.Text;
List<SteamAuth.SteamGuardAccount> accountList = new List<SteamAuth.SteamGuardAccount>();
string[] contents;
var ext = Path.GetExtension(path);
if (ext == ".txt")
{
contents = File.ReadAllLines(path);
}
else if(ext == ".zip")
{
ZipFile zf = null;
List<string> contentsList = new List<string>();
try
{
FileStream fs = File.OpenRead(path);
zf = new ZipFile(fs);
if (!String.IsNullOrEmpty(txtPassword.Text))
{
zf.Password = txtPassword.Text; // AES encrypted entries are handled automatically
}
else
{
return;
}
foreach (ZipEntry zipEntry in zf)
{
if (!zipEntry.IsFile)
{
continue; // Ignore directories
}
String entryFileName = zipEntry.Name;
// to remove the folder from the entry:- entryFileName = Path.GetFileName(entryFileName);
// Optionally match entrynames against a selection list here to skip as desired.
// The unpacked length is available in the zipEntry.Size property.

// Look for the winauth text file.
if(!entryFileName.Contains("winauth"))
{
continue;
}

Stream zipStream;
try
{

zipStream = zf.GetInputStream(zipEntry);
}
catch (Exception)
{
MessageBox.Show("Incorrect Password");
return;
}

// Read the contents from the zip stream
// The "using" will close the stream even if an exception occurs.
using (StreamReader reader = new StreamReader(zipStream))
{
while (!reader.EndOfStream)
{
contentsList.Add(reader.ReadLine());
}
}
}
}
finally
{
if (zf != null)
{
zf.IsStreamOwner = true; // Makes close also shut the underlying stream
zf.Close(); // Ensure we release resources
}
}
contents = contentsList.ToArray();
}
else
{
return;
}

foreach (var line in contents)
{
// Checking if it's a steam export
if (line.Contains("Steam"))
{
// WinAuth export is similar to http query paramters
var collection = ParseQueryString(line);

// The data assigned to data is actually valid json
var jsondata = collection.GetValues("data")[0];
var account = JsonConvert.DeserializeObject<SteamAuth.SteamGuardAccount>(jsondata);

// WinAuth stores DeviceID outside of the data json
account.DeviceID = collection.GetValues("deviceid")[0];

accountList.Add(account);
listAccounts.Items.Add(account.AccountName);
}
}
steamAccounts = accountList.ToArray();
}

// Function copied from WinAuth code - WinAuth/WinAuthHelper.cs.
/// <summary>
/// Our own version of HttpUtility.ParseQueryString so we can remove the reference to System.Web
/// which is not available in client profile.
/// </summary>
/// <param name="qs">string query string</param>
/// <returns>collection of name value pairs</returns>
public static NameValueCollection ParseQueryString(string qs)
{
NameValueCollection pairs = new NameValueCollection();

// ignore blanks and remove initial "?"
if (string.IsNullOrEmpty(qs) == true)
{
return pairs;
}
if (qs.StartsWith("?") == true)
{
qs = qs.Substring(1);
}

// get each a=b&... key-value pair
foreach (string p in qs.Split('&'))
{
string[] keypair = p.Split('=');
string key = keypair[0];
string v = (keypair.Length >= 2 ? keypair[1] : null);
if (string.IsNullOrEmpty(v) == false)
{
// decode (without using System.Web)
string newv;
while ((newv = Uri.UnescapeDataString(v)) != v)
{
v = newv;
}
}
pairs.Add(key, v);
}

return pairs;
}

private void listAccounts_SelectedIndexChanged(object sender, EventArgs e)
{
if (listAccounts.SelectedIndex == -1) return;
var accountName = (string)listAccounts.SelectedItem;
for (int i = 0; i < steamAccounts.Length; i++)
{
var account = steamAccounts[i];
if (account.AccountName == (string)listAccounts.Items[listAccounts.SelectedIndex])
{
selectedAccount = account;
break;
}
}
}

private void btnOk_Click(object sender, EventArgs e)
{
LoginAccount();
}
}
}
1,879 changes: 1,879 additions & 0 deletions Steam Desktop Authenticator/ImportWinAuthForm.resx

Large diffs are not rendered by default.

35 changes: 30 additions & 5 deletions Steam Desktop Authenticator/InstallRedistribForm.cs
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.Net;
using System.Diagnostics;
using System.IO;

namespace Steam_Desktop_Authenticator
{
@@ -23,13 +24,38 @@ public InstallRedistribForm(bool inlineInstall = false)

string path = Manifest.GetExecutableDir() + "/vcredist_x86.exe";

WebClient client = new WebClient();
client.DownloadFileAsync(new Uri("https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe"), path);
client.DownloadProgressChanged += Client_DownloadProgressChanged;
client.DownloadFileCompleted += Client_DownloadFileCompleted;
// Not downloading the file again if it already exists
if (File.Exists(path))
{
using (var md5 = System.Security.Cryptography.MD5.Create())
{
using (var stream = File.OpenRead(path))
{
var md5String = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLower();
// Hardcoding the md5 since file doesn't change
if (md5String == "0fc525b6b7b96a87523daa7a0013c69d")
{
progressBar1.Value = progressBar1.Maximum;
Install();
}
}
}
}
else
{
WebClient client = new WebClient();
client.DownloadFileAsync(new Uri("https://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe"), path);
client.DownloadProgressChanged += Client_DownloadProgressChanged;
client.DownloadFileCompleted += Client_DownloadFileCompleted;
}
}

private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
Install();
}

private void Install()
{
progressBar1.Style = ProgressBarStyle.Marquee;
try
@@ -51,7 +77,6 @@ private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs
this.Close();
}
}

private void InstallProcess_Exited(object sender, EventArgs e)
{
if (inlineInstall)
85 changes: 49 additions & 36 deletions Steam Desktop Authenticator/MainForm.Designer.cs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions Steam Desktop Authenticator/MainForm.cs
Original file line number Diff line number Diff line change
@@ -685,5 +685,10 @@ private void UpdateClient_DownloadStringCompleted(object sender, DownloadStringC
MessageBox.Show("Failed to check for updates.");
}
}

private void menuImportWinAuth_Click(object sender, EventArgs e)
{
new ImportWinAuthForm().ShowDialog();
}
}
}
2 changes: 1 addition & 1 deletion Steam Desktop Authenticator/PhoneBridge.cs
Original file line number Diff line number Diff line change
@@ -150,7 +150,7 @@ private string GetDeviceID(bool root)
console.OutputDataReceived += f1;

if (root)
ExecuteCommand("adb shell \"cat /data/data/$STEAMAPP/shared_prefs/steam.uuid.xml\" & echo Done");
ExecuteCommand("adb shell \"su -c 'cat /data/data/$STEAMAPP/shared_prefs/steam.uuid.xml'\" & echo Done");
else
ExecuteCommand("adb shell \"cat /sdcard/steamauth/apps/$STEAMAPP/sp/steam.uuid.xml\" & echo Done");
mre.Wait();
13 changes: 13 additions & 0 deletions Steam Desktop Authenticator/Steam Desktop Authenticator.csproj
Original file line number Diff line number Diff line change
@@ -109,6 +109,10 @@
<ApplicationIcon>icon.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
@@ -147,6 +151,12 @@
<Compile Include="ImportAccountForm.Designer.cs">
<DependentUpon>ImportAccountForm.cs</DependentUpon>
</Compile>
<Compile Include="ImportWinAuthForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="ImportWinAuthForm.Designer.cs">
<DependentUpon>ImportWinAuthForm.cs</DependentUpon>
</Compile>
<Compile Include="InputForm.cs">
<SubType>Form</SubType>
</Compile>
@@ -214,6 +224,9 @@
<EmbeddedResource Include="ImportAccountForm.resx">
<DependentUpon>ImportAccountForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ImportWinAuthForm.resx">
<DependentUpon>ImportWinAuthForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="InputForm.resx">
<DependentUpon>InputForm.cs</DependentUpon>
</EmbeddedResource>
20 changes: 17 additions & 3 deletions Steam Desktop Authenticator/WelcomeForm.Designer.cs
15 changes: 15 additions & 0 deletions Steam Desktop Authenticator/WelcomeForm.cs
Original file line number Diff line number Diff line change
@@ -106,5 +106,20 @@ private void btnAndroidImport_Click(object sender, EventArgs e)
showMainForm();
}
}

private void btnWinAuthImport_Click(object sender, EventArgs e)
{
int oldEntries = man.Entries.Count;

new ImportWinAuthForm().ShowDialog();

if (man.Entries.Count > oldEntries)
{
// Mark as not first run anymore
man.FirstRun = false;
man.Save();
showMainForm();
}
}
}
}
1 change: 1 addition & 0 deletions Steam Desktop Authenticator/packages.config
Original file line number Diff line number Diff line change
@@ -5,4 +5,5 @@
<package id="CefSharp.Common" version="45.0.0" targetFramework="net452" />
<package id="CefSharp.WinForms" version="45.0.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net452" />
<package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
</packages>