sym 2.0.2 → 2.0.3

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: 54b712e7e8491557d2ca064b7864b6bf8b53b908
4
- data.tar.gz: 3c867fd002b7597eae078e995b47b47331c6d3d0
3
+ metadata.gz: 9d1c0e747eef0d680cc7a8f69f01173744c4e29d
4
+ data.tar.gz: 194dc2f5f74011848f9673bf2d4e5b018baa166f
5
5
  SHA512:
6
- metadata.gz: 185731d39d78c99cd75899cd1769ee333c1757e0e7df195c1909f3bb3bdb022276fa24d309548cba08bf3f5a5400f2a8e10fe2e2b69118ed0b8b4fbae3954d28
7
- data.tar.gz: 56360fe600e09f6d8e6fecb55fd92a69d162b4af507eb0074c7606fe303093c8e3cd61f4d9dcd883ca772197e6930e4352b134de1e6ce82e4958e636e4090a8a
6
+ metadata.gz: b7bb4fed47d8a416622963d25209033dcf444f505db8c16edd08be6ef8a16beee92762e678cfb6f75f0588c92c2b0ebdb1058e5dd9c96e4382c598cac6a28550
7
+ data.tar.gz: 3df569a2f8ea1995401c0e916dbfd34bcf8bcb41ca6747fe51918fbe7dc89e3025f8aa4c90dc05997676d5507ea4bba126c5c7e60ea870597d4a0fdd2819daa1
data/.codeclimate.yml CHANGED
@@ -12,6 +12,11 @@ engines:
12
12
  enabled: true
13
13
  rubocop:
14
14
  enabled: true
15
+ checks:
16
+ Rubocop/Metrics/MethodLength:
17
+ enabled: false
18
+ Rubocop/Metrics/CyclomaticComplexity:
19
+ enabled: false
15
20
  ratings:
16
21
  paths:
17
22
  - "**.inc"
data/.travis.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  language: ruby
2
2
  env:
3
- - CODECLIMATE_REPO_TOKEN=be1a1a266b0ffc81fa0bd1e432a229f2a4ab420dcb9e9e15c1e75e2acad573b7
3
+ - CODECLIMATE_REPO_TOKEN=c71874cc22acffe1e2543d3388d3a96c73a65f0cfe17169dadd8de4a6c062c39
4
4
  rvm:
5
5
  - 2.4.0
6
6
  - 2.3.3
@@ -16,7 +16,7 @@ notifications:
16
16
  secure: GcACCHmcmo99lYE5dgt2TmY4YIPMWr75q0Bkm4Lddegq/1eMXgcZDz00j8iHWtnveyJSjEUpZFQ9uyx+P7dvxT7D5gl43arKZEylS4vMRg9QRgZu7/ROrXbJtrUyKulFRUTdFrmOiK9nDKpAzlvLvMKC4kaQnn88Xtu9pYMU8y4n5fCtl29gZM9ZjVbrBBvV/SumnTDLla2oQ7oFgUZdZhQZ1qsevYknxNq4eIcvPDjbon+bovfsIISEVRSNo2C3yjO+mqWKed3jfuCA4taAZ8/aVVFEKURMH10HFms1CiC3lE/gF4YfBXsqKpjnB+bKjBcWox2FQrp96FulMEIfkKQrnuncO96o7MGHX9oNqKSMoycf3+SZFwNa+5Mfq7SBepbHYCoU7/ow31UTyStrc5idG19XzYgI85yjQHdzQN299Xf0O8cGf9q9qAu7rS7JlM3ekR+3rZYO+OxNYTF8rcW1fYIj6GKcbsV8BvuhAVQRFOsk/ibcIb2N7rGVd/ZbU4HAk3RE1ywt+XowinpIHktu2PQUPDNpgRQwM6xqZHO/7s9r7oW0ULmZCMLZ9CMKNjKzrQ9wfh90+v+FiEiUKsaVj4cCwF3PvhVYvxU2AKbCeHtSEb7K6to86+DYNoIKnGH1ryKoyCtyOTZpNMLGFt34Msv7WfEylhG+DpVMvkM=
17
17
  addons:
18
18
  code_climate:
19
- repo_token: be1a1a266b0ffc81fa0bd1e432a229f2a4ab420dcb9e9e15c1e75e2acad573b7
19
+ repo_token: c71874cc22acffe1e2543d3388d3a96c73a65f0cfe17169dadd8de4a6c062c39
20
20
  # regular test configuration
21
21
  after_success:
22
22
  - bundle exec codeclimate-test-reporter
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ **2.0.3** (January 22, 2017)
2
+
3
+ * Removed clipboard copy functionality, as it's easy to achieve with `pbcopy`.
4
+ * Removed natural language processing stuff
5
+ * Removed `keychain-del` feature
6
+ * Refactored bash-completion to install a separate ~/.sym.completion file
7
+ * Updated README
8
+
9
+ **2.0.2** (January 20, 2017)
10
+
11
+ * Added bash-completion installation
12
+ * Fixed a bug where a newline was added to file redirects, making
13
+ redirecting encrypted data or keys unusable.
14
+
data/README.md CHANGED
@@ -1,6 +1,4 @@
1
-
2
-
3
- # Sym — Your Encryption Best Friend
1
+ # Sym — Light Weight Symmetric Encryption for Humans
4
2
 
