Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Feature: Windows Auth API of CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
xfoxfu committed Jul 18, 2015
2 parents bbec204 + d01484b commit e1aeeee
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 180 deletions.
19 changes: 3 additions & 16 deletions Auth/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,10 @@ static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
// callback& app
var callback = DecodeUrlString(args[0]);
var app = Crypt.Decrypt(Crypt.Decrypt(Crypt.Decrypt(args[1])));
var waitFrm = new Wait(callback, app);
// app
var app = Crypt.Decrypt(Crypt.Decrypt(Crypt.Decrypt(args[0])));
var waitFrm = new Wait(app);
Application.Run(waitFrm);
}

/*
* (C) 2015 @ogi from StackOverflow
* Original Post: http://stackoverflow.com/questions/1405048/how-do-i-decode-a-url-parameter-using-c
*/
private static string DecodeUrlString(string url)
{
string newUrl;
while ((newUrl = Uri.UnescapeDataString(url)) != url)
url = newUrl;
return newUrl;
}
}
}
4 changes: 2 additions & 2 deletions Auth/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.13")]
[assembly: AssemblyFileVersion("1.2.0.13")]
[assembly: AssemblyVersion("1.2.0.19")]
[assembly: AssemblyFileVersion("1.2.0.19")]
21 changes: 10 additions & 11 deletions Auth/Wait.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,10 @@ namespace RapID.Auth
{
public partial class Wait : Form
{
private string _callback;
private string _app;
public Wait(string callback, string app)
public Wait(string app)
{
InitializeComponent();
this._callback = callback;
this._app = app;
}

Expand Down Expand Up @@ -58,6 +56,7 @@ private async void okButton_Click(object sender, EventArgs e)
const string auth_prefix = "AUTH";
const string authok_prefix = "AUTHOK";
const string authfail_prefix = "AUTHFAIL";
const string c_cliResultPrefix = "#Rap-ID-Windows/CLI/1.0d/Auth/";

this.SetInfoText("正在读取配置文件...");

Expand Down Expand Up @@ -85,25 +84,25 @@ private async void okButton_Click(object sender, EventArgs e)
using (var tcpStreamReader = new StreamReader(tcpClient.GetStream()))
{
var message = Crypt.Decrypt(await tcpStreamReader.ReadLineAsync(), Crypt.GenerateKey(cryptionKey));
#if DEBUG
MessageBox.Show(message);
#endif
if (message.StartsWith(authok_prefix))
{
var token = message.Remove(message.IndexOf(authok_prefix), authok_prefix.Length);
#if DEBUG
MessageBox.Show(token);
#endif
this.SetInfoText("授权成功!");
System.Threading.Thread.Sleep(1000);
if (_callback != String.Empty)
{
System.Diagnostics.Process.Start(_callback + message.Replace(authok_prefix, String.Empty));
}
// output token
Console.WriteLine(c_cliResultPrefix + "result=ok;token=" + token);
}
else if (message.StartsWith(authfail_prefix))
{
this.SetInfoText("授权失败!");
System.Threading.Thread.Sleep(1000);
// output error
Console.WriteLine(c_cliResultPrefix + "result=fail;error=NotImpled");
}
}

}
}
Application.Exit();
Expand Down
4 changes: 2 additions & 2 deletions Configure/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.9")]
[assembly: AssemblyFileVersion("1.1.0.9")]
[assembly: AssemblyVersion("1.1.0.10")]
[assembly: AssemblyFileVersion("1.1.0.10")]
4 changes: 2 additions & 2 deletions CryptionDebugger/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.1.6")]
[assembly: AssemblyFileVersion("1.1.1.6")]
[assembly: AssemblyVersion("1.1.1.9")]
[assembly: AssemblyFileVersion("1.1.1.9")]
4 changes: 2 additions & 2 deletions Installer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.15")]
[assembly: AssemblyFileVersion("1.0.0.15")]
[assembly: AssemblyVersion("1.0.0.18")]
[assembly: AssemblyFileVersion("1.0.0.18")]
6 changes: 1 addition & 5 deletions Library/Library.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,12 @@
</Compile>
<Compile Include="Objects\Device.cs" />
<Compile Include="Utils\Encoding.cs" />
<Compile Include="Utils\Error.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Utils\Error.cs" />
<Compile Include="Utils\INetwork.cs" />
<Compile Include="Utils\Log.cs" />
<Compile Include="Utils\Network.cs" />
<Compile Include="Utils\Crypt.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utils\TCPClient.cs" />
<Compile Include="Utils\TCPServer.cs" />
<Compile Include="Utils\UDPServer.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions Library/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.11")]
[assembly: AssemblyFileVersion("1.2.0.11")]
[assembly: AssemblyVersion("1.2.0.15")]
[assembly: AssemblyFileVersion("1.2.0.15")]
88 changes: 0 additions & 88 deletions Library/Utils/TCPClient.cs

This file was deleted.

45 changes: 0 additions & 45 deletions Library/Utils/TCPServer.cs

This file was deleted.

36 changes: 34 additions & 2 deletions URLSchemeHandler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Program
{
const string scheme_name = "rapid";
const string uri_host = "authorize";
const string c_cliTokenResultPrefix = "#Rap-ID-Windows/CLI/1.0d/Auth/result=ok;token=";
static void Main(string[] args)
{
if (args.Count() == 1)
Expand All @@ -26,8 +27,26 @@ static void Main(string[] args)
{
case uri_host:
{
var query = uri.Query;
Process.Start(AppDomain.CurrentDomain.BaseDirectory + "auth.exe", GetParam(query, "callback") + " " + GetParam(query, "app"));
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "auth.exe";
p.StartInfo.Arguments = GetParam(uri.Query, "app");
p.Start();
var resultGot = false;
while(!resultGot)
{
var message = p.StandardOutput.ReadLine();
if (message.StartsWith(c_cliTokenResultPrefix))
{
var token = message.Remove(message.IndexOf(c_cliTokenResultPrefix), c_cliTokenResultPrefix.Length);
var callback = DecodeUrlString(GetParam(uri.Query, "callback"));
Process.Start(callback + token);
resultGot = true;
}
}
break;
}
default:
Expand Down Expand Up @@ -56,5 +75,18 @@ private static string GetParam(string query, string paramName)
}
throw new KeyNotFoundException();
}


/*
* (C) 2015 @ogi from StackOverflow
* Original Post: http://stackoverflow.com/questions/1405048/how-do-i-decode-a-url-parameter-using-c
*/
private static string DecodeUrlString(string url)
{
string newUrl;
while ((newUrl = Uri.UnescapeDataString(url)) != url)
url = newUrl;
return newUrl;
}
}
}
4 changes: 2 additions & 2 deletions URLSchemeHandler/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.17")]
[assembly: AssemblyFileVersion("1.1.0.17")]
[assembly: AssemblyVersion("1.1.0.22")]
[assembly: AssemblyFileVersion("1.1.0.22")]
5 changes: 4 additions & 1 deletion URLSchemeHandler/URLSchemeHandler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{3F20C6B6-4AFB-451A-9E70-0A4229A96147}</ProjectGuid>
<OutputType>Exe</OutputType>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RapID.URLSchemeHandler</RootNamespace>
<AssemblyName>URLSchemeHandler</AssemblyName>
Expand Down Expand Up @@ -37,6 +37,9 @@
<PropertyGroup>
<ApplicationIcon>Rap-ID.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down

0 comments on commit e1aeeee

Please sign in to comment.