Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed MSYS-857 & MSYS-838 #37

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/win32/certstore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lib/win32/certstore/mixin/crypto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/win32/unit/certstore_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down