mirror of
https://github.com/bitwarden/server.git
synced 2025-04-06 05:28:15 -05:00
Extracted logic to get Identity cert (#889)
This commit is contained in:
parent
66e67d2172
commit
2fb18d8cf2
@ -188,13 +188,13 @@ namespace Bit.Core.Utilities
|
||||
{
|
||||
var blobClient = cloudStorageAccount.CreateCloudBlobClient();
|
||||
var containerRef = blobClient.GetContainerReference(container);
|
||||
if (await containerRef.ExistsAsync())
|
||||
if (await containerRef.ExistsAsync().ConfigureAwait(false))
|
||||
{
|
||||
var blobRef = containerRef.GetBlobReference(file);
|
||||
if (await blobRef.ExistsAsync())
|
||||
if (await blobRef.ExistsAsync().ConfigureAwait(false))
|
||||
{
|
||||
var blobBytes = new byte[blobRef.Properties.Length];
|
||||
await blobRef.DownloadToByteArrayAsync(blobBytes, 0);
|
||||
await blobRef.DownloadToByteArrayAsync(blobBytes, 0).ConfigureAwait(false);
|
||||
return new X509Certificate2(blobBytes, password);
|
||||
}
|
||||
}
|
||||
@ -621,5 +621,30 @@ namespace Bit.Core.Utilities
|
||||
// Product website
|
||||
(!globalSettings.SelfHosted && origin == "https://bitwarden.com");
|
||||
}
|
||||
|
||||
public static X509Certificate2 GetIdentityServerCertificate(GlobalSettings globalSettings)
|
||||
{
|
||||
if (globalSettings.SelfHosted &&
|
||||
SettingHasValue(globalSettings.IdentityServer.CertificatePassword)
|
||||
&& File.Exists("identity.pfx"))
|
||||
{
|
||||
return GetCertificate("identity.pfx",
|
||||
globalSettings.IdentityServer.CertificatePassword);
|
||||
}
|
||||
else if (SettingHasValue(globalSettings.IdentityServer.CertificateThumbprint))
|
||||
{
|
||||
return GetCertificate(
|
||||
globalSettings.IdentityServer.CertificateThumbprint);
|
||||
}
|
||||
else if (!globalSettings.SelfHosted &&
|
||||
SettingHasValue(globalSettings.Storage?.ConnectionString) &&
|
||||
SettingHasValue(globalSettings.IdentityServer.CertificatePassword))
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
|
||||
return GetBlobCertificateAsync(storageAccount, "certificates",
|
||||
"identity.pfx", globalSettings.IdentityServer.CertificatePassword).GetAwaiter().GetResult();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,28 +375,10 @@ namespace Bit.Core.Utilities
|
||||
public static IIdentityServerBuilder AddIdentityServerCertificate(
|
||||
this IIdentityServerBuilder identityServerBuilder, IWebHostEnvironment env, GlobalSettings globalSettings)
|
||||
{
|
||||
if (globalSettings.SelfHosted &&
|
||||
CoreHelpers.SettingHasValue(globalSettings.IdentityServer.CertificatePassword)
|
||||
&& File.Exists("identity.pfx"))
|
||||
var certificate = CoreHelpers.GetIdentityServerCertificate(globalSettings);
|
||||
if (certificate != null)
|
||||
{
|
||||
var identityServerCert = CoreHelpers.GetCertificate("identity.pfx",
|
||||
globalSettings.IdentityServer.CertificatePassword);
|
||||
identityServerBuilder.AddSigningCredential(identityServerCert);
|
||||
}
|
||||
else if (CoreHelpers.SettingHasValue(globalSettings.IdentityServer.CertificateThumbprint))
|
||||
{
|
||||
var identityServerCert = CoreHelpers.GetCertificate(
|
||||
globalSettings.IdentityServer.CertificateThumbprint);
|
||||
identityServerBuilder.AddSigningCredential(identityServerCert);
|
||||
}
|
||||
else if (!globalSettings.SelfHosted &&
|
||||
CoreHelpers.SettingHasValue(globalSettings.Storage?.ConnectionString) &&
|
||||
CoreHelpers.SettingHasValue(globalSettings.IdentityServer.CertificatePassword))
|
||||
{
|
||||
var storageAccount = CloudStorageAccount.Parse(globalSettings.Storage.ConnectionString);
|
||||
var identityServerCert = CoreHelpers.GetBlobCertificateAsync(storageAccount, "certificates",
|
||||
"identity.pfx", globalSettings.IdentityServer.CertificatePassword).GetAwaiter().GetResult();
|
||||
identityServerBuilder.AddSigningCredential(identityServerCert);
|
||||
identityServerBuilder.AddSigningCredential(certificate);
|
||||
}
|
||||
else if (env.IsDevelopment())
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user