Permalink
Browse files

2.4.1 release, adding GetCertificateByThumbprint().

  • Loading branch information...
1 parent 165aff2 commit 12dc50cb9e42dfdf611bdedd30c7b04fba55a3f0 @bertjohnson committed Dec 23, 2016
View
@@ -0,0 +1,7 @@
+### Changelog ###
+
+2.4.1 - 2016-12-23
+ * Added `GetCertificateByThumbprint` helper method.
+
+2.4.0 and earlier
+ * History can be found from the commit messages at https://github.com/bertjohnson/opaquemail.
@@ -1,3 +1,5 @@
+### License ###
+
OpaqueMail (https://opaquemail.org/).
Licensed according to the MIT License (http://mit-license.org/).
@@ -31,6 +31,7 @@
using Org.BouncyCastle.X509;
using Org.BouncyCastle.Utilities;
using System.Security.Cryptography;
+using System.Text.RegularExpressions;
namespace OpaqueMail
{
@@ -212,7 +213,7 @@ public static X509Certificate2 GetCertificateBySerialNumber(StoreLocation locati
{
X509Store store = new X509Store(location);
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
- X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber.Replace(" ", "").ToUpper(), true);
+ X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySerialNumber, serialNumber.Replace(" ", "").ToLower(), true);
store.Close();
// If no certificate is found, return null;
@@ -242,6 +243,28 @@ public static X509Certificate2 GetCertificateBySubjectName(StoreLocation locatio
}
/// <summary>
+ /// Retrieve a certificate from the Windows certificate store based on its thumbprint.
+ /// </summary>
+ /// <param name="location">Location of the certificate; either the Current User or Local Machine.</param>
+ /// <param name="thumbprint">Thumbprint of the certificate.</param>
+ public static X509Certificate2 GetCertificateByThumbprint(StoreLocation location, string thumbprint)
+ {
+ // Sanitize the input.
+ thumbprint = Regex.Replace(thumbprint, @"[^\da-zA-z]", string.Empty).ToUpper();
+
+ X509Store store = new X509Store(location);
+ store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadOnly);
+ X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, true);
+ store.Close();
+
+ // If no certificate is found, return null;
+ if (certs.Count < 1)
+ return null;
+ else
+ return certs[0];
+ }
+
+ /// <summary>
/// Retrieve a collection of all certificates from the Windows certificate store.
/// </summary>
/// <param name="location">Location of the certificates; either the Current User or Local Machine.</param>
@@ -25,7 +25,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Bert Johnson")]
[assembly: AssemblyProduct("OpaqueMail")]
-[assembly: AssemblyCopyright("Copyright © 2013-2016")]
+[assembly: AssemblyCopyright("Copyright © 2013-2016 Bert Johnson")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -47,5 +47,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.4.0")]
-[assembly: AssemblyFileVersion("2.4.0")]
+[assembly: AssemblyVersion("2.4.1")]
+[assembly: AssemblyFileVersion("2.4.1")]
@@ -25,7 +25,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Bert Johnson")]
[assembly: AssemblyProduct("OpaqueMail")]
-[assembly: AssemblyCopyright("Copyright © 2013-2016")]
+[assembly: AssemblyCopyright("Copyright © 2013-2016 Bert Johnson")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -47,5 +47,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.4.0")]
-[assembly: AssemblyFileVersion("2.4.0")]
+[assembly: AssemblyVersion("2.4.1")]
+[assembly: AssemblyFileVersion("2.4.1")]
@@ -24,7 +24,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Bert Johnson")]
[assembly: AssemblyProduct("OpaqueMail")]
-[assembly: AssemblyCopyright("Copyright © 2013-2016")]
+[assembly: AssemblyCopyright("Copyright © 2013-2016 Bert Johnson")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -46,5 +46,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.4.0")]
-[assembly: AssemblyFileVersion("2.4.0")]
+[assembly: AssemblyVersion("2.4.1")]
+[assembly: AssemblyFileVersion("2.4.1")]
@@ -24,7 +24,7 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Bert Johnson")]
[assembly: AssemblyProduct("OpaqueMail")]
-[assembly: AssemblyCopyright("Copyright © 2013-2016")]
+[assembly: AssemblyCopyright("Copyright © 2013-2016 Bert Johnson")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -46,5 +46,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("2.4.0")]
-[assembly: AssemblyFileVersion("2.4.0")]
+[assembly: AssemblyVersion("2.4.1")]
+[assembly: AssemblyFileVersion("2.4.1")]
Oops, something went wrong.

0 comments on commit 12dc50c

Please sign in to comment.