diff --git a/lib/win32/certstore.rb b/lib/win32/certstore.rb index 328d071..06c2658 100644 --- a/lib/win32/certstore.rb +++ b/lib/win32/certstore.rb @@ -71,8 +71,8 @@ def search(certificate_name) end # Validate certificate from open certificate store and return boolean - def verify(certificate_name) - cert_verify(certstore_handler, certificate_name) + def valid?(certificate_thumbprint) + cert_validate(certificate_thumbprint) end # To close and destroy pointer of open certificate store handler diff --git a/lib/win32/certstore/mixin/helper.rb b/lib/win32/certstore/mixin/helper.rb index f2b0671..1bdac82 100644 --- a/lib/win32/certstore/mixin/helper.rb +++ b/lib/win32/certstore/mixin/helper.rb @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +require 'date' + module Win32 class Certstore module Mixin @@ -38,11 +40,11 @@ def cert_ps_cmd(thumbprint) end # validate certificate not_before and not_after date in UTC - def valid_duration(cert_obj) + def valid_duration?(cert_obj) cert_obj.not_before < Time.now.utc && cert_obj.not_after > Time.now.utc end + end end end end - diff --git a/lib/win32/certstore/store_base.rb b/lib/win32/certstore/store_base.rb index 7dc9936..f5b2272 100644 --- a/lib/win32/certstore/store_base.rb +++ b/lib/win32/certstore/store_base.rb @@ -105,7 +105,7 @@ def cert_delete(store_handler, certificate_thumbprint) # Verify certificate from open certificate store and return boolean or exceptions # store_handler => Open certificate store handler # certificate_thumbprint => thumbprint is a hash. which could be sha1 or md5. - def cert_verify(store_handler, certificate_thumbprint) + def cert_validate(certificate_thumbprint) validate_thumbprint(certificate_thumbprint) thumbprint = update_thumbprint(certificate_thumbprint) cert_pem = get_cert_pem(thumbprint) @@ -135,6 +135,12 @@ def update_thumbprint(certificate_thumbprint) certificate_thumbprint.gsub(/[^A-Za-z0-9]/, '') end + # Verify OpenSSL::X509::Certificate object + def verify_certificate(cert_pem) + return "Certificate not found" if cert_pem.empty? + valid_duration?(build_openssl_obj(cert_pem)) + end + # Convert OpenSSL::X509::Certificate object in .der formate def der_cert(cert_obj) FFI::MemoryPointer.from_string(cert_obj.to_der) @@ -151,12 +157,6 @@ def get_rdn(cert_obj) cert_obj.issuer.to_s.concat("/").scan(/=(.*?)\//).join(", ") end - # Verify OpenSSL::X509::Certificate object - def verify_certificate(cert_pem) - return "Certificate not found" if cert_pem.empty? - valid_duration(build_openssl_obj(cert_pem)) - end - # Format pem def format_pem(cert_pem) cert_pem.delete("\r")