mirror of
https://github.com/bitwarden/server.git
synced 2025-07-02 08:32:50 -05:00
load certs from azure storage
This commit is contained in:
@ -15,6 +15,8 @@ using System.Globalization;
|
||||
using System.Web;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
using Bit.Core.Enums;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.WindowsAzure.Storage;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
@ -149,6 +151,24 @@ namespace Bit.Core.Utilities
|
||||
}
|
||||
}
|
||||
|
||||
public async static Task<X509Certificate2> GetBlobCertificateAsync(CloudStorageAccount cloudStorageAccount,
|
||||
string container, string file, string password)
|
||||
{
|
||||
var blobClient = cloudStorageAccount.CreateCloudBlobClient();
|
||||
var containerRef = blobClient.GetContainerReference(container);
|
||||
if(await containerRef.ExistsAsync())
|
||||
{
|
||||
var blobRef = containerRef.GetBlobReference(file);
|
||||
if(await blobRef.ExistsAsync())
|
||||
{
|
||||
var blobBytes = new byte[blobRef.Properties.Length];
|
||||
await blobRef.DownloadToByteArrayAsync(blobBytes, 0);
|
||||
return new X509Certificate2(blobBytes, password);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static long ToEpocMilliseconds(DateTime date)
|
||||
{
|
||||
return (long)Math.Round((date - _epoc).TotalMilliseconds, 0);
|
||||
|
Reference in New Issue
Block a user