sfn-vault 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,56 @@
1
+ require 'sfn-vault'
2
+
3
+ module SfnVault
4
+ module Utils
5
+
6
+ def vault_client
7
+ certs = SfnVault::CertificateStore.default_ssl_cert_store
8
+
9
+ conf = {
10
+ address: vault_addr,
11
+ token: vault_token,
12
+ }
13
+ conf.merge!({ssl_ca_path: '/etc/ssl/certs'}) unless SfnVault::Platform.windows?
14
+ conf.merge!({ssl_cert_store: certs}) if certs
15
+
16
+ client = Vault::Client.new(conf)
17
+ client
18
+ end
19
+
20
+ def vault_addr
21
+ address = config.fetch(:vault, :vault_addr, ENV['VAULT_ADDR'])
22
+ if address.nil?
23
+ ui.error 'Set vault_addr in .sfn or VAULT_ADDR in environment'
24
+ exit
25
+ end
26
+ ui.debug "Vault address is #{address}"
27
+ address
28
+ end
29
+
30
+ def vault_token
31
+ token = config.fetch(:vault, :vault_token, ENV['VAULT_TOKEN'])
32
+ if token.nil?
33
+ ui.error 'Set :vault_token in .sfn or VAULT_TOKEN in environment'
34
+ exit
35
+ end
36
+ ui.debug "Vault token is #{token}"
37
+ token
38
+ end
39
+
40
+ # Test write/read/delete operations
41
+ # to determine if we can save a secret
42
+ # @param [Vault::Client] client
43
+ # @return [TrueClass, FalseClass]
44
+ def vault_writeable?(client)
45
+ secret = 'cubbyhole/SfnVaultCallbackCheck'
46
+ value = 'ensure_writeable'
47
+ if client.logical.write(secret, value: value)
48
+ read = client.logical.read(test_secret)
49
+ client.logical.delete(test_secret)
50
+ if read.data == value
51
+ return true
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -1,3 +1,3 @@
1
1
  module SfnVault
2
- VERSION = Gem::Version.new('0.1.1')
2
+ VERSION = Gem::Version.new('0.1.3')
3
3
  end
@@ -0,0 +1,10 @@
1
+ require 'sfn-vault'
2
+
3
+ module SfnVault
4
+ class Windows
5
+ end
6
+ end
7
+
8
+ # if SfnVault::Platform.windows?
9
+ # require_relative './windows/root_certs'
10
+ # end
@@ -0,0 +1,110 @@
1
+ require 'openssl'
2
+ require 'ffi'
3
+
4
+ # This class abstracts operations with the Windows certificate store and hides
5
+ # ugly ffi functions
6
+ module SfnVault
7
+ class Windows
8
+ class RootCerts
9
+ include Enumerable
10
+ extend FFI::Library
11
+
12
+ typedef :ulong, :dword
13
+ typedef :uintptr_t, :handle
14
+
15
+ def initialize(roots)
16
+ @roots = roots
17
+ end
18
+
19
+ # Enumerates each root certificate.
20
+ # @yieldparam cert [OpenSSL::X509::Certificate] each root certificate
21
+ # @api public
22
+ def each
23
+ @roots.each { |cert| yield cert }
24
+ end
25
+
26
+ # Returns a new instance.
27
+ # @return [TrustedRootsStore::RootCerts] object constructed from current root certificates
28
+ def self.instance
29
+ new(load_certs)
30
+ end
31
+
32
+ # Returns an array of root certificates.
33
+ #
34
+ # @return [Array<[OpenSSL::X509::Certificate]>] an array of root certificates
35
+ # @api private
36
+ # rubocop:disable all
37
+ def self.load_certs
38
+ certs = []
39
+
40
+ # This is based on a patch submitted to openssl:
41
+ # http://www.mail-archive.com/openssl-dev@openssl.org/msg26958.html
42
+ ptr = FFI::Pointer::NULL
43
+ # This could be smarter and extend FFI usage to enumerate stores
44
+ # through CertEnumSystemStore:
45
+ # see: https://msdn.microsoft.com/en-us/library/aa376058(v=vs.85).aspx
46
+
47
+ %w(ROOT CA).each do |system_store|
48
+ store = CertOpenSystemStoreA(nil, system_store)
49
+ begin
50
+ while (ptr = CertEnumCertificatesInStore(store, ptr)) and not ptr.null?
51
+ context = CertContext.new(ptr)
52
+ cert_buf = context[:pbCertEncoded].read_bytes(context[:cbCertEncoded])
53
+ begin
54
+ certs << OpenSSL::X509::Certificate.new(cert_buf)
55
+ rescue => detail
56
+ warn("Failed to import certificate: #{detail.inspect} from #{system_store}")
57
+ end
58
+ end
59
+ ensure
60
+ CertCloseStore(store, 0)
61
+ end
62
+ end
63
+
64
+ certs
65
+ end
66
+ # rubocop:enable all
67
+
68
+ private
69
+
70
+ # typedef ULONG_PTR HCRYPTPROV_LEGACY;
71
+ # typedef void *HCERTSTORE;
72
+ class CertContext < FFI::Struct
73
+ layout(
74
+ :dwCertEncodingType, :dword,
75
+ :pbCertEncoded, :pointer,
76
+ :cbCertEncoded, :dword,
77
+ :pCertInfo, :pointer,
78
+ :hCertStore, :handle
79
+ )
80
+ end
81
+
82
+ # HCERTSTORE
83
+ # WINAPI
84
+ # CertOpenSystemStoreA(
85
+ # __in_opt HCRYPTPROV_LEGACY hProv,
86
+ # __in LPCSTR szSubsystemProtocol
87
+ # );
88
+ ffi_lib :crypt32
89
+ attach_function :CertOpenSystemStoreA, [:pointer, :string], :handle
90
+
91
+ # PCCERT_CONTEXT
92
+ # WINAPI
93
+ # CertEnumCertificatesInStore(
94
+ # __in HCERTSTORE hCertStore,
95
+ # __in_opt PCCERT_CONTEXT pPrevCertContext
96
+ # );
97
+ ffi_lib :crypt32
98
+ attach_function :CertEnumCertificatesInStore, [:handle, :pointer], :pointer
99
+
100
+ # BOOL
101
+ # WINAPI
102
+ # CertCloseStore(
103
+ # __in_opt HCERTSTORE hCertStore,
104
+ # __in DWORD dwFlags
105
+ # );
106
+ ffi_lib :crypt32
107
+ attach_function :CertCloseStore, [:handle, :dword], :bool
108
+ end
109
+ end
110
+ end
@@ -11,8 +11,10 @@ Gem::Specification.new do |s|
11
11
  s.license = 'Apache-2.0'
