sym 2.5.3 → 2.6.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
2
  SHA1:
3
- metadata.gz: aca611feea26256020a9d946efbbdc7cba379ce4
4
- data.tar.gz: 2948a5e41803333a67c7aae070a13d2742a0156a
3
+ metadata.gz: 4f617e5a540da0d9f51124c4ba3f8affa335593b
4
+ data.tar.gz: 5fe223d7450486ba4fc3b201bfb06311968f9963
5
5
  SHA512:
6
- metadata.gz: 238dace75955c11031173d5584dc3672fc623c34dd0dd491948147e471750d7fdf8685c8b77b5f27db29a0317abd9fb70ea94da2286f7837c48ec0ea9db68073
7
- data.tar.gz: 5678caa99c45624bb438954a3fc2bc9e70d1accb699104c0b061e244b53b18a444297b6953fe4438683b67a3174b8676fc38c7cb7a02258f28756f40cc9f35ec
6
+ metadata.gz: c17e78d532c9f3edbb075e1e1936619a187244a0e514b5b7600d6b686103f43af99b1f949846c489860875cb750c255bda8792ce5892163f1d968cb7498677d7
7
+ data.tar.gz: 4ae3a762791fcdf65417185ad0d0d3d9c85ef2d7b6db51cecd6d9ab4911768b125c10dba7e8815b92f9bb226230a92177cb309c0932253f5364b220b2ce4d687
@@ -4,6 +4,22 @@
4
4
 
5
5
  [Changes since the last tag](https://github.com/kigster/sym/compare/v2.5.1...HEAD)
6
6
 
7
+ ## [v2.6.0](https://github.com/kigster/sym/tree/v2.6.0) (2017-03-11)
8
+ [Full Changelog](https://github.com/kigster/sym/compare/v2.5.3...v2.6.0)
9
+
10
+ * Added `Sym::MagicFile` API for easy access to encrypted files.
11
+ * Moving output processing into the `Sym::Application` class.
12
+
13
+ ## [v2.5.3](https://github.com/kigster/sym/tree/v2.5.3) (2017-03-09)
14
+ [Full Changelog](https://github.com/kigster/sym/compare/v2.5.2...v2.5.3)
15
+
16
+ * Added a "\n" to all printouts to STDOUT as long as it's a TTY
17
+
18
+ ## [v2.5.2](https://github.com/kigster/sym/tree/v2.5.2) (2017-03-06)
19
+ [Full Changelog](https://github.com/kigster/sym/compare/v2.5.1...v2.5.2)
20
+
21
+ * Minor bug fixes around `symit` bash script, and `--bash-support` flag.
22
+
7
23
  ## [v2.5.1](https://github.com/kigster/sym/tree/v2.5.0) (2017-03-06)
8
24
  [Full Changelog](https://github.com/kigster/sym/compare/v2.5.0...v2.5.1)
9
25
 
data/README.md CHANGED
@@ -13,9 +13,11 @@
13
13
 
14
14
  <hr/>
15
15
 
16
+ **March 10th, 2017**: Please read the blog post [Dead Simple Encryption with Sym](http://kig.re/2017/03/10/dead-simple-encryption-with-sym.html) launching this tool and a library. Please leave comments or questions in the discussion thread at the bottom of that post. Thanks!
17
+
16
18
  ## Description
17
19
 
18
- <div style="padding 20px; font-size: 13pt;">
20
+ <div style="padding 40px; margin: 40px; font-size: 13pt;">
19
21
 
20
22
  <strong>sym</strong> is a command line utility and a Ruby API that makes it <em>trivial to encrypt and decrypt sensitive data</em>. Unlike many other existing encryption tools, <strong>sym</strong> focuses on usability and streamlined interface (CLI), with the goal of making encryption easy and transparent. The result? There is no longer any excuse for keeping your application secrets unencrypted or outside of your repo.<br /><br />
21
23
 
@@ -39,10 +41,11 @@ __Sym__ is a layer built on top of the [`OpenSSL`](https://www.openssl.org/) lib
39
41
 
40
42
  This gem includes two primary components:
41
43
 
42
- * [Rich command line interface CLI](#cli) with many features to streamline encryption/decryption.
43
- * Ruby API:
44
+ 1. [Rich command line interface CLI](#cli) with many features to streamline encryption/decryption.
45
+ 2. Ruby API:
44
46
  * [Basic Encryption/Decryption API](#rubyapi) is activated by including `Sym` module in a class, it adds easy to use `encr`/`decr` methods.
45
47
  * [Application API](#rubyapi-app) is activated by instantiating `Sym::Application`, and using the instance to drive sym's complete set of functionality, as if it was invoked from the CLI.
48
+ * [Sym::MagicFile API](#magic-file) is a convenience class allowing you to read encrypted files in your ruby code with a couple of lines of code.
46
49
  * [Sym::Configuration](#rubyapi-config) class for overriding default cipher, and many other parameters such as compression, cache location, zlib compression, and more.
47
50
 
48
51
  ### Massive Time Savers
@@ -176,7 +179,9 @@ Note the `diff` shown after save.
176
179
 
177
180
  ## Ruby API
178
181
 
179
- You start by including `Sym` module into your class or a module. Such class will be decorated with new class methods `#private_key` and `#create_private_key`, as well as instance methods `#encr`, and `#decr`.
182
+ ### Including `Sym` module
183
+
184
+ Low-level encryption routines can be imported by including `Sym` module into your class or a module. Such class will be decorated with new class methods `#private_key` and `#create_private_key`, as well as instance methods `#encr`, and `#decr`.
180
185
 
181
186
  #### Class Method `#create_private_key()`
182
187
 
@@ -207,7 +212,7 @@ end
207
212
  @key.eql?(SomeClass.private_key) # => true (it was assigned)
208
213
  ```
209
214
 
210
- #### Encrypting and Decrypting Data
215
+ #### Encrypting and Decrypting
211
216
 
212
217
  So how would we use this library from another Ruby project to encrypt and decrypt values?
213
218
 
@@ -246,7 +251,7 @@ They can be used independently of `encr` and `decr` to encrypt/decrypt any data
246
251
 
247
252
  <a name="rubyapi-app"></a>
248
253
 
249
- #### Full Application API
254
+ ### `Sym::Application`
250
255
 
251
256
  Since the command line interface offers much more than just encryption/decryption of data with a key, majority of these features are available through `Sym::Application` instance.
252
257
 
@@ -261,6 +266,50 @@ key = Sym::Application.new(generate: true).execute
261
266
  # => '75ngenJpB6zL47/8Wo7Ne6JN1pnOsqNEcIqblItpfg4='
262
267
  ```
263
268
 
269
+ ### `Sym::MagicFile` for Reading Encrypted Data
270
+
271
+ This is probably the easiest way to leverage Sym-encrypted files, by loading them into memory.
272
+
273
+ `Sym::MagicFile` provides a very simple API for loading and reading encrypted files
274
+ into memory, while supporting all of the convenience features of the rich
275
+ application API.
276
+
277
+ You initialize this class with just two things: a `pathname` to a file (encrypted
278
+ or not), and the `key` identifier. The identifier can either be a filename, or
279
+ OS-X Keychain entry, or environment variable name, etc — basically it is resolve
280
+ like any other `-k <value>` CLI flag.
281
+
282
+ #### Example: Using `Sym::MagicFile` with the `RailsConfig` gem
283
+
284
+ In this example, we assume that the environment variable `$PRIVATE_KEY` contain
285
+ the key to be used in decryption. Note that methods `#decrypt` and `#read` on `Sym::MagicFile` instance are synomymous.
286
+
287
+ ```ruby
288
+ require 'sym/magic_file'
289
+ require 'yaml'
290
+ secrets = Sym::MagicFile.new('/usr/local/etc/secrets.yml.enc', 'PRIVATE_KEY')
291
+ hash = YAML.load(secrets.decrypt)
292
+ ```
293
+
294
+ Let's say that you are using [RailsConfig](https://github.com/railsconfig/config) gem for managing your Rails application setings. Since the gem allows appending settings from a hash, you can simply do the following in your `settings_initializer.rb`, and after all of the unencrypted settings are loaded:
295
+
296
+ ```ruby
297
+ require 'config'
298
+ require 'sym/magic_file'
299
+ require 'yaml'
300
+ Settings.add_source!(
301
+ YAML.load(
302
+ Sym::MagicFile.new(
303
+ '/usr/local/etc/secrets.yml.enc',
304
+ 'PRIVATE_KEY'
305
+ ).decrypt)
306
+ )
307
+ Settings.reload!
308
+ ```
309
+
310
+ ### Ruby API Conclusion
311
+
312
+ Using `Sym`'s rich ruby API you can perform both low-level encryption/decryption, as well as high-level management of encrypted files. By using `Sym::MagicFile` and/or `Sym::Application` classes you can access the entire set of functionality expressed vi the CLI, described in details below.
264
313
 
265
314
  <a name="cli"></a>
266
315
  ## Using `sym` with the Command Line
@@ -98,12 +98,9 @@ module Sym
98
98
  def execute
99
99
  return Sym::App.exit_code if Sym::App.exit_code != 0
100
100
  result = application.execute
101
- case result
102
- when Hash
103
- self.output_proc ::Sym::App::Args.new({}).output_class
104
- error(result)
105
- else
106
- self.output_proc.call(result)
101
+ if result.is_a?(Hash)
102
+ self.output_proc ::Sym::App::Args.new({}).output_class
103
+ error(result)
107
104
  end
108
105
  Sym::App.exit_code
109
106
  end
@@ -61,7 +61,7 @@ module Sym
61
61
  end
62
62
 
63
63
  def content
64
- @content ||= (opts[:string] || (opts[:file].eql?('-') ? STDIN.read : File.read(opts[:file]).chomp))
64
+ @content ||= (opts[:string] || (opts[:file].eql?('-') ? STDIN.read : ::File.read(opts[:file]).chomp))
65
65
  end
66
66
 
67
67
  def to_s
@@ -7,6 +7,7 @@ module Sym
7
7
  required_option :output
8
8
 
9
9
  def output_proc
10
+ Sym::App.log :info, "writing to a file #{opts[:output]}"
10
11
  ->(data) {
11
12
  ::File.open(opts[:output], 'w') { |f| f.write(data) }
12
13
  }
@@ -51,8 +51,17 @@ module Sym
51
51
  end
52
52
  end
53
53
 
54
+ def process_output(result)
55
+ unless result.is_a?(Hash)
56
+ self.output.call(result)
57
+ result
58
+ else
59
+ result
60
+ end
61
+ end
62
+
54
63
  def execute
55
- execute!
64
+ process_output(execute!)
56
65
  rescue ::OpenSSL::Cipher::CipherError => e
57
66
  { reason: 'Invalid key provided',
58
67
  exception: e }
@@ -0,0 +1,88 @@
1
+ require 'sym/application'
2
+ module Sym
3
+ # This class provides a very simple API for loading/reading encrypted files
4
+ # into memory buffers, while supporting all of the convenience features of the
5
+ # sym CLI.
6
+ #
7
+ # You initialize this class with just two things: a pathname to a file (encrypted
8
+ # or not), and the key identifier. The identifier can either be a filename, or
9
+ # OS-X Keychain entry, or environment variable name, etc — basically it is resolved
10
+ # like any other `-k <value>` CLI flag.
11
+ #
12
+ # == Example
13
+ #
14
+ # In this example, we assume that the environment variable $PRIVATE_KEY contain
15
+ # the key to be used in decryption. Note that methods +decrypt+ and +read+ are
16
+ # synomymous
17
+ #
18
+ # require 'sym/magic_file'
19
+ # magic = Sym::MagicFile.new('/usr/local/etc/secrets.yml.enc', 'PRIVATE_KEY')
20
+ # YAML.load(magic.read)
21
+ #
22
+ # Or, lets say you are using the +config+ gem. Then you would do something like this:
23
+ #
24
+ # require 'config'
25
+ # Settings.add_source!(YAML.load(magic.decrypt))
26
+ #
27
+ class MagicFile
28
+ attr_accessor :pathname, :opts, :key_value, :action
29
+
30
+ def initialize(pathname, key_value, **opts)
31
+ init(key_value, opts, pathname)
32
+ end
33
+
34
+ # Returns decrypted string
35
+ def read
36
+ decrypt
37
+ end
38
+
39
+ # Encrypts +pathname+ to a +filename+
40
+ def encrypt_to(filename)
41
+ self.opts.merge!({output: filename})
42
+ encrypt
43
+ end
44
+
45
+ # Decrypts +pathname+ to a +filename+
46
+ def decrypt_to(filename)
47
+ self.opts.merge!({output: filename})
48
+ decrypt
49
+ end
50
+
51
+ # Returns encrypted string
52
+ def encrypt
53
+ self.opts.merge!({ encrypt: true })
54
+ action
55
+ end
56
+
57
+ # Returns decrypted string
58
+ def decrypt
59
+ self.opts.merge!({ decrypt: true })
60
+ action
61
+ end
62
+
63
+ private
64
+
65
+ def init(key_value, opts, pathname)
66
+ raise ArgumentError, 'pathname does not exist' unless ::File.exist?(pathname)
67
+ self.pathname = pathname
68
+ self.opts = opts || {}
69
+ self.key_value = key_value
70
+ self.opts.merge!({ file: pathname, key: key_value, quiet: true})
71
+ end
72
+
73
+ def action
74
+ app = Sym::Application.new(opts)
75
+ result = app.execute
76
+ if result.is_a?(Hash)
77
+ log :error, result.inspect
78
+ raise result[:exception] if result[:exception]
79
+ else
80
+ return result
81
+ end
82
+ end
83
+
84
+ def log(*args)
85
+ Sym::App.log(*args, **opts)
86
+ end
87
+ end
88
+ end
@@ -1,5 +1,5 @@
1
1
  module Sym
2
- VERSION = '2.5.3'
2
+ VERSION = '2.6.0'
3
3
  DESCRIPTION = <<-eof
4
4
  Sym is a command line utility plus a straightforward Ruby API that makes it easy to
5
5
  transparently handle sensitive data such as application secrets using symmetric
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sym
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Gredeskoul
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-11 00:00:00.000000000 Z
11
+ date: 2017-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -299,6 +299,7 @@ files:
299
299
  - lib/sym/extensions/stdlib.rb
300
300
  - lib/sym/extensions/with_retry.rb
301
301
  - lib/sym/extensions/with_timeout.rb
302
+ - lib/sym/magic_file.rb
302
303
  - lib/sym/version.rb
303
304
  - sym-3.0-cli.md
304
305
  - sym.gemspec