From d935772ec9dfd7a871f3264723224a4f02379e9d Mon Sep 17 00:00:00 2001 From: "Aaron (Qilong)" <173288704@qq.com> Date: Sun, 19 Nov 2023 14:16:29 -0800 Subject: [PATCH] Remove Sign Dynamo Project (#14597) --- src/Dynamo.All.sln | 6 - src/DynamoCrypto/Dynamo.cer | Bin 686 -> 0 bytes src/DynamoCrypto/DynamoCrypto.cs | 200 ------------------ src/DynamoCrypto/DynamoCrypto.csproj | 18 -- src/DynamoCrypto/Properties/AssemblyInfo.cs | 11 - src/Tools/SignDynamo/App.config | 6 - src/Tools/SignDynamo/Program.cs | 129 ----------- .../SignDynamo/Properties/AssemblyInfo.cs | 10 - src/Tools/SignDynamo/SignDynamo.csproj | 23 -- src/Tools/SignDynamo/SignDynamo.sln | 20 -- 10 files changed, 423 deletions(-) delete mode 100644 src/DynamoCrypto/Dynamo.cer delete mode 100644 src/DynamoCrypto/DynamoCrypto.cs delete mode 100644 src/DynamoCrypto/DynamoCrypto.csproj delete mode 100644 src/DynamoCrypto/Properties/AssemblyInfo.cs delete mode 100644 src/Tools/SignDynamo/App.config delete mode 100644 src/Tools/SignDynamo/Program.cs delete mode 100644 src/Tools/SignDynamo/Properties/AssemblyInfo.cs delete mode 100644 src/Tools/SignDynamo/SignDynamo.csproj delete mode 100644 src/Tools/SignDynamo/SignDynamo.sln diff --git a/src/Dynamo.All.sln b/src/Dynamo.All.sln index e5b0e4c705b..01c0f093706 100644 --- a/src/Dynamo.All.sln +++ b/src/Dynamo.All.sln @@ -103,8 +103,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamoCoreTests", "..\test\ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FFITarget", "..\test\Engine\FFITarget\FFITarget.csproj", "{C70FE632-5500-4C57-B3D6-9B5574137551}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DynamoCrypto", "DynamoCrypto\DynamoCrypto.csproj", "{96643E77-C786-498C-AAA9-80E449854CE9}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProtoTestFx", "..\test\Engine\ProtoTestFx\ProtoTestFx.csproj", "{2235F7CA-AB25-4177-92BC-4B574D2D5DF6}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ProtoTest", "..\test\Engine\ProtoTest\ProtoTest.csproj", "{6E1177DB-5E4F-4E2E-82E7-902437E56AED}" @@ -343,10 +341,6 @@ Global {C70FE632-5500-4C57-B3D6-9B5574137551}.Debug|Any CPU.Build.0 = Debug|Any CPU {C70FE632-5500-4C57-B3D6-9B5574137551}.Release|Any CPU.ActiveCfg = Release|Any CPU {C70FE632-5500-4C57-B3D6-9B5574137551}.Release|Any CPU.Build.0 = Release|Any CPU - {96643E77-C786-498C-AAA9-80E449854CE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {96643E77-C786-498C-AAA9-80E449854CE9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {96643E77-C786-498C-AAA9-80E449854CE9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {96643E77-C786-498C-AAA9-80E449854CE9}.Release|Any CPU.Build.0 = Release|Any CPU {2235F7CA-AB25-4177-92BC-4B574D2D5DF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {2235F7CA-AB25-4177-92BC-4B574D2D5DF6}.Debug|Any CPU.Build.0 = Debug|Any CPU {2235F7CA-AB25-4177-92BC-4B574D2D5DF6}.Release|Any CPU.ActiveCfg = Release|Any CPU diff --git a/src/DynamoCrypto/Dynamo.cer b/src/DynamoCrypto/Dynamo.cer deleted file mode 100644 index b9d26a00e6ba203023e673c16386922b510d0e10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 686 zcmXqLVp?U;#FVvwnTe5!N#NVhvOBU~(zASGY^?cbdPNy*t2Z$ayaLm-;0%%iWn88$wH3A743i>3KxJj~$0A|NXwDyZyS{M2`gbS9x6%{pMXs z;9$JOwlm~P_|j8VCY@gw$^~r~4%wru{Ccx2*EwlRbsL55LpzH4CJFxklb29G*Kc~M zzDD5EO(q*ppE_SZA^lg{5}^%7u_ny!i{$$b2$Up+7k^S$VO0IMK(1MNul);8=EfEV zpfkeCmcG3&7_Y2jVr&(g?)vWI<|2#LKigSu1vy3j5s}hVJGd^bdAD`p`LM~M3#OWX z&gr@7v?Q*h)?wAod)%91*x4G&o#zOqPw%{Z$?2AQ@;Rv}>Dq1Y&)>cmqjju2_lEUy z&L?|*JGH!)YJcW6NhC@3smG@fS&fr-A6>P&bbGh2_+mE$7Xv3?{L3=3SQ}V22vn!6 zF}4o=w&#>q(XM{ilgSH(vBY;1z9hx0&tRa#B%;1?O}>WZ)sP1UwfbypZhq_$k6*?l aQnk^h-@$L$+xG`n-n{Kr(6#B}0cQZMI2&>R diff --git a/src/DynamoCrypto/DynamoCrypto.cs b/src/DynamoCrypto/DynamoCrypto.cs deleted file mode 100644 index b79a6d90463..00000000000 --- a/src/DynamoCrypto/DynamoCrypto.cs +++ /dev/null @@ -1,200 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Security.Cryptography; -using System.Security.Cryptography.X509Certificates; - -namespace DynamoCrypto -{ - /// - /// This class contains static methods for finding Dynamo certificates in - /// a user, or a local machine's certificate store. It also has methods - /// for signing or verifying a file using public/private key pairs. These methods - /// use the DSA algorithm for verification. - /// - public class Utils - { - /// - /// Find a certificate in the key store and return the - /// private key, if one is available. - /// - /// The key container name. - /// An X509Certificate2 object containing a private key. - /// A byte array of the private key. - public static byte[] GetPrivateKeyFromCertificate(X509Certificate2 certificate) - { - byte[] privateBlob; - - if (certificate.HasPrivateKey) - { - var dsa = certificate.PrivateKey as DSACryptoServiceProvider; - - if (dsa == null) - { - Console.WriteLine("There was an error getting the private key from the certificate."); - return null; - } - - privateBlob = dsa.ExportCspBlob(true); - dsa.Dispose(); - } - else - { - Console.WriteLine("The certificate does not contain a private key."); - return null; - } - - return privateBlob; - } - - /// - /// Find a certificate in the key store and return the - /// public key, if one is available. - /// - /// The key container name. - /// A X509Certificate2 object containing a public key. - /// A byte array of the the public key or null if the certificate does not contain a public key. - public static byte[] GetPublicKeyFromCertificate(X509Certificate2 certificate) - { - var dsa = certificate.PublicKey.Key as DSACryptoServiceProvider; - - if (dsa == null) - { - Console.WriteLine("There was an error getting the public key from the certificate."); - return null; - } - - byte[] publicBlob = dsa.ExportCspBlob(false); - dsa.Dispose(); - - return publicBlob; - } - - /// - /// Generate a signature file using a private key. - /// - /// The file whose contents will be hashed. - /// The path of the generated signature file. - /// The private key. - public static void SignFile(string filePath, string signatureFilePath, byte[] privateBlob) - { - try - { - if (privateBlob.Length == 0) - { - throw new Exception("The specified private key is invalid."); - } - - byte[] hash = null; - - using (Stream fileStream = File.Open(filePath, FileMode.Open)) - { - SHA1 sha1 = new SHA1CryptoServiceProvider(); - hash = sha1.ComputeHash(fileStream); - } - - // Import the private key - var dsa = new DSACryptoServiceProvider(); - dsa.ImportCspBlob(privateBlob); - var rsaFormatter = new DSASignatureFormatter(dsa); - rsaFormatter.SetHashAlgorithm("SHA1"); - - // Create a signature based on the private key - byte[] signature = rsaFormatter.CreateSignature(hash); - - // Write the signature file - File.WriteAllBytes(signatureFilePath, signature); - } - catch (Exception e) - { - Debug.WriteLine(e); - } - } - - /// - /// Verify a file using a signature file and a public key. - /// - /// The file whose contents will be hashed. - /// The path of the signature file. - /// The public key. - /// True if the file is verified, otherwise false. - public static bool VerifyFile(string filePath, string signatureFilePath, byte[] publicBlob) - { - if (publicBlob.Length == 0) - return false; - - bool verified = false; - byte[] hash = null; - - try - { - // Compute a hash of the installer - using (Stream fileStream = File.Open(filePath, FileMode.Open)) - { - SHA1 sha1 = new SHA1CryptoServiceProvider(); - hash = sha1.ComputeHash(fileStream); - } - - // Import the public key - var dsa = new DSACryptoServiceProvider(); - dsa.ImportCspBlob(publicBlob); - - var dsaDeformatter = new DSASignatureDeformatter(dsa); - dsaDeformatter.SetHashAlgorithm("SHA1"); - - // Read the signature file - byte[] signature = File.ReadAllBytes(signatureFilePath); - - // Verify the signature against the hash of the installer - verified = dsaDeformatter.VerifySignature(hash, signature); - - Console.WriteLine("File verified: {0}", verified); - } - catch (Exception e) - { - Debug.WriteLine(e); - - return false; - } - - return verified; - } - - /// - /// Find a certificate in the key store. - /// - /// The key container name. - /// An X509Certificate2 or null if no certificate can be found. - public static X509Certificate2 FindCertificateForCurrentUser(string keyContainerName, StoreLocation location) - { - // Look for the Dynamo certificate in the certificate store. - // http://stackoverflow.com/questions/6304773/how-to-get-x509certificate-from-certificate-store-and-generate-xml-signature-dat - var store = new X509Store(location); - store.Open(OpenFlags.ReadOnly); - var cers = store.Certificates.Find(X509FindType.FindBySubjectName, keyContainerName, false); - - X509Certificate2 cer = null; - if (cers.Count == 0) - { - Console.WriteLine("The certificate could not be found in the certificate store."); - return null; - } - - cer = cers[0]; - return cer; - } - - /// - /// Install a certificate in the local machine certificate store. - /// - /// The installed certificate. - public static X509Certificate2 InstallCertificateForCurrentUser(string certPath) - { - var store = new X509Store(StoreLocation.CurrentUser); - store.Open(OpenFlags.ReadWrite); - var cert = new X509Certificate2(certPath); - store.Add(cert); - return cert; - } - } -} diff --git a/src/DynamoCrypto/DynamoCrypto.csproj b/src/DynamoCrypto/DynamoCrypto.csproj deleted file mode 100644 index e5dd1fd49d8..00000000000 --- a/src/DynamoCrypto/DynamoCrypto.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - {96643E77-C786-498C-AAA9-80E449854CE9} - Library - Properties - DynamoCrypto - DynamoCrypto - - - - PreserveNewest - - - - \ No newline at end of file diff --git a/src/DynamoCrypto/Properties/AssemblyInfo.cs b/src/DynamoCrypto/Properties/AssemblyInfo.cs deleted file mode 100644 index 95f6482d058..00000000000 --- a/src/DynamoCrypto/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Reflection; -using System.Runtime.InteropServices; - -// 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("DynamoCrypto")] -[assembly: AssemblyCulture("")] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("523c59b7-6fb8-4a80-a119-f031faf5cbd3")] diff --git a/src/Tools/SignDynamo/App.config b/src/Tools/SignDynamo/App.config deleted file mode 100644 index 4bfa0056185..00000000000 --- a/src/Tools/SignDynamo/App.config +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/src/Tools/SignDynamo/Program.cs b/src/Tools/SignDynamo/Program.cs deleted file mode 100644 index 32b83ca42e1..00000000000 --- a/src/Tools/SignDynamo/Program.cs +++ /dev/null @@ -1,129 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Security.Cryptography.X509Certificates; -using CommandLine; -using CommandLine.Text; -using DynamoCrypto; - -namespace SignDynamo -{ - internal class CMDLineOptions - { - [Option('i', "installer", Required = false, HelpText = "The path to the installer to sign.")] - public string Installer { get; set; } = String.Empty; - - [Option('h', "help", Required = false, HelpText = "Show this message and exit.")] - public bool ShowHelp { get; set; } - } - - class Program - { - private static byte[] privateBlob = null; - private static string installerPath; - private const string keyContainerName = "Dynamo"; - - static void Main(string[] args) - { - if (!ParseArguments(args)) - { - Console.WriteLine("Could not parse the input arguments."); - Console.WriteLine("Press any key to quit."); - Console.ReadKey(); - return; - } - - //First try at LocalMachine store location, if certificate is not installed check at CurrentUser - //store location. - var cert = Utils.FindCertificateForCurrentUser(keyContainerName, StoreLocation.LocalMachine); - if (cert == null) - { - cert = Utils.FindCertificateForCurrentUser(keyContainerName, StoreLocation.CurrentUser); - if (null == cert) - return; - } - - privateBlob = Utils.GetPrivateKeyFromCertificate(cert); - if (privateBlob == null) - { - return; - } - - var sigPath = Path.Combine(Path.GetDirectoryName(installerPath), - Path.GetFileNameWithoutExtension(installerPath) + ".sig"); - - Utils.SignFile(installerPath, sigPath, privateBlob); - - Console.WriteLine("Signature generation complete."); - } - - private static bool ParseArguments(IEnumerable args) - { - var showHelp = false; - var parser = new Parser(options => - { - options.IgnoreUnknownArguments = true; options.HelpWriter = Console.Out; - options.CaseSensitive = false; - }); - var notParsed = new List(); - - const string helpMessage = "Try 'SignDynamo --help' for more information."; - - ParserResult parserResult; - var lineOptions = new CMDLineOptions(); - var errors = new List(); - - try - { - parserResult = Parser.Default.ParseArguments(args) - .WithParsed(o => lineOptions = o) - .WithNotParsed(e => errors = (List)e); - - errors.ForEach(x => notParsed.Add(x.ToString())); - installerPath = lineOptions.Installer; - showHelp = lineOptions.ShowHelp; - } - catch (AggregateException e) - { - Console.WriteLine(e.Message); - Console.WriteLine(helpMessage); - return false; - } - - if (notParsed.Count > 0) - { - Console.WriteLine(String.Join(" ", notParsed.ToArray())); - return false; - } - - if (showHelp) - { - ShowHelp(parserResult); - return false; - } - - if (string.IsNullOrEmpty(installerPath)) - { - Console.WriteLine("You must specify a path to an installer to be signed when using the -s flag."); - return false; - } - - if (!File.Exists(installerPath)) - { - Console.Write("The specified installer path does not exist."); - return false; - } - - return true; - } - - private static void ShowHelp(ParserResult results) - { - Console.WriteLine("Usage: SignDynamo [OPTIONS]"); - Console.WriteLine("Generate a signature file for a dynamo installer."); - Console.WriteLine(); - Console.WriteLine("Options:"); - Console.WriteLine(HelpText.AutoBuild(results, null, null).ToString()); - } - } -} diff --git a/src/Tools/SignDynamo/Properties/AssemblyInfo.cs b/src/Tools/SignDynamo/Properties/AssemblyInfo.cs deleted file mode 100644 index 16077b933ab..00000000000 --- a/src/Tools/SignDynamo/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// 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("SignDynamo")] -[assembly: AssemblyCulture("")] -[assembly: Guid("bbe6abc4-a097-49a4-a687-b86dd2de7408")] diff --git a/src/Tools/SignDynamo/SignDynamo.csproj b/src/Tools/SignDynamo/SignDynamo.csproj deleted file mode 100644 index 4c8559aa961..00000000000 --- a/src/Tools/SignDynamo/SignDynamo.csproj +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - {A84E15A2-6735-4575-A1DA-7C64AF7582B1} - Exe - Properties - SignDynamo - SignDynamo - bin\$(Configuration)\ - - - - - - - {96643e77-c786-498c-aaa9-80e449854ce9} - DynamoCrypto - True - - - diff --git a/src/Tools/SignDynamo/SignDynamo.sln b/src/Tools/SignDynamo/SignDynamo.sln deleted file mode 100644 index 1a7af7e5bf1..00000000000 --- a/src/Tools/SignDynamo/SignDynamo.sln +++ /dev/null @@ -1,20 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2012 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SignDynamo", "SignDynamo.csproj", "{A84E15A2-6735-4575-A1DA-7C64AF7582B1}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|Any CPU = Debug|Any CPU - Release|Any CPU = Release|Any CPU - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {A84E15A2-6735-4575-A1DA-7C64AF7582B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A84E15A2-6735-4575-A1DA-7C64AF7582B1}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A84E15A2-6735-4575-A1DA-7C64AF7582B1}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A84E15A2-6735-4575-A1DA-7C64AF7582B1}.Release|Any CPU.Build.0 = Release|Any CPU - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal