1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-22 12:15:36 +01: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>
<VersionPrefix>1.8.2</VersionPrefix>
<TargetFramework>net461</TargetFramework>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>Api</AssemblyName>
<RootNamespace>Bit.Api</RootNamespace>
<UserSecretsId>bitwarden-Api</UserSecretsId>

View File

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

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<AssemblyName>Core</AssemblyName>
<RootNamespace>Bit.Core</RootNamespace>
</PropertyGroup>
@ -44,7 +44,6 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="1.1.3" />
<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.UserSecrets" Version="1.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
@ -57,7 +56,6 @@
<PackageReference Include="U2F.Core" Version="1.0.3" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.4" />
<PackageReference Include="Otp.NET" Version="1.0.1" />
<PackageReference Include="YubicoDotNetClient" Version="1.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
@ -65,6 +63,12 @@
<Reference Include="System.Data" />
<Reference Include="System" />
<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>
</Project>

View File

@ -2,7 +2,9 @@
using Microsoft.AspNetCore.Identity;
using Bit.Core.Models.Table;
using Bit.Core.Enums;
#if NET461
using YubicoDotNetClient;
#endif
using System.Linq;
namespace Bit.Core.Identity
@ -55,9 +57,14 @@ namespace Bit.Core.Identity
return Task.FromResult(false);
}
#if NET461
var client = new YubicoClient(_globalSettings.Yubico.ClientId, _globalSettings.Yubico.Key);
var response = client.Verify(token);
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)
{
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)
{
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 _unblockIpQueue;
private bool _didInit = false;
public AzureQueueBlockIpService(
GlobalSettings globalSettings)
@ -17,14 +18,12 @@ namespace Bit.Core.Services
var queueClient = storageAccount.CreateCloudQueueClient();
_blockIpQueue = queueClient.GetQueueReference("blockip");
_blockIpQueue.CreateIfNotExists();
_unblockIpQueue = queueClient.GetQueueReference("unblockip");
_unblockIpQueue.CreateIfNotExists();
}
public async Task BlockIpAsync(string ipAddress, bool permanentBlock)
{
await InitAsync();
var message = new CloudQueueMessage(ipAddress);
await _blockIpQueue.AddMessageAsync(message);
@ -33,5 +32,17 @@ namespace Bit.Core.Services
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 Bit.Core.Models.Table;
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.Threading.Tasks;
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)
{
var table = new DataTable();
var table = new DataTable($"{columnName}Array", "dbo");
table.Columns.Add(columnName, typeof(T));
table.SetTypeName($"[dbo].[{columnName}Array]");
if(values != null)
{
@ -74,8 +73,7 @@ namespace Bit.Core.Utilities
public static DataTable ToArrayTVP(this IEnumerable<SelectionReadOnly> values)
{
var table = new DataTable();
table.SetTypeName("[dbo].[SelectionReadOnlyArray]");
var table = new DataTable("SelectionReadOnlyArray", "dbo");
var idColumn = new DataColumn("Id", typeof(Guid));
table.Columns.Add(idColumn);

View File

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

View File

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

View File

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