Module: Win32::Certstore::Mixin::Helper

Included in:
StoreBase
Defined in:
lib/win32/certstore/mixin/helper.rb

Instance Method Summary collapse

Instance Method Details

#cert_ps_cmd(thumbprint, store_location: "LocalMachine", store_name: "My") ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/win32/certstore/mixin/helper.rb', line 24

def cert_ps_cmd(thumbprint, store_location: "LocalMachine", store_name: "My")
  # the PowerShell block below uses a "Here-String" - it is explicitly formatted against the left margin.
  "    $cert = Get-ChildItem Cert:\\\\\#{store_location}\\\\\#{store_name} -Recurse -Force | Where-Object { $_.Thumbprint -eq \"\#{thumbprint}\" }\n\n    if ([string]::IsNullOrEmpty($cert)){\n      return \"Certificate Not Found\"\n    }\n\n    $certdata = [System.Convert]::ToBase64String($cert.RawData, 'InsertLineBreaks')\n    $content = $null\n    if($null -ne $cert)\n    {\n      $content =\n@\"\n-----BEGIN CERTIFICATE-----\n$($certdata)\n-----END CERTIFICATE-----\n\"@\n    }\n    $content\n  EOH\nend\n"

#valid_duration?(cert_obj) ⇒ Boolean

validate certificate not_before and not_after date in UTC



49
50
51
# File 'lib/win32/certstore/mixin/helper.rb', line 49

def valid_duration?(cert_obj)
  cert_obj.not_before < Time.now.utc && cert_obj.not_after > Time.now.utc
end