diff --git a/Auth/Program.cs b/Auth/Program.cs index a8b231a..7b64e79 100644 --- a/Auth/Program.cs +++ b/Auth/Program.cs @@ -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; - } } } diff --git a/Auth/Properties/AssemblyInfo.cs b/Auth/Properties/AssemblyInfo.cs index 99338c8..3b91fa4 100644 --- a/Auth/Properties/AssemblyInfo.cs +++ b/Auth/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Auth/Wait.cs b/Auth/Wait.cs index 85c72da..61c1c68 100644 --- a/Auth/Wait.cs +++ b/Auth/Wait.cs @@ -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; } @@ -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("正在读取配置文件..."); @@ -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(); diff --git a/Configure/Properties/AssemblyInfo.cs b/Configure/Properties/AssemblyInfo.cs index 7c0d2d7..0bd445f 100644 --- a/Configure/Properties/AssemblyInfo.cs +++ b/Configure/Properties/AssemblyInfo.cs @@ -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")] diff --git a/CryptionDebugger/Properties/AssemblyInfo.cs b/CryptionDebugger/Properties/AssemblyInfo.cs index d25262d..28f80df 100644 --- a/CryptionDebugger/Properties/AssemblyInfo.cs +++ b/CryptionDebugger/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Installer/Properties/AssemblyInfo.cs b/Installer/Properties/AssemblyInfo.cs index 1ab5198..bc1ab84 100644 --- a/Installer/Properties/AssemblyInfo.cs +++ b/Installer/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Library/Library.csproj b/Library/Library.csproj index 5734d05..ce6d920 100644 --- a/Library/Library.csproj +++ b/Library/Library.csproj @@ -56,16 +56,12 @@ - - Form - + - - diff --git a/Library/Properties/AssemblyInfo.cs b/Library/Properties/AssemblyInfo.cs index 0c3700b..bf12098 100644 --- a/Library/Properties/AssemblyInfo.cs +++ b/Library/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Library/Utils/TCPClient.cs b/Library/Utils/TCPClient.cs deleted file mode 100644 index 37aa4ce..0000000 --- a/Library/Utils/TCPClient.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Net; -using System.Net.Sockets; -using System.IO; - -namespace RapID.ClassLibrary -{ - public class TCPClient : INetworkSender - { - private TcpClient tcpClient { get; set; } - private IPEndPoint remote { get; set; } - private NetworkStream stream - { - get - { - return this.tcpClient.GetStream(); - } - } - private StreamReader reader; - private StreamWriter writer; - public bool listening { get; private set; } - public bool Connected - { - get - { - return this.tcpClient.Connected; - } - } - public TCPClient(IPEndPoint remote) - { - this.remote = remote; - this.tcpClient = new TcpClient(); - } - public TCPClient(IPAddress IP, int Port) - : this(new IPEndPoint(IP, Port)) - { - } - public TCPClient(string IP, int Port) - : this(new IPEndPoint(IPAddress.Parse(IP), Port)) - { - } - public TCPClient(TcpClient client) - { - this.tcpClient = client; - } - public void Connect() - { - this.tcpClient.Connect(this.remote.Address, this.remote.Port); - this.reader = new StreamReader(this.stream, Encodes.UTF8NoBOM); - this.writer = new StreamWriter(this.stream, Encodes.UTF8NoBOM); - this.listening = true; - Read(); - } - public async void Send(string msg) - { - var cmsg = Crypt.Encrypt(msg); - await this.writer.WriteLineAsync(cmsg); - await this.writer.FlushAsync(); - } - public void SendSync(string msg) - { - var cmsg = Crypt.Encrypt(msg); - this.writer.WriteLine(cmsg); - this.writer.Flush(); - } - public delegate void OnMessageEventHandler(object sender, string message); - public event OnMessageEventHandler OnMessage; - private async void Read() - { - while (listening) - { - var msg = await this.reader.ReadLineAsync(); - if (msg != String.Empty) - { - OnMessage.Invoke(this, Crypt.Decrypt(msg)); - } - } - } - public void Close() - { - this.listening = false; - this.tcpClient.Close(); - } - } -} diff --git a/Library/Utils/TCPServer.cs b/Library/Utils/TCPServer.cs deleted file mode 100644 index 17892b1..0000000 --- a/Library/Utils/TCPServer.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net; -using System.Net.Sockets; -using System.IO; - -namespace RapID.ClassLibrary -{ - public class TCPServer - { - private TcpListener tcpServer { get; set; } - public bool looping { get; private set; } - public TCPServer(int port) - { - this.tcpServer = new TcpListener(IPAddress.Any, port); - this.tcpServer.Start(); - Loop(); - } - - private async void Loop() - { - var tcpClient = await this.tcpServer.AcceptTcpClientAsync(); - if (tcpClient.Connected == true) - { - OnConnection.Invoke(new TCPClient(tcpClient)); - } - if (looping) - { - Loop(); - } - } - - public void Stop() - { - this.looping = false; - this.tcpServer.Stop(); - } - - public delegate void OnConnectionEventHandler(TCPClient client); - public event OnConnectionEventHandler OnConnection; - } -} diff --git a/URLSchemeHandler/Program.cs b/URLSchemeHandler/Program.cs index 8cf597c..bfd03d2 100644 --- a/URLSchemeHandler/Program.cs +++ b/URLSchemeHandler/Program.cs @@ -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) @@ -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: @@ -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; + } } } diff --git a/URLSchemeHandler/Properties/AssemblyInfo.cs b/URLSchemeHandler/Properties/AssemblyInfo.cs index 31c3a10..3eeef5b 100644 --- a/URLSchemeHandler/Properties/AssemblyInfo.cs +++ b/URLSchemeHandler/Properties/AssemblyInfo.cs @@ -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")] diff --git a/URLSchemeHandler/URLSchemeHandler.csproj b/URLSchemeHandler/URLSchemeHandler.csproj index 9175b4d..a062ce7 100644 --- a/URLSchemeHandler/URLSchemeHandler.csproj +++ b/URLSchemeHandler/URLSchemeHandler.csproj @@ -5,7 +5,7 @@ Debug AnyCPU {3F20C6B6-4AFB-451A-9E70-0A4229A96147} - Exe + WinExe Properties RapID.URLSchemeHandler URLSchemeHandler @@ -37,6 +37,9 @@ Rap-ID.ico + + +