diff --git a/PolicyStorageService/App.config b/PolicyStorageService/App.config index ec866df..c7a426a 100644 --- a/PolicyStorageService/App.config +++ b/PolicyStorageService/App.config @@ -7,11 +7,11 @@ - + - + diff --git a/PolicyStorageService/EncryptionUtil.cs b/PolicyStorageService/EncryptionUtil.cs index ee44b8f..c7f8c19 100644 --- a/PolicyStorageService/EncryptionUtil.cs +++ b/PolicyStorageService/EncryptionUtil.cs @@ -7,6 +7,8 @@ using System.IO; using System.Security.Cryptography; using System.Runtime.Remoting.Contexts; using System.Fabric; +using System.Runtime.InteropServices; +using System.Security; namespace PolicyStorageService { @@ -14,56 +16,38 @@ namespace PolicyStorageService { public static string Encrypt(string clearText) { - string EncryptionKey = GetEncryptionKey(); - byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); - using (Aes encryptor = Aes.Create()) - { - Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); - encryptor.Key = pdb.GetBytes(32); - encryptor.IV = pdb.GetBytes(16); - using (MemoryStream ms = new MemoryStream()) - { - using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write)) - { - cs.Write(clearBytes, 0, clearBytes.Length); - cs.Close(); - } - clearText = Convert.ToBase64String(ms.ToArray()); - } - } - return clearText; - } - public static string Decrypt(string cipherText) - { - string EncryptionKey = GetEncryptionKey(); - cipherText = cipherText.Replace(" ", "+"); - byte[] cipherBytes = Convert.FromBase64String(cipherText); - using (Aes encryptor = Aes.Create()) - { - Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 }); - encryptor.Key = pdb.GetBytes(32); - encryptor.IV = pdb.GetBytes(16); - using (MemoryStream ms = new MemoryStream()) - { - using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)) - { - cs.Write(cipherBytes, 0, cipherBytes.Length); - cs.Close(); - } - cipherText = Encoding.Unicode.GetString(ms.ToArray()); - } - } - return cipherText; + var thumbprint = GetCertThumbprint(); + return System.Fabric.Security.EncryptionUtility.EncryptText(clearText, thumbprint, "My"); } - public static string GetEncryptionKey() + public static string Decrypt(string cipherText) + { + // TODO: Make users of Decrypt use SecureString instead + return SecureStringToString(System.Fabric.Security.EncryptionUtility.DecryptText(cipherText)); + } + + public static string SecureStringToString(SecureString value) + { + IntPtr valuePtr = IntPtr.Zero; + try + { + valuePtr = Marshal.SecureStringToGlobalAllocUnicode(value); + return Marshal.PtrToStringUni(valuePtr); + } + finally + { + Marshal.ZeroFreeGlobalAllocUnicode(valuePtr); + } + } + + public static string GetCertThumbprint() { CodePackageActivationContext activationContext = FabricRuntime.GetActivationContext(); var configurationPackage = activationContext.GetConfigurationPackageObject("Config"); - string policyStorageEncryptionKey = configurationPackage.Settings.Sections["PolicyStorageSecurityConfig"].Parameters["PolicyStorageEncryptionKey"].Value; + string policyStorageCertThumbprint = configurationPackage.Settings.Sections["PolicyStorageSecurityConfig"].Parameters["PolicyStorageCertThumbprint"].Value; - return policyStorageEncryptionKey; + return policyStorageCertThumbprint; } } } diff --git a/PolicyStorageService/PolicyStorageService.csproj b/PolicyStorageService/PolicyStorageService.csproj index d127be7..f622d5a 100644 --- a/PolicyStorageService/PolicyStorageService.csproj +++ b/PolicyStorageService/PolicyStorageService.csproj @@ -43,64 +43,64 @@ ..\packages\Alienlab.NetExtensions.1.0.8\lib\Alienlab.NetExtensions.dll - ..\packages\Microsoft.ServiceFabric.Data.3.1.306\lib\net461\Microsoft.ServiceFabric.Data.dll + ..\packages\Microsoft.ServiceFabric.Data.3.3.638\lib\net461\Microsoft.ServiceFabric.Data.dll - - ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.3.306\lib\net461\Microsoft.ServiceFabric.Data.Extensions.dll + + ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.4.638\lib\net461\Microsoft.ServiceFabric.Data.Extensions.dll - ..\packages\Microsoft.ServiceFabric.Data.Interfaces.3.1.306\lib\net461\Microsoft.ServiceFabric.Data.Interfaces.dll + ..\packages\Microsoft.ServiceFabric.Data.Interfaces.3.3.638\lib\net461\Microsoft.ServiceFabric.Data.Interfaces.dll - ..\packages\Microsoft.ServiceFabric.Diagnostics.Internal.3.1.306\lib\net461\Microsoft.ServiceFabric.Diagnostics.dll + ..\packages\Microsoft.ServiceFabric.Diagnostics.Internal.3.3.638\lib\net461\Microsoft.ServiceFabric.Diagnostics.dll - ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.1.306\lib\net461\Microsoft.ServiceFabric.FabricTransport.dll + ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.3.638\lib\net461\Microsoft.ServiceFabric.FabricTransport.dll - ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.1.306\lib\net461\Microsoft.ServiceFabric.FabricTransport.V2.dll + ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.3.638\lib\net461\Microsoft.ServiceFabric.FabricTransport.V2.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\Microsoft.ServiceFabric.Internal.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\Microsoft.ServiceFabric.Internal.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\Microsoft.ServiceFabric.Internal.Strings.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\Microsoft.ServiceFabric.Internal.Strings.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\Microsoft.ServiceFabric.Preview.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\Microsoft.ServiceFabric.Preview.dll - ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.3.306\lib\net461\Microsoft.ServiceFabric.ReliableCollection.Interop.dll + ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.4.638\lib\net461\Microsoft.ServiceFabric.ReliableCollection.Interop.dll - ..\packages\Microsoft.ServiceFabric.Services.3.1.306\lib\net461\Microsoft.ServiceFabric.Services.dll + ..\packages\Microsoft.ServiceFabric.Services.3.3.638\lib\net461\Microsoft.ServiceFabric.Services.dll - ..\packages\Microsoft.ServiceFabric.Services.Remoting.3.1.306\lib\net461\Microsoft.ServiceFabric.Services.Remoting.dll + ..\packages\Microsoft.ServiceFabric.Services.Remoting.3.3.638\lib\net461\Microsoft.ServiceFabric.Services.Remoting.dll ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\packages\System.Diagnostics.DiagnosticSource.4.6.0-preview.19073.11\lib\net46\System.Diagnostics.DiagnosticSource.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\System.Fabric.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\System.Fabric.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\System.Fabric.Management.ServiceModel.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\System.Fabric.Management.ServiceModel.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\System.Fabric.Strings.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\System.Fabric.Strings.dll - - ..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll ..\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Extensions.dll diff --git a/PolicyStorageService/packages.config b/PolicyStorageService/packages.config index 6a7dcad..d44eafd 100644 --- a/PolicyStorageService/packages.config +++ b/PolicyStorageService/packages.config @@ -1,18 +1,18 @@  - - - - - - - - + + + + + + + + - - - + + + diff --git a/RestoreService/App.config b/RestoreService/App.config index 6af1af4..aadb96b 100644 --- a/RestoreService/App.config +++ b/RestoreService/App.config @@ -11,11 +11,11 @@ - + - + diff --git a/RestoreService/RestoreService.cs b/RestoreService/RestoreService.cs index ab61541..990bf58 100644 --- a/RestoreService/RestoreService.cs +++ b/RestoreService/RestoreService.cs @@ -31,7 +31,7 @@ namespace RestoreService private System.Threading.Timer timer; - long periodTimeSpan = 300000; + long periodTimeSpan = 300000; // 5 mins in ms public RestoreService(StatefulServiceContext context) : base(context) @@ -64,7 +64,7 @@ namespace RestoreService { // To trigger OnTimerTick method every minute - var periodTimeSpan = TimeSpan.FromMinutes(1); + var periodTimeSpan = TimeSpan.FromMinutes(5); timer.Change(0, Timeout.Infinite); @@ -83,7 +83,7 @@ namespace RestoreService } finally { - // Configure timer to trigger after 1 Min. + // Configure timer to trigger after 5 Min. timer.Change(this.periodTimeSpan, Timeout.Infinite); } } @@ -665,7 +665,7 @@ namespace RestoreService if (response.IsSuccessStatusCode) { var content = response.Content.ReadAsAsync().Result; - string restoreState = content["RestoreState"].ToString(); + string restoreState = (content != null) ? content["RestoreState"].ToString() : ""; return restoreState; } else diff --git a/RestoreService/RestoreService.csproj b/RestoreService/RestoreService.csproj index 18fa235..99a2f74 100644 --- a/RestoreService/RestoreService.csproj +++ b/RestoreService/RestoreService.csproj @@ -43,70 +43,70 @@ ..\packages\Alienlab.NetExtensions.1.0.8\lib\Alienlab.NetExtensions.dll - ..\packages\Microsoft.ServiceFabric.Data.3.1.306\lib\net461\Microsoft.ServiceFabric.Data.dll + ..\packages\Microsoft.ServiceFabric.Data.3.3.638\lib\net461\Microsoft.ServiceFabric.Data.dll - - ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.3.306\lib\net461\Microsoft.ServiceFabric.Data.Extensions.dll + + ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.4.638\lib\net461\Microsoft.ServiceFabric.Data.Extensions.dll - ..\packages\Microsoft.ServiceFabric.Data.Interfaces.3.1.306\lib\net461\Microsoft.ServiceFabric.Data.Interfaces.dll + ..\packages\Microsoft.ServiceFabric.Data.Interfaces.3.3.638\lib\net461\Microsoft.ServiceFabric.Data.Interfaces.dll - ..\packages\Microsoft.ServiceFabric.Diagnostics.Internal.3.1.306\lib\net461\Microsoft.ServiceFabric.Diagnostics.dll + ..\packages\Microsoft.ServiceFabric.Diagnostics.Internal.3.3.638\lib\net461\Microsoft.ServiceFabric.Diagnostics.dll - ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.1.306\lib\net461\Microsoft.ServiceFabric.FabricTransport.dll + ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.3.638\lib\net461\Microsoft.ServiceFabric.FabricTransport.dll - ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.1.306\lib\net461\Microsoft.ServiceFabric.FabricTransport.V2.dll + ..\packages\Microsoft.ServiceFabric.FabricTransport.Internal.3.3.638\lib\net461\Microsoft.ServiceFabric.FabricTransport.V2.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\Microsoft.ServiceFabric.Internal.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\Microsoft.ServiceFabric.Internal.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\Microsoft.ServiceFabric.Internal.Strings.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\Microsoft.ServiceFabric.Internal.Strings.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\Microsoft.ServiceFabric.Preview.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\Microsoft.ServiceFabric.Preview.dll - ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.3.306\lib\net461\Microsoft.ServiceFabric.ReliableCollection.Interop.dll + ..\packages\Microsoft.ServiceFabric.Data.Extensions.1.4.638\lib\net461\Microsoft.ServiceFabric.ReliableCollection.Interop.dll - ..\packages\Microsoft.ServiceFabric.Services.3.1.306\lib\net461\Microsoft.ServiceFabric.Services.dll + ..\packages\Microsoft.ServiceFabric.Services.3.3.638\lib\net461\Microsoft.ServiceFabric.Services.dll - ..\packages\Microsoft.ServiceFabric.Services.Remoting.3.1.306\lib\net461\Microsoft.ServiceFabric.Services.Remoting.dll + ..\packages\Microsoft.ServiceFabric.Services.Remoting.3.3.638\lib\net461\Microsoft.ServiceFabric.Services.Remoting.dll ..\packages\Microsoft.Win32.Primitives.4.3.0\lib\net46\Microsoft.Win32.Primitives.dll - - ..\packages\Newtonsoft.Json.11.0.2\lib\net45\Newtonsoft.Json.dll + + ..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll - - ..\packages\System.Diagnostics.DiagnosticSource.4.5.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + ..\packages\System.Diagnostics.DiagnosticSource.4.6.0-preview.19073.11\lib\net46\System.Diagnostics.DiagnosticSource.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\System.Fabric.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\System.Fabric.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\System.Fabric.Management.ServiceModel.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\System.Fabric.Management.ServiceModel.dll - ..\packages\Microsoft.ServiceFabric.6.2.306\lib\net461\System.Fabric.Strings.dll + ..\packages\Microsoft.ServiceFabric.6.4.638\lib\net461\System.Fabric.Strings.dll - - ..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll + + ..\packages\System.Net.Http.4.3.4\lib\net46\System.Net.Http.dll ..\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Extensions.dll - - ..\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Formatting.dll + + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll ..\packages\System.Net.Http.Formatting.Extension.5.2.3.0\lib\System.Net.Http.Primitives.dll diff --git a/RestoreService/packages.config b/RestoreService/packages.config index d0e1f7b..f8cad26 100644 --- a/RestoreService/packages.config +++ b/RestoreService/packages.config @@ -1,19 +1,19 @@  - - - - - - - - - + + + + + + + + + - - - + + + diff --git a/SFAppDRTool.sln b/SFAppDRTool.sln index d36cbce..e7528ae 100644 --- a/SFAppDRTool.sln +++ b/SFAppDRTool.sln @@ -20,6 +20,7 @@ Global EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Debug|Any CPU.ActiveCfg = Debug|x64 + {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Debug|Any CPU.Build.0 = Debug|x64 {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Debug|x64.ActiveCfg = Debug|x64 {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Debug|x64.Build.0 = Debug|x64 {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Debug|x64.Deploy.0 = Debug|x64 @@ -28,6 +29,7 @@ Global {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Release|x64.Build.0 = Release|x64 {24AA149A-8ECC-434A-8F3F-655D1A2B33B3}.Release|x64.Deploy.0 = Release|x64 {39BB8062-DD86-4133-94FF-08CB85037AC9}.Debug|Any CPU.ActiveCfg = Debug|x64 + {39BB8062-DD86-4133-94FF-08CB85037AC9}.Debug|Any CPU.Build.0 = Debug|x64 {39BB8062-DD86-4133-94FF-08CB85037AC9}.Debug|x64.ActiveCfg = Debug|x64 {39BB8062-DD86-4133-94FF-08CB85037AC9}.Debug|x64.Build.0 = Debug|x64 {39BB8062-DD86-4133-94FF-08CB85037AC9}.Release|Any CPU.ActiveCfg = Release|x64 @@ -42,6 +44,7 @@ Global {2AA68720-BB20-48A8-9977-52CA3D5E0255}.Release|x64.ActiveCfg = Release|Any CPU {2AA68720-BB20-48A8-9977-52CA3D5E0255}.Release|x64.Build.0 = Release|Any CPU {FB6F9FE6-FD39-4D4D-AB99-711759A15A29}.Debug|Any CPU.ActiveCfg = Debug|x64 + {FB6F9FE6-FD39-4D4D-AB99-711759A15A29}.Debug|Any CPU.Build.0 = Debug|x64 {FB6F9FE6-FD39-4D4D-AB99-711759A15A29}.Debug|x64.ActiveCfg = Debug|x64 {FB6F9FE6-FD39-4D4D-AB99-711759A15A29}.Debug|x64.Build.0 = Debug|x64 {FB6F9FE6-FD39-4D4D-AB99-711759A15A29}.Release|Any CPU.ActiveCfg = Release|x64 diff --git a/SFAppDRToolApplication/ApplicationParameters/Cloud.xml b/SFAppDRToolApplication/ApplicationParameters/Cloud.xml index 12d51bc..fa4eaf1 100644 --- a/SFAppDRToolApplication/ApplicationParameters/Cloud.xml +++ b/SFAppDRToolApplication/ApplicationParameters/Cloud.xml @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/SFAppDRToolApplication/ApplicationParameters/Local.1Node.xml b/SFAppDRToolApplication/ApplicationParameters/Local.1Node.xml index 9931f84..830ca81 100644 --- a/SFAppDRToolApplication/ApplicationParameters/Local.1Node.xml +++ b/SFAppDRToolApplication/ApplicationParameters/Local.1Node.xml @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/SFAppDRToolApplication/ApplicationParameters/Local.5Node.xml b/SFAppDRToolApplication/ApplicationParameters/Local.5Node.xml index 9931f84..830ca81 100644 --- a/SFAppDRToolApplication/ApplicationParameters/Local.5Node.xml +++ b/SFAppDRToolApplication/ApplicationParameters/Local.5Node.xml @@ -8,6 +8,6 @@ - + \ No newline at end of file diff --git a/SFAppDRToolApplication/PublishProfiles/Cloud.xml b/SFAppDRToolApplication/PublishProfiles/Cloud.xml index fab9a3a..6c0fc5b 100644 --- a/SFAppDRToolApplication/PublishProfiles/Cloud.xml +++ b/SFAppDRToolApplication/PublishProfiles/Cloud.xml @@ -20,13 +20,7 @@ AzureActiveDirectory="true" ServerCertThumbprint="0123456789012345678901234567890123456789" /> --> - + \ No newline at end of file diff --git a/WebInterface/WebInterface.csproj b/WebInterface/WebInterface.csproj index 14a7486..1e44369 100644 --- a/WebInterface/WebInterface.csproj +++ b/WebInterface/WebInterface.csproj @@ -8,22 +8,22 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + +