1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-23 04:21:05 -05:00

add x-platform support with netcore 2.0

This commit is contained in:
Kyle Spearrin 2017-07-31 16:58:27 -04:00
parent d6d9ceab87
commit 3880edfb79
12 changed files with 80 additions and 25 deletions

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<VersionPrefix>1.8.2</VersionPrefix> <VersionPrefix>1.8.2</VersionPrefix>
<TargetFramework>net461</TargetFramework> <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>Api</AssemblyName> <AssemblyName>Api</AssemblyName>
<RootNamespace>Bit.Api</RootNamespace> <RootNamespace>Bit.Api</RootNamespace>
<UserSecretsId>bitwarden-Api</UserSecretsId> <UserSecretsId>bitwarden-Api</UserSecretsId>

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<VersionPrefix>1.8.2</VersionPrefix> <VersionPrefix>1.8.2</VersionPrefix>
<TargetFramework>net461</TargetFramework> <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>Billing</AssemblyName> <AssemblyName>Billing</AssemblyName>
<RootNamespace>Bit.Billing</RootNamespace> <RootNamespace>Bit.Billing</RootNamespace>
<UserSecretsId>bitwarden-Billing</UserSecretsId> <UserSecretsId>bitwarden-Billing</UserSecretsId>

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net461</TargetFramework> <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>Core</AssemblyName> <AssemblyName>Core</AssemblyName>
<RootNamespace>Bit.Core</RootNamespace> <RootNamespace>Bit.Core</RootNamespace>
</PropertyGroup> </PropertyGroup>
@ -44,7 +44,6 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="1.1.3" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="1.1.3" />
<PackageReference Include="Dapper" Version="1.50.2" /> <PackageReference Include="Dapper" Version="1.50.2" />
<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="1.0.8" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" /> <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
@ -57,7 +56,6 @@
<PackageReference Include="U2F.Core" Version="1.0.3" /> <PackageReference Include="U2F.Core" Version="1.0.3" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.4" /> <PackageReference Include="WindowsAzure.Storage" Version="8.1.4" />
<PackageReference Include="Otp.NET" Version="1.0.1" /> <PackageReference Include="Otp.NET" Version="1.0.1" />
<PackageReference Include="YubicoDotNetClient" Version="1.0.0" />
</ItemGroup> </ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' "> <ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
@ -65,6 +63,12 @@
<Reference Include="System.Data" /> <Reference Include="System.Data" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="Microsoft.CSharp" /> <Reference Include="Microsoft.CSharp" />
<PackageReference Include="YubicoDotNetClient" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.NotificationHubs" Version="1.0.8" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' ">
<PackageReference Include="System.Data.SqlClient" Version="4.4.0-preview2-25405-01" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -2,7 +2,9 @@
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Bit.Core.Enums; using Bit.Core.Enums;
#if NET461
using YubicoDotNetClient; using YubicoDotNetClient;
#endif
using System.Linq; using System.Linq;
namespace Bit.Core.Identity namespace Bit.Core.Identity
@ -55,9 +57,14 @@ namespace Bit.Core.Identity
return Task.FromResult(false); return Task.FromResult(false);
} }
#if NET461
var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.Key); var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.Key);
var response = client.Verify(token); var response = client.Verify(token);
return Task.FromResult(response.Status == YubicoResponseStatus.Ok); return Task.FromResult(response.Status == YubicoResponseStatus.Ok);
#else
return Task.FromResult(false);
#endif
} }
} }
} }

View File

@ -98,24 +98,50 @@ namespace Bit.Core.Services
public async Task CleanupAsync(Guid cipherId) public async Task CleanupAsync(Guid cipherId)
{ {
await InitAsync(); await InitAsync();
foreach(var blob in _attachmentsContainer.ListBlobs($"temp/{cipherId}", true)) var segment = await _attachmentsContainer.ListBlobsSegmentedAsync($"temp/{cipherId}", true,
BlobListingDetails.None, 100, null, null, null);
while(true)
{ {
if(blob is CloudBlockBlob blockBlob) foreach(var blob in segment.Results)
{ {
await blockBlob.DeleteIfExistsAsync(); if(blob is CloudBlockBlob blockBlob)
{
await blockBlob.DeleteIfExistsAsync();
}
} }
if(segment.ContinuationToken == null)
{
break;
}
segment = await _attachmentsContainer.ListBlobsSegmentedAsync(segment.ContinuationToken);
} }
} }
public async Task DeleteAttachmentsForCipherAsync(Guid cipherId) public async Task DeleteAttachmentsForCipherAsync(Guid cipherId)
{ {
await InitAsync(); await InitAsync();
foreach(var blob in _attachmentsContainer.ListBlobs(cipherId.ToString(), true)) var segment = await _attachmentsContainer.ListBlobsSegmentedAsync(cipherId.ToString(), true,
BlobListingDetails.None, 100, null, null, null);
while(true)
{ {
if(blob is CloudBlockBlob blockBlob) foreach(var blob in segment.Results)
{ {
await blockBlob.DeleteIfExistsAsync(); if(blob is CloudBlockBlob blockBlob)
{
await blockBlob.DeleteIfExistsAsync();
}
} }
if(segment.ContinuationToken == null)
{
break;
}
segment = await _attachmentsContainer.ListBlobsSegmentedAsync(segment.ContinuationToken);
} }
} }

View File

@ -9,6 +9,7 @@ namespace Bit.Core.Services
{ {
private readonly CloudQueue _blockIpQueue; private readonly CloudQueue _blockIpQueue;
private readonly CloudQueue _unblockIpQueue; private readonly CloudQueue _unblockIpQueue;
private bool _didInit = false;
public AzureQueueBlockIpService( public AzureQueueBlockIpService(
GlobalSettings globalSettings) GlobalSettings globalSettings)
@ -17,14 +18,12 @@ namespace Bit.Core.Services
var queueClient = storageAccount.CreateCloudQueueClient(); var queueClient = storageAccount.CreateCloudQueueClient();
_blockIpQueue = queueClient.GetQueueReference("blockip"); _blockIpQueue = queueClient.GetQueueReference("blockip");
_blockIpQueue.CreateIfNotExists();
_unblockIpQueue = queueClient.GetQueueReference("unblockip"); _unblockIpQueue = queueClient.GetQueueReference("unblockip");
_unblockIpQueue.CreateIfNotExists();
} }
public async Task BlockIpAsync(string ipAddress, bool permanentBlock) public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
{ {
await InitAsync();
var message = new CloudQueueMessage(ipAddress); var message = new CloudQueueMessage(ipAddress);
await _blockIpQueue.AddMessageAsync(message); await _blockIpQueue.AddMessageAsync(message);
@ -33,5 +32,17 @@ namespace Bit.Core.Services
await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(12, 0, 0), null, null); await _unblockIpQueue.AddMessageAsync(message, null, new TimeSpan(12, 0, 0), null, null);
} }
} }
private async Task InitAsync()
{
if(_didInit)
{
return;
}
await _blockIpQueue.CreateIfNotExistsAsync();
await _unblockIpQueue.CreateIfNotExistsAsync();
_didInit = true;
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; #if NET461
using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Bit.Core.Models.Table; using Bit.Core.Models.Table;
using Microsoft.Azure.NotificationHubs; using Microsoft.Azure.NotificationHubs;
@ -161,3 +162,4 @@ namespace Bit.Core.Services
} }
} }
} }
#endif

View File

@ -1,4 +1,5 @@
using System; #if NET461
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Azure.NotificationHubs; using Microsoft.Azure.NotificationHubs;
@ -144,3 +145,4 @@ namespace Bit.Core.Services
} }
} }
} }
#endif

View File

@ -57,9 +57,8 @@ namespace Bit.Core.Utilities
public static DataTable ToArrayTVP<T>(this IEnumerable<T> values, string columnName) public static DataTable ToArrayTVP<T>(this IEnumerable<T> values, string columnName)
{ {
var table = new DataTable(); var table = new DataTable($"{columnName}Array", "dbo");
table.Columns.Add(columnName, typeof(T)); table.Columns.Add(columnName, typeof(T));
table.SetTypeName($"[dbo].[{columnName}Array]");
if(values != null) if(values != null)
{ {
@ -74,8 +73,7 @@ namespace Bit.Core.Utilities
public static DataTable ToArrayTVP(this IEnumerable<SelectionReadOnly> values) public static DataTable ToArrayTVP(this IEnumerable<SelectionReadOnly> values)
{ {
var table = new DataTable(); var table = new DataTable("SelectionReadOnlyArray", "dbo");
table.SetTypeName("[dbo].[SelectionReadOnlyArray]");
var idColumn = new DataColumn("Id", typeof(Guid)); var idColumn = new DataColumn("Id", typeof(Guid));
table.Columns.Add(idColumn); table.Columns.Add(idColumn);

View File

@ -52,9 +52,14 @@ namespace Bit.Core.Utilities
{ {
services.AddSingleton<IMailService, RazorViewMailService>(); services.AddSingleton<IMailService, RazorViewMailService>();
services.AddSingleton<IMailDeliveryService, SendGridMailDeliveryService>(); services.AddSingleton<IMailDeliveryService, SendGridMailDeliveryService>();
#if NET461
services.AddSingleton<IPushNotificationService, NotificationHubPushNotificationService>(); services.AddSingleton<IPushNotificationService, NotificationHubPushNotificationService>();
services.AddSingleton<IBlockIpService, AzureQueueBlockIpService>();
services.AddSingleton<IPushRegistrationService, NotificationHubPushRegistrationService>(); services.AddSingleton<IPushRegistrationService, NotificationHubPushRegistrationService>();
#else
services.AddSingleton<IPushNotificationService, NoopPushNotificationService>();
services.AddSingleton<IPushRegistrationService, NoopPushRegistrationService>();
#endif
services.AddSingleton<IBlockIpService, AzureQueueBlockIpService>();
services.AddSingleton<IAttachmentStorageService, AzureAttachmentStorageService>(); services.AddSingleton<IAttachmentStorageService, AzureAttachmentStorageService>();
} }
@ -154,6 +159,7 @@ namespace Bit.Core.Utilities
public static void AddCustomDataProtectionServices( public static void AddCustomDataProtectionServices(
this IServiceCollection services, IHostingEnvironment env, GlobalSettings globalSettings) this IServiceCollection services, IHostingEnvironment env, GlobalSettings globalSettings)
{ {
#if NET461
if(!env.IsDevelopment()) if(!env.IsDevelopment())
{ {
var dataProtectionCert = CoreHelpers.GetCertificate(globalSettings.DataProtection.CertificateThumbprint); var dataProtectionCert = CoreHelpers.GetCertificate(globalSettings.DataProtection.CertificateThumbprint);
@ -162,6 +168,7 @@ namespace Bit.Core.Utilities
.PersistKeysToAzureBlobStorage(storageAccount, "aspnet-dataprotection/keys.xml") .PersistKeysToAzureBlobStorage(storageAccount, "aspnet-dataprotection/keys.xml")
.ProtectKeysWithCertificate(dataProtectionCert); .ProtectKeysWithCertificate(dataProtectionCert);
} }
#endif
} }
public static GlobalSettings AddGlobalSettingsServices(this IServiceCollection services, public static GlobalSettings AddGlobalSettingsServices(this IServiceCollection services,

View File

@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<VersionPrefix>1.8.2</VersionPrefix> <VersionPrefix>1.8.2</VersionPrefix>
<TargetFramework>net461</TargetFramework> <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>Identity</AssemblyName> <AssemblyName>Identity</AssemblyName>
<RootNamespace>Bit.Identity</RootNamespace> <RootNamespace>Bit.Identity</RootNamespace>
<UserSecretsId>bitwarden-Identity</UserSecretsId> <UserSecretsId>bitwarden-Identity</UserSecretsId>

View File

@ -1,10 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>Mail</AssemblyName> <AssemblyName>Mail</AssemblyName>
<RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
<RootNamespace>Bit.Mail</RootNamespace> <RootNamespace>Bit.Mail</RootNamespace>
</PropertyGroup> </PropertyGroup>