mail-gpg 0.3.3 → 0.4.0

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
- SHA1:
3
- metadata.gz: dc0c7bb838506fa1e0e3f01fbce200a95e13e76f
4
- data.tar.gz: a528a571122d6c9b61c5ce2152b37973bdec88d9
2
+ SHA256:
3
+ metadata.gz: 441163acdac450c30cee15a61caf0cdfced59f1014a3a25fb73725730c9dd04f
4
+ data.tar.gz: b9e69f9dbb562f7b776dba943990255bd16fe89367b3100afa9ec6b54aed1387
5
5
  SHA512:
6
- metadata.gz: 40c3c768a539f4e016fc259cbd13b5d7323b423bde90be8dcb4a970017dc9d33e686d73e5d1a834facd8db82e9816f96f1e1e08eebbdbfa21773eeb435e51493
7
- data.tar.gz: 1b37f11b4beb3311a1c894c2b1c77e626f8cadfd4cacdac74ab9bb96e528c6773ad10a91b093585276677825ed589555e21a7fe1673e82fd6193960e71bb7d87
6
+ metadata.gz: b53943970f5df90c515ed50d696bae79fa6842c9d5352bafba7e4fd278b0da9f322233a397d2c385d867220fe859714fa4d9f3664164b00adde1d9170ba99d27
7
+ data.tar.gz: 55124752f123ac57bab57450b93ad14e822868c7241c8f343a242278462985d918dfedfb6830ac21b25b8b855c99119d2c580974999cf7da9b80baa970c0adf6
@@ -1,3 +1,13 @@
1
+ == 0.4.0 2018-05-19
2
+
3
+ * [MIGHT BREAK THINGS] changes to the way keys are looked up #55
4
+ Previously, keys that were not explicitly mentioned but already present in
5
+ the key chain for one of the recipient addresses would have been used
6
+ silently. This is no longer the case, if the :keys option is given, all
7
+ necessary keys have to be specified as either key data, key id, fingerprint
8
+ or GPGME::Key object.
9
+ * fix error when calling encrypt with actual key objects #60
10
+
1
11
  == 0.3.3 2018-04-01
2
12
 
3
13
  * fix broken GpgmeHelper#keys_for_data #59
data/README.md CHANGED
@@ -84,6 +84,13 @@ In theory you only need to specify the key once like that, however doing it
84
84
  every time does not hurt as gpg is clever enough to recognize known keys, only
85
85
  updating it's db when necessary.
86
86
 
87
+ Note: Mail-Gpg in version 0.4 and up is more strict regarding the keys option:
88
+ if it is present, only key material from there (either given as key data like
89
+ above, or as key id, key fingerprint or `GPGMe::Key` object if they have been
90
+ imported before) will be used. Keys already present in the local keychain for
91
+ any of the recipients that are not explicitly mentioned in the `keys` hash will
92
+ be ignored.
93
+
87
94
  You may also want to have a look at the [GPGME](https://github.com/ueno/ruby-gpgme) docs and code base for more info on the various options, especially regarding the `passphrase_callback` arguments.
88
95
 
89
96
 
data/Rakefile CHANGED
@@ -53,5 +53,6 @@ Rake::TestTask.new(:test) do |test|
53
53
  test.libs << 'test'
54
54
  test.test_files = FileList['test/**/*_test.rb']
55
55
  test.verbose = true
56
+ test.warning = false
56
57
  end
57
58
 
@@ -11,7 +11,10 @@ module Mail
11
11
  # :recipients : array of receiver addresses
12
12
  # :keys : A hash mapping recipient email addresses to public keys or public
13
13
  # key ids. Imports any keys given here that are not already part of the
14
- # local keychain before sending the mail.
14
+ # local keychain before sending the mail. If this option is given, strictly
15
+ # only the key material from this hash is used, ignoring any keys for
16
+ # recipients that might have been added to the local key chain but are
17
+ # not mentioned here.
15
18
  # :always_trust : send encrypted mail to untrusted receivers, true by default
16
19
  # :filename : define a custom name for the encrypted file attachment
17
20
  def initialize(cleartext_mail, options = {})
@@ -115,16 +115,31 @@ module Mail
115
115
 
116
116
  # normalizes the list of recipients' emails, key ids and key data to a
117
117
  # list of Key objects
118
+ #
119
+ # if key_data is given, _only_ key material from there is used,
120
+ # and eventually already imported keys in the keychain are ignored.
118
121
  def self.keys_for_data(emails_or_shas_or_keys, key_data = nil)
119
122
  if key_data
123
+ # in this case, emails_or_shas_or_keys is supposed to be the list of
124
+ # recipients, and key_data the key material to be used.
125
+ # We now map these to whatever we find in key_data for each of these
126
+ # addresses.
120
127
  [emails_or_shas_or_keys].flatten.map do |r|
121
- # import any given keys
122
128
  k = key_data[r]
123
- if k and k =~ /-----BEGIN PGP/
124
- k = GPGME::Key.import(k).imports.map(&:fpr)
125
- k = nil if k.size == 0
126
- end
127
- key_id = k || r
129
+ key_id = case k
130
+ when GPGME::Key
131
+ # assuming this is already imported
132
+ k.fingerprint
133
+ when nil, ''
134
+ # nothing
135
+ nil
136
+ when /-----BEGIN PGP/
137
+ # ASCII key data
138
+ GPGME::Key.import(k).imports.map(&:fpr)
139
+ else
140
+ # key id or fingerprint
141
+ k
142
+ end
128
143
  unless key_id.nil? || key_id.empty?
129
144
  GPGME::Key.find(:public, key_id, :encrypt)
130
145
  end
@@ -1,5 +1,5 @@
1
1
  module Mail
2
2
  module Gpg
3
- VERSION = "0.3.3"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
@@ -15,6 +15,7 @@ class GpgmeHelperTest < Test::Unit::TestCase
15
15
  assert_equal [], Mail::Gpg::GpgmeHelper.send(:keys_for_data, [])
16
16
  end
17
17
 
18
+ # no keys given, assuming they are already in the keychain
18
19
  context 'with email address' do
19
20
  setup do
20
21
  @email = 'jane@foo.bar'
@@ -29,9 +30,10 @@ class GpgmeHelperTest < Test::Unit::TestCase
29
30
  assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, [@email])
