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
# 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.
  <<-EOH
    $cert = Get-ChildItem Cert:\\#{store_location}\\#{store_name} -Recurse | Where-Object { $_.Thumbprint -eq "#{thumbprint}" }

    $certdata = [System.Convert]::ToBase64String($cert.RawData, 'InsertLineBreaks')
    $content = $null
    if($null -ne $cert)
    {
      $content =
@"
-----BEGIN CERTIFICATE-----
$($certdata)
-----END CERTIFICATE-----
"@
    }
    $content
  EOH
end

#valid_duration?(cert_obj) ⇒ Boolean

validate certificate not_before and not_after date in UTC

Returns:

  • (Boolean)


45
46
47
# File 'lib/win32/certstore/mixin/helper.rb', line 45

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