win32-certstore 0.6.11 → 0.6.14
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db28ffd12affe3acf9263b88c836aeed195465aefca15e1bdaf61d960a776fe5
|
4
|
+
data.tar.gz: 28b6bc27ef0e591d1c44664169545a53775c9d3ab6c636792d7989251d7bbef2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d6bb300e1450f191b102e7d6add3810d78edb95baf9f02fb371f53958e403f963ac0258371a71b42b8e758307250cebd25aab65611ce26aad84bbe8aa03206d
|
7
|
+
data.tar.gz: '093dbcbcbbf617b1e0d8740eb935c37b78dc5694887ef1e2d469b29b40760354dc7d94c0e99a1f69f51d71dc5fbdd2d9b91ed372a154b8ace366a8a473e0b5da'
|
@@ -43,7 +43,7 @@ module Win32
|
|
43
43
|
|
44
44
|
# Validate thumbprint
|
45
45
|
def validate_thumbprint(cert_thumbprint)
|
46
|
-
if cert_thumbprint.nil? || cert_thumbprint.empty? || cert_thumbprint.strip.empty?
|
46
|
+
if cert_thumbprint.nil? || cert_thumbprint.empty? || cert_thumbprint.strip.empty? || cert_thumbprint.length < 40
|
47
47
|
raise ArgumentError, "Invalid certificate thumbprint."
|
48
48
|
end
|
49
49
|
end
|
@@ -24,7 +24,11 @@ module Win32
|
|
24
24
|
def cert_ps_cmd(thumbprint, store_location: "LocalMachine", store_name: "My")
|
25
25
|
# the PowerShell block below uses a "Here-String" - it is explicitly formatted against the left margin.
|
26
26
|
<<-EOH
|
27
|
-
$cert = Get-ChildItem Cert:\\#{store_location}\\#{store_name} -Recurse | Where-Object { $_.Thumbprint -eq "#{thumbprint}" }
|
27
|
+
$cert = Get-ChildItem Cert:\\#{store_location}\\#{store_name} -Recurse -Force | Where-Object { $_.Thumbprint -eq "#{thumbprint}" }
|
28
|
+
|
29
|
+
if ([string]::IsNullOrEmpty($cert)){
|
30
|
+
return "Certificate Not Found"
|
31
|
+
}
|
28
32
|
|
29
33
|
$certdata = [System.Convert]::ToBase64String($cert.RawData, 'InsertLineBreaks')
|
30
34
|
$content = $null
|
@@ -146,10 +146,11 @@ module Win32
|
|
146
146
|
def cert_validate(certificate_thumbprint)
|
147
147
|
validate_thumbprint(certificate_thumbprint)
|
148
148
|
thumbprint = update_thumbprint(certificate_thumbprint)
|
149
|
-
|
150
149
|
cert_pem = get_cert_pem(thumbprint)
|
150
|
+
return cert_pem if cert_pem == "Certificate Not Found"
|
151
151
|
cert_pem = format_pem(cert_pem)
|
152
|
-
verify_certificate(cert_pem)
|
152
|
+
result = verify_certificate(cert_pem)
|
153
|
+
result == false ? "Certificate Has Expired" : result
|
153
154
|
end
|
154
155
|
|
155
156
|
# Search certificate from open certificate store and return list
|
@@ -184,13 +185,16 @@ module Win32
|
|
184
185
|
end
|
185
186
|
powershell_cmd = <<~EOH
|
186
187
|
$result = Get-ChildItem -Path Cert:\\#{converted_store}\\#{store_name} | Where-Object { $_.Subject -match "#{search_token.strip}" } | Select-Object Thumbprint
|
188
|
+
if ([string]::IsNullOrEmpty($result)){
|
189
|
+
return "Certificate Not Found"
|
190
|
+
}
|
187
191
|
return $result[0].Thumbprint
|
188
192
|
EOH
|
189
193
|
|
190
194
|
powershell_exec!(powershell_cmd, :powershell, timeout: timeout).result
|
191
195
|
|
192
196
|
rescue ChefPowerShell::PowerShellExceptions::PowerShellCommandFailed
|
193
|
-
|
197
|
+
raise ArgumentError, "PowerShell threw an error retreiving the certificate. You asked for a cert with this Search Token : #{search_token}, located in this store : #{store_name}, at this location : #{store_location}"
|
194
198
|
end
|
195
199
|
|
196
200
|
# To close and destroy pointer of open certificate store handler
|
data/lib/win32/certstore.rb
CHANGED
@@ -84,7 +84,7 @@ module Win32
|
|
84
84
|
def get!(certificate_thumbprint)
|
85
85
|
cert_pem = cert_get(certificate_thumbprint)
|
86
86
|
|
87
|
-
raise ArgumentError, "Unable to retrieve the certificate" if cert_pem.empty?
|
87
|
+
raise ArgumentError, "Unable to retrieve the certificate" if cert_pem.empty? || cert_pem == "Certificate Not Found"
|
88
88
|
|
89
89
|
cert_pem
|
90
90
|
end
|
@@ -118,13 +118,7 @@ module Win32
|
|
118
118
|
# @param request[thumbprint<string>] of certificate
|
119
119
|
# @return [true, false] only true or false
|
120
120
|
def valid?(certificate_thumbprint)
|
121
|
-
cert_validate(certificate_thumbprint)
|
122
|
-
if x.is_a?(TrueClass) || x.is_a?(FalseClass)
|
123
|
-
x
|
124
|
-
else
|
125
|
-
false
|
126
|
-
end
|
127
|
-
end
|
121
|
+
cert_validate(certificate_thumbprint)
|
128
122
|
end
|
129
123
|
|
130
124
|
# To close and destroy pointer of open certificate store handler
|
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.6.
|
4
|
+
version: 0.6.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-05-
|
11
|
+
date: 2022-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|