win32-certstore 0.4.1 → 0.5.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/win32/certstore.rb +11 -7
- data/lib/win32/certstore/mixin/crypto.rb +3 -0
- data/lib/win32/certstore/mixin/helper.rb +2 -4
- data/lib/win32/certstore/mixin/{shell_out.rb → shell_exec.rb} +4 -4
- data/lib/win32/certstore/store_base.rb +9 -3
- data/lib/win32/certstore/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b391e4d81e324162538a2a3644aea74f0da1f8679409733a58dcf4c590734a6c
|
4
|
+
data.tar.gz: 5ed7821ec5bffe58cb09608cfc008b287874b5ddafe8556662fa27f42a25c1b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc5c77cd659695ac3a58480ab875a6c5daa2b93cd83e45f1fcdfcd1bd89e0cf9653d38d63ae9e5260ecff90a7277f6ee600b91137665d53e672fbb77e1543cfb
|
7
|
+
data.tar.gz: 5b6a8025b85ae8ce026a9a7b603a35137000525ba182bbbcc8fc9667fb78dd6cf179ad1cfbb1cbdcdf582dd4749f82795a17df01181720d7f77a36a4477dc639
|
data/lib/win32/certstore.rb
CHANGED
@@ -31,18 +31,21 @@ module Win32
|
|
31
31
|
|
32
32
|
attr_accessor :store_name
|
33
33
|
|
34
|
-
|
34
|
+
# Initializes a new instance of a certificate store.
|
35
|
+
# takes 2 parameters - the store name (My, Root, etc) and the location (CurrentUser or LocalMachine), it defaults to LocalMachine for backwards compatibility
|
36
|
+
def initialize(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE)
|
35
37
|
@store_name = store_name
|
36
|
-
@
|
38
|
+
@store_location = store_location
|
39
|
+
@certstore_handler = open(store_name, store_location: store_location)
|
37
40
|
end
|
38
41
|
|
39
42
|
# To open given certificate store
|
40
|
-
def self.open(store_name)
|
43
|
+
def self.open(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE)
|
41
44
|
validate_store(store_name)
|
42
45
|
if block_given?
|
43
|
-
yield new(store_name)
|
46
|
+
yield new(store_name, store_location: store_location)
|
44
47
|
else
|
45
|
-
new(store_name)
|
48
|
+
new(store_name, store_location: store_location)
|
46
49
|
end
|
47
50
|
end
|
48
51
|
|
@@ -118,8 +121,9 @@ module Win32
|
|
118
121
|
attr_reader :certstore_handler
|
119
122
|
|
120
123
|
# To open certstore and return open certificate store pointer
|
121
|
-
|
122
|
-
|
124
|
+
|
125
|
+
def open(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE)
|
126
|
+
certstore_handler = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0, nil, store_location, wstring(store_name))
|
123
127
|
unless certstore_handler
|
124
128
|
last_error = FFI::LastError.error
|
125
129
|
raise SystemCallError.new("Unable to open the Certificate Store `#{store_name}`.", last_error)
|
@@ -88,6 +88,9 @@ module Win32
|
|
88
88
|
|
89
89
|
CERT_STORE_PROV_SYSTEM = 10
|
90
90
|
CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000
|
91
|
+
CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000
|
92
|
+
CERT_SYSTEM_STORE_SERVICES = 0x00050000
|
93
|
+
CERT_SYSTEM_STORE_USERS = 0x00060000
|
91
94
|
|
92
95
|
# Define ffi pointer
|
93
96
|
HCERTSTORE = FFI::TypeDefs[:pointer]
|
@@ -21,12 +21,11 @@ module Win32
|
|
21
21
|
class Certstore
|
22
22
|
module Mixin
|
23
23
|
module Helper
|
24
|
-
|
25
24
|
# PSCommand to search certificate from thumbprint and convert in pem
|
26
|
-
def cert_ps_cmd(thumbprint, store_name)
|
25
|
+
def cert_ps_cmd(thumbprint, store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE)
|
27
26
|
<<-EOH
|
28
27
|
$content = $null
|
29
|
-
$cert = Get-ChildItem Cert:\\
|
28
|
+
$cert = Get-ChildItem Cert:\\'#{store_location}'\\'#{store_name}' -Recurse | Where { $_.Thumbprint -eq '#{thumbprint}' }
|
30
29
|
if($cert -ne $null)
|
31
30
|
{
|
32
31
|
$content = @(
|
@@ -43,7 +42,6 @@ module Win32
|
|
43
42
|
def valid_duration?(cert_obj)
|
44
43
|
cert_obj.not_before < Time.now.utc && cert_obj.not_after > Time.now.utc
|
45
44
|
end
|
46
|
-
|
47
45
|
end
|
48
46
|
end
|
49
47
|
end
|
@@ -20,7 +20,7 @@ require "mixlib/shellout" unless defined?(Mixlib::ShellOut)
|
|
20
20
|
module Win32
|
21
21
|
class Certstore
|
22
22
|
module Mixin
|
23
|
-
module
|
23
|
+
module ShellExec
|
24
24
|
def shell_out_command(*command_args)
|
25
25
|
cmd = Mixlib::ShellOut.new(*command_args)
|
26
26
|
cmd.live_stream
|
@@ -39,7 +39,7 @@ module Win32
|
|
39
39
|
# @param script [String] script to run
|
40
40
|
# @param options [Hash] options hash
|
41
41
|
# @return [Mixlib::Shellout] mixlib-shellout object
|
42
|
-
def
|
42
|
+
def powershell_exec(*command_args)
|
43
43
|
script = command_args.first
|
44
44
|
options = command_args.last.is_a?(Hash) ? command_args.last : nil
|
45
45
|
|
@@ -52,8 +52,8 @@ module Win32
|
|
52
52
|
# @param script [String] script to run
|
53
53
|
# @param options [Hash] options hash
|
54
54
|
# @return [Mixlib::Shellout] mixlib-shellout object
|
55
|
-
def
|
56
|
-
cmd =
|
55
|
+
def powershell_exec!(*command_args)
|
56
|
+
cmd = powershell_exec(*command_args)
|
57
57
|
cmd.error!
|
58
58
|
cmd
|
59
59
|
end
|
@@ -17,7 +17,7 @@
|
|
17
17
|
|
18
18
|
require_relative "mixin/crypto"
|
19
19
|
require_relative "mixin/string"
|
20
|
-
require_relative "mixin/
|
20
|
+
require_relative "mixin/shell_exec"
|
21
21
|
require_relative "mixin/unicode"
|
22
22
|
require "openssl" unless defined?(OpenSSL)
|
23
23
|
require "json" unless defined?(JSON)
|
@@ -28,7 +28,7 @@ module Win32
|
|
28
28
|
include Win32::Certstore::Mixin::Crypto
|
29
29
|
include Win32::Certstore::Mixin::Assertions
|
30
30
|
include Win32::Certstore::Mixin::String
|
31
|
-
include Win32::Certstore::Mixin::
|
31
|
+
include Win32::Certstore::Mixin::ShellExec
|
32
32
|
include Win32::Certstore::Mixin::Unicode
|
33
33
|
include Win32::Certstore::Mixin::Helper
|
34
34
|
|
@@ -231,8 +231,14 @@ module Win32
|
|
231
231
|
|
232
232
|
# Get certificate pem
|
233
233
|
def get_cert_pem(thumbprint)
|
234
|
-
|
234
|
+
converted_store = if @store_location == CERT_SYSTEM_STORE_LOCAL_MACHINE
|
235
|
+
"LocalMachine"
|
236
|
+
else
|
237
|
+
"CurrentUser"
|
238
|
+
end
|
239
|
+
get_data = powershell_exec!(cert_ps_cmd(thumbprint, store_name, store_location: converted_store))
|
235
240
|
get_data.stdout
|
241
|
+
# get_data.result
|
236
242
|
end
|
237
243
|
|
238
244
|
# Format pem
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: win32-certstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -79,7 +79,7 @@ files:
|
|
79
79
|
- lib/win32/certstore/mixin/assertions.rb
|
80
80
|
- lib/win32/certstore/mixin/crypto.rb
|
81
81
|
- lib/win32/certstore/mixin/helper.rb
|
82
|
-
- lib/win32/certstore/mixin/
|
82
|
+
- lib/win32/certstore/mixin/shell_exec.rb
|
83
83
|
- lib/win32/certstore/mixin/string.rb
|
84
84
|
- lib/win32/certstore/mixin/unicode.rb
|
85
85
|
- lib/win32/certstore/store_base.rb
|
@@ -97,15 +97,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
97
97
|
requirements:
|
98
98
|
- - ">="
|
99
99
|
- !ruby/object:Gem::Version
|
100
|
-
version: '2.
|
100
|
+
version: '2.5'
|
101
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
102
|
requirements:
|
103
103
|
- - ">="
|
104
104
|
- !ruby/object:Gem::Version
|
105
105
|
version: '0'
|
106
106
|
requirements: []
|
107
|
-
rubygems_version: 3.
|
107
|
+
rubygems_version: 3.1.4
|
108
108
|
signing_key:
|
109
109
|
specification_version: 4
|
110
|
-
summary: Ruby library for accessing the certificate
|
110
|
+
summary: Ruby library for accessing the certificate stores on Windows.
|
111
111
|
test_files: []
|