diff --git a/src/Console/App.config b/src/Console/App.config deleted file mode 100644 index 6bcb7b7a..00000000 --- a/src/Console/App.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/Console/Console.csproj b/src/Console/Console.csproj index 0ee8f0e5..628b7b50 100644 --- a/src/Console/Console.csproj +++ b/src/Console/Console.csproj @@ -1,59 +1,12 @@ - - - + + - Debug - AnyCPU - {DD4E5CD2-C9DD-4912-9A25-1600A07BF8C2} Exe - Bit.Console - Console - v4.6.1 - 512 - true - - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + netcoreapp2.0;net461 + - - - - - - - - + - - - - - - - - - - {ae082484-a34c-4b3a-a69f-49e5ef298b27} - Core - - - - \ No newline at end of file + + diff --git a/src/Console/Properties/AssemblyInfo.cs b/src/Console/Properties/AssemblyInfo.cs deleted file mode 100644 index 985b6e8e..00000000 --- a/src/Console/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +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("Console")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Console")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[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)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("dd4e5cd2-c9dd-4912-9a25-1600a07bf8c2")] - -// 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: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Core/Core.csproj b/src/Core/Core.csproj index 6c53e6d4..f309a616 100644 --- a/src/Core/Core.csproj +++ b/src/Core/Core.csproj @@ -1,136 +1,25 @@ - - - + + - Debug - AnyCPU - {AE082484-A34C-4B3A-A69F-49E5EF298B27} - Library - Properties + netstandard2.0;net461 Bit.Core Core - v4.6.1 - 512 - - - - true - full - false - bin\Debug\ - DEBUG;TRACE - prompt - 4 - - - pdbonly - true - bin\Release\ - TRACE - prompt - 4 + - - ..\..\packages\BouncyCastle.1.8.1\lib\BouncyCastle.Crypto.dll - - - ..\..\packages\Google.Apis.1.28.0\lib\net45\Google.Apis.dll - - - ..\..\packages\Google.Apis.Admin.Directory.directory_v1.1.28.0.934\lib\net45\Google.Apis.Admin.Directory.directory_v1.dll - - - ..\..\packages\Google.Apis.Auth.1.28.0\lib\net45\Google.Apis.Auth.dll - - - ..\..\packages\Google.Apis.Auth.1.28.0\lib\net45\Google.Apis.Auth.PlatformServices.dll - - - ..\..\packages\Google.Apis.Core.1.28.0\lib\net45\Google.Apis.Core.dll - - - ..\..\packages\Google.Apis.1.28.0\lib\net45\Google.Apis.PlatformServices.dll - - - ..\..\packages\Microsoft.Graph.1.5.1\lib\net45\Microsoft.Graph.dll - - - ..\..\packages\Microsoft.Graph.Core.1.6.1\lib\net45\Microsoft.Graph.Core.dll - - - ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.16.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll - - - ..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.16.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll - - - ..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll - - - + + + + + + + + - - - - + + - - - - - ..\..\packages\Zlib.Portable.Signed.1.11.0\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch+MonoAndroid\Zlib.Portable.dll - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Designer - - - - - \ No newline at end of file + + diff --git a/src/Core/Models/AzureConfiguration.cs b/src/Core/Models/AzureConfiguration.cs index cd7258a0..de9964f4 100644 --- a/src/Core/Models/AzureConfiguration.cs +++ b/src/Core/Models/AzureConfiguration.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.DirectoryServices; - -namespace Bit.Core.Models +namespace Bit.Core.Models { public class AzureConfiguration { diff --git a/src/Core/Models/EncryptedData.cs b/src/Core/Models/EncryptedData.cs index d1b79ebc..8d75a214 100644 --- a/src/Core/Models/EncryptedData.cs +++ b/src/Core/Models/EncryptedData.cs @@ -14,14 +14,18 @@ namespace Bit.Core.Models public EncryptedData(byte[] plainValue) { IV = RandomBytes(); +#if NET461 Value = ProtectedData.Protect(plainValue, IV, DataProtectionScope.LocalMachine); +#endif } public EncryptedData(string plainValue) { var bytes = Encoding.UTF8.GetBytes(plainValue); IV = RandomBytes(); +#if NET461 Value = ProtectedData.Protect(bytes, IV, DataProtectionScope.LocalMachine); +#endif } public byte[] Value { get; set; } @@ -29,12 +33,20 @@ namespace Bit.Core.Models public byte[] Decrypt() { +#if NET461 return ProtectedData.Unprotect(Value, IV, DataProtectionScope.LocalMachine); +#else + return new byte[0]; +#endif } public string DecryptToString() { +#if NET461 var bytes = ProtectedData.Unprotect(Value, IV, DataProtectionScope.LocalMachine); +#else + var bytes = new byte[0]; +#endif return Encoding.UTF8.GetString(bytes); } diff --git a/src/Core/Models/LdapConfiguration.cs b/src/Core/Models/LdapConfiguration.cs index 7fb509a3..1cd4e343 100644 --- a/src/Core/Models/LdapConfiguration.cs +++ b/src/Core/Models/LdapConfiguration.cs @@ -1,11 +1,8 @@ using Bit.Core.Services; -using Newtonsoft.Json; using System; -using System.Collections.Generic; +#if NET461 using System.DirectoryServices; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +#endif namespace Bit.Core.Models { @@ -18,6 +15,7 @@ namespace Bit.Core.Models public EncryptedData Password { get; set; } public Enums.DirectoryType Type { get; set; } = Enums.DirectoryType.ActiveDirectory; +#if NET461 public DirectoryEntry GetUserDirectoryEntry() { return GetPathedDirectoryEntry(SettingsService.Instance.Sync.Ldap.UserPath); @@ -56,6 +54,7 @@ namespace Bit.Core.Models return new DirectoryEntry(ServerPath(path), Username, Password.DecryptToString(), AuthenticationTypes.None); } } +#endif private string ServerPath(string path) { diff --git a/src/Core/Models/ServerConfiguration.cs b/src/Core/Models/ServerConfiguration.cs index 92be0bf8..6e33f2a4 100644 --- a/src/Core/Models/ServerConfiguration.cs +++ b/src/Core/Models/ServerConfiguration.cs @@ -1,11 +1,6 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; -using System.DirectoryServices; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - namespace Bit.Core.Models { public class ServerConfiguration diff --git a/src/Core/Models/SyncConfiguration.cs b/src/Core/Models/SyncConfiguration.cs index 15bedd34..da86bbcb 100644 --- a/src/Core/Models/SyncConfiguration.cs +++ b/src/Core/Models/SyncConfiguration.cs @@ -1,11 +1,4 @@ using Bit.Core.Enums; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.DirectoryServices; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Bit.Core.Models { diff --git a/src/Core/Properties/AssemblyInfo.cs b/src/Core/Properties/AssemblyInfo.cs deleted file mode 100644 index e9633e6a..00000000 --- a/src/Core/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,36 +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("Core")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("Core")] -[assembly: AssemblyCopyright("Copyright © 2017")] -[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)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("ae082484-a34c-4b3a-a69f-49e5ef298b27")] - -// 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: AssemblyFileVersion("1.0.0.0")] diff --git a/src/Core/Services/AuthService.cs b/src/Core/Services/AuthService.cs index 181af6e0..c1d67b1f 100644 --- a/src/Core/Services/AuthService.cs +++ b/src/Core/Services/AuthService.cs @@ -1,11 +1,7 @@ using Bit.Core.Enums; using Bit.Core.Models; using Bit.Core.Utilities; -using System; -using System.Collections.Generic; using System.Linq; -using System.Security; -using System.Text; using System.Threading.Tasks; namespace Bit.Core.Services diff --git a/src/Core/Services/AzureDirectoryService.cs b/src/Core/Services/AzureDirectoryService.cs index 84b67c29..c45dcc39 100644 --- a/src/Core/Services/AzureDirectoryService.cs +++ b/src/Core/Services/AzureDirectoryService.cs @@ -3,8 +3,6 @@ using System; using System.Threading.Tasks; using System.Collections.Generic; using Microsoft.Graph; -using System.Net.Http.Headers; -using System.Diagnostics; using System.Linq; using Bit.Core.Utilities; diff --git a/src/Core/Services/ControllerService.cs b/src/Core/Services/ControllerService.cs index 17fdfc8c..84efeb67 100644 --- a/src/Core/Services/ControllerService.cs +++ b/src/Core/Services/ControllerService.cs @@ -1,13 +1,7 @@ -using Bit.Core.Enums; -using Bit.Core.Models; -using Bit.Core.Utilities; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security; +using Bit.Core.Utilities; +#if NET461 using System.ServiceProcess; -using System.Text; -using System.Threading.Tasks; +#endif namespace Bit.Core.Services { @@ -17,7 +11,9 @@ namespace Bit.Core.Services private ControllerService() { +#if NET461 Controller = new ServiceController(Constants.ProgramName); +#endif } public static ControllerService Instance @@ -33,6 +29,7 @@ namespace Bit.Core.Services } } +#if NET461 public ServiceController Controller { get; private set; } public ServiceControllerStatus Status { @@ -42,7 +39,6 @@ namespace Bit.Core.Services return Controller.Status; } } - public string StatusString => Controller == null ? "Unavailable" : Status.ToString(); public bool Running => Status == ServiceControllerStatus.Running; public bool Paused => Status == ServiceControllerStatus.Paused; public bool Stopped => Status == ServiceControllerStatus.Stopped; @@ -51,9 +47,23 @@ namespace Bit.Core.Services Status == ServiceControllerStatus.PausePending || Status == ServiceControllerStatus.StartPending || Status == ServiceControllerStatus.StopPending; +#endif + public string StatusString + { + get + { +#if NET461 + return Controller == null ? "Unavailable" : Status.ToString(); +#else + return "Unavailable"; +#endif + } + } + public bool Start() { +#if NET461 if(Controller == null || !Stopped) { return false; @@ -61,17 +71,25 @@ namespace Bit.Core.Services Controller.Start(); return true; +#else + throw new System.Exception("Controller unavailable."); +#endif } public bool Stop() { +#if NET461 if(Controller == null || !Controller.CanStop) { return false; } Controller.Stop(); + return true; +#else + throw new System.Exception("Controller unavailable."); +#endif } } } diff --git a/src/Core/Services/LdapDirectoryService.cs b/src/Core/Services/LdapDirectoryService.cs index e2f13a49..276ab99a 100644 --- a/src/Core/Services/LdapDirectoryService.cs +++ b/src/Core/Services/LdapDirectoryService.cs @@ -1,4 +1,5 @@ -using Bit.Core.Enums; +#if NET461 +using Bit.Core.Enums; using Bit.Core.Models; using Bit.Core.Utilities; using System; @@ -397,3 +398,4 @@ namespace Bit.Core.Services } } } +#endif diff --git a/src/Core/Services/SettingsService.cs b/src/Core/Services/SettingsService.cs index edd5faba..b1366430 100644 --- a/src/Core/Services/SettingsService.cs +++ b/src/Core/Services/SettingsService.cs @@ -2,12 +2,8 @@ using Bit.Core.Utilities; using Newtonsoft.Json; using System; -using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Security; using System.Text; -using System.Threading.Tasks; namespace Bit.Core.Services { diff --git a/src/Core/Services/TokenService.cs b/src/Core/Services/TokenService.cs index 0412150c..5e7f9d43 100644 --- a/src/Core/Services/TokenService.cs +++ b/src/Core/Services/TokenService.cs @@ -1,11 +1,7 @@ using Bit.Core.Models; using Newtonsoft.Json.Linq; using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Cryptography; using System.Text; -using System.Threading.Tasks; namespace Bit.Core.Services { diff --git a/src/Core/Utilities/AzureAuthenticationProvider.cs b/src/Core/Utilities/AzureAuthenticationProvider.cs index f1fd44a7..7fc14fdc 100644 --- a/src/Core/Utilities/AzureAuthenticationProvider.cs +++ b/src/Core/Utilities/AzureAuthenticationProvider.cs @@ -23,11 +23,5 @@ namespace Bit.Core.Utilities var authResult = await authContext.AcquireTokenAsync("https://graph.microsoft.com/", creds); request.Headers.Add("Authorization", $"Bearer {authResult.AccessToken}"); } - - // ref: https://github.com/AzureAD/azure-activedirectory-library-for-dotnet/issues/511 - private static void SomeMethodToLinkPlatform() - { - var creds = new UserPasswordCredential("user", "pass"); - } } } diff --git a/src/Core/Utilities/Extensions.cs b/src/Core/Utilities/Extensions.cs index 784f406d..199d0488 100644 --- a/src/Core/Utilities/Extensions.cs +++ b/src/Core/Utilities/Extensions.cs @@ -1,11 +1,9 @@ using System; -using System.Collections.Generic; using System.Collections.Specialized; +#if NET461 using System.DirectoryServices; +#endif using System.Globalization; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Bit.Core.Utilities { @@ -23,6 +21,7 @@ namespace Bit.Core.Utilities return date.ToString("yyyyMMddHHmmss.f'Z'"); } +#if NET461 public static DateTime? ParseDateTime(this ResultPropertyCollection collection, string dateKey) { DateTime date; @@ -34,6 +33,7 @@ namespace Bit.Core.Utilities return null; } +#endif public static NameValueCollection ParseQueryString(this Uri uri) { diff --git a/src/Core/Utilities/Helpers.cs b/src/Core/Utilities/Helpers.cs index fd63631b..609bb0a7 100644 --- a/src/Core/Utilities/Helpers.cs +++ b/src/Core/Utilities/Helpers.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Security.Principal; -using System.Text; -using System.Threading.Tasks; +using System.Security.Principal; namespace Bit.Core.Utilities { @@ -11,9 +6,13 @@ namespace Bit.Core.Utilities { public static bool IsAdministrator() { +#if NET461 var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); return principal.IsInRole(WindowsBuiltInRole.Administrator); +#else + return false; +#endif } } } diff --git a/src/Core/Utilities/Sync.cs b/src/Core/Utilities/Sync.cs index cad0e0ec..894fa160 100644 --- a/src/Core/Utilities/Sync.cs +++ b/src/Core/Utilities/Sync.cs @@ -110,7 +110,11 @@ namespace Bit.Core.Utilities case Enums.DirectoryType.GSuite: return GSuiteDirectoryService.Instance; default: +#if NET461 return LdapDirectoryService.Instance; +#else + throw new Exception("LdapDirectoryService not supported."); +#endif } } diff --git a/src/Core/app.config b/src/Core/app.config deleted file mode 100644 index 6bcb7b7a..00000000 --- a/src/Core/app.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - diff --git a/src/Core/packages.config b/src/Core/packages.config deleted file mode 100644 index 2eab3722..00000000 --- a/src/Core/packages.config +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Service/App.config b/src/Service/App.config index 6bcb7b7a..fd3b4100 100644 --- a/src/Service/App.config +++ b/src/Service/App.config @@ -3,12 +3,4 @@ - - - - - - - -