1
0
mirror of https://github.com/bitwarden/directory-connector synced 2025-12-05 23:53:21 +00:00

Compare commits

...

11 Commits

Author SHA1 Message Date
Kyle Spearrin
2c2f1921c1 filter users from filtered groups 2017-12-12 15:55:24 -05:00
Kyle Spearrin
1e5e28e2b6 use proper entry for group user search 2017-12-11 11:29:08 -05:00
Kyle Spearrin
41f8263a7c setup reference file manually. 2017-12-07 12:17:26 -05:00
Kyle Spearrin
818a4db96e update libs. convert service to new csproj format 2017-12-07 11:53:17 -05:00
Kyle Spearrin
51ab260fe6 remove framework netcore2.0 target for now
- setup installer does not pick correct output
2017-12-06 12:31:27 -05:00
Kyle Spearrin
be393f7a63 client side filtering for azure ad 2017-12-05 09:10:24 -05:00
Kyle Spearrin
28c0509886 null checks 2017-11-30 15:50:05 -05:00
Kyle Spearrin
835c9f9cac added clear cache to menu option 9 2017-11-10 15:36:09 -05:00
Kyle Spearrin
6e4e78c30e proper default namespace 2017-10-24 17:21:19 -04:00
Kyle Spearrin
7d3ea444f4 convert projects to netstandard lib & netcore app 2017-10-24 17:13:56 -04:00
Kyle Spearrin
fef8bd1e00 switch to bearer auth headers 2017-10-17 08:39:14 -04:00
29 changed files with 1546 additions and 2588 deletions

View File