5
3
  [![Gem Version](https://badge.fury.io/rb/sym.svg)](https://badge.fury.io/rb/sym)
6
4
  [![Downloads](http://ruby-gem-downloads-badge.herokuapp.com/sym?type=total)](https://rubygems.org/gems/sym)
@@ -15,7 +13,7 @@
15
13
 
16
14
  ### Summary
17
15
 
18
- > __sym__ is little program that makes it _trivial to encrypt and decrypt sensitive data_. But, unlike many other existing tools, __sym__'s goal is to dramatically simplify the command line interface (CLI), and make symmetric encryption as routine as listing directories in Terminal.
16
+ > __sym__ is a utility and an API that makes it _trivial to encrypt and decrypt sensitive data_. Unlike many other existing tools, __sym__'s goal is to dramatically simplify the command line interface (CLI), and make symmetric encryption as routine as listing directories in Terminal.
19
17
 
20
18
  With this tool I wanted to make it easy to memorize the most common options, so that there is little no longer a barrier to the full power of encryption offered by [`OpenSSL`](https://www.openssl.org/) library.
21
19
 
@@ -73,7 +71,11 @@ Or install it into the global namespace with `gem install` command:
73
71
 
74
72
  ### BASH Completion (Optional Step)
75
73
 
76
- After gem installation, an message will tell you to install a shown BASH script to your `~/.bashrc` or equivalent.
74
+ After gem installation, an message will tell you to install bash completion into to your `~/.bashrc` or equivalent:
75
+
76
+ ```bash
77
+ sym --bash-completion ~/.bashrc
78
+ ```
77
79
 
78
80
  Should you choose to install it (this part is optional), you will be able to use "tab-tab" after typing `sym` and you'll be able to choose from all supported flags.
79
81
 
@@ -85,7 +87,7 @@ This library relies on the existance of the 32-byte private key (aka, *a secret*
85
87
 
86
88
  The key can be easily:
87
89
 
88
- * generated by this gem and displayed, copied to the clipboard, or saved to the KeyChain
90
+ * generated by this gem and displayed, or saved to Mac OS-X KeyChain
89
91
  * one way or another must be kept very well protected and secure from attackers
90
92
  * can be fetched from the the Keychain in subsequent encryption/decryption steps
91
93
  * password-protected, which you can enable during the generation with the `-p` flag.
@@ -103,9 +105,9 @@ You can generate using the command line, or in a programmatic way. First we'll d
103
105
 
104
106
  #### Generating and Using Private Keys
105
107
 
106
- Once the gem is installed you will be able to run an executable `sym`. Now let's generate and copy the new private key to the clipboard. Clipboard copy is activated with the -c flag:
108
+ Once the gem is installed you will be able to run an executable `sym`. Now let's generate and copy the new private key to the clipboard (using `pbcopy` command on Mac OS-X):
107
109
 
108
- sym -gc
110
+ sym -g | pbcopy
109
111
 
110
112
  Or save a new key into a bash variable
111
113
 
@@ -161,47 +163,43 @@ You can use this to add an existing key that can be used with the `sym` later. O
161
163
  This may be a good time to take a look at the full help message for the `sym` tool, shown naturally with a `-h` or `--help` option.
162
164
 
163
165
  ```
164
- Sym (1.7.0) – encrypt/decrypt data with a private key
166
+ Sym (2.0.2) – encrypt/decrypt data with a private key
165
167
 
166
168
  Usage:
167
169
  # Generate a new key:
168
- sym -g [ -c ] [ -p ] [ -x keychain ] [ -o keyfile | -q | ]
170
+ sym -g [ -c ] [ -p ] [ -x keychain ] [ -o keyfile | -q | ]
169
171
 
170
172
  # Encrypt/Decrypt
171
- sym [ -d | -e ] [ -f <file> | -s <string> ]
173
+ sym [ -d | -e ] [ -f <file> | -s <string> ]
172
174
  [ -k key | -K keyfile | -x keychain | -i ]
173
175
  [ -o <output file> ]
174
176
 
175
177
  # Edit an encrypted file in $EDITOR
176
- sym -t -f <file> [ -b ][ -k key | -K keyfile | -x keychain | -i ]
178
+ sym -t -f <file> [ -b ][ -k key | -K keyfile | -x keychain | -i ]
177
179
 
178
180
  Modes:
179
181
  -e, --encrypt encrypt mode
180
182
  -d, --decrypt decrypt mode
181
183
  -t, --edit decrypt, open an encr. file in an $EDITOR
182
184
 
183
- Create a private key:
185
+ Create a new private key:
184
186
  -g, --generate generate a new private key
185
187
  -p, --password encrypt the key with a password
186
- -c, --copy copy the new key to the clipboard
187
188
  -x, --keychain [key-name] add to (or read from) the OS-X Keychain
188
-
189
- Password Caching:
190
189
  -M, --password-timeout [timeout] when passwords expire (in seconds)
191
- -P, --no-password-cache disables key password caching
190
+ -P, --no-password-cache disables caching of key passwords
192
191
 
193
- Provide a private key:
192
+ Read existing private key from:
194
193
  -i, --interactive Paste or type the key interactively
195
194
  -k, --private-key [key] private key as a string
196
195
  -K, --keyfile [key-file] private key from a file
197
196
 
198
- Data:
197
+ Data to Encrypt/Decrypt:
199
198
  -s, --string [string] specify a string to encrypt/decrypt
200
199
  -f, --file [file] filename to read from
201
200
  -o, --output [file] filename to write to
202
201
 
203
202
  Flags:
204
- --keychain-del [key-name] delete keychain entry with that name
205
203
  -b, --backup create a backup file in the edit mode
206
204
  -v, --verbose show additional information
207
205
  -T, --trace print a backtrace of any errors
@@ -209,6 +207,9 @@ Flags:
209
207
  -V, --version print library version
210
208
  -N, --no-color disable color output
211
209
 
210
+ Utility:
211
+ -a, --bash-completion [file] append shell completion to a file
212
+
212
213
  Help & Examples:
213
214
  -E, --examples show several examples
214
215
  -L, --language natural language examples
@@ -225,9 +226,9 @@ Generate a new private key into an environment variable:
225
226
  echo $KEY
226
227
  # => 75ngenJpB6zL47/8Wo7Ne6JN1pnOsqNEcIqblItpfg4=
227
228
 
228
- Generate a new password-protected key, copy to the clipboard & save to a file:
229
+ Generate a new password-protected key & save to a file:
229
230
 
230
- sym -gpc -o ~/.key
231
+ sym -gp -o ~/.key
231
232
  New Password : ••••••••••
232
233
  Confirm Password : ••••••••••
233
234
 
@@ -274,81 +275,6 @@ To edit an encrypted file in $EDITOR, while asking to paste the key (`-i | --int
274
275
  # ---
275
276
  # # (c) 2016 Konstantin Gredeskoul. All rights reserved.
276
277
 
277
-
278
- ### Natural Language Processing
279
-
280
- When sym is invoked, and the first argument does not begin with a dash,
281
- then the the NLP (natural language processing) Translator is invoked.
282
- The Translator is based on a very simple algorithm:
283
-
284
- * ignore any of the words tagged STRIPPED. These are the ambiguous words, or words with duplicate meaning.
285
- * map the remaining arguments to regular double-dashed options using the DICTIONARY
286
- * words that are a direct match for a --option are automatically double-dashed
287
- * remaining words are left as is (these would be file names, key names, etc).
288
- * finally, the resulting "new" command line is parsed with regular options.
289
- * When arguments include "verbose", NLP system will print "before" and "after"
290
- of the arguments, so that any issues can be debugged and corrected.
291
-
292
- #### CURRENTLY IGNORED WORDS:
293
-
294
- and, a, the, it, item, to, key, with, about, for, of, new, make, store, in, print
295
-
296
- #### REGULAR WORD MAPPING
297
-
298
- ```
299
- ________________________________________________________________________
300
- clipboard ───────➤ --copy
301
- unlock ───────➤ --decrypt
302
- open ───────➤ --edit
303
- lock ───────➤ --encrypt
304
- ───────➤ --backup
305
- ───────➤ --keychain
306
- read ───────➤ --file
307
- create ───────➤ --generate
308
- ask enter type ───────➤ --interactive
309
- from ───────➤ --keyfile
310
- save write ───────➤ --output
311
- using private ───────➤ --private_key
312
- value ───────➤ --string
313
- silently quietly silent sym ───────➤ --quiet
314
- secure secured protected ───────➤ --password
315
- ________________________________________________________________________
316
- ```
317
-
318
- #### EXAMPLES
319
-
320
- ```bash
321
- # generate a new private key and copy to the clipboard but do not print to terminal
322
- sym create new key to clipboard quietly
323
-
324
- # generate and save to a file a password-protected key, silently
325
- sym create a secure key and save it to "my.key"
326
-
327
- # encrypt a plain text string with a key, and save the output to a file
328
- sym encrypt string "secret string" using $(cat my.key) save to file.enc
329
-
330
- # decrypt a previously encrypted string:
331
- sym decrypt string $ENC using $(cat my.key)
332
-
333
- # encrypt "file.txt" with key from my.key and save it to file.enc
334
- sym encrypt file file.txt with key from my.key and save it to file.enc
335
-
336
- # decrypt an encrypted file and print it to STDOUT:
337
- sym decrypt file file.enc with key from "my.key"
338
-
339
- # edit an encrypted file in $EDITOR, ask for key, and create a backup upon save
340
- sym edit file file.enc ask for a key and make a backup
341
-
342
- # generate a new password-encrypted key, save it to your Keychain:
343
- sym create a new protected key store in keychain "my-keychain-key"
344
-
345
- # print the key stored in the keychain item "my-keychain-key"
346
- sym print keychain "my-keychain-key"
347
-
348
- # use the new key to encrypt a file:
349
- sym encrypt with keychain "my-keychain-key" file "password.txt" and write to "passwords.enc"
350
- ```
351
-
352
278
  ### Ruby API
353
279
 
354
280
  To use this library you must include the main `Sym` module into your library.
@@ -444,19 +370,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
444
370
 
445
371
  ## Contributing
446
372
 
447
- Bug reports and pull requests are welcome on GitHub at https://github.com/kigster/sym.
448
-
449
- ## Feature Ideas
450
-
451
- ### Natural Language Based API
452
-
453
- This is the proposed mini-idea/specification for an alternative CLI that is at a feature parity with the standard flag-based CLI.
454
-
455
- sym generate key to the clipboard and keychain
456
- sym encrypt file 'hello' using $key [to output.enc]
457
- sym edit 'passwords.enc' using $key
458
- sym decrypt /etc/secrets encrypted with $key save to ./secrets
459
- sym encrypt with keychain $item file $input
373
+ Bug reports and pull requests are welcome on GitHub at (https://github.com/kigster/sym)[https://github.com/kigster/sym].
460
374
 
461
375
  ## License
462
376
 
@@ -464,5 +378,5 @@ The gem is available as open source under the terms of the [MIT License](http://
464
378
 
465
379
  ## Author
466
380
 
467
- This library is the work of [Konstantin Gredeskoul](http:/kig.re), &copy; 2016, distributed under the MIT license.
381
+ This library is the work of [Konstantin Gredeskoul](http:/kig.re), &copy; 2016-2017, distributed under the MIT license.
468
382
 
@@ -1,4 +1,3 @@
1
-
2
1
  #!/usr/bin/env bash
3
2
  #
4
3
  # Sym command line completion
data/exe/keychain CHANGED
@@ -9,7 +9,7 @@ require 'sym/app/keychain'
9
9
  require 'colored2'
10
10
 
11
11
  def usage
12
- puts 'Usage: ' + 'keychain'.bold.blue + ' item [ add <contents> | find | delete ]'.bold.green
12
+ puts 'Usage: ' + 'keychain'.bold.blue + ' name [ add <contents> | find | delete ]'.bold.green
13
13
  exit 0
14
14
  end
15
15
 
data/exe/sym CHANGED
@@ -8,9 +8,7 @@ require 'sym/app'
8
8
 
9
9
  #ARGV.any?{ |a| a =~ /^-/ } ?
10
10
  begin
11
- ARGV.first =~ /^-/ ?
12
- ::Sym::App::CLI.new(ARGV.dup).execute :
13
- ::Sym::App::NLP::Translator.new(ARGV.dup).translate.and.execute
11
+ ::Sym::App::CLI.new(ARGV.dup).execute
14
12
  rescue Interrupt => e
15
13
  STDERR.flush
16
14
  STDERR.puts "Interrupt, #{e.message}, exiting."
data/lib/sym/app/cli.rb CHANGED
@@ -9,7 +9,6 @@ require 'sym/errors'
9
9
  require 'sym/app/commands'
10
10
  require 'sym/app/keychain'
11
11
  require 'sym/app/private_key/handler'
12
- require 'sym/app/nlp/constants'
13
12
  require 'highline'
14
13
 
15
14
  require_relative 'output/file'
@@ -124,7 +123,7 @@ module Sym
124
123
  o.banner = "Sym (#{Sym::VERSION}) – encrypt/decrypt data with a private key\n".bold.white
125
124
  o.separator 'Usage:'.yellow
126
125
  o.separator ' # Generate a new key:'.dark
127
- o.separator ' sym -g '.green.bold + '[ -c ] [ -p ] [ -x keychain ] [ -o keyfile | -q | ] '.green
126
+ o.separator ' sym -g '.green.bold + '[ -p ] [ -x keychain ] [ -o keyfile | -q | ] '.green
128
127
  o.separator ''
129
128
  o.separator ' # Encrypt/Decrypt '.dark
130
129
  o.separator ' sym [ -d | -e ] '.green.bold + '[ -f <file> | -s <string> ] '.green
@@ -142,37 +141,30 @@ module Sym
142
141
  o.bool '-t', '--edit', ' decrypt, open an encr. file in an $EDITOR'
143
142
 
144
143
  o.separator ' '
145
- o.separator 'Create a private key:'.yellow
144
+ o.separator 'Create a new private key:'.yellow
146
145
 
147
146
  o.bool '-g', '--generate', ' generate a new private key'
148
147
  o.bool '-p', '--password', ' encrypt the key with a password'
149
- o.bool '-c', '--copy', ' copy the new key to the clipboard'
150
148
 
151
149
  if Sym::App.is_osx?
152
150
  o.string '-x', '--keychain', '[key-name] '.blue + 'add to (or read from) the OS-X Keychain'
153
151
  end
154
152
 
155
- o.separator ' '
156
- o.separator 'Password Caching:'.yellow
157
-
158
153
  o.integer '-M', '--password-timeout', '[timeout]'.blue + ' when passwords expire (in seconds)'
159
- o.bool '-P', '--no-password-cache', ' disables key password caching'
154
+ o.bool '-P', '--no-password-cache', ' disables caching of key passwords'
160
155
 
161
156
  o.separator ' '
162
- o.separator 'Provide a private key:'.yellow
163
- o.bool '-i', '--interactive', ' Paste or type the key interactively'
164
- o.string '-k', '--private-key', '[key] '.blue + ' private key as a string'
165
- o.string '-K', '--keyfile', '[key-file]'.blue + ' private key from a file'
157
+ o.separator 'Read existing private key from:'.yellow
158
+ o.bool '-i', '--interactive', ' Paste or type the key interactively'
159
+ o.string '-k', '--private-key', '[key] '.blue + ' private key as a string'
160
+ o.string '-K', '--keyfile', '[key-file]'.blue + ' private key from a file'
166
161
  o.separator ' '
167
- o.separator 'Data:'.yellow
162
+ o.separator 'Data to Encrypt/Decrypt:'.yellow
168
163
  o.string '-s', '--string', '[string]'.blue + ' specify a string to encrypt/decrypt'
169
164
  o.string '-f', '--file', '[file] '.blue + ' filename to read from'
170
165
  o.string '-o', '--output', '[file] '.blue + ' filename to write to'
171
166
  o.separator ' '
172
167
  o.separator 'Flags:'.yellow
173
- if Sym::App.is_osx?
174
- o.string '--keychain-del', '[key-name] '.blue + 'delete keychain entry with that name'
175
- end
176
168
  o.bool '-b', '--backup', ' create a backup file in the edit mode'
177
169
  o.bool '-v', '--verbose', ' show additional information'
178
170
  o.bool '-T', '--trace', ' print a backtrace of any errors'
@@ -180,9 +172,11 @@ module Sym
180
172
  o.bool '-V', '--version', ' print library version'
181
173
  o.bool '-N', '--no-color', ' disable color output'
182
174
  o.separator ' '
175
+ o.separator 'Utility:'.yellow
176
+ o.string '-a', '--bash-completion', '[file]'.blue + ' append shell completion to a file'
177
+ o.separator ' '
183
178
  o.separator 'Help & Examples:'.yellow
184
179
  o.bool '-E', '--examples', ' show several examples'
185
- o.bool '-L', '--language', ' natural language examples'
186
180
  o.bool '-h', '--help', ' show help'
187
181
 
188
182
  end
@@ -0,0 +1,39 @@
1
+ require_relative 'command'
2
+ module Sym
3
+ module App
4
+ module Commands
5
+ class BashCompletion < Command
6
+
7
+ required_options [:bash_completion]
8
+ try_after :generate_key, :open_editor, :encrypt_decrypt
9
+
10
+
11
+ def execute
12
+ install_completion_file
13
+ file = opts[:bash_completion]
14
+ if File.exist?(file)
15
+ if File.read(file).include?(Sym::BASH_COMPLETION[:script])
16
+ "#{'Hmmm'.bold.yellow}: #{file.bold.yellow} had completion for #{'sym'.bold.red} already installed\n"
17
+ else
18
+ append_completion_script(file)
19
+ "#{'OK'.bold.green}: appended completion for #{'sym'.bold.red} to #{file.bold.yellow}\n"
20
+ end
21
+ else
22
+ append_completion_script(file)
23
+ "#{'OK'.bold.green}: created new file #{file.bold.yellow} and installed BASH completion for #{'sym'.bold.red}\n"
24
+ end
25
+ end
26
+
27
+ def install_completion_file
28
+ FileUtils.cp(Sym::BASH_COMPLETION[:file], Sym::COMPLETION_PATH)
29
+ end
30
+
31
+ def append_completion_script(file)
32
+ File.open(file, 'a') do |fd|
33
+ fd.write(Sym::BASH_COMPLETION[:script])
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -14,8 +14,6 @@ module Sym
14
14
  new_private_key = encr_password(new_private_key,
15
15
  application.input_handler.new_password) if opts[:password]
16
16
 
17
- clipboard_copy(new_private_key) if opts[:copy]
18
-
19
17
  Sym::App::KeyChain.new(opts[:keychain], opts).
20
18
  add(new_private_key) if opts[:keychain] && Sym::App.is_osx?
21
19
 
@@ -25,12 +23,6 @@ module Sym
25
23
  retry if (retries += 1) < 3
26
24
  end
27
25
 
28
- private
29
-
30
- def clipboard_copy(key)
31
- require 'clipboard'
32
- Clipboard.copy(key)
33
- end
34
26
  end
35
27
  end
36
28
  end
@@ -15,8 +15,8 @@ module Sym
15
15
  echo: 'echo $KEY',
16
16
  result: '75ngenJpB6zL47/8Wo7Ne6JN1pnOsqNEcIqblItpfg4='.green)
17
17
 
18
- output << example(comment: 'generate a new password-protected key, copy to the clipboard & save to a file',
19
- command: 'sym -gpc -o ~/.key',
18
+ output << example(comment: 'generate a new password-protected key & save to a file',
19
+ command: 'sym -gp -o ~/.key',
20
20
  echo: 'New Password : ' + '••••••••••'.green,
21
21
  result: 'Confirm Password : ' + '••••••••••'.green)
22
22
 
@@ -35,7 +35,7 @@ module Sym
35
35
  output << example(comment: 'decrypt an encrypted file and print it to STDOUT:',
36
36
  command: 'sym -df sym.enc -k $KEY')
37
37
 
38
- output << example(comment: 'edit an encrypted file in $EDITOR, ask for key, create a backup',
38
+ output << example(comment: 'edit an encrypted file in $EDITOR, ask for key, create file backup',
39
39
  command: 'sym -tibf ecrets.enc',
40
40
  result: '
41
41
  Private Key: ••••••••••••••••••••••••••••••••••••••••••••
data/lib/sym/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sym
2
- VERSION = '2.0.2'
2
+ VERSION = '2.0.3'
3
3
  end
data/lib/sym.rb CHANGED
@@ -5,11 +5,11 @@ require 'coin'
5
5
  require_relative 'sym/configuration'
6
6
 
7
7
  Sym::Configuration.configure do |config|
8
- config.password_cipher = 'AES-128-CBC'
9
- config.data_cipher = 'AES-256-CBC'
10
- config.private_key_cipher = config.data_cipher
8
+ config.password_cipher = 'AES-128-CBC'
9
+ config.data_cipher = 'AES-256-CBC'
10
+ config.private_key_cipher = config.data_cipher
11
11
  config.compression_enabled = true
12
- config.compression_level = Zlib::BEST_COMPRESSION
12
+ config.compression_level = Zlib::BEST_COMPRESSION
13
13
  end
14
14
 
15
15
  #
@@ -109,5 +109,13 @@ module Sym
109
109
  end
110
110
  end
111
111
  end
112
+
113
+ COMPLETION_FILE = '.sym.completion'
114
+ COMPLETION_PATH = "#{ENV['HOME']}/#{COMPLETION_FILE}"
115
+
116
+ BASH_COMPLETION = {
117
+ file: File.expand_path('../../bin/sym.completion', __FILE__),
118
+ script: "[[ -f '#{COMPLETION_PATH}' ]] && source '#{COMPLETION_PATH}'",
119
+ }
112
120
  end
113
121
 
data/sym.gemspec CHANGED
@@ -27,20 +27,22 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
  spec.required_ruby_version = '>= 2.2'
30
- spec.post_install_message = "
30
+ spec.post_install_message = <<-EOF
31
+ Thank you for installing this gem!
32
+ To enable bash command line completion, please run the following
33
+ command, which appends sym's shell completion to the specified file:
31
34
 
32
- Please copy and paste the following BASH function into your ~/.bashrc or
33
- equivalent, in order to enable command completion:
35
+ sym --bash-completion ~/.bash_profile
34
36
 
35
- Thank you for installing Sym!
36
- -- KG (github.com/kigster)
37
- "
37
+ (or any other shell initialization file of your preference).
38
38
 
39
+ Thank you for checking out Sym and happy crypting :)
40
+ -- KG ( github.com/kigster | twitter.com/kig )
41
+ EOF
39
42
  spec.add_dependency 'colored2', '~> 2.0'
40
43
  spec.add_dependency 'slop', '~> 4.3'
41
44
  spec.add_dependency 'activesupport'
42
45
  spec.add_dependency 'highline', '~> 1.7'
43
- spec.add_dependency 'clipboard', '~> 1.1'
44
46
  spec.add_dependency 'coin', '~> 0.1.8'
45
47
 
46
48
  spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0'
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.0.2
4
+ version: 2.0.3
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-01-21 00:00:00.000000000 Z
11
+ date: 2017-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '1.7'
69
- - !ruby/object:Gem::Dependency
70
- name: clipboard
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '1.1'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '1.1'
83
69
  - !ruby/object:Gem::Dependency
84
70
  name: coin
85
71
  requirement: !ruby/object:Gem::Requirement
@@ -215,14 +201,14 @@ files:
215
201
  - ".rubocop.yml"
216
202
  - ".travis.yml"
217
203
  - ".yardopts"
204
+ - CHANGELOG.md
218
205
  - Gemfile
219
206
  - LICENSE
220
- - MANAGING-KEYS.md
221
207
  - README.md
222
208
  - Rakefile
223
209
  - bin/console
224
210
  - bin/setup
225
- - bin/sym.bash-completion
211
+ - bin/sym.completion
226
212
  - exe/keychain
227
213
  - exe/sym
228
214
  - lib/sym.rb
@@ -230,22 +216,17 @@ files:
230
216
  - lib/sym/app/args.rb
231
217
  - lib/sym/app/cli.rb
232
218
  - lib/sym/app/commands.rb
219
+ - lib/sym/app/commands/bash_completion.rb
233
220
  - lib/sym/app/commands/command.rb
234
- - lib/sym/app/commands/delete_keychain_item.rb
235
221
  - lib/sym/app/commands/encrypt_decrypt.rb
236
222
  - lib/sym/app/commands/generate_key.rb
237
223
  - lib/sym/app/commands/open_editor.rb
238
224
  - lib/sym/app/commands/print_key.rb
239
225
  - lib/sym/app/commands/show_examples.rb
240
226
  - lib/sym/app/commands/show_help.rb
241
- - lib/sym/app/commands/show_language_examples.rb
242
227
  - lib/sym/app/commands/show_version.rb
243
228
  - lib/sym/app/input/handler.rb
244
229
  - lib/sym/app/keychain.rb
245
- - lib/sym/app/nlp.rb
246
- - lib/sym/app/nlp/constants.rb
247
- - lib/sym/app/nlp/translator.rb
248
- - lib/sym/app/nlp/usage.rb
249
230
  - lib/sym/app/output.rb
250
231
  - lib/sym/app/output/base.rb
251
232
  - lib/sym/app/output/file.rb
@@ -273,14 +254,11 @@ files:
273
254
  homepage: https://github.com/kigster/sym
274
255
  licenses: []
275
256
  metadata: {}
276
- post_install_message: |2
277
-
278
-
279
- Please copy and paste the following BASH function into your ~/.bashrc or
280
- equivalent, in order to enable command completion:
281
-
282
- Thank you for installing Sym!
283
- -- KG (github.com/kigster)
257
+ post_install_message: "Thank you for installing this gem! \nTo enable bash command
258
+ line completion, please run the following \ncommand, which appends sym's shell completion
259
+ to the specified file:\n\n sym --bash-completion ~/.bash_profile \n\n(or any other
260
+ shell initialization file of your preference).\n\nThank you for checking out Sym
261
+ and happy crypting :)\n -- KG ( github.com/kigster | twitter.com/kig )\n"
284
262
  rdoc_options: []
285
263
  require_paths:
286
264
  - lib
data/MANAGING-KEYS.md DELETED
@@ -1,67 +0,0 @@
1
- # Managing Private Keys
2
-
3
- In this document we discuss several methods of keeping the private keys safe and yet conveniently available when needed. We also note the possible security implications of each method.
4
-
5
- We assume that you have some data or files that have been previously encrypted with a 32-byte key using this library, and that you want to be able to access the data easily with your private key, but at the same time not make it too easy for an attacker to find the keys.
6
-
7
- ## Method 1.<br>Keychain Access on Mac OS-X
8
-
9
- How you store the secret, is up to you, but here is one way that leverages Mac OS-X Keychain. In fact you can store multiple keys if you like. In the example below we'll store two separate keys, one for staging and one for production:
10
-
11
- In your terminal, type these two commands. Note that the `-s` parameter is something you might want to customize, and make it easy to find. For example, instead of using `production` you could use `big-corp-django-secret-production`. The name should be such that it's easy to find once you open KeyChain Editor later.
12
-
13
- ```bash
14
- security add-generic-password -a $USER -D "secret-cipher-base64" -s "staging"
15
- security add-generic-password -a $USER -D "secret-cipher-base64" -s "production"
16
- ```
17
-
18
- This step does not actually store any key, it simply creates a KeyChain placeholder for it. We'll generate and add the key next.
19
-
20
- Finally, to make this a bit more efficient, I recommend listing the key names in an array-type environment variable set in your `~/.bashrc` file, for example:
21
-
22
- ```bash
23
- # ~/.bashrc
24
- declare -a secret_names=(production staging)
25
- ```
26
-
27
- After declaring this array, you can even rewrite the above command as a loop, which could be handy if you are storing not 2 or 3 but 10+ keys.
28
-
29
- ```bash
30
- for secret_name in ${secret_names[@]}; do
31
- security add-generic-password -a $USER \
32
- -D "secret-cipher-base64" -s $secret_name
33
- done
34
- ```
35
-
36
- ### Saving the Secret to KeyChain
37
-
38
- * Open `KeyChain Access` application
39
- * Search for the token you specified, for example `production`
40
- * Double-click on the matching entry
41
- * Click "Show password"
42
- * Paste the copied value in that field
43
- * Click "Save Changes"
44
- * Repeat for `staging` or any other key you want to save.
45
-
46
- ### Retrieving Secret from the KeyChain
47
-
48
- Using the below bash function, you can retrieve and export the sym as environment variables, which can later be read by your code:
49
-
50
- ```bash
51
- # append this function to your ~/.bashrc or ~/.bash_profile
52
- function load_keys() {
53
- declare -a secret_names=(production staging)
54
- for secret_name in ${secret_names[@]}; do
55
- varname="secret_${secret_name}" # eg, $secret_production
56
- secret=`security find-generic-password -g -a $USER -w -D "secret-cipher-base64" -s "$secret_name"`
57
- eval "export $varname=$secret"
58
- done
59
- }
60
- ```
61
-
62
- With this out of the way, we just need to type `load_keys` in Terminal to get our keys automatically exported.
63
-
64
- ### Security
65
-
66
- In this model, an attacker who obtains login access to your account will be able to quickly examine the local environment to discover one or more private keys already exported.
67
-
@@ -1,17 +0,0 @@
1
- require_relative 'command'
2
- require 'sym/app/keychain'
3
- module Sym
4
- module App
5
- module Commands
6
- class DeleteKeychainItem < Command
7
-
8
- required_options :keychain_del
9
- try_after :generate_key, :open_editor, :encrypt_decrypt
10
-
11
- def execute
12
- Sym::App::KeyChain.new(opts[:keychain_del]).delete
13
- end
14
- end
15
- end
16
- end
17
- end
@@ -1,81 +0,0 @@
1
- require 'colored2'
2
- require_relative 'command'
3
- require_relative '../nlp'
4
- module Sym
5
- module App
6
- module Commands
7
- class ShowLanguageExamples < Command
8
- required_options :language
9
- try_after :show_help
10
-
11
-
12
-
13
- def execute
14
- output = []
15
-
16
- output << Sym::App::NLP::Base.usage
17
-
18
- output << example(comment: 'generate a new private key and copy to the clipboard but do not print to terminal',
19
- command: 'sym create new key to clipboard quietly'
20
- )
21
-
22
- output << example(comment: 'generate and save to a file a password-protected key, silently',
23
- command: 'sym create a secure key and save it to "my.key"',
24
- )
25
-
26
- output << example(comment: 'encrypt a plain text string with a key, and save the output to a file',
27
- command: 'sym encrypt string "secret string" using $(cat my.key) save to file.enc')
28
-
29
- output << example(comment: 'decrypt a previously encrypted string:',
30
- command: 'sym decrypt string $ENC using $(cat my.key)')
31
-
32
- output << example(comment: 'encrypt "file.txt" with key from my.key and save it to file.enc',
33
- command: 'sym encrypt file file.txt with key from my.key and save it to file.enc')
34
-
35
- output << example(comment: 'decrypt an encrypted file and print it to STDOUT:',
36
- command: 'sym decrypt file file.enc with key from "my.key"')
37
-
38
- output << example(comment: 'edit an encrypted file in $EDITOR, ask for key, and create a backup upon save',
39
- command: 'sym edit file file.enc ask for a key and make a backup',
40
- )
41
-
42
- if Sym::App.is_osx?
43
- output << example(comment: 'generate a new password-encrypted key, save it to your Keychain:',
44
- command: 'sym create a new protected key store in keychain "my-keychain-key"')
45
-
46
- output << example(comment: 'print the key stored in the keychain item "my-keychain-key"',
47
- command: 'sym print keychain "my-keychain-key"')
48
-
49
- output << example(comment: 'use the new key to encrypt a file:',
50
- command: 'sym encrypt with keychain "my-keychain-key" file "password.txt" and write to "passwords.enc"')
51
-
52
- end
53
-
54
- output.flatten.compact.join("\n")
55
- end
56
-
57
- def example(comment: nil, command: nil, echo: nil, result: nil)
58
- @dict ||= ::Sym::App::NLP::Constants::DICTIONARY.to_a.flatten!
59
- _command = command.split(' ').map do |w|
60
- _w = w.to_sym
61
- if w == 'sym'
62
- w.italic.yellow
63
- elsif ::Sym::App::NLP::Constants::STRIPPED.include?(_w)
64
- w.italic.red
65
- elsif @dict.include?(_w)
66
- w.blue
67
- else
68
- w
69
- end
70
- end.join(' ') if command
71
- out = []
72
- out << "# #{comment}".white.dark.italic if comment
73
- out << "#{_command}" if command
74
- out << "#{echo}" if echo
75
- out << "#{result}" if result
76
- out << (' '*80).dark
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,32 +0,0 @@
1
- module Sym
2
- module App
3
- module NLP
4
- module Constants
5
- STRIPPED = %i(and a the it item to key with about for of new make store in print)
6
-
7
- DICTIONARY = {
8
- # option (Slop)
9
- # list of english words that map to it
10
- :copy => [:clipboard],
11
- :decrypt => [:unlock],
12
- :edit => [:open],
13
- :encrypt => [:lock],
14
- :backup => [],
15
- :keychain => [],
16
- :file => [:read],
17
- :generate => [:create],
18
- :interactive => [:ask, :enter, :type],
19
- :keyfile => [:from],
20
- :output => [:save, :write],
21
- :private_key => [:using, :private],
22
- :string => [:value],
23
- :quiet => [:silently, :quietly, :silent, :sym],
24
- :password => [:secure, :secured, :protected]
25
- }
26
-
27
- end
28
-
29
- end
30
- end
31
- end
32
-
@@ -1,61 +0,0 @@
1
- require_relative 'constants'
2
- module Sym
3
- module App
4
- module NLP
5
- class Translator
6
-
7
- attr_accessor :argv, :translated_argv, :opts
8
-
9
- def initialize(argv)
10
- self.argv = argv
11
- self.opts = CLI.new(%w(-E)).opts.to_hash
12
- self.translated_argv = []
13
- end
14
-
15
- def dict
16
- ::Sym::App::NLP::Constants::DICTIONARY
17
- end
18
-
19
- def stripped
20
- ::Sym::App::NLP::Constants::STRIPPED
21
- end
22
-
23
- def translate
24
- self.translated_argv = argv.map do |value|
25
- nlp_argument = value.to_sym
26
- arg = nil
27
- arg ||= dict.keys.find do |key|
28
- dict[key].include?(nlp_argument) || key == nlp_argument
29
- end
30
- arg ||= nlp_argument
31
-
32
- if stripped.include?(arg)
33
- # nada
34
- elsif opts.to_hash.key?(arg)
35
- '--' + "#{arg.to_s.gsub(/_/, '-')}"
36
- else
37
- arg.to_s
38
- end
39
- end.compact
40
-
41
- counts = {}
42
- translated_argv.each{ |arg| counts.key?(arg) ? counts[arg] += 1 : counts[arg] = 1 }
43
- translated_argv.delete_if{ |arg| counts[arg] > 1 }
44
- self
45
- end
46
-
47
- def and
48
- translate if translated_argv.empty?
49
- if self.translated_argv.include?('--verbose')
50
- STDERR.puts 'Original arguments: '.dark + "#{argv.join(' ').green}"
51
- STDERR.puts ' Translated argv: '.dark + "#{translated_argv.join(' ').blue}"
52
- end
53
- ::Sym::App::CLI.new(self.translated_argv)
54
- end
55
-
56
- alias_method :application, :and
57
-
58
- end
59
- end
60
- end
61
- end
@@ -1,72 +0,0 @@
1
- require 'pp'
2
- module Sym
3
- module App
4
- # sym generate key to the clipboard and keychain
5
- # sym encrypt file 'hello' using $key [to output.enc]
6
- # sym edit 'passwords.enc' using $key
7
- # sym decrypt /etc/secrets encrypted with $key save to ./secrets
8
- # sym encrypt file $input with keychain $item
9
- module NLP
10
- module Usage
11
-
12
- def usage
13
- out = ''
14
- out << %Q`
15
- #{header('Natural Language Processing')}
16
-
17
- #{'When '.dark.normal}#{'sym'.bold.blue} #{'is invoked, and the first argument does not begin with a dash,
18
- then the the NLP (natural language processing) Translator is invoked.
19
- The Translator is based on a very simple algorithm:
20
-
21
- * ignore any of the words tagged STRIPPED. These are the ambiguous words,
22
- or words with duplicate meaning.
23
-
24
- * map the remaining arguments to regular double-dashed options using the DICTIONARY
25
-
26
- * words that are a direct match for a --option are automatically double-dashed
27
-
28
- * remaining words are left as is (these would be file names, key names, etc).
29
-
30
- * finally, the resulting "new" command line is parsed with regular options.
31
-
32
- * When arguments include "verbose", NLP system will print "before" and "after"
33
- of the arguments, so that any issues can be debugged and corrected.
34
-
35
- '.dark.normal}
36
-
37
- #{header('Currently ignored words:')}
38
- #{Constants::STRIPPED.join(', ').red.italic}
39
-
40
- #{header('Regular Word Mapping')}
41
- #{Constants::DICTIONARY.pretty_inspect.split(/\n/).map do |line|
42
- line.gsub(
43
- /[\:\}\,\[\]]/, ''
44
- ).gsub(
45
- /[ {](\w+)=>([^\n]*)/, '\2|\1'
46
- )
47
- end.map { |line| convert_dictionary(*line.split('|')) }.join}
48
-
49
- #{header('Examples')}
50
- `
51
- out
52
- end
53
-
54
- def convert_dictionary(left = '', right = '')
55
- [
56
- sprintf('%35.35s', left.gsub(/ /, ' ')).italic.yellow,
57
- ' ───────➤ '.dark,
58
- sprintf('--%-20.20s', right).blue,
59
-
60
- "\n"
61
- ].join
62
- end
63
-
64
- private
65
- def header(title)
66
- title.upcase.bold.underlined
67
- end
68
-
69
- end
70
- end
71
- end
72
- end
data/lib/sym/app/nlp.rb DELETED
@@ -1,18 +0,0 @@
1
- require_relative 'cli'
2
- require_relative 'nlp/constants'
3
- require_relative 'nlp/usage'
4
- require_relative 'nlp/translator'
5
- module Sym
6
- module App
7
- # sym generate key to the clipboard and keychain
8
- # sym encrypt file 'hello' using $key [to output.enc]
9
- # sym edit 'passwords.enc' using $key
10
- # sym decrypt /etc/secrets encrypted with $key save to ./secrets
11
- # sym encrypt file $input with keychain $item
12
- module NLP
13
- class Base
14
- extend Usage
15
- end
16
- end
17
- end
18
- end