win32-certstore
Ruby library for accessing the certificate store on Microsoft Windows:
Subcommands
This library provides the following features.
Open certificate store
Any valid certificate store can be opened in two ways:
Win32::Certstore.open("Root") do |store|
//your code should be here!
end
or
store = Win32::Certstore.open("Root")
Add certificate
This method adds a new certificate to an open certificate store.
Input - Certificate Object (OpenSSL::X509)
Return - True/False
Notes: The certificate must be passed as an OpenSSL::X509 object.
raw = File.read "C:\GlobalSignRootCA.pem"
certificate_object = OpenSSL::X509::Certificate.new raw
Win32::Certstore.open('Root') do |store|
store.add(certificate_object)
endor
raw = File.read "C:\GlobalSignRootCA.pem"
certificate_object = OpenSSL::X509::Certificate.new raw
store = Win32::Certstore.open('Root')
store.add(certificate_object)
store.closeGet certificate
Gets a certificate from an open certificate store and returns it as an OpenSSL::X509 object.
Input - Certificate thumbprint
Return - Certificate Object (OpenSSL::X509)
Win32::Certstore.open("Root") do |store|
store.get(certificate_thumbprint)
endor
store = Win32::Certstore.open("Root")
store.get(certificate_thumbprint)
store.closeList certificates
Lists all certificates in a certificate store.
Input - NA
Return - Certificate List in JSON format.
Win32::Certstore.open("Root") do |store|
store.list
endor
store = Win32::Certstore.open("Root")
store.list
store.closeDelete certificate
Deletes a certificate from a certificate store.
Input - Certificate thumbprint
Return - True/False
Win32::Certstore.open("Root") do |store|
store.delete(certificate_thumbprint)
endor
store = Win32::Certstore.open("Root")
store.delete(certificate_thumbprint)
store.closeSearch certificate
Searches for a certificate in an open certificate store.
Input - Search Token as: Comman name, Friendly name, RDN and other attributes
Return - Matching certificate list
Win32::Certstore.open("Root") do |store|
store.search(search_token)
endor
store = Win32::Certstore.open("Root")
store.search(search_token)
store.closeValidate certificate
Validates a certificate in a certificate store on the basis of time validity.
Input - Certificate thumbprint
Return - True/False
Win32::Certstore.open("Root") do |store|
store.valid?(certificate_thumbprint)
endor
store = Win32::Certstore.open("Root")
store.valid?(certificate_thumbprint)
store.closePerforming multiple operations
To perform more than one operations with single certificate store object
raw = File.read "C:\GlobalSignRootCA.pem"
certificate_object = OpenSSL::X509::Certificate.new raw
Win32::Certstore.open('Root') do |store|
store.add(certificate_object)
store.list
endor
raw = File.read "C:\GlobalSignRootCA.pem"
certificate_object = OpenSSL::X509::Certificate.new raw
store = Win32::Certstore.open('Root')
store.add(certificate_object)
store.list
store.closeRequirements / setup
Ruby
Ruby 2.5+ is required.
Contributing
For information on contributing to this project see https://github.com/chef/chef/blob/main/CONTRIBUTING.md
More information on the contribution process for Chef projects can be found in the Chef Contributions document.
LICENSE
Author:: Bryan McLellan (btm@chef.io) Copyright:: 2017-2021 Chef Software, Inc. License:: Apache License, Version 2.0
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.