Module: Win32::Certstore::Mixin::Helper
- Included in:
- StoreBase
- Defined in:
- lib/win32/certstore/mixin/helper.rb
Instance Method Summary collapse
- #cert_ps_cmd(thumbprint, store_location: "LocalMachine", store_name: "My") ⇒ Object
-
#valid_duration?(cert_obj) ⇒ Boolean
validate certificate not_before and not_after date in UTC.
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. <<-EOH $cert = Get-ChildItem Cert:\\#{store_location}\\#{store_name} -Recurse -Force | 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) { $content = @" -----BEGIN CERTIFICATE----- $($certdata) -----END CERTIFICATE----- "@ } $content EOH end |
#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 |