12
12
  s.require_path = 'lib'
13
13
  s.add_dependency 'sfn', '>= 3.0', '< 4.0'
14
- s.add_dependency 'vault', '~> 0.7.3'
14
+ s.add_dependency 'vault', '~> 0.9.0'
15
+ s.add_dependency 'ffi', '~> 1.9.14'
15
16
  s.add_development_dependency 'pry', '~> 0.10.4'
16
- s.add_development_dependency 'pry-coolline'
17
+ s.add_development_dependency 'pry-byebug', '~> 3.4', '>= 3.4.2'
18
+ s.add_development_dependency 'rb-readline', '~> 0.5.3'
17
19
  s.files = Dir['{lib,bin,docs}/**/*'] + %w(sfn-vault.gemspec README.md CHANGELOG.md LICENSE)
18
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfn-vault
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Escriva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-03 00:00:00.000000000 Z
11
+ date: 2017-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sfn
@@ -36,14 +36,28 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.7.3
39
+ version: 0.9.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.7.3
46
+ version: 0.9.0
47
+ - !ruby/object:Gem::Dependency
48
+ name: ffi
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: 1.9.14
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: 1.9.14
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: pry
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -59,19 +73,39 @@ dependencies:
59
73
  - !ruby/object:Gem::Version
60
74
  version: 0.10.4
61
75
  - !ruby/object:Gem::Dependency
62
- name: pry-coolline
76
+ name: pry-byebug
63
77
  requirement: !ruby/object:Gem::Requirement
64
78
  requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.4'
65
82
  - - ">="
66
83
  - !ruby/object:Gem::Version
67
- version: '0'
84
+ version: 3.4.2
68
85
  type: :development
69
86
  prerelease: false
70
87
  version_requirements: !ruby/object:Gem::Requirement
71
88
  requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: '3.4'
72
92
  - - ">="
73
93
  - !ruby/object:Gem::Version
74
- version: '0'
94
+ version: 3.4.2
95
+ - !ruby/object:Gem::Dependency
96
+ name: rb-readline
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: 0.5.3
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: 0.5.3
75
109
  description: SparkleFormation Vault Callback
76
110
  email: sean.escriva@gmail.com
77
111
  executables: []
@@ -81,13 +115,15 @@ files:
81
115
  - CHANGELOG.md
82
116
  - LICENSE
83
117
  - README.md
84
- - bin/coderay
85
- - bin/generate_sparkle_docs
86
- - bin/graph
87
- - bin/pry
88
- - bin/sfn
89
118
  - lib/sfn-vault.rb
119
+ - lib/sfn-vault/callback.rb
120
+ - lib/sfn-vault/certificate_store.rb
121
+ - lib/sfn-vault/inject.rb
122
+ - lib/sfn-vault/platform.rb
123
+ - lib/sfn-vault/utils.rb
90
124
  - lib/sfn-vault/version.rb
125
+ - lib/sfn-vault/windows.rb
126
+ - lib/sfn-vault/windows/root_certs.rb
91
127
  - sfn-vault.gemspec
92
128
  homepage: http://github.com/webframp/sfn-vault
93
129
  licenses:
@@ -109,7 +145,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
145
  version: '0'
110
146
  requirements: []
111
147
  rubyforge_project:
112
- rubygems_version: 2.6.8
148
+ rubygems_version: 2.6.10
113
149
  signing_key:
114
150
  specification_version: 4
115
151
  summary: SparkleFormation Vault Callback
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'coderay' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("coderay", "coderay")
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'generate_sparkle_docs' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("sparkle_formation", "generate_sparkle_docs")
data/bin/graph DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'graph' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("graph", "graph")
data/bin/pry DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'pry' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("pry", "pry")
data/bin/sfn DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
- #
4
- # This file was generated by Bundler.
5
- #
6
- # The application 'sfn' is installed as part of a gem, and
7
- # this file is here to facilitate running it.
8
- #
9
-
10
- require "pathname"
11
- ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
12
- Pathname.new(__FILE__).realpath)
13
-
14
- require "rubygems"
15
- require "bundler/setup"
16
-
17
- load Gem.bin_path("sfn", "sfn")