hiera-eyaml-gpg_ruby 0.5 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1113a5bd3e83150d3f368f627085a531895d003
4
- data.tar.gz: 23077e7de1fdef016abe4877e1cacf671905a209
3
+ metadata.gz: f977e0b374e9acc78af2c238573bf15dc5f30e76
4
+ data.tar.gz: 757317de188420c1687b61fd5f8b8ae7e503b773
5
5
  SHA512:
6
- metadata.gz: 2f0611e3d8125b4a558ac6283f0ece66f8f569bd43cedc94e0d171bc94910f7c4c9bb051e1c08c6bb855f54c21575dd3a12c70de4cd677f70caa08258be07c52
7
- data.tar.gz: ba5ef926bf73f74dba4faacc4ad09cc9c7051640087b85e911f49497116aba9eb0a7cce5cc5b74b8521686e2e020609a9d4334be02fd2627d2b699340b11e710
6
+ metadata.gz: dd63716ef95adcf8768b30aaf0ad99215fcde7944a7f54c7c067cbd7285a2e6de77cd3e99fcfa81e1fd22693522a85d9df239268045794f4d055242ad9b82c26
7
+ data.tar.gz: b417987eb441341f2db218a7767dc6663f430705dbe938964d6080c4ef5397fa56ca7fc9079774a6c68e062a0366ec3cca9912adea433349e1d30d040b85d57f
data/Gemfile CHANGED
@@ -1,8 +1,8 @@
1
1
  source 'https://rubygems.org/'
2
2
 
3
3
  gem 'hiera-eyaml', ">=1.3.8"
4
- gem 'ruby_gpg', ">=0.3.0"
4
+ gem 'gpgme', ">=2.0.0"
5
5
 
6
6
  group :development do
7
7
  gem "aruba"
8
- end
8
+ end
@@ -1,4 +1,4 @@
1
- require 'gpgme'
1
+ require 'ruby_gpg'
2
2
  require 'base64'
3
3
  require 'pathname'
4
4
  require 'hiera/backend/eyaml/encryptor'
@@ -94,75 +94,25 @@ class Hiera
94
94
 
95
95
  def self.encrypt plaintext
96
96
  gnupghome = self.option :gnupghome
97
- GPGME::Engine.home_dir = gnupghome
98
97
  debug("GNUPGHOME is #{gnupghome}")
99
-
100
- ctx = GPGME::Ctx.new
98
+ RubyGpg.config.homedir = gnupghome
101
99
 
102
100
  recipients = self.find_recipients
103
101
  debug("Recipents are #{recipients}")
104
102
 
105
103
  raise RecoverableError, 'No recipients provided, don\'t know who to encrypt to' if recipients.empty?
106
104
 
107
- keys = recipients.map {|r|
108
- key_to_use = ctx.keys(r).first
109
- if key_to_use.nil?
110
- raise RecoverableError, "No key found on keyring for #{r}"
111
- end
112
- key_to_use
113
- }
114
- debug("Keys: #{keys}")
115
-
116
- always_trust = self.option(:always_trust)
117
- unless always_trust
118
- # check validity of recipients (this is possibly naive, but better than the unhelpful
119
- # error that it would spit out otherwise)
120
- keys.each do |key|
121
- unless key.primary_uid.validity >= GPGME::VALIDITY_FULL
122
- raise RecoverableError, "Key #{key.sha} (#{key.email}) not trusted (if key trust is established by another means then specify always-trust)"
123
- end
124
- end
125
- end
126
-
127
- data = GPGME::Data.from_str(plaintext)
128
- crypto = GPGME::Crypto.new(:always_trust => always_trust)
105
+ # TODO: check that keys are trusted
129
106
 
130
- ciphertext = crypto.encrypt(data, :recipients => keys)
131
- ciphertext.seek 0
132
- ciphertext.read
107
+ RubyGpg.encrypt_string(plaintext, recipients)
133
108
  end
134
109
 
135
110
  def self.decrypt ciphertext
136
111
  gnupghome = self.option :gnupghome
137
- GPGME::Engine.home_dir = gnupghome
138
112
  debug("GNUPGHOME is #{gnupghome}")
113
+ RubyGpg.config.homedir = gnupghome
139
114
 
140
- ctx = if hiera?
141
- GPGME::Ctx.new
142
- else
143
- GPGME::Ctx.new(:passphrase_callback => method(:passfunc))
144
- end
145
-
146
- if !ctx.keys.empty?
147
- raw = GPGME::Data.new(ciphertext)
148
- txt = GPGME::Data.new
149
-
150
- begin
151
- txt = ctx.decrypt(raw)
152
- rescue GPGME::Error::DecryptFailed => e
153
- warn("Fatal: Failed to decrypt ciphertext (check settings and that you are a recipient)")
154
- raise e
155
- rescue Exception => e
156
- warn("Warning: General exception decrypting GPG file")
157
- raise e
158
- end
159
-
160
- txt.seek 0
161
- txt.read
162
- else
163
- warn("No usable keys found in #{gnupghome}. Check :gpg_gnupghome value in hiera.yaml is correct")
164
- raise ArgumentError, "No usable keys found in #{gnupghome}. Check :gpg_gnupghome value in hiera.yaml is correct"
165
- end
115
+ RubyGpg.decrypt_string(ciphertext)
166
116
  end
167
117
 
168
118
  def self.create_keys
@@ -3,7 +3,7 @@ class Hiera
3
3
  module Eyaml
4
4
  module Encryptors
5
5
  module Gpg
6
- VERSION = "0.5"
6
+ VERSION = "0.6"
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hiera-eyaml-gpg_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.5'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Raphaël Pinson