gpgr 0.0.4 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/{README.markdown → README.md} +31 -31
- data/Rakefile +2 -53
- data/bin/gpgr-console +14 -0
- data/bin/gpgr-setup +8 -0
- data/gpgr.gemspec +34 -0
- data/lib/gpgr.rb +32 -30
- data/lib/gpgr/version.rb +3 -0
- metadata +87 -71
- data/COPYING +0 -340
- data/HACKING +0 -1
- data/LICENSE +0 -56
- data/test/generate_keys.rb +0 -31
- data/test/john_and_marks_keys/john.pub +0 -25
- data/test/john_and_marks_keys/mark.pub +0 -25
- data/test/test_file_encryption_functionality.rb +0 -48
- data/test/test_helper.rb +0 -19
- data/test/test_key_management_functionality.rb +0 -52
- data/test/test_keys/testing_1268859016.pub +0 -25
- data/test/test_keys/testing_1268859023.pub +0 -25
- data/test/test_keys/testing_1268859031.pub +0 -25
- data/test/test_keys_with_non_key_files/test.csv +0 -1
- data/test/test_keys_with_non_key_files/testing_1268859016.pub +0 -25
- data/test/test_keys_with_non_key_files/testing_1268859023.pub +0 -25
- data/test/test_keys_with_non_key_files/testing_1268859031.pub +0 -25
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: aa19ce161bda622a5e0f932624e885421b6e1345
|
4
|
+
data.tar.gz: 77ec9bf0a0f814c93d1ad5d1f411aab296d74a71
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: db43325774a05f02c6c4dbfd2d22cd7c879d73cd928efddb437ead88b3d29a04c5c9a391e99f87b2d4926afbdab5315958f12995f6c68b7758fbf09d0acf022c
|
7
|
+
data.tar.gz: ba54d526fb0f3c7aed077cc5cc28ab0222a2090513437cb578466a4d3b0114d8aa747d2f81680ec76b8e32c374477555d7c06f39fb45ac4fc14d8e09d2211f84
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at ryan@ryanstenhouse.eu. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Ryan Stenhouse
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
@@ -1,8 +1,12 @@
|
|
1
|
-
#gpgr - GNU Privacy Guard Encryption in Ruby
|
2
|
-
March 2010, Ryan Stenhouse <ryan@ryanstenhouse.eu>
|
3
|
-
Card Consultancy Limited][1]
|
1
|
+
# gpgr - GNU Privacy Guard Encryption in Ruby
|
2
|
+
March 2010 - Present, Ryan Stenhouse <ryan@ryanstenhouse.eu>
|
3
|
+
Originally behalf of [Purchasing Card Consultancy Limited][1].
|
4
4
|
|
5
|
-
|
5
|
+
> The current development version of gpgr is released under the MIT
|
6
|
+
> license. Previous versions were licensed under the GNU GPL. If you
|
7
|
+
> require the use of a GNU GPL version, please use `0.0.4`.
|
8
|
+
|
9
|
+
## About
|
6
10
|
|
7
11
|
gpgr is a lightweight and fast wrapper around the <tt>gpg</tt> command
|
8
12
|
commonly found on Linux and other Unix-like operating systems.
|
@@ -12,28 +16,28 @@ end aside from some basic key-management support, it will not wrap any
|
|
12
16
|
other parts of the gpg functionality.
|
13
17
|
|
14
18
|
If you need something that will elegantly and quickly encrypt files for
|
15
|
-
you and make managing the keys used within your application for this
|
19
|
+
you and make managing the keys used within your application for this
|
16
20
|
purpose a snap, use this. If not, use something else.
|
17
21
|
|
18
|
-
##Installation
|
22
|
+
## Installation
|
19
23
|
|
20
24
|
From Rubygems:
|
21
25
|
|
22
|
-
|
26
|
+
gem install gpgr
|
23
27
|
|
24
28
|
From GitHub:
|
25
|
-
|
26
|
-
|
27
|
-
|
29
|
+
|
30
|
+
Download or Clone the repoistory or just gpgr.rb and include it where
|
31
|
+
you need it.
|
28
32
|
|
29
33
|
|
30
|
-
##Requirements
|
34
|
+
## Requirements
|
31
35
|
|
32
36
|
gpgr has only really been tested on *nix environments, and indeed the path
|
33
37
|
hard-coded by default for the gpg binary will only be meaningful if you're
|
34
38
|
using a Linux-based or other UNIX-like operating system.
|
35
39
|
|
36
|
-
The only requirement (apart, obviously, from Ruby) is that you have gpg
|
40
|
+
The only requirement (apart, obviously, from Ruby) is that you have gpg
|
37
41
|
installed. On most modern Linux distributions, it should be there by default
|
38
42
|
to verify, open a terminal and key in:
|
39
43
|
|
@@ -42,19 +46,19 @@ to verify, open a terminal and key in:
|
|
42
46
|
If you see something like:
|
43
47
|
|
44
48
|
<pre>
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
49
|
+
ryan@ubuntu:~$ gpg --version
|
50
|
+
gpg (GnuPG) 1.4.6
|
51
|
+
Copyright (C) 2006 Free Software Foundation, Inc.
|
52
|
+
This program comes with ABSOLUTELY NO WARRANTY.
|
53
|
+
This is free software, and you are welcome to redistribute it
|
54
|
+
under certain conditions. See the file COPYING for details.
|
55
|
+
|
56
|
+
Home: ~/.gnupg
|
57
|
+
Supported algorithms:
|
58
|
+
Pubkey: RSA, RSA-E, RSA-S, ELG-E, DSA
|
59
|
+
Cipher: 3DES, CAST5, BLOWFISH, AES, AES192, AES256, TWOFISH
|
60
|
+
Hash: MD5, SHA1, RIPEMD160, SHA256, SHA384, SHA512, SHA224
|
61
|
+
Compression: Uncompressed, ZIP, ZLIB, BZIP2
|
58
62
|
</pre>
|
59
63
|
|
60
64
|
Congratulations.
|
@@ -67,11 +71,11 @@ As well as installing the command-line tools gpgr expects, seahorse which,
|
|
67
71
|
is a fantastic graphical tool for managing your keys, will be installed
|
68
72
|
|
69
73
|
|
70
|
-
For **Mac OS X**, you will first need to install <tt>gpg</tt>, you can do
|
74
|
+
For **Mac OS X**, you will first need to install <tt>gpg</tt>, you can do
|
71
75
|
this through MacPorts or Frink, but the best way is through [MacGPG][2], just
|
72
76
|
[download the latest version][3] and install int <tt>.pkg</tt> file it downloads.
|
73
77
|
|
74
|
-
##A Note on Testing
|
78
|
+
## A Note on Testing
|
75
79
|
|
76
80
|
Since gpgr really is just firing of to the GPG binary to all of the real work, there is little
|
77
81
|
to test within gpgr itself. I've added the tests I feel are prudent and useful. Feel free to
|
@@ -81,10 +85,6 @@ I do take the view, however, that GPG it's self is a very well established and p
|
|
81
85
|
project; and as such - any tests which attempt to test that *gpg* is functioning correctly will
|
82
86
|
not be accepted - I'm happy to assume that it is.
|
83
87
|
|
84
|
-
##Status
|
85
|
-
|
86
|
-
Published as a gem, current version 0.0.4
|
87
|
-
|
88
88
|
[1]: http://www.pccl.co.uk
|
89
89
|
[2]: http://macgpg.sourceforge.net/
|
90
90
|
[3]: http://sourceforge.net/projects/macgpg2/files/
|
data/Rakefile
CHANGED
@@ -1,62 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require 'rake'
|
1
|
+
require "bundler/gem_tasks"
|
3
2
|
require 'rake/testtask'
|
4
|
-
require "rake/rdoctask"
|
5
|
-
require "rake/gempackagetask"
|
6
3
|
|
7
|
-
|
4
|
+
task :default => :test
|
8
5
|
|
9
|
-
task :default => [:test]
|
10
|
-
|
11
|
-
desc "Run all tests, test-spec, mocha, and pdf-reader required"
|
12
6
|
Rake::TestTask.new do |test|
|
13
7
|
# test.ruby_opts << "-w" # .should == true triggers a lot of warnings
|
14
8
|
test.libs << "testrb"
|
15
9
|
test.test_files = Dir[ "test/test_*.rb" ]
|
16
10
|
test.verbose = true
|
17
11
|
end
|
18
|
-
|
19
|
-
desc "genrates documentation"
|
20
|
-
Rake::RDocTask.new do |rdoc|
|
21
|
-
rdoc.rdoc_files.include( "README.markdown",
|
22
|
-
"COPYING",
|
23
|
-
"LICENSE",
|
24
|
-
"HACKING", "lib/" )
|
25
|
-
rdoc.main = "lib/gpgr.rb"
|
26
|
-
rdoc.rdoc_dir = "doc/html"
|
27
|
-
rdoc.title = "Gpgr Documentation"
|
28
|
-
end
|
29
|
-
|
30
|
-
spec = Gem::Specification.new do |spec|
|
31
|
-
spec.name = "gpgr"
|
32
|
-
spec.version = GPGR_VERSION
|
33
|
-
spec.platform = Gem::Platform::RUBY
|
34
|
-
spec.summary = "A lightweight GPG CLI interface for encyrypting files"
|
35
|
-
spec.files = Dir.glob("{lib,spec,test}/**/**/*") +
|
36
|
-
["Rakefile"]
|
37
|
-
spec.require_path = "lib"
|
38
|
-
|
39
|
-
spec.test_files = Dir[ "test/*_test.rb" ]
|
40
|
-
spec.has_rdoc = true
|
41
|
-
spec.extra_rdoc_files = %w{HACKING README.markdown LICENSE COPYING}
|
42
|
-
spec.rdoc_options << '--title' << 'Gpgr Documentation' <<
|
43
|
-
'--main' << 'lib/gpgr.rb' << '-q'
|
44
|
-
spec.author = "Ryan Stenhouse"
|
45
|
-
spec.email = " ryan@ryanstenhouse.eu"
|
46
|
-
spec.rubyforge_project = "gpgr"
|
47
|
-
spec.homepage = "http://ryanstenhouse.eu"
|
48
|
-
spec.description = <<END_DESC
|
49
|
-
gpgr is a very light interface to the command-line GPG (GNU
|
50
|
-
Privacy Guard) tool which is soley concerned with making it
|
51
|
-
as easy as possible to encrypt files with one (or more) public
|
52
|
-
keys.
|
53
|
-
|
54
|
-
It does not provide any major key management tools and does not
|
55
|
-
support decryption.
|
56
|
-
END_DESC
|
57
|
-
end
|
58
|
-
|
59
|
-
Rake::GemPackageTask.new(spec) do |pkg|
|
60
|
-
pkg.need_zip = true
|
61
|
-
pkg.need_tar = true
|
62
|
-
end
|
data/bin/gpgr-console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gpgr"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/gpgr-setup
ADDED
data/gpgr.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "gpgr/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "gpgr"
|
8
|
+
spec.version = Gpgr::VERSION
|
9
|
+
spec.authors = ["Ryan Stenhouse"]
|
10
|
+
spec.email = ["ryan@ryanstenhouse.eu"]
|
11
|
+
|
12
|
+
spec.summary = %q{A lightweight GPG CLI interface for encyrypting files}
|
13
|
+
spec.description = <<-END_DESC
|
14
|
+
gpgr is a very light interface to the command-line GPG (GNU
|
15
|
+
Privacy Guard) tool which is soley concerned with making it
|
16
|
+
as easy as possible to encrypt files with one (or more) public
|
17
|
+
keys.
|
18
|
+
It does not provide any major key management tools and does not
|
19
|
+
support decryption.
|
20
|
+
END_DESC
|
21
|
+
spec.homepage = "https://ryanstenhouse.jp"
|
22
|
+
spec.license = "MIT"
|
23
|
+
|
24
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
25
|
+
f.match(%r{^(test|spec|features)/})
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 1.15"
|
32
|
+
spec.add_development_dependency "minitest"#, "~> 1.15"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
data/lib/gpgr.rb
CHANGED
@@ -1,16 +1,18 @@
|
|
1
|
+
require "gpgr/version"
|
2
|
+
|
1
3
|
# Gpgr by Ryan Stenhouse <ryan@ryanstenhouse.eu>, March 2010
|
2
4
|
# on behalf of Purchasing Card Consultancy Limited.
|
3
5
|
#
|
4
|
-
# gpgr is a very light interface to the command-line GPG (GNU
|
6
|
+
# gpgr is a very light interface to the command-line GPG (GNU
|
5
7
|
# Privacy Guard) tool which is soley concerned with making it
|
6
8
|
# as easy as possible to encrypt files with one (or more) public
|
7
9
|
# keys.
|
8
10
|
#
|
9
11
|
# It does not provide any major key management tools and does not
|
10
|
-
# support decryption.
|
12
|
+
# support decryption.
|
11
13
|
#
|
12
14
|
# Usage:
|
13
|
-
#
|
15
|
+
#
|
14
16
|
# require 'rubygems'
|
15
17
|
# require 'gpgr'
|
16
18
|
#
|
@@ -22,14 +24,14 @@
|
|
22
24
|
# # To import all the public keys in a given directory
|
23
25
|
# #
|
24
26
|
# Gpgr::Keys.import_keys_at('/path/to/public/keys')
|
25
|
-
#
|
27
|
+
#
|
26
28
|
# # Will encrypt for every single person you have a public key for
|
27
29
|
# #
|
28
30
|
# Gpgr::Encrypt.file('/some_file.txt', :to => '/encrypted.gpg').encrypt_using(Gpgr::Keys.installed_public_keys)
|
29
31
|
#
|
30
32
|
module Gpgr
|
31
33
|
|
32
|
-
# Returns the command to execute to run GPG. It is defualted to /use/bin/env gpg
|
34
|
+
# Returns the command to execute to run GPG. It is defualted to /use/bin/env gpg
|
33
35
|
# which should correctly track down gpg on any UNIX-like operating system. If you
|
34
36
|
# need to use this on Windows, simply change the method to return the path to where
|
35
37
|
# gpg is installed.
|
@@ -45,7 +47,7 @@ module Gpgr
|
|
45
47
|
# is done by the class GpgGileForEncryption.
|
46
48
|
#
|
47
49
|
module Encrypt
|
48
|
-
|
50
|
+
|
49
51
|
# Takes the path to the file you want to encrypt; and returns a GpgFileForEncryption
|
50
52
|
# object for you to modify with the people (e-mail addresses) you want to encrypt this
|
51
53
|
# file for. Optionally you can specify where you want the encrypted file to be written,
|
@@ -56,7 +58,7 @@ module Gpgr
|
|
56
58
|
default_options = { :to => "#{path}.pgp" }.merge(options)
|
57
59
|
GpgFileForEncryption.new(path, default_options[:to])
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
# Raised if there is an invalid e-mail address provided to encrypt with
|
61
63
|
#
|
62
64
|
class InvalidEmailException < Exception; end
|
@@ -64,15 +66,15 @@ module Gpgr
|
|
64
66
|
# Raised if the input or output files for the GPG Encryption are invalid somehow
|
65
67
|
#
|
66
68
|
class InvalidFileException < Exception; end
|
67
|
-
|
69
|
+
|
68
70
|
|
69
71
|
# Contians the details used to encrypt specified +file+, is what actually does
|
70
72
|
# any encryption.
|
71
|
-
#
|
73
|
+
#
|
72
74
|
class GpgFileForEncryption
|
73
|
-
|
75
|
+
|
74
76
|
attr_accessor :email_addresses, :file, :file_output
|
75
|
-
|
77
|
+
|
76
78
|
# The path to the file which GPG Will be encrypting and the path where
|
77
79
|
# you want the encrypted file to be output.
|
78
80
|
#
|
@@ -85,34 +87,34 @@ module Gpgr
|
|
85
87
|
end
|
86
88
|
@email_addresses = []
|
87
89
|
end
|
88
|
-
|
90
|
+
|
89
91
|
# Takes a list of e-mail addresses and then encrypts the file straight away.
|
90
92
|
#
|
91
93
|
def encrypt_using(email_addresses)
|
92
94
|
using(email_addresses)
|
93
95
|
encrypt
|
94
96
|
end
|
95
|
-
|
96
|
-
# Expects an array of e-mail addresses for people who this file file should be
|
97
|
-
# decryptable by.
|
97
|
+
|
98
|
+
# Expects an array of e-mail addresses for people who this file file should be
|
99
|
+
# decryptable by.
|
98
100
|
#
|
99
101
|
def using(email_addresses)
|
100
102
|
@email_addresses = email_addresses
|
101
103
|
end
|
102
|
-
|
104
|
+
|
103
105
|
# Encrypts the current file for the list of recipients specific (if they are valid)
|
104
|
-
#
|
106
|
+
#
|
105
107
|
def encrypt
|
106
108
|
bad_key = @email_addresses.empty?
|
107
|
-
|
108
|
-
if File.
|
109
|
+
|
110
|
+
if File.exist?(@file)
|
109
111
|
unless File.readable?(@file)
|
110
112
|
raise InvalidFileException.new("File at #{@file} is not readable.") and return
|
111
113
|
end
|
112
114
|
else
|
113
115
|
raise InvalidFileException.new("File at #{@file} does not exist.") and return
|
114
116
|
end
|
115
|
-
|
117
|
+
|
116
118
|
@email_addresses.each do |add|
|
117
119
|
unless Gpgr::Keys.public_key_installed?(add)
|
118
120
|
bad_key = true
|
@@ -125,7 +127,7 @@ module Gpgr
|
|
125
127
|
system(command)
|
126
128
|
end
|
127
129
|
end
|
128
|
-
|
130
|
+
|
129
131
|
end
|
130
132
|
|
131
133
|
end
|
@@ -133,7 +135,7 @@ module Gpgr
|
|
133
135
|
# Encapsulates all the functionality for dealing with GPG Keys. There isn't much here since
|
134
136
|
# key managment isn't really one of the goals of this project. It will, however, allow you
|
135
137
|
# to import new keys and provides a means to list existing installed keys.
|
136
|
-
#
|
138
|
+
#
|
137
139
|
module Keys
|
138
140
|
|
139
141
|
# Imports the key at the specified path into the keyring. Since this is
|
@@ -146,14 +148,14 @@ module Gpgr
|
|
146
148
|
|
147
149
|
# Iterates through all of the files at a specified path and attempts to import
|
148
150
|
# those which are likely to be GPG / PGP Public Keys.
|
149
|
-
#
|
151
|
+
#
|
150
152
|
def self.import_keys_at(path)
|
151
153
|
Dir.new(path).each do |file|
|
152
154
|
next if ['..','.'].include?(file)
|
153
155
|
Gpgr::Keys.import(path + '/' + file)
|
154
156
|
end
|
155
157
|
end
|
156
|
-
|
158
|
+
|
157
159
|
# Returns an array with the e-mail addresses of every installed public key
|
158
160
|
# for looping through and detecting if a particular key is installed.
|
159
161
|
#
|
@@ -164,26 +166,26 @@ module Gpgr
|
|
164
166
|
# Select the output to grep for, which is different depending on the version
|
165
167
|
# of GPG installed. This is tested on 1.4 and 2.1.
|
166
168
|
#
|
167
|
-
if `#{Gpgr.command} --version | grep GnuPG`.include?('
|
168
|
-
grep_for = 'pub'
|
169
|
-
else
|
169
|
+
if `#{Gpgr.command} --version | grep GnuPG`.include?('2.')
|
170
170
|
grep_for = 'uid'
|
171
|
+
else
|
172
|
+
grep_for = 'pub'
|
171
173
|
end
|
172
174
|
|
173
|
-
`#{Gpgr.command} --list-public-keys --with-colons | grep #{grep_for}`.split("\n").each do |key|
|
175
|
+
`#{Gpgr.command} --list-public-keys --with-colons | grep #{grep_for}`.split("\n").each do |key|
|
174
176
|
keys << email_regexp.match(key)[1].upcase
|
175
177
|
end
|
176
178
|
|
177
179
|
keys.uniq
|
178
180
|
end
|
179
|
-
|
181
|
+
|
180
182
|
# Simply checks to see if the e-mail address passed through as an argument has a
|
181
183
|
# public key attached to it by checking in installed_public_keys.
|
182
184
|
#
|
183
185
|
def self.public_key_installed?(email)
|
184
186
|
installed_public_keys.include?(email.upcase)
|
185
187
|
end
|
186
|
-
|
188
|
+
|
187
189
|
end
|
188
190
|
|
189
191
|
end
|