@@ -1,13 +1,13 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.10
VisualStudioVersion = 15.0.27004.2009
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Console", "src\Console\Console.csproj", "{DD4E5CD2-C9DD-4912-9A25-1600A07BF8C2}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Console", "src\Console\Console.csproj", "{DD4E5CD2-C9DD-4912-9A25-1600A07BF8C2}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Core", "src\Core\Core.csproj", "{AE082484-A34C-4B3A-A69F-49E5EF298B27}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Core", "src\Core\Core.csproj", "{AE082484-A34C-4B3A-A69F-49E5EF298B27}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Service", "src\Service\Service.csproj", "{A8FD8CED-5510-4EBD-AACE-5D3CBB7516DB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Service", "src\Service\Service.csproj", "{A8FD8CED-5510-4EBD-AACE-5D3CBB7516DB}"
EndProject
Project("{54435603-DBB4-11D2-8724-00A0C9A8B90C}") = "Setup", "src\Setup\Setup.vdproj", "{4D852DF8-9327-43D0-93AB-FA68D4F3414B}"
EndProject

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -1,59 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{DD4E5CD2-C9DD-4912-9A25-1600A07BF8C2}</ProjectGuid>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<RootNamespace>Bit.Console</RootNamespace>
<AssemblyName>Console</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</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>
</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>
<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" />
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{ae082484-a34c-4b3a-a69f-49e5ef298b27}</Project>
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View File

@@ -62,7 +62,8 @@ namespace Bit.Console
Con.WriteLine("6. Sync directory");
Con.WriteLine("7. Control background service");
Con.WriteLine("8. Configure environment");
Con.WriteLine("9. Exit");
Con.WriteLine("9. Clear sync cache");
Con.WriteLine("10. Exit");
Con.WriteLine();
Con.Write("What would you like to do? ");
selection = Con.ReadLine();
@@ -112,15 +113,16 @@ namespace Bit.Console
await ConfigEnvironmentAsync();
break;
case "9":
case "cache":
case "clearcache":
await ClearCacheAsync();
break;
case "10":
case "exit":
case "quit":
case "q":
_exit = true;
break;
case "cache":
case "clearcache":
await ClearCacheAsync();
break;
default:
Con.WriteLine("Unknown command.");
break;

View File

@@ -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")]

View File

@@ -1,136 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{AE082484-A34C-4B3A-A69F-49E5EF298B27}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<TargetFramework>net461</TargetFramework>
<RootNamespace>Bit.Core</RootNamespace>
<AssemblyName>Core</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="BouncyCastle.Crypto, Version=1.8.1.0, Culture=neutral, PublicKeyToken=0e99375e54769942">
<HintPath>..\..\packages\BouncyCastle.1.8.1\lib\BouncyCastle.Crypto.dll</HintPath>
</Reference>
<Reference Include="Google.Apis, Version=1.28.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\Google.Apis.1.28.0\lib\net45\Google.Apis.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.Admin.Directory.directory_v1, Version=1.28.0.934, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\Google.Apis.Admin.Directory.directory_v1.1.28.0.934\lib\net45\Google.Apis.Admin.Directory.directory_v1.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.Auth, Version=1.28.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\Google.Apis.Auth.1.28.0\lib\net45\Google.Apis.Auth.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.Auth.PlatformServices, Version=1.28.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\Google.Apis.Auth.1.28.0\lib\net45\Google.Apis.Auth.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.Core, Version=1.28.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\Google.Apis.Core.1.28.0\lib\net45\Google.Apis.Core.dll</HintPath>
</Reference>
<Reference Include="Google.Apis.PlatformServices, Version=1.28.0.0, Culture=neutral, PublicKeyToken=4b01fa6e34db77ab, processorArchitecture=MSIL">
<HintPath>..\..\packages\Google.Apis.1.28.0\lib\net45\Google.Apis.PlatformServices.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Graph, Version=1.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Graph.1.5.1\lib\net45\Microsoft.Graph.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Graph.Core, Version=1.6.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.Graph.Core.1.6.1\lib\net45\Microsoft.Graph.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=3.16.0.14, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.16.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory.Platform, Version=3.16.0.14, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.3.16.0\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<PackageReference Include="Google.Apis.Admin.Directory.directory_v1" Version="1.31.0.1061" />
<PackageReference Include="Microsoft.Graph" Version="1.6.2" />
<PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="3.17.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.1.3" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System.DirectoryServices" />
<Reference Include="System.DirectoryServices.Protocols" />
<Reference Include="System.Security" />
<Reference Include="System.ServiceProcess" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Security" />
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="Zlib.Portable, Version=1.11.0.0, Culture=neutral, PublicKeyToken=431cba815f6a8b5b, processorArchitecture=MSIL">
<HintPath>..\..\packages\Zlib.Portable.Signed.1.11.0\lib\portable-net4+sl5+wp8+win8+wpa81+MonoTouch+MonoAndroid\Zlib.Portable.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Enums\DirectoryType.cs" />
<Compile Include="Enums\OrganizationUserType.cs" />
<Compile Include="Enums\OrganizationUserStatusType.cs" />
<Compile Include="Enums\TwoFactorProviderType.cs" />
<Compile Include="Enums\UserAccountControl.cs" />
<Compile Include="Models\ApiError.cs" />
<Compile Include="Models\ApiResult.cs" />
<Compile Include="Models\Entry.cs" />
<Compile Include="Models\GSuiteConfiguration.cs" />
<Compile Include="Models\ImportRequest.cs" />
<Compile Include="Models\AzureConfiguration.cs" />
<Compile Include="Models\ServerConfiguration.cs" />
<Compile Include="Models\Organization.cs" />
<Compile Include="Models\ProfileOrganizationResponse.cs" />
<Compile Include="Models\SyncConfiguration.cs" />
<Compile Include="Models\LdapConfiguration.cs" />
<Compile Include="Models\LoginResult.cs" />
<Compile Include="Models\ErrorResponse.cs" />
<Compile Include="Models\EncryptedData.cs" />
<Compile Include="Models\SyncResult.cs" />
<Compile Include="Models\TokenRequest.cs" />
<Compile Include="Models\ProfileResponse.cs" />
<Compile Include="Models\TokenResponse.cs" />
<Compile Include="Models\TwoFactorEmailRequest.cs" />
<Compile Include="Services\ApiService.cs" />
<Compile Include="Services\GSuiteDirectoryService.cs" />
<Compile Include="Services\ControllerService.cs" />
<Compile Include="Services\AzureDirectoryService.cs" />
<Compile Include="Services\LdapDirectoryService.cs" />
<Compile Include="Services\IDirectoryService.cs" />
<Compile Include="Services\SettingsService.cs" />
<Compile Include="Utilities\AzureAuthenticationProvider.cs" />
<Compile Include="Utilities\Constants.cs" />
<Compile Include="Utilities\Crypto.cs" />
<Compile Include="Services\TokenService.cs" />
<Compile Include="Services\AuthService.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Utilities\Extensions.cs" />
<Compile Include="Utilities\Helpers.cs" />
<Compile Include="Utilities\Sync.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.DirectoryServices;
namespace Bit.Core.Models
namespace Bit.Core.Models
{
public class AzureConfiguration
{

View File

@@ -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);
}

View File

@@ -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)
{

View File

@@ -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

View File

@@ -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
{

View File

@@ -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")]

View File

@@ -90,7 +90,7 @@ namespace Bit.Core.Services
Content = new StringContent(stringContent, Encoding.UTF8, "application/json"),
};
requestMessage.Headers.Add("Authorization", $"Bearer3 {TokenService.Instance.AccessToken}");
requestMessage.Headers.Add("Authorization", $"Bearer {TokenService.Instance.AccessToken}");
try
{
@@ -122,7 +122,7 @@ namespace Bit.Core.Services
RequestUri = new Uri(string.Concat(SettingsService.Instance.ApiBaseUrl, "/accounts/profile")),
};
requestMessage.Headers.Add("Authorization", $"Bearer3 {TokenService.Instance.AccessToken}");
requestMessage.Headers.Add("Authorization", $"Bearer {TokenService.Instance.AccessToken}");
try
{

View File

@@ -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

View File

@@ -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;
@@ -59,13 +57,20 @@ namespace Bit.Core.Services
List<GroupEntry> groups = null;
if(SettingsService.Instance.Sync.SyncGroups)
{
groups = await GetGroupsAsync(force || (users?.Any(u => !u.Deleted && !u.Disabled) ?? false));
var filter = CreateSetFromFilter(SettingsService.Instance.Sync.GroupFilter);
groups = await GetGroupsAsync(force || (users?.Any(u => !u.Deleted && !u.Disabled) ?? false), filter);
if(filter != null && users != null)
{
users = users.Where(u => u.Disabled || u.Deleted ||
groups.Any(g => g.UserMemberExternalIds.Contains(u.ExternalId))).ToList();
}
}
return new Tuple<List<GroupEntry>, List<UserEntry>>(groups, users);
}
private async static Task<List<GroupEntry>> GetGroupsAsync(bool force = false)
private async static Task<List<GroupEntry>> GetGroupsAsync(bool force, Tuple<bool, HashSet<string>> filter)
{
if(!SettingsService.Instance.Sync.SyncGroups)
{
@@ -93,7 +98,7 @@ namespace Bit.Core.Services
try
{
var delataRequest = _graphClient.Groups.Delta().Request().Filter(SettingsService.Instance.Sync.GroupFilter);
var delataRequest = _graphClient.Groups.Delta().Request();
if(!getFullResults)
{
delataRequest.QueryOptions.Add(new QueryOption("$deltatoken", SettingsService.Instance.GroupDeltaToken));
@@ -106,6 +111,11 @@ namespace Bit.Core.Services
{
foreach(var group in groupsDelta)
{
if(FilterOutResult(filter, group.DisplayName))
{
continue;
}
var entry = await BuildGroupAsync(group);
entries.Add(entry);
}
@@ -136,16 +146,21 @@ namespace Bit.Core.Services
}
catch { }
if(getFullResults || (!getFullResults && !changedGroupIds.Any()))
if(getFullResults || !changedGroupIds.Any())
{
return entries;
}
var groups = await _graphClient.Groups.Request().Filter(SettingsService.Instance.Sync.GroupFilter).GetAsync();
var groups = await _graphClient.Groups.Request().GetAsync();
while(true)
{
foreach(var group in groups)
{
if(FilterOutResult(filter, group.DisplayName))
{
continue;
}
var entry = await BuildGroupAsync(group);
entries.Add(entry);
}
@@ -188,7 +203,7 @@ namespace Bit.Core.Services
return entry;
}
private async static Task<List<UserEntry>> GetUsersAsync(bool force = false)
private async static Task<List<UserEntry>> GetUsersAsync(bool force)
{
if(!SettingsService.Instance.Sync.SyncUsers)
{
@@ -211,6 +226,7 @@ namespace Bit.Core.Services
}
var entries = new List<UserEntry>();
var filter = CreateSetFromFilter(SettingsService.Instance.Sync.UserFilter);
var userRequest = _graphClient.Users.Delta();
IUserDeltaCollectionPage users = null;
@@ -219,7 +235,7 @@ namespace Bit.Core.Services
{
try
{
var delataRequest = userRequest.Request().Filter(SettingsService.Instance.Sync.UserFilter);
var delataRequest = userRequest.Request();
delataRequest.QueryOptions.Add(new QueryOption("$deltatoken", SettingsService.Instance.UserDeltaToken));
users = await delataRequest.GetAsync();
}
@@ -231,7 +247,7 @@ namespace Bit.Core.Services
if(users == null)
{
users = await userRequest.Request().Filter(SettingsService.Instance.Sync.UserFilter).GetAsync();
users = await userRequest.Request().GetAsync();
}
while(true)
@@ -246,8 +262,12 @@ namespace Bit.Core.Services
Disabled = !user.AccountEnabled.GetValueOrDefault(true)
};
object deleted;
if(user.AdditionalData.TryGetValue("@removed", out deleted) && deleted.ToString().Contains("changed"))
if(FilterOutResult(filter, entry.Email))
{
continue;
}
if(user.AdditionalData.TryGetValue("@removed", out object deleted) && deleted.ToString().Contains("changed"))
{
entry.Deleted = true;
}
@@ -261,8 +281,7 @@ namespace Bit.Core.Services
if(users.NextPageRequest == null)
{
object deltaLink;
if(users.AdditionalData.TryGetValue("@odata.deltaLink", out deltaLink))
if(users.AdditionalData.TryGetValue("@odata.deltaLink", out object deltaLink))
{
var deltaUriQuery = new Uri(deltaLink.ToString()).ParseQueryString();
if(deltaUriQuery["$deltatoken"] != null)
@@ -280,5 +299,55 @@ namespace Bit.Core.Services
return entries;
}
private static Tuple<bool, HashSet<string>> CreateSetFromFilter(string filter)
{
if(string.IsNullOrWhiteSpace(filter))
{
return null;
}
var parts = filter.Split(':');
if(parts.Length != 2)
{
return null;
}
var exclude = true;
if(string.Equals(parts[0].Trim(), "include", StringComparison.InvariantCultureIgnoreCase))
{
exclude = false;
}
else if(string.Equals(parts[0].Trim(), "exclude", StringComparison.InvariantCultureIgnoreCase))
{
exclude = true;
}
else
{
return null;
}
var list = new HashSet<string>(parts[1].Split(',').Select(p => p.Trim()));
return new Tuple<bool, HashSet<string>>(exclude, list);
}
private static bool FilterOutResult(Tuple<bool, HashSet<string>> filter, string result)
{
if(filter != null)
{
// excluded
if(filter.Item1 && filter.Item2.Contains(result, StringComparer.InvariantCultureIgnoreCase))
{
return true;
}
// included
else if(!filter.Item1 && !filter.Item2.Contains(result, StringComparer.InvariantCultureIgnoreCase))
{
return true;
}
}
return false;
}
}
}

View File

@@ -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
}
}
}

View File

@@ -1,4 +1,5 @@
using Bit.Core.Enums;
#if NET461
using Bit.Core.Enums;
using Bit.Core.Models;
using Bit.Core.Utilities;
using System;
@@ -83,7 +84,7 @@ namespace Bit.Core.Services
throw new ApplicationException("Not authenticated.");
}
var entry = SettingsService.Instance.Server.Ldap.GetGroupDirectoryEntry();
var groupEntry = SettingsService.Instance.Server.Ldap.GetGroupDirectoryEntry();
var originalFilter = BuildBaseFilter(SettingsService.Instance.Sync.Ldap.GroupObjectClass,
SettingsService.Instance.Sync.GroupFilter);
@@ -93,8 +94,8 @@ namespace Bit.Core.Services
var searchSinceRevision = filter != revisionFilter;
filter = revisionFilter;
Console.WriteLine("Group search: {0} => {1}", entry.Path, filter);
var searcher = new DirectorySearcher(entry, filter);
Console.WriteLine("Group search: {0} => {1}", groupEntry.Path, filter);
var searcher = new DirectorySearcher(groupEntry, filter);
var result = searcher.FindAll();
var initialSearchGroupIds = new List<string>();
@@ -109,13 +110,14 @@ namespace Bit.Core.Services
}
else if(searchSinceRevision)
{
searcher = new DirectorySearcher(entry, originalFilter);
searcher = new DirectorySearcher(groupEntry, originalFilter);
result = searcher.FindAll();
}
var userEntry = SettingsService.Instance.Server.Ldap.GetUserDirectoryEntry();
var userFilter = BuildBaseFilter(SettingsService.Instance.Sync.Ldap.UserObjectClass,
SettingsService.Instance.Sync.UserFilter);
var userSearcher = new DirectorySearcher(entry, userFilter);
var userSearcher = new DirectorySearcher(userEntry, userFilter);
var userResult = userSearcher.FindAll();
var userIdsDict = MakeIdIndex(userResult);
@@ -237,13 +239,13 @@ namespace Bit.Core.Services
throw new ApplicationException("Not authenticated.");
}
var entry = SettingsService.Instance.Server.Ldap.GetUserDirectoryEntry();
var userEntry = SettingsService.Instance.Server.Ldap.GetUserDirectoryEntry();
var filter = BuildBaseFilter(SettingsService.Instance.Sync.Ldap.UserObjectClass,
SettingsService.Instance.Sync.UserFilter);
filter = BuildRevisionFilter(filter, force, SettingsService.Instance.LastUserSyncDate);
Console.WriteLine("User search: {0} => {1}", entry.Path, filter);
var searcher = new DirectorySearcher(entry, filter);
Console.WriteLine("User search: {0} => {1}", userEntry.Path, filter);
var searcher = new DirectorySearcher(userEntry, filter);
var result = searcher.FindAll();
var users = new List<UserEntry>();
@@ -397,3 +399,4 @@ namespace Bit.Core.Services
}
}
}
#endif

