From cc4dca85b49b9036283c473c2b0f28bacc60171d Mon Sep 17 00:00:00 2001 From: mjs Date: Sat, 23 Jul 2011 01:12:58 +0200 Subject: [PATCH 001/259] First version --- RiftAuthenticator.sln | 20 + RiftAuthenticator/App.xaml | 8 + RiftAuthenticator/App.xaml.cs | 16 + RiftAuthenticator/Configuration.cs | 98 + RiftAuthenticator/CreateNewSecretKey.xaml | 12 + RiftAuthenticator/CreateNewSecretKey.xaml.cs | 47 + RiftAuthenticator/DataConverter.cs | 1837 +++++++++++++++++ RiftAuthenticator/Information.xaml | 37 + RiftAuthenticator/Information.xaml.cs | 31 + RiftAuthenticator/Login.xaml | 26 + RiftAuthenticator/Login.xaml.cs | 37 + RiftAuthenticator/LoginToken.cs | 19 + RiftAuthenticator/MainWindow.xaml | 15 + RiftAuthenticator/MainWindow.xaml.cs | 164 ++ RiftAuthenticator/Properties/AssemblyInfo.cs | 55 + .../Properties/Resources.Designer.cs | 71 + RiftAuthenticator/Properties/Resources.resx | 117 ++ .../Properties/Settings.Designer.cs | 30 + .../Properties/Settings.settings | 7 + RiftAuthenticator/QueryDeviceId.xaml | 11 + RiftAuthenticator/QueryDeviceId.xaml.cs | 37 + RiftAuthenticator/RiftAuthenticator.csproj | 146 ++ .../RiftAuthenticator.csproj.user | 3 + RiftAuthenticator/SecurityQuestions.xaml | 30 + RiftAuthenticator/SecurityQuestions.xaml.cs | 32 + RiftAuthenticator/TrionServer.cs | 166 ++ RiftAuthenticator/TrionServerException.cs | 25 + RiftAuthenticator/Util.cs | 60 + 28 files changed, 3157 insertions(+) create mode 100644 RiftAuthenticator.sln create mode 100644 RiftAuthenticator/App.xaml create mode 100644 RiftAuthenticator/App.xaml.cs create mode 100644 RiftAuthenticator/Configuration.cs create mode 100644 RiftAuthenticator/CreateNewSecretKey.xaml create mode 100644 RiftAuthenticator/CreateNewSecretKey.xaml.cs create mode 100644 RiftAuthenticator/DataConverter.cs create mode 100644 RiftAuthenticator/Information.xaml create mode 100644 RiftAuthenticator/Information.xaml.cs create mode 100644 RiftAuthenticator/Login.xaml create mode 100644 RiftAuthenticator/Login.xaml.cs create mode 100644 RiftAuthenticator/LoginToken.cs create mode 100644 RiftAuthenticator/MainWindow.xaml create mode 100644 RiftAuthenticator/MainWindow.xaml.cs create mode 100644 RiftAuthenticator/Properties/AssemblyInfo.cs create mode 100644 RiftAuthenticator/Properties/Resources.Designer.cs create mode 100644 RiftAuthenticator/Properties/Resources.resx create mode 100644 RiftAuthenticator/Properties/Settings.Designer.cs create mode 100644 RiftAuthenticator/Properties/Settings.settings create mode 100644 RiftAuthenticator/QueryDeviceId.xaml create mode 100644 RiftAuthenticator/QueryDeviceId.xaml.cs create mode 100644 RiftAuthenticator/RiftAuthenticator.csproj create mode 100644 RiftAuthenticator/RiftAuthenticator.csproj.user create mode 100644 RiftAuthenticator/SecurityQuestions.xaml create mode 100644 RiftAuthenticator/SecurityQuestions.xaml.cs create mode 100644 RiftAuthenticator/TrionServer.cs create mode 100644 RiftAuthenticator/TrionServerException.cs create mode 100644 RiftAuthenticator/Util.cs diff --git a/RiftAuthenticator.sln b/RiftAuthenticator.sln new file mode 100644 index 0000000..83edea9 --- /dev/null +++ b/RiftAuthenticator.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual C# Express 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RiftAuthenticator", "RiftAuthenticator\RiftAuthenticator.csproj", "{C0156421-FA95-4631-82C1-85AA7CC65B5E}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x86 = Debug|x86 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C0156421-FA95-4631-82C1-85AA7CC65B5E}.Debug|x86.ActiveCfg = Debug|x86 + {C0156421-FA95-4631-82C1-85AA7CC65B5E}.Debug|x86.Build.0 = Debug|x86 + {C0156421-FA95-4631-82C1-85AA7CC65B5E}.Release|x86.ActiveCfg = Release|x86 + {C0156421-FA95-4631-82C1-85AA7CC65B5E}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/RiftAuthenticator/App.xaml b/RiftAuthenticator/App.xaml new file mode 100644 index 0000000..1896040 --- /dev/null +++ b/RiftAuthenticator/App.xaml @@ -0,0 +1,8 @@ + + + + + diff --git a/RiftAuthenticator/App.xaml.cs b/RiftAuthenticator/App.xaml.cs new file mode 100644 index 0000000..ef3d387 --- /dev/null +++ b/RiftAuthenticator/App.xaml.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Windows; + +namespace RiftAuthenticator +{ + /// + /// Interaktionslogik für "App.xaml" + /// + public partial class App : Application + { + } +} diff --git a/RiftAuthenticator/Configuration.cs b/RiftAuthenticator/Configuration.cs new file mode 100644 index 0000000..8d5372c --- /dev/null +++ b/RiftAuthenticator/Configuration.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace RiftAuthenticator +{ + class Configuration + { + static readonly System.Text.Encoding Encoding = System.Text.Encoding.Default; + + const string DeviceIdKey = "DeviceId"; + const string SerialKeyKey = "SerialKey"; + const string SecretKeyKey = "SecretKey"; + const string TimeOffsetKey = "TimeOffset"; + + public string DeviceId { get; set; } + public string SerialKey { get; set; } + public string SecretKey { get; set; } + public long TimeOffset { get; set; } + + public string FormattedSerialKey + { + get + { + var result = new StringBuilder(); + for (int i = 0; i < SerialKey.Length; i += 4) + { + var remaining = Math.Min(SerialKey.Length - i, 4); + if (i != 0) + result.Append("-"); + result.Append(SerialKey.Substring(i, remaining)); + } + return result.ToString(); + } + } + + public bool IsEmpty + { + get + { + return string.IsNullOrEmpty(DeviceId); + } + } + + string AccountRegistryPath + { + get + { + return "SOFTWARE\\Public Domain\\Rift Authenticator\\Account 1"; + } + } + + public void Load() + { + using (var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(AccountRegistryPath)) + { + DeviceId = (string)key.GetValue(DeviceIdKey, string.Empty); + SerialKey = (string)key.GetValue(SerialKeyKey, string.Empty); + SecretKey = (string)key.GetValue(SecretKeyKey, string.Empty); + TimeOffset = Convert.ToInt64(key.GetValue(TimeOffsetKey, 0)); + } + } + + public void Save() + { + using (var key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(AccountRegistryPath)) + { + key.SetValue(DeviceIdKey, DeviceId ?? string.Empty); + key.SetValue(SerialKeyKey, SerialKey ?? string.Empty); + key.SetValue(SecretKeyKey, SecretKey ?? string.Empty); + key.SetValue(TimeOffsetKey, TimeOffset); + } + } + + public LoginToken CalculateToken() + { + var secretKey = Encoding.GetBytes(SecretKey); + var now = DateTime.Now; + var nowMillis = Util.timeToMillis(now); + long intervalNumber = (nowMillis + TimeOffset) / 30000; + // Value must be written as big endian byte buffer + var intervalByteBuffer = Mono.DataConverter.Pack("^l", intervalNumber); + + var digest = new System.Security.Cryptography.HMACSHA1(secretKey); + var hash = digest.ComputeHash(intervalByteBuffer); + + var rawTokenPos = hash[hash.Length - 1] & 0xF; + + // Raw token value must be read as big endian 32 bit integer value + var rawTokenValue = (long)(uint)Mono.DataConverter.Unpack("^I", hash, rawTokenPos)[0]; + var remainingMillis = ((intervalNumber + 1) * 30000 - TimeOffset) - nowMillis; + + var tokenValue = rawTokenValue % 100000000; + return new LoginToken(string.Format("{0:D08}", tokenValue), remainingMillis); + } + } +} diff --git a/RiftAuthenticator/CreateNewSecretKey.xaml b/RiftAuthenticator/CreateNewSecretKey.xaml new file mode 100644 index 0000000..d410672 --- /dev/null +++ b/RiftAuthenticator/CreateNewSecretKey.xaml @@ -0,0 +1,12 @@ + + + +