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

Commit

Permalink
Merge branch 'version/1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
xfoxfu committed Jul 10, 2015
2 parents a79fb9e + 4b18ed8 commit e546212
Show file tree
Hide file tree
Showing 28 changed files with 5,206 additions and 420 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Compiled Files
out

## Assembly temp files
AssemblyInfo.old

Expand Down
25 changes: 8 additions & 17 deletions Auth/Auth.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2F77EE62-C235-4233-BE2E-1456DBBC7225}</ProjectGuid>
<ProjectGuid>{AD0DE7FC-43C6-4CC9-883D-43841B3319FF}</ProjectGuid>
<OutputType>WinExe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RapID.AuthUI</RootNamespace>
<RootNamespace>RapID.Auth</RootNamespace>
<AssemblyName>auth</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
Expand Down Expand Up @@ -51,17 +51,11 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Startup.cs">
<Compile Include="Wait.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Startup.Designer.cs">
<DependentUpon>Startup.cs</DependentUpon>
</Compile>
<Compile Include="Waiting.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Waiting.Designer.cs">
<DependentUpon>Waiting.cs</DependentUpon>
<Compile Include="Wait.Designer.cs">
<DependentUpon>Wait.cs</DependentUpon>
</Compile>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
Expand All @@ -73,11 +67,8 @@
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="Startup.resx">
<DependentUpon>Startup.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Waiting.resx">
<DependentUpon>Waiting.cs</DependentUpon>
<EmbeddedResource Include="Wait.resx">
<DependentUpon>Wait.cs</DependentUpon>
</EmbeddedResource>
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
Expand All @@ -95,7 +86,7 @@
<ItemGroup>
<ProjectReference Include="..\Library\Library.csproj">
<Project>{5e05b7e6-bf49-45b4-8bcb-6e8c7d169c58}</Project>
<Name>Rap-IDClassLibrary</Name>
<Name>Library</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
Expand Down
106 changes: 103 additions & 3 deletions Auth/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,120 @@
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using RapID.ClassLibrary;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace RapID.AuthUI
namespace RapID.Auth
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Startup(args[0], args[1]));
// callback& app
var callback = DecodeUrlString(args[0]);
var app = Crypt.Decrypt(Crypt.Decrypt(Crypt.Decrypt(args[1])));
// ask for permission
var ifAuth = MessageBox.Show("是否同意应用" + app + "发起鉴权请求?", "Rap-ID", MessageBoxButtons.YesNo);
if (ifAuth != DialogResult.Yes)
{
// exit on denying
Application.Exit();
}
// start user interface
var waitFrm = new Wait();
waitFrm.Show();
// start authentication
#region Authentication
const string auth_prefix = "AUTH";
const string authok_prefix = "AUTHOK";
const string authfail_prefix = "AUTHFAIL";

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

string cryptionKey, pairKey;
Device device;
using (var sr = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + "pair"))
{
var name = Crypt.Decrypt( sr.ReadLine());
pairKey = Crypt.Decrypt( sr.ReadLine());
cryptionKey = Crypt.Decrypt( sr.ReadLine());
device = WaitForIP(name);
}
waitFrm.SetInfoText("配置文件成功读取,正在建立连接...");
using (var tcpClient = new TcpClient())
{
tcpClient.Connect(device.IP, NetworkPorts.Auth);
waitFrm.SetInfoText("连接已建立,正在发送消息...");

using (var tcpStreamWriter = new StreamWriter(tcpClient.GetStream()))
{
tcpStreamWriter.WriteLine(Crypt.Encrypt(auth_prefix + pairKey, Crypt.GenerateKey(cryptionKey)));
tcpStreamWriter.Flush();
waitFrm.SetInfoText("消息发送成功,正在等待手机端回应...");

using (var tcpStreamReader = new StreamReader(tcpClient.GetStream()))
{
var message = Crypt.Decrypt( tcpStreamReader.ReadLine(), Crypt.GenerateKey(cryptionKey));
#if DEBUG
MessageBox.Show(message);
#endif
if (message.StartsWith(authok_prefix))
{
waitFrm.SetInfoText("授权成功!");
System.Threading.Thread.Sleep(1000);
if (callback != String.Empty)
{
System.Diagnostics.Process.Start(callback + message.Replace(authok_prefix, String.Empty));
}
}
else if (message.StartsWith(authfail_prefix))
{
waitFrm.SetInfoText("授权失败!");
System.Threading.Thread.Sleep(1000);
}
}

}
}
#endregion
Application.Exit();
}

