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/assertions.rb,
lib/win32/certstore/mixin/shell_exec.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
"0.6.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_CURRENT_USER, Mixin::Crypto::CERT_SYSTEM_STORE_LOCAL_MACHINE, Mixin::Crypto::CERT_SYSTEM_STORE_SERVICES, Mixin::Crypto::CERT_SYSTEM_STORE_USERS, 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, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE) ⇒ 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.
-
#get_pfx(certificate_thumbprint, store_location: @store_location, export_password:, output_path: "") ⇒ Object
Returns a filepath to a PKCS12 container.
-
#initialize(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE) ⇒ Certstore
constructor
Initializes a new instance of a certificate store.
-
#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::ShellExec
#powershell_exec, #powershell_exec!, #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, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE) ⇒ Certstore
Initializes a new instance of a certificate store. takes 2 parameters - the store name (My, Root, etc) and the location (CurrentUser or LocalMachine), it defaults to LocalMachine for backwards compatibility
36 37 38 39 40 |
# File 'lib/win32/certstore.rb', line 36 def initialize(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE) @store_name = store_name @store_location = store_location @certstore_handler = open(store_name, store_location: store_location) 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
127 128 129 |
# File 'lib/win32/certstore.rb', line 127 def self.finalize(certstore_handler) proc { certstore_handler.to_s } end |
.open(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE) ⇒ Object
To open given certificate store
43 44 45 46 47 48 49 50 |
# File 'lib/win32/certstore.rb', line 43 def self.open(store_name, store_location: CERT_SYSTEM_STORE_LOCAL_MACHINE) validate_store(store_name) if block_given? yield new(store_name, store_location: store_location) else new(store_name, store_location: store_location) end end |
Instance Method Details
#add(certificate_obj) ⇒ true, false
Adds a new certificate to an open certificate store
55 56 57 |
# File 'lib/win32/certstore.rb', line 55 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
70 71 72 |
# File 'lib/win32/certstore.rb', line 70 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
122 123 124 125 |
# File 'lib/win32/certstore.rb', line 122 def close close_cert_store remove_finalizer end |
#delete(certificate_thumbprint) ⇒ true, false
Delete existing certificate from open certificate store
103 104 105 |
# File 'lib/win32/certstore.rb', line 103 def delete(certificate_thumbprint) cert_delete(certstore_handler, certificate_thumbprint) end |
#get(certificate_thumbprint) ⇒ Object
Return ‘OpenSSL::X509` certificate object
77 78 79 |
# File 'lib/win32/certstore.rb', line 77 def get(certificate_thumbprint) cert_get(certificate_thumbprint) end |
#get_pfx(certificate_thumbprint, store_location: @store_location, export_password:, output_path: "") ⇒ Object
Returns a filepath to a PKCS12 container. The filepath is in a temporary folder so normal housekeeping by the OS should clear it. However, you should delete it yourself anyway. them and a password is required to export them.
89 90 91 |
# File 'lib/win32/certstore.rb', line 89 def get_pfx(certificate_thumbprint, store_location: @store_location, export_password:, output_path: "") get_cert_pfx(certificate_thumbprint, store_location: store_location, export_password: export_password, output_path: output_path) end |
#list ⇒ Array
Returns all the certificates in a store
96 97 98 |
# File 'lib/win32/certstore.rb', line 96 def list cert_list(certstore_handler) end |
#search(search_token) ⇒ Array
Returns all matching certificates in a store
110 111 112 |
# File 'lib/win32/certstore.rb', line 110 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
117 118 119 |
# File 'lib/win32/certstore.rb', line 117 def valid?(certificate_thumbprint) cert_validate(certificate_thumbprint) end |