View File

@@ -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
{

View File

@@ -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
{
@@ -42,7 +38,7 @@ namespace Bit.Core.Services
}
var encBytes = SettingsService.Instance.AccessToken;
if(encBytes != null)
if(encBytes?.Value != null)
{
_accessToken = Encoding.ASCII.GetString(encBytes.Decrypt());
}

View File

@@ -18,16 +18,10 @@ namespace Bit.Core.Utilities
var authContext = new AuthenticationContext(
$"https://login.windows.net/{SettingsService.Instance.Server.Azure.Tenant}/oauth2/token");
var creds = new ClientCredential(SettingsService.Instance.Server.Azure.Id,
SettingsService.Instance.Server.Azure.Secret.DecryptToString());
var secret = SettingsService.Instance.Server.Azure.Secret.DecryptToString();
var creds = new ClientCredential(SettingsService.Instance.Server.Azure.Id, secret);
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");
}
}
}

View File

@@ -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)
{

View File

@@ -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
}
}
}

View File

@@ -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
}
}

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="BouncyCastle" version="1.8.1" targetFramework="net452" />
<package id="Google.Apis" version="1.28.0" targetFramework="net452" />
<package id="Google.Apis.Admin.Directory.directory_v1" version="1.28.0.934" targetFramework="net452" />
<package id="Google.Apis.Auth" version="1.28.0" targetFramework="net452" />
<package id="Google.Apis.Core" version="1.28.0" targetFramework="net452" />
<package id="Microsoft.Graph" version="1.5.1" targetFramework="net452" />
<package id="Microsoft.Graph.Core" version="1.6.1" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="3.16.0" targetFramework="net452" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net452" />
<package id="System.Net.Http" version="4.3.2" targetFramework="net452" requireReinstallation="true" />
<package id="Zlib.Portable.Signed" version="1.11.0" targetFramework="net452" />
</packages>

View File

@@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@@ -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("Service")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Service")]
[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("a8fd8ced-5510-4ebd-aace-5d3cbb7516db")]
// 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")]

View File

@@ -1,63 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{A8FD8CED-5510-4EBD-AACE-5D3CBB7516DB}</ProjectGuid>
<OutputType>WinExe</OutputType>
<RootNamespace>Service</RootNamespace>
<AssemblyName>Service</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</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>
</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>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Configuration.Install" />
<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.ServiceProcess" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration.Install" />
</ItemGroup>
<ItemGroup>
<Compile Include="Installer.cs" />
<Compile Include="Service.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Core\Core.csproj">
<Project>{ae082484-a34c-4b3a-a69f-49e5ef298b27}</Project>
<Name>Core</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

File diff suppressed because it is too large Load Diff