From 9fbf8feb6225957d8906e455f23928157cbee2df Mon Sep 17 00:00:00 2001 From: piyushawasthi Date: Tue, 20 Mar 2018 05:04:30 -0700 Subject: [PATCH] MSYS-547 Added feature to verify certificate from certificate store Signed-off-by: piyushawasthi --- lib/win32/certstore/mixin/helper.rb | 4 +++- lib/win32/certstore/store_base.rb | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/win32/certstore/mixin/helper.rb b/lib/win32/certstore/mixin/helper.rb index f2b0671..6cfbbc1 100644 --- a/lib/win32/certstore/mixin/helper.rb +++ b/lib/win32/certstore/mixin/helper.rb @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +require 'date' + module Win32 class Certstore module Mixin @@ -41,8 +43,8 @@ def cert_ps_cmd(thumbprint) def valid_duration(cert_obj) cert_obj.not_before < Time.now.utc && cert_obj.not_after > Time.now.utc end + end end end end - diff --git a/lib/win32/certstore/store_base.rb b/lib/win32/certstore/store_base.rb index cb192fa..ede21c4 100644 --- a/lib/win32/certstore/store_base.rb +++ b/lib/win32/certstore/store_base.rb @@ -127,6 +127,12 @@ def update_thumbprint(certificate_thumbprint) certificate_thumbprint.gsub(/[^A-Za-z0-9]/, '') end + # Verify OpenSSL::X509::Certificate object + def verify_certificate(cert_pem) + return "Certificate not found" if cert_pem.empty? + valid_duration(build_openssl_obj(cert_pem)) + end + # Convert OpenSSL::X509::Certificate object in .der formate def der_cert(cert_obj) FFI::MemoryPointer.from_string(cert_obj.to_der)