mirror of
https://github.com/bitwarden/server.git
synced 2025-07-03 17:12:49 -05:00
added identity server real cert loading
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Bit.Core.Utilities
|
||||
{
|
||||
@ -36,5 +38,24 @@ namespace Bit.Core.Utilities
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user