Class: Win32::Certstore
- Inherits:
-
Object
- Object
- Win32::Certstore
- Extended by:
- Mixin::Assertions
- Includes:
- Mixin::Crypto, Mixin::String, StoreBase
- Defined in:
- lib/win32/certstore.rb,
lib/win32/certstore/version.rb,
lib/win32/certstore/store_base.rb,
lib/win32/certstore/mixin/crypto.rb,
lib/win32/certstore/mixin/helper.rb,
lib/win32/certstore/mixin/string.rb,
lib/win32/certstore/mixin/shell_out.rb,
lib/win32/certstore/mixin/assertions.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.4.1".freeze
Constants included from Mixin::Crypto
Mixin::Crypto::BLOB, Mixin::Crypto::BOOL, Mixin::Crypto::BYTE, Mixin::Crypto::CERT_CLOSE_STORE_CHECK_FLAG, Mixin::Crypto::CERT_CLOSE_STORE_FORCE_FLAG, Mixin::Crypto::CERT_COMPARE_ANY, Mixin::Crypto::CERT_COMPARE_NAME_STR_W, Mixin::Crypto::CERT_COMPARE_SHA1_HASH, Mixin::Crypto::CERT_COMPARE_SHIFT, Mixin::Crypto::CERT_FIND_ANY, Mixin::Crypto::CERT_FIND_SHA1_HASH, Mixin::Crypto::CERT_FIND_SUBJECT_STR, Mixin::Crypto::CERT_INFO_SUBJECT_FLAG, Mixin::Crypto::CERT_NAME_ATTR_TYPE, Mixin::Crypto::CERT_NAME_DISABLE_IE4_UTF8_FLAG, Mixin::Crypto::CERT_NAME_DNS_TYPE, Mixin::Crypto::CERT_NAME_EMAIL_TYPE, Mixin::Crypto::CERT_NAME_FRIENDLY_DISPLAY_TYPE, Mixin::Crypto::CERT_NAME_ISSUER_FLAG, Mixin::Crypto::CERT_NAME_RDN_TYPE, Mixin::Crypto::CERT_NAME_SEARCH_ALL_NAMES_FLAG, Mixin::Crypto::CERT_NAME_SIMPLE_DISPLAY_TYPE, Mixin::Crypto::CERT_NAME_STR_ENABLE_PUNYCODE_FLAG, Mixin::Crypto::CERT_NAME_UPN_TYPE, Mixin::Crypto::CERT_NAME_URL_TYPE, Mixin::Crypto::CERT_STORE_ADD_REPLACE_EXISTING, Mixin::Crypto::CERT_STORE_ADD_USE_EXISTING, Mixin::Crypto::CERT_STORE_PROV_SYSTEM, Mixin::Crypto::CERT_SYSTEM_STORE_LOCAL_MACHINE, Mixin::Crypto::CRYPT_ASN_ENCODING, Mixin::Crypto::CRYPT_NDR_ENCODING, Mixin::Crypto::DWORD, Mixin::Crypto::ENCODING_TYPE, Mixin::Crypto::HCERTSTORE, Mixin::Crypto::HCRYPTPROV_LEGACY, Mixin::Crypto::INT_PTR, Mixin::Crypto::LMSTR, Mixin::Crypto::LONG, Mixin::Crypto::LPCTSTR, Mixin::Crypto::LPFILETIME, Mixin::Crypto::LPSTR, Mixin::Crypto::LPTSTR, Mixin::Crypto::LPVOID, Mixin::Crypto::PCCERT_CONTEXT, Mixin::Crypto::PCERT_INFO, Mixin::Crypto::PCTL_USAGE, Mixin::Crypto::PCTL_VERIFY_USAGE_PARA, Mixin::Crypto::PCTL_VERIFY_USAGE_STATUS, Mixin::Crypto::PKCS_7_ASN_ENCODING, Mixin::Crypto::PKCS_7_NDR_ENCODING, Mixin::Crypto::PKCS_7_OR_X509_ASN_ENCODING, Mixin::Crypto::PWSTR, Mixin::Crypto::X509_ASN_ENCODING, Mixin::Crypto::X509_NDR_ENCODING
Instance Attribute Summary collapse
-
#store_name ⇒ Object
Returns the value of attribute store_name.
Class Method Summary collapse
- .finalize(certstore_handler) ⇒ Object
-
.open(store_name) ⇒ Object
To open given certificate store.
Instance Method Summary collapse
-
#add(certificate_obj) ⇒ true, false
Adds a new certificate to an open certificate store.
-
#add_pfx(path, password, key_properties = 0) ⇒ Boolean
Adds a PFX certificate to certificate store.
-
#close ⇒ Object
To close and destroy pointer of open certificate store handler.
-
#delete(certificate_thumbprint) ⇒ true, false
Delete existing certificate from open certificate store.
-
#get(certificate_thumbprint) ⇒ Object
Return ‘OpenSSL::X509` certificate object.
-
#initialize(store_name) ⇒ Certstore
constructor
A new instance of Certstore.
-
#list ⇒ Array
Returns all the certificates in a store.
-
#search(search_token) ⇒ Array
Returns all matching certificates in a store.
-
#valid?(certificate_thumbprint) ⇒ true, false
Validates a certificate in a certificate store on the basis of time validity.
Methods included from Mixin::Assertions
lookup_error, validate!, validate_certificate, validate_certificate_obj, validate_store, validate_thumbprint
Methods included from StoreBase
#cert_add, #cert_add_pfx, #cert_delete, #cert_get, #cert_list, #cert_search, #cert_validate, #close_cert_store
Methods included from Mixin::Helper
#cert_ps_cmd, #valid_duration?
Methods included from Mixin::ShellOut
#powershell_out, #powershell_out!, #shell_out_command
Methods included from Mixin::String
#utf8_to_wide, #wide_to_utf8, #wstring
Methods included from FFI::Library
Constructor Details
#initialize(store_name) ⇒ Certstore
Returns a new instance of Certstore.
34 35 36 37 |
# File 'lib/win32/certstore.rb', line 34 def initialize(store_name) @store_name = store_name @certstore_handler = open(store_name) end |
Instance Attribute Details
#store_name ⇒ Object
Returns the value of attribute store_name.
32 33 34 |
# File 'lib/win32/certstore.rb', line 32 def store_name @store_name end |
Class Method Details
.finalize(certstore_handler) ⇒ Object
112 113 114 |
# File 'lib/win32/certstore.rb', line 112 def self.finalize(certstore_handler) proc { certstore_handler.to_s } end |
.open(store_name) ⇒ Object
To open given certificate store
40 41 42 43 44 45 46 47 |
# File 'lib/win32/certstore.rb', line 40 def self.open(store_name) validate_store(store_name) if block_given? yield new(store_name) else new(store_name) end end |
Instance Method Details
#add(certificate_obj) ⇒ true, false
Adds a new certificate to an open certificate store
52 53 54 |
# File 'lib/win32/certstore.rb', line 52 def add(certificate_obj) cert_add(certstore_handler, certificate_obj) end |
#add_pfx(path, password, key_properties = 0) ⇒ Boolean
Unlike other certificates, PFX can be password protected and may contain a private key. Therefore we need a different approach to import them.
Adds a PFX certificate to certificate store
67 68 69 |
# File 'lib/win32/certstore.rb', line 67 def add_pfx(path, password, key_properties = 0) cert_add_pfx(certstore_handler, path, password, key_properties) end |
#close ⇒ Object
To close and destroy pointer of open certificate store handler
107 108 109 110 |
# File 'lib/win32/certstore.rb', line 107 def close close_cert_store remove_finalizer end |
#delete(certificate_thumbprint) ⇒ true, false
Delete existing certificate from open certificate store
88 89 90 |
# File 'lib/win32/certstore.rb', line 88 def delete(certificate_thumbprint) cert_delete(certstore_handler, certificate_thumbprint) end |
#get(certificate_thumbprint) ⇒ Object
Return ‘OpenSSL::X509` certificate object
74 75 76 |
# File 'lib/win32/certstore.rb', line 74 def get(certificate_thumbprint) cert_get(certificate_thumbprint) end |
#list ⇒ Array
Returns all the certificates in a store
81 82 83 |
# File 'lib/win32/certstore.rb', line 81 def list cert_list(certstore_handler) end |
#search(search_token) ⇒ Array
Returns all matching certificates in a store
95 96 97 |
# File 'lib/win32/certstore.rb', line 95 def search(search_token) cert_search(certstore_handler, search_token) end |
#valid?(certificate_thumbprint) ⇒ true, false
Validates a certificate in a certificate store on the basis of time validity
102 103 104 |
# File 'lib/win32/certstore.rb', line 102 def valid?(certificate_thumbprint) cert_validate(certificate_thumbprint) end |