From f45f53e71a730a379a15f37d59a03e182948dac1 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Sun, 15 May 2022 14:34:45 +0600 Subject: [PATCH 1/2] refactoring to correct for not finding certs correctly in some cases. Signed-off-by: John McCrae --- lib/win32/certstore/mixin/helper.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/win32/certstore/mixin/helper.rb b/lib/win32/certstore/mixin/helper.rb index 44ac440..2be0342 100644 --- a/lib/win32/certstore/mixin/helper.rb +++ b/lib/win32/certstore/mixin/helper.rb @@ -26,6 +26,10 @@ def cert_ps_cmd(thumbprint, store_location: "LocalMachine", store_name: "My") <<-EOH $cert = Get-ChildItem Cert:\\#{store_location}\\#{store_name} -Recurse | Where-Object { $_.Thumbprint -eq "#{thumbprint}" } + if ([string]::IsNullOrEmpty($cert)){ + return "Certificate Not Found" + } + $certdata = [System.Convert]::ToBase64String($cert.RawData, 'InsertLineBreaks') $content = $null if($null -ne $cert) From 401b8d28923d4bbbc80f7b90c3a6dc7ac52af423 Mon Sep 17 00:00:00 2001 From: John McCrae Date: Sun, 15 May 2022 16:14:13 +0600 Subject: [PATCH 2/2] refactoring to correct for not finding certs correctly in some cases. Signed-off-by: John McCrae --- lib/win32/certstore/mixin/assertions.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/win32/certstore/mixin/assertions.rb b/lib/win32/certstore/mixin/assertions.rb index a7f1936..9bdd85f 100644 --- a/lib/win32/certstore/mixin/assertions.rb +++ b/lib/win32/certstore/mixin/assertions.rb @@ -43,7 +43,7 @@ def validate_certificate_obj(cert_obj) # Validate thumbprint def validate_thumbprint(cert_thumbprint) - if cert_thumbprint.nil? || cert_thumbprint.empty? || cert_thumbprint.strip.empty? + if cert_thumbprint.nil? || cert_thumbprint.empty? || cert_thumbprint.strip.empty? || cert_thumbprint.length < 40 raise ArgumentError, "Invalid certificate thumbprint." end end