30
31
  check_key_list keys
31
32
  end
32
-
33
33
  end
34
34
 
35
+ # this is a use case we do not really need but it works due to the way
36
+ # Gpgme looks up keys
35
37
  context 'with key id' do
36
38
  setup do
37
39
  @key_id = GPGME::Key.find(:public, 'jane@foo.bar').first.sha
@@ -47,6 +49,8 @@ class GpgmeHelperTest < Test::Unit::TestCase
47
49
  end
48
50
  end
49
51
 
52
+ # this is a use case we do not really need but it works due to the way
53
+ # Gpgme looks up keys
50
54
  context 'with key fingerprint' do
51
55
  setup do
52
56
  @key_fpr = GPGME::Key.find(:public, 'jane@foo.bar').first.fingerprint
@@ -62,17 +66,94 @@ class GpgmeHelperTest < Test::Unit::TestCase
62
66
  end
63
67
  end
64
68
 
65
- context 'with emails and key data' do
69
+ context 'with email addresses' do
66
70
  setup do
67
- @key = GPGME::Key.find(:public, 'jane@foo.bar').first.export(armor: true).to_s
71
+ @key = GPGME::Key.find(:public, 'jane@foo.bar').first
68
72
  @emails = ['jane@foo.bar']
69
- @key_data = { 'jane@foo.bar' => @key }
70
73
  end
71
74
 
72
- should 'resolve to gpg keys' do
73
- assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails, @key_data)
74
- check_key_list keys
75
+ # probably the most common use case - one or more recipient addresses and a
76
+ # hash mapping them to public key data that the user pasted into a text
77
+ # field at some point
78
+ context 'and key data' do
79
+ setup do
80
+ @key = @key.export(armor: true).to_s
81
+ @key_data = { 'jane@foo.bar' => @key }
82
+ end
83
+
84
+ should 'resolve to gpg key for single address' do
85
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails.first, @key_data)
86
+ check_key_list keys
87
+ end
88
+
89
+ should 'resolve to gpg keys' do
90
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails, @key_data)
91
+ check_key_list keys
92
+ end
93
+
94
+ should 'ignore unknown addresses' do
95
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, ['john@doe.com'], @key_data)
96
+ assert keys.blank?
97
+ end
98
+
99
+ should 'ignore invalid key data and not use existing key' do
100
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, ['jane@foo.bar'], { 'jane@foo.bar' => "-----BEGIN PGP\ninvalid key data" })
101
+ assert keys.blank?
102
+ end
75
103
  end
104
+
105
+ context 'and key id or fpr' do
106
+ setup do
107
+ @key_id = @key.sha
108
+ @key_fpr = @key.fingerprint
109
+ @email = @emails.first
110
+ end
111
+
112
+ should 'resolve id to gpg key for single address' do
113
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails.first, { @email => @key_id })
114
+ check_key_list keys
115
+ end
116
+
117
+ should 'resolve id to gpg key' do
118
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails, { @email => @key_id })
119
+ check_key_list keys
120
+ end
121
+
122
+ should 'resolve fpr to gpg key' do
123
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails, { @email => @key_fpr })
124
+ check_key_list keys
125
+ end
126
+
127
+ should 'ignore unknown addresses' do
128
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, ['john@doe.com'], { @email => @key_fpr })
129
+ assert keys.blank?
130
+ end
131
+
132
+ should 'ignore invalid key id and not use existing key' do
133
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails, { @email => "invalid key id" })
134
+ assert keys.blank?
135
+ end
136
+
137
+ end
138
+
139
+ # mapping email addresses to already retrieved key objects or
140
+ # key fingerprints is also possible.
141
+ context 'and key object' do
142
+ setup do
143
+ @key_data = { 'jane@foo.bar' => @key }
144
+ end
145
+
146
+ should 'resolve to gpg keys for these addresses' do
147
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, @emails, @key_data)
148
+ check_key_list keys
149
+ end
150
+
151
+ should 'ignore unknown addresses' do
152
+ assert keys = Mail::Gpg::GpgmeHelper.send(:keys_for_data, ['john@doe.com'], @key_data)
153
+ assert keys.blank?
154
+ end
155
+ end
156
+
76
157
  end
77
158
  end
78
159
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mail-gpg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Kraemer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-31 00:00:00.000000000 Z
11
+ date: 2018-05-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mail
@@ -210,7 +210,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
210
210
  version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.4.5
213
+ rubygems_version: 2.7.6
214
214
  signing_key:
215
215
  specification_version: 4
216
216
  summary: GPG/MIME encryption plugin for the Ruby Mail Library