From a20c3fa60009ed8144f3c55d6144c03c70cc0c48 Mon Sep 17 00:00:00 2001 From: Mathieu Morrissette Date: Thu, 24 Oct 2019 14:30:12 -0400 Subject: [PATCH] validate cipher signature helper in csharp wrapper --- devolutionscrypto/Cargo.toml | 2 +- wrappers/csharp/Enums.cs | 9 +++++++++ wrappers/csharp/GeneratePackage.py | 10 +++++----- wrappers/csharp/Utils.cs | 15 +++++++++++++++ .../Devolutions.Crypto.Android.csproj | 3 +++ .../Devolutions.Crypto.iOS.csproj | 3 +++ .../Devolutions.Crypto.Mac.csproj | 3 +++ 7 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 wrappers/csharp/Enums.cs diff --git a/devolutionscrypto/Cargo.toml b/devolutionscrypto/Cargo.toml index cb19c3fa7..bac303ecb 100644 --- a/devolutionscrypto/Cargo.toml +++ b/devolutionscrypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "devolutionscrypto" -version = "0.1.6" +version = "0.1.7" authors = ["Philippe Dugre ", "Mathieu Morrissette "] edition = "2018" readme = "../README.md" diff --git a/wrappers/csharp/Enums.cs b/wrappers/csharp/Enums.cs new file mode 100644 index 000000000..1f5ae476f --- /dev/null +++ b/wrappers/csharp/Enums.cs @@ -0,0 +1,9 @@ +namespace Devolutions.Cryptography +{ + enum DataType + { + Key = 1, + Cipher = 2, + Hash = 3 + } +} \ No newline at end of file diff --git a/wrappers/csharp/GeneratePackage.py b/wrappers/csharp/GeneratePackage.py index 06af2ae7d..3d5722373 100644 --- a/wrappers/csharp/GeneratePackage.py +++ b/wrappers/csharp/GeneratePackage.py @@ -130,7 +130,7 @@ if rdm: define += ";RDM" - command= subprocess.Popen([csc_path,"-out:./" + folder + "/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./" + folder + "/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", define ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "./" + folder + "/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) + command= subprocess.Popen([csc_path,"-out:./" + folder + "/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./" + folder + "/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", define ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "Enums.cs", "./" + folder + "/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) output = command.stdout.read().decode('utf-8') print(output) @@ -182,7 +182,7 @@ print("Building Managed Library...") # TODO create universal library with lipo - command= subprocess.Popen(["csc", "-out:./macos/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./macos/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:MAC" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "./macos/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) + command= subprocess.Popen(["csc", "-out:./macos/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./macos/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:MAC" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "Enums.cs", "./macos/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) output = command.stdout.read().decode('utf-8') print(output) @@ -256,7 +256,7 @@ print("Building Managed Library...") # TODO create universal library with lipo - command= subprocess.Popen(["csc", "-out:./ios/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./ios/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:IOS" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "./ios/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) + command= subprocess.Popen(["csc", "-out:./ios/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./ios/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:IOS" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "Enums.cs", "./ios/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) output = command.stdout.read().decode('utf-8') print(output) @@ -328,7 +328,7 @@ print("Building Managed Library...") - command = subprocess.Popen(["csc", "-out:./android/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./android/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:ANDROID" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "./android/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) + command = subprocess.Popen(["csc", "-out:./android/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./android/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:ANDROID" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "Enums.cs", "./android/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) output = command.stdout.read().decode('utf-8') print(output) @@ -385,7 +385,7 @@ print("Building Managed Library...") - command= subprocess.Popen(["csc", "-out:./linux/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./linux/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:LINUX" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "./linux/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) + command= subprocess.Popen(["csc", "-out:./linux/bin/Devolutions.Crypto.dll", "-debug:pdbonly" ,"-pdb:./linux/bin/Devolutions.Crypto.pdb", "-target:library", "-platform:anycpu", "-define:LINUX" ,"NativeError.cs", "Native.cs", "Native.Xamarin.cs", "ManagedError.cs", "Managed.cs", "KeyExchange.cs", "Utils.cs", "Enums.cs", "./linux/bin/AssemblyInfo.cs"], stdout=subprocess.PIPE) output = command.stdout.read().decode('utf-8') print(output) diff --git a/wrappers/csharp/Utils.cs b/wrappers/csharp/Utils.cs index b15ace24c..021fefc13 100644 --- a/wrappers/csharp/Utils.cs +++ b/wrappers/csharp/Utils.cs @@ -5,6 +5,21 @@ namespace Devolutions.Cryptography public static partial class Utils { + public static bool ValidateCiphertextSignature(byte[] data) + { + if(data == null) + { + return false; + } + + if(data.Length >= 8) + { + return data[0] == '\xD' && data[1] == '\xC' && data[2] == (int)DataType.Cipher && data[3] == 0 && data[4] == 0 && data[5] == 0; + } + + return false; + } + public static byte[] StringToByteArray(string data) { if (data == null) diff --git a/wrappers/csharp/nuget/Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android.csproj b/wrappers/csharp/nuget/Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android.csproj index f4349a4c1..fe2d48cf3 100644 --- a/wrappers/csharp/nuget/Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android.csproj +++ b/wrappers/csharp/nuget/Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android/Devolutions.Crypto.Android.csproj @@ -67,6 +67,9 @@ Utils.cs + + + Enums.cs diff --git a/wrappers/csharp/nuget/iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS.csproj b/wrappers/csharp/nuget/iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS.csproj index 96e711511..0c6400356 100644 --- a/wrappers/csharp/nuget/iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS.csproj +++ b/wrappers/csharp/nuget/iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS/Devolutions.Crypto.iOS.csproj @@ -62,6 +62,9 @@ Utils.cs + + + Enums.cs diff --git a/wrappers/csharp/nuget/macOS/Modern/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac.csproj b/wrappers/csharp/nuget/macOS/Modern/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac.csproj index 96121eeb2..a8033c5ee 100644 --- a/wrappers/csharp/nuget/macOS/Modern/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac.csproj +++ b/wrappers/csharp/nuget/macOS/Modern/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac/Devolutions.Crypto.Mac.csproj @@ -56,6 +56,9 @@ Utils.cs + + Enums.cs +