/*
* (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;
}

private static Device WaitForIP(string name)
{
IPAddress ip = IPAddress.Any;
using (var udp = new UdpClient(new IPEndPoint(IPAddress.Any, NetworkPorts.Boradcast)))
{
string message = String.Empty;
while (message != name)
{
IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
var result = udp.Receive(ref RemoteIpEndPoint);
message = Encodes.UTF8NoBOM.GetString(result);
ip = RemoteIpEndPoint.Address;
}
}
return new Device(name, ip);
}
}
}
120 changes: 120 additions & 0 deletions Auth/Program.cs.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using RapID.ClassLibrary;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace RapID.Auth
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static async 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])));
// ask for permission
var ifAuth = MessageBox.Show("是否同意应用" + app + "发起鉴权请求?", "Rap-ID", MessageBoxButtons.YesNo);
if (ifAuth != DialogResult.Yes)
{
// exit on denying
Application.Exit();
}
// start user interface
var waitFrm = new Wait();
// start authentication
#region Authentication
const string auth_prefix = "AUTH";
const string authok_prefix = "AUTHOK";
const string authfail_prefix = "AUTHFAIL";

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

string cryptionKey, pairKey;
Device device;
using (var sr = new System.IO.StreamReader(AppDomain.CurrentDomain.BaseDirectory + "pair"))
{
var name = Crypt.Decrypt(await sr.ReadLineAsync());
pairKey = Crypt.Decrypt(await sr.ReadLineAsync());
cryptionKey = Crypt.Decrypt(await sr.ReadLineAsync());
device = await WaitForIP(name);
}
waitFrm.SetInfoText("配置文件成功读取,正在建立连接...");
using (var tcpClient = new TcpClient())
{
await tcpClient.ConnectAsync(device.IP, NetworkPorts.Auth);
waitFrm.SetInfoText("连接已建立,正在发送消息...");

using (var tcpStreamWriter = new StreamWriter(tcpClient.GetStream()))
{
await tcpStreamWriter.WriteLineAsync(Crypt.Encrypt(auth_prefix + pairKey, Crypt.GenerateKey(cryptionKey)));
await tcpStreamWriter.FlushAsync();
waitFrm.SetInfoText("消息发送成功,正在等待手机端回应...");

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))
{
waitFrm.SetInfoText("授权成功!");
System.Threading.Thread.Sleep(1000);
if (callback != String.Empty)
{
System.Diagnostics.Process.Start(callback + message.Replace(authok_prefix, String.Empty));
}
}
else if (message.StartsWith(authfail_prefix))
{
waitFrm.SetInfoText("授权失败!");
System.Threading.Thread.Sleep(1000);
}
}

}
}
#endregion
Application.Exit();
}

/*
* (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;
}

private static async Task<Device> WaitForIP(string name)
{
IPAddress ip = IPAddress.Any;
using (var udp = new UdpClient(new IPEndPoint(IPAddress.Any, NetworkPorts.Boradcast)))
{
string message = String.Empty;
while (message != name)
{
var result = await udp.ReceiveAsync();
message = Encodes.UTF8NoBOM.GetString(result.Buffer);
ip = result.RemoteEndPoint.Address;
}
}
return new Device(name, ip);
}
}
}
14 changes: 7 additions & 7 deletions Auth/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Rap-ID AuthUI")]
[assembly: AssemblyDescription("authorize UI for Rap-ID")]
[assembly: AssemblyTitle("Auth")]
[assembly: AssemblyDescription("auth ui provider for Rap-ID")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Cotr Community")]
[assembly: AssemblyProduct("Rap-ID")]
Expand All @@ -22,15 +22,15 @@
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("13d4c4b5-996d-4b06-848a-0de873e9d5ac")]

// 程序集的版本信息由下面四个值组成:
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.9")]
[assembly: AssemblyFileVersion("1.1.0.9")]
[assembly: AssemblyVersion("1.2.0.8")]
[assembly: AssemblyFileVersion("1.2.0.8")]
4 changes: 2 additions & 2 deletions Auth/Properties/Resources.Designer.cs

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

2 changes: 1 addition & 1 deletion Auth/Properties/Settings.Designer.cs

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

Loading

0 comments on commit e546212

Please sign in to comment.