diff options
author | sr55 <[email protected]> | 2016-04-29 21:24:57 +0100 |
---|---|---|
committer | sr55 <[email protected]> | 2016-04-29 21:24:57 +0100 |
commit | 04463e2dae2e7b86f2179a3df1a39e2085479a81 (patch) | |
tree | 6d35488bd41e8313c0291212d3eb1aa30d099355 /win/CS/HandBrakeTools | |
parent | c851af449ec95b3a39b40cf803bb41e317b73403 (diff) |
WinGui: Simple tool for generating a signed hash of the HandBrake download.
Diffstat (limited to 'win/CS/HandBrakeTools')
-rw-r--r-- | win/CS/HandBrakeTools/App.config | 6 | ||||
-rw-r--r-- | win/CS/HandBrakeTools/HandBrakeTools.csproj | 86 | ||||
-rw-r--r-- | win/CS/HandBrakeTools/Program.cs | 101 | ||||
-rw-r--r-- | win/CS/HandBrakeTools/Properties/AssemblyInfo.cs | 45 |
4 files changed, 238 insertions, 0 deletions
diff --git a/win/CS/HandBrakeTools/App.config b/win/CS/HandBrakeTools/App.config new file mode 100644 index 000000000..731f6de6c --- /dev/null +++ b/win/CS/HandBrakeTools/App.config @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8" ?> +<configuration> + <startup> + <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> + </startup> +</configuration>
\ No newline at end of file diff --git a/win/CS/HandBrakeTools/HandBrakeTools.csproj b/win/CS/HandBrakeTools/HandBrakeTools.csproj new file mode 100644 index 000000000..53cf0d96e --- /dev/null +++ b/win/CS/HandBrakeTools/HandBrakeTools.csproj @@ -0,0 +1,86 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <ProjectGuid>{3BAEBAC7-9042-4863-876F-C550ADCA66DC}</ProjectGuid> + <OutputType>Exe</OutputType> + <AppDesignerFolder>Properties</AppDesignerFolder> + <RootNamespace>HandBrakeTools</RootNamespace> + <AssemblyName>HandBrakeTools</AssemblyName> + <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> + <FileAlignment>512</FileAlignment> + <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> + <PublishUrl>publish\</PublishUrl> + <Install>true</Install> + <InstallFrom>Disk</InstallFrom> + <UpdateEnabled>false</UpdateEnabled> + <UpdateMode>Foreground</UpdateMode> + <UpdateInterval>7</UpdateInterval> + <UpdateIntervalUnits>Days</UpdateIntervalUnits> + <UpdatePeriodically>false</UpdatePeriodically> + <UpdateRequired>false</UpdateRequired> + <MapFileExtensions>true</MapFileExtensions> + <ApplicationRevision>0</ApplicationRevision> + <ApplicationVersion>1.0.0.%2a</ApplicationVersion> + <IsWebBootstrapper>false</IsWebBootstrapper> + <UseApplicationTrust>false</UseApplicationTrust> + <BootstrapperEnabled>true</BootstrapperEnabled> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugSymbols>true</DebugSymbols> + <DebugType>full</DebugType> + <Optimize>false</Optimize> + <OutputPath>bin\Debug\</OutputPath> + <DefineConstants>DEBUG;TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + <Prefer32Bit>false</Prefer32Bit> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + <PlatformTarget>AnyCPU</PlatformTarget> + <DebugType>pdbonly</DebugType> + <Optimize>true</Optimize> + <OutputPath>bin\Release\</OutputPath> + <DefineConstants>TRACE</DefineConstants> + <ErrorReport>prompt</ErrorReport> + <WarningLevel>4</WarningLevel> + </PropertyGroup> + <PropertyGroup> + <SignAssembly>false</SignAssembly> + </PropertyGroup> + <ItemGroup> + <Reference Include="System" /> + <Reference Include="System.Core" /> + <Reference Include="System.Xml.Linq" /> + <Reference Include="System.Data.DataSetExtensions" /> + <Reference Include="Microsoft.CSharp" /> + <Reference Include="System.Data" /> + <Reference Include="System.Net.Http" /> + <Reference Include="System.Xml" /> + </ItemGroup> + <ItemGroup> + <Compile Include="Program.cs" /> + <Compile Include="Properties\AssemblyInfo.cs" /> + </ItemGroup> + <ItemGroup> + <None Include="App.config" /> + </ItemGroup> + <ItemGroup> + <BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1"> + <Visible>False</Visible> + <ProductName>.NET Framework 3.5 SP1</ProductName> + <Install>false</Install> + </BootstrapperPackage> + </ItemGroup> + <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> + <!-- To modify your build process, add your task inside one of the targets below and uncomment it. + Other similar extension points exist, see Microsoft.Common.targets. + <Target Name="BeforeBuild"> + </Target> + <Target Name="AfterBuild"> + </Target> + --> +</Project>
\ No newline at end of file diff --git a/win/CS/HandBrakeTools/Program.cs b/win/CS/HandBrakeTools/Program.cs new file mode 100644 index 000000000..d4da0dbf5 --- /dev/null +++ b/win/CS/HandBrakeTools/Program.cs @@ -0,0 +1,101 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="Program.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// HandBrake Toolkit +// </summary> +// -------------------------------------------------------------------------------------------------------------------- + +namespace HandBrakeTools +{ + using System; + using System.Diagnostics; + using System.IO; + using System.Security.Cryptography; + + public class Program + { + static void Main(string[] args) + { + if (args.Length == 0) + { + Console.WriteLine("Invalid Comand. Either 'genkeys' or 'sign <filename>'"); + Console.Read(); + return; + } + + string command = args[0]; + string file = args.Length > 1 ? args[1] : null; + switch (command) + { + case "genkeys": + GenKeyFiles(); + return; + case "sign": + string hash = SignDownload(file); + Console.WriteLine(VerifyDownload(hash, file) ? "Passed Verification Test" : "Failed Verification Test"); + Console.WriteLine("Hash: " + hash); + File.WriteAllText("file.hash", hash); + return; + } + + Console.WriteLine("Done."); + Console.Read(); + } + + public static void GenKeyFiles() + { + RSACryptoServiceProvider provider = new RSACryptoServiceProvider { KeySize = 2048 }; + + using (StreamWriter sw = new StreamWriter("private.key")) + { + sw.Write(provider.ToXmlString(true)); + } + + using (StreamWriter sw = new StreamWriter("public.key")) + { + sw.Write(provider.ToXmlString(false)); + } + } + + public static string SignDownload(string updateFile) + { + RSACryptoServiceProvider provider = new RSACryptoServiceProvider(); + provider.FromXmlString(File.ReadAllText("private.key")); + byte[] signedBytes = provider.SignData(File.ReadAllBytes(updateFile), "SHA256"); + return Convert.ToBase64String(signedBytes); + } + + public static bool VerifyDownload(string signature, string updateFile) + { + // Sanity Checks + if (!File.Exists(updateFile)) + { + return false; + } + + if (string.IsNullOrEmpty(signature)) + { + return false; + } + + // Fetch our Public Key + string publicKey = File.ReadAllText("public.key"); + + // Verify the file against the Signature. + try + { + byte[] file = File.ReadAllBytes(updateFile); + RSACryptoServiceProvider verifyProfider = new RSACryptoServiceProvider(); + verifyProfider.FromXmlString(publicKey); + return verifyProfider.VerifyData(file, "SHA256", Convert.FromBase64String(signature)); + } + catch (Exception e) + { + Debug.WriteLine(e); + return false; + } + } + } +} diff --git a/win/CS/HandBrakeTools/Properties/AssemblyInfo.cs b/win/CS/HandBrakeTools/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..2ab186bf4 --- /dev/null +++ b/win/CS/HandBrakeTools/Properties/AssemblyInfo.cs @@ -0,0 +1,45 @@ +// -------------------------------------------------------------------------------------------------------------------- +// <copyright file="AssemblyInfo.cs" company="HandBrake Project (http://handbrake.fr)"> +// This file is part of the HandBrake source code - It may be used under the terms of the GNU General Public License. +// </copyright> +// <summary> +// Assembly Info +// </summary> +// <auto-generated/> +// -------------------------------------------------------------------------------------------------------------------- + +using System.Reflection; +using System.Resources; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Windows; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("HandBrake Toolkit")] +[assembly: AssemblyDescription("The toolkit app has utility classes for signing and building HandBrake")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("HandBrake Team")] +[assembly: AssemblyProduct("HandBrake")] +[assembly: AssemblyCopyright("Copyright © 2003-2016 HandBrake Team ")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: NeutralResourcesLanguage("")]
\ No newline at end of file |