-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from chef/btm/file_structure
set initial file hierarchy
- Loading branch information
Showing
17 changed files
with
639 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,92 @@ | ||
# win32-certstore | ||
Ruby library for accessing the certificate store on Windows | ||
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: | ||
|
||
**Notes: Valid certificate store names: | ||
`CA -> Certification authority certificates.` | ||
`MY -> A certificate store that holds certificates with associated private keys.` | ||
`ROOT -> Root certificates.` | ||
`SPC -> Software Publisher Certificate.`** | ||
|
||
``` | ||
Win32::Certstore.open("Root") do |store| | ||
//your code should be here! | ||
end | ||
``` | ||
or | ||
``` | ||
store = Win32::Certstore.open("Root") | ||
``` | ||
|
||
### List certificates | ||
|
||
Lists certificates of a valid certificate store and returns output in JSON format: | ||
|
||
``` | ||
Win32::Certstore.open("Root") do |store| | ||
store.list | ||
end | ||
``` | ||
or | ||
``` | ||
store = Win32::Certstore.open("Root") | ||
store.list | ||
``` | ||
|
||
### Add certificate | ||
|
||
Add a valid certificate in a certificate store. | ||
|
||
**Notes: The new certificate should be in the following formats `.cer|.crt|.pfx|.der`:** | ||
|
||
``` | ||
Win32::Certstore.open("Root") do |store| | ||
store.add(certificate_file_path) | ||
end | ||
``` | ||
or | ||
``` | ||
store = Win32::Certstore.open("Root") | ||
store.add(certificate_file_path) | ||
``` | ||
|
||
## Requirements / setup | ||
|
||
### Ruby | ||
|
||
Ruby 1.9.3+ is required. | ||
|
||
### Chef version | ||
|
||
This library requires >= Chef 11.0.0. | ||
|
||
## CONTRIBUTING: | ||
|
||
Please file bugs against the WIN32-CERTSTORE project at https://github.com/chef/win32-certstore/issues. | ||
|
||
More information on the contribution process for Chef projects can be found in the [Chef Contributions document](http://docs.chef.io/community_contributions.html). | ||
|
||
# LICENSE: | ||
|
||
Author:: Bryan McLellan (<[email protected]>) | ||
Copyright:: Copyright (c) 2017 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# | ||
# Author:: Nimisha Sharad (<[email protected]>) | ||
# Copyright:: Copyright (c) 2017 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. | ||
|
||
require 'certstore/mixin/crypto' | ||
require 'certstore/mixin/assertions' | ||
require 'certstore/store_base' | ||
require 'certstore/version' | ||
|
||
module Win32 | ||
class Certstore | ||
include Win32::Certstore::Mixin::Crypto | ||
extend Win32::Certstore::Mixin::Assertions | ||
include Chef::Mixin::WideString | ||
include Win32::Certstore::StoreBase | ||
|
||
attr_reader :store_name | ||
|
||
def initialize(store_name) | ||
@certstore_handler = open(store_name) | ||
end | ||
|
||
def self.open(store_name) | ||
validate_store(store_name) | ||
if block_given? | ||
yield self.new(store_name) | ||
else | ||
self.new(store_name) | ||
end | ||
end | ||
|
||
def list | ||
list = cert_list(@certstore_handler) | ||
close | ||
return list | ||
end | ||
|
||
def add(cert_file_path) | ||
add = cert_add(@certstore_handler, cert_file_path) | ||
close | ||
return add | ||
end | ||
|
||
private | ||
|
||
attr_reader :certstore_handler | ||
|
||
def open(store_name) | ||
certstore_handler = CertOpenSystemStoreW(nil, wstring(store_name)) | ||
unless certstore_handler | ||
last_error = FFI::LastError.error | ||
raise Chef::Exceptions::Win32APIError, "Unable to open the Certificate Store `#{store_name}` with error: #{last_error}." | ||
end | ||
add_finalizer(certstore_handler) | ||
certstore_handler | ||
end | ||
|
||
def add_finalizer(certstore_handler) | ||
ObjectSpace.define_finalizer(self, self.class.finalize(certstore_handler)) | ||
end | ||
|
||
def self.finalize(certstore_handler) | ||
proc { puts "DESTROY OBJECT #{certstore_handler}" } | ||
end | ||
|
||
def close | ||
closed = CertCloseStore(@certstore_handler, CERT_CLOSE_STORE_FORCE_FLAG) | ||
unless closed | ||
last_error = FFI::LastError.error | ||
raise Chef::Exceptions::Win32APIError, "Unable to close the Certificate Store with error: #{last_error}." | ||
end | ||
remove_finalizer | ||
end | ||
|
||
def remove_finalizer | ||
ObjectSpace.undefine_finalizer(self) | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# | ||
# Author:: Piyush Awasthi (<[email protected]>) | ||
# Copyright:: Copyright (c) 2017 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. | ||
|
||
module Win32::Certstore::Mixin::Assertions | ||
|
||
# Validate certificate store name | ||
def validate_store(store_name) | ||
unless valid_store_name.include?(store_name&.upcase) | ||
raise ArgumentError, "Invalid Certificate Store." | ||
end | ||
end | ||
|
||
# Validate certificate type | ||
def validate_certificate(cert_file_path) | ||
unless (!cert_file_path.nil? && File.extname(cert_file_path) =~ /.cer|.crt|.pfx|.der/ ) | ||
raise ArgumentError, "Invalid Certificate format." | ||
end | ||
end | ||
|
||
private | ||
|
||
# These Are Valid certificate store name | ||
# CA -> Certification authority certificates. | ||
# MY -> A certificate store that holds certificates with associated private keys. | ||
# ROOT -> Root certificates. | ||
# SPC -> Software Publisher Certificate. | ||
def valid_store_name | ||
["MY", "CA", "ROOT", "SPC"] | ||
end | ||
end |
Oops, something went wrong.