mirror of
https://github.com/bitwarden/server.git
synced 2025-05-29 15:24:51 -05:00
added identity server real cert loading
This commit is contained in:
parent
f105bd775d
commit
6cde9ed223
@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Security.Claims;
|
using System.Security.Claims;
|
||||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Identity;
|
using Microsoft.AspNetCore.Identity;
|
||||||
@ -29,6 +28,7 @@ using IdentityServer4.Validation;
|
|||||||
using IdentityServer4.Services;
|
using IdentityServer4.Services;
|
||||||
using IdentityModel.AspNetCore.OAuth2Introspection;
|
using IdentityModel.AspNetCore.OAuth2Introspection;
|
||||||
using IdentityServer4.Stores;
|
using IdentityServer4.Stores;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Api
|
namespace Bit.Api
|
||||||
{
|
{
|
||||||
@ -87,9 +87,9 @@ namespace Bit.Api
|
|||||||
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
|
services.AddSingleton<IRateLimitCounterStore, MemoryCacheRateLimitCounterStore>();
|
||||||
|
|
||||||
// IdentityServer
|
// IdentityServer
|
||||||
|
var identityServerCert = CoreHelpers.GetCertificate(globalSettings.IdentityServer.CertificateThumbprint);
|
||||||
services.AddIdentityServer()
|
services.AddIdentityServer()
|
||||||
// TODO: Add proper signing creds
|
.AddSigningCredential(identityServerCert)
|
||||||
.AddTemporarySigningCredential()
|
|
||||||
.AddInMemoryApiResources(ApiResources.GetApiResources())
|
.AddInMemoryApiResources(ApiResources.GetApiResources())
|
||||||
.AddInMemoryClients(Clients.GetClients());
|
.AddInMemoryClients(Clients.GetClients());
|
||||||
services.AddSingleton<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
|
services.AddSingleton<IResourceOwnerPasswordValidator, ResourceOwnerPasswordValidator>();
|
||||||
|
@ -24,6 +24,9 @@
|
|||||||
"gcmApiKey": "SECRET",
|
"gcmApiKey": "SECRET",
|
||||||
"gcmAppPackageName": "com.x8bit.bitwarden"
|
"gcmAppPackageName": "com.x8bit.bitwarden"
|
||||||
},
|
},
|
||||||
|
"identityServer": {
|
||||||
|
"certificateThumbprint": "SECRET"
|
||||||
|
},
|
||||||
"storage": {
|
"storage": {
|
||||||
"connectionString": "SECRET"
|
"connectionString": "SECRET"
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
public virtual LoggrSettings Loggr { get; set; } = new LoggrSettings();
|
public virtual LoggrSettings Loggr { get; set; } = new LoggrSettings();
|
||||||
public virtual PushSettings Push { get; set; } = new PushSettings();
|
public virtual PushSettings Push { get; set; } = new PushSettings();
|
||||||
public virtual StorageSettings Storage { get; set; } = new StorageSettings();
|
public virtual StorageSettings Storage { get; set; } = new StorageSettings();
|
||||||
|
public virtual IdentityServerSettings IdentityServer { get; set; } = new IdentityServerSettings();
|
||||||
|
|
||||||
public class SqlServerSettings
|
public class SqlServerSettings
|
||||||
{
|
{
|
||||||
@ -41,5 +42,10 @@
|
|||||||
public string GcmApiKey { get; set; }
|
public string GcmApiKey { get; set; }
|
||||||
public string GcmAppPackageName { get; set; }
|
public string GcmAppPackageName { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class IdentityServerSettings
|
||||||
|
{
|
||||||
|
public string CertificateThumbprint { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,13 +8,12 @@ using PushSharp.Google;
|
|||||||
using PushSharp.Apple;
|
using PushSharp.Apple;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using PushSharp.Core;
|
using PushSharp.Core;
|
||||||
using System.Security.Cryptography.X509Certificates;
|
|
||||||
using Bit.Core.Domains;
|
using Bit.Core.Domains;
|
||||||
using Bit.Core.Enums;
|
using Bit.Core.Enums;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using Bit.Core.Utilities;
|
||||||
|
|
||||||
namespace Bit.Core.Services
|
namespace Bit.Core.Services
|
||||||
{
|
{
|
||||||
@ -191,7 +190,7 @@ namespace Bit.Core.Services
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var apnsCertificate = GetCertificate(globalSettings.Push.ApnsCertificateThumbprint);
|
var apnsCertificate = CoreHelpers.GetCertificate(globalSettings.Push.ApnsCertificateThumbprint);
|
||||||
if(apnsCertificate == null)
|
if(apnsCertificate == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -240,24 +239,6 @@ namespace Bit.Core.Services
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private X509Certificate2 GetCertificate(string thumbprint)
|
|
||||||
{
|
|
||||||
// Clean possible garbage characters from thumbprint copy/paste
|
|
||||||
// ref http://stackoverflow.com/questions/8448147/problems-with-x509store-certificates-find-findbythumbprint
|
|
||||||
thumbprint = Regex.Replace(thumbprint, @"[^\da-zA-z]", string.Empty).ToUpper();
|
|
||||||
|
|
||||||
X509Certificate2 cert = null;
|
|
||||||
var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
|
|
||||||
certStore.Open(OpenFlags.ReadOnly);
|
|
||||||
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
|
|
||||||
if(certCollection.Count > 0)
|
|
||||||
{
|
|
||||||
cert = certCollection[0];
|
|
||||||
}
|
|
||||||
certStore.Close();
|
|
||||||
return cert;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FeedbackService_FeedbackReceived(string deviceToken, DateTime timestamp)
|
private void FeedbackService_FeedbackReceived(string deviceToken, DateTime timestamp)
|
||||||
{
|
{
|
||||||
// Remove the deviceToken from your database
|
// Remove the deviceToken from your database
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace Bit.Core.Utilities
|
namespace Bit.Core.Utilities
|
||||||
{
|
{
|
||||||
@ -36,5 +38,24 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
return new Guid(guidArray);
|
return new Guid(guidArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static X509Certificate2 GetCertificate(string thumbprint)
|
||||||
|
{
|
||||||
|
// Clean possible garbage characters from thumbprint copy/paste
|
||||||
|
// ref http://stackoverflow.com/questions/8448147/problems-with-x509store-certificates-find-findbythumbprint
|
||||||
|
thumbprint = Regex.Replace(thumbprint, @"[^\da-zA-z]", string.Empty).ToUpper();
|
||||||
|
|
||||||
|
X509Certificate2 cert = null;
|
||||||
|
var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser);
|
||||||
|
certStore.Open(OpenFlags.ReadOnly);
|
||||||
|
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, false);
|
||||||
|
if(certCollection.Count > 0)
|
||||||
|
{
|
||||||
|
cert = certCollection[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
certStore.Close();
|
||||||
|
return cert;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user