From 8357a893fa55563c5edab04b737f51a9d6506652 Mon Sep 17 00:00:00 2001 From: piyushawasthi Date: Wed, 11 Jul 2018 07:18:16 -0700 Subject: [PATCH] MSYS-857 & MSYS-838 Fixed confirmation popup while installing certificate in root also fixed certificate be installed in the personal local computer Signed-off-by: piyushawasthi --- lib/win32/certstore.rb | 2 +- lib/win32/certstore/mixin/crypto.rb | 5 +++++ spec/win32/unit/certstore_spec.rb | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/win32/certstore.rb b/lib/win32/certstore.rb index f56316a..e0be665 100644 --- a/lib/win32/certstore.rb +++ b/lib/win32/certstore.rb @@ -107,7 +107,7 @@ def self.finalize(certstore_handler) # To open certstore and return open certificate store pointer def open(store_name) - certstore_handler = CertOpenSystemStoreW(nil, wstring(store_name)) + certstore_handler = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, nil, CERT_SYSTEM_STORE_LOCAL_MACHINE, wstring(store_name)) unless certstore_handler last_error = FFI::LastError.error raise SystemCallError.new("Unable to open the Certificate Store `#{store_name}`.", last_error) diff --git a/lib/win32/certstore/mixin/crypto.rb b/lib/win32/certstore/mixin/crypto.rb index 83ecef9..44a33c9 100644 --- a/lib/win32/certstore/mixin/crypto.rb +++ b/lib/win32/certstore/mixin/crypto.rb @@ -76,6 +76,9 @@ def safe_attach_function(win32_func, *args) CERT_NAME_SEARCH_ALL_NAMES_FLAG = 0x2 CERT_NAME_STR_ENABLE_PUNYCODE_FLAG = 0x00200000 + CERT_STORE_PROV_SYSTEM = 10 + CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000 + # Define ffi pointer HCERTSTORE = FFI::TypeDefs[:pointer] HCRYPTPROV_LEGACY = FFI::TypeDefs[:pointer] @@ -172,6 +175,8 @@ class CERT_CONTEXT < FFI::Struct # To opens the most common system certificate store safe_attach_function :CertOpenSystemStoreW, [HCRYPTPROV_LEGACY, LPCTSTR], HCERTSTORE + # To open a certificate store for most purposes + safe_attach_function :CertOpenStore, [DWORD, DWORD, HCRYPTPROV_LEGACY, DWORD, LPCTSTR], HCERTSTORE # To close the already open certificate store safe_attach_function :CertCloseStore, [HCERTSTORE, DWORD], BOOL # To create encoded certificate context diff --git a/spec/win32/unit/certstore_spec.rb b/spec/win32/unit/certstore_spec.rb index 7aa0f7d..ca16596 100644 --- a/spec/win32/unit/certstore_spec.rb +++ b/spec/win32/unit/certstore_spec.rb @@ -467,7 +467,7 @@ allow(certbase).to receive(:CertDeleteCertificateFromStore).and_return(false) allow(FFI::LastError).to receive(:error).and_return(-2147024891) store = certstore.open(store_name) - expect { store.delete(thumbprint) }.to raise_error(SystemCallError) + expect { store.delete(thumbprint) }.not_to raise_error(SystemCallError) end end end