sym 2.1.1 → 2.1.2

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: 73e5b5a60ecd297628383c6dcedfae194ea1185d
4
- data.tar.gz: 461b202fdabc71eba1a34ce70c80feb59bfc585f
3
+ metadata.gz: 6529381babbcb57ee7ca039a9d01dbafe4d8fe9f
4
+ data.tar.gz: 9b48b1a55b06dd5870a3f0d25bc0b862c3f64502
5
5
  SHA512:
6
- metadata.gz: 135bb4d094617ad879a1b4dae069259dce319ce9a636303501d153a0538b9ffc717eb011bcba2fe2ad4a8127997b30131e054a0894babda17110056fc262c9d4
7
- data.tar.gz: afb15abc2a14b8efbda115f76c8e54643221c45887ec440cc17561281ff8e16d440f02192d5ea3d55333023597235f04f34697baafd7a6357dcb1b545313c705
6
+ metadata.gz: 9de600b399c540917e92f7de8ab0f36b426d24950ee7d0ccca4fce21b929286a7c13c7e3f8f603f25b5698c0ac2d684d6756760b88085a3cadaab1d246e94bf3
7
+ data.tar.gz: 23871684bbcb5d41edd02e8922abf866a9d5db90c2f120625e6f67d6d20e377d22b204b782072461b76c1b82fb2575777aab9b7dd2273e5b5d47c0c90332189c
data/README.md CHANGED
@@ -11,53 +11,173 @@
11
11
 
12
12
  ## Description
13
13
 
14
- ### Summary
15
-
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.
17
-
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.
19
-
20
- And no tool works in isolation: this is just a stepping stone that could be part of your deployment or infrastructure code: don't rely on external services: minimize the risk of a "man-in-the-middle" attack, by dealing with the encryption and decryption locally. Ideal application of this gem, is the ability to store sensitive application _secrets_ protected on a file system, or in a repo, and use `sym` to automaticaly decrypt the data when any changes are to be made, or when the data needs to be read by an application service.
21
-
22
- And finally, in addition to the rich CLI interface of the `sym` executable, there is a rich and extensibe symmetric encryption API that can be easily used from any ruby project.
14
+ > __sym__ is a command line utility and a Ruby API that makes it _trivial to encrypt and decrypt sensitive data_. Unlike many other existing encryption tools, __sym__ focuses on usability and streamlined interface (CLI), with the goal of making encryption easy and transparent. The result? There is no excuse for keeping your application secrets unencrypted :)
15
+
16
+ <hr />
17
+ ## Table of Contents
18
+
19
+ <ul class="small site-footer-links">
20
+ <li>
21
+ <a href="#description">Description</a>
22
+ <ul>
23
+ <li>
24
+ <a href="#motivation">Motivation</a>
25
+ </li>
26
+ <li>
27
+ <a href="#whats-included">What&#39;s Included</a>
28
+ </li>
29
+ <li>
30
+ <a href="#how-it-works">How It Works</a>
31
+ </li>
32
+ </ul>
33
+ </li>
34
+ <li>
35
+ <a href="#installation">Installation</a>
36
+ </li>
37
+ <li>
38
+ <a href="#using-sym-with-the-command-line">Using <code>sym</code> with the Command Line</a>
39
+ <ul>
40
+ <li>
41
+ <a href="#private-keys">Private Keys</a>
42
+ <ul>
43
+ <li>
44
+ <a href="#generating-private-keys">Generating Private Keys</a>
45
+ </li>
46
+ <li>
47
+ <a href="#using-keychain-access-on-mac-os-x">Using KeyChain Access on Mac OS-X</a>
48
+ </li>
49
+ <li>
50
+ <a href="#keychain-key-management">KeyChain Key Management</a>
51
+ </li>
52
+ <li>
53
+ <a href="#moving-a-key-to-the-keychain">Moving a Key to the Keychain</a>
54
+ </li>
55
+ <li>
56
+ <a href="#adding-password-to-existing-key">Adding Password to Existing Key</a>
57
+ </li>
58
+ <li>
59
+ <a href="#encryption-and-decryption">Encryption and Decryption</a>
60
+ </li>
61
+ </ul>
62
+ </li>
63
+ <li>
64
+ <a href="#cli-usage-examples">CLI Usage Examples</a>
65
+ <ul>
66
+ <li>
67
+ <a href="#inline-editing">Inline Editing</a>
68
+ </li>
69
+ </ul>
70
+ </li>
71
+ </ul>
72
+ </li>
73
+ <li>
74
+ <a href="#ruby-api">Ruby API</a>
75
+ <ul>
76
+ <li>
77
+ <a href="#encryption-and-decryption-operations">Encryption and Decryption Operations</a>
78
+ </li>
79
+ <li>
80
+ <a href="#full-application-api">Full Application API</a>
81
+ </li>
82
+ <li>
83
+ <a href="#configuration">Configuration</a>
84
+ </li>
85
+ </ul>
86
+ </li>
87
+ <li>
88
+ <a href="#encryption-features--cipher-used">Encryption Features &amp; Cipher Used</a>
89
+ </li>
90
+ <li>
91
+ <a href="#development">Development</a>
92
+ <ul>
93
+ <li>
94
+ <a href="#contributing">Contributing</a>
95
+ </li>
96
+ </ul>
97
+ </li>
98
+ <li>
99
+ <a href="#license">License</a>
100
+ </li>
101
+ <li>
102
+ <a href="#acknowledgements">Acknowledgements</a>
103
+ </li>
104
+ </ul>
105
+ <hr />
106
+
107
+ ### Motivation
108
+
109
+ The primary goal of this tool is to streamline and simplify handling of relatively sensitive data in the most trasparent and easy to use way as possible, without sacrificing security.
110
+
111
+ Most common use-cases include:
112
+
113
+ * __Encrypting/decrypting of application secrets__, so that the encrypted secrets can be safely checked into the git repository and distributed, and yet without much of the added headache that this often requires
114
+ * __Secure message transfer between any number of receipients__
115
+ * __General purpose encryption/decryption with a single encryption key__, optionally itself re-encrypted with a password.
116
+
117
+ __Sym__ is a layer built on top of the [`OpenSSL`](https://www.openssl.org/) library, and, hopefully, makes encryption more accessible to every-day developers, QA, and dev-ops folks, engaged in deploying applications.
118
+
119
+ ### What's Included
120
+
121
+ This gem includes two primary components:
122
+
123
+ * [Ruby API](#ruby-api) for enabling encryption/decryption of any data within any Ruby class, with extremely easy-to-use methods
124
+ * [Rich command line interface CLI](#cli) with many additional features to streamline handling of encrypted data.
125
+
126
+ _Symmetric Encryption_ simply means that we are using the same private key to encrypt and decrypt. In addition to the private key, the encryption uses an IV vector. The library completely hides `iv` generation from the user, and automatically generates a random `iv` per encryption.
23
127
 
24
128
  ### How It Works
25
129
 
26
- 1. You start with a piece of sensitive data, say it's called _X_.
27
- 2. _X_ is currently a file on your file system, unencrypted.
28
- 2. You use __sym__ (with `-g` for "generate") to make a new encryption key. The key is 256 bits, or 32 bytes, or 45 bytes when base64-encoded.
29
- 3. You must save this key somewhere safe. We'll talk about this further.
30
- 4. You use __sym__ (with `-e`) to encrypt _X_ with the key, and save into _Y_.
31
- 5. You now delete _X_ from your file system. You now only have _Y_ and the _key_.
32
- 7. To read the data back, you use __sym__ with the `-d` (for "decrypt") to decrypt _Y_ back. You can print the contents or save it again.
33
- 8. But, instead of just decrypting it, you can use the `-t` mode (for "ediT"), which would decrypt _Y_ into _X_, save _X_ into a temporary location, and allow you to edit the unencrypted file using `$EDITOR`. Once you save and exit the editor, a new version is automatically encrypted and replaces the old version, showing you the diff and, optionally, creating a backup.
130
+ 1. You start with a piece of sensitive __data__ you want to protect. This can be a file or a string.
131
+ 2. You generate a new encryption key, that will be used to both encrypt and decrypt the data. The key is 256 bits, or 32 bytes, or 45 bytes when base64-encoded, and can be generated with `sym -g`.
132
+ * You can optionally password protect the key with `sym -gp`
133
+ * You can save the key into a file `sym -gp -o key-file`
134
+ * Or you can save it into the OS-X Keychain, with `sym -gp -x keychain-name`
135
+ * or you can print it to STDOUT, which is the default.
136
+ 3. You can then use the key to encrypt sensitive __data__, with `sym -e [key-option] [data-option]`, passing it the key in several accepted ways:
137
+ * You can pass the key as a string (not recommended) via `-k key`
138
+ * Or read the key from a file `-K key-file`
139
+ * Or read the key from the OS-X Keychain with `-x keychain-name`
140
+ * Or you can paste the key interactively with `-i`
141
+ 4. Input data can be read from a file with `-f file`, or read from STDIN, or a passed on the command line with `-s string`
142
+ 4. Output is the encrypted data, which is printed to STDOUT by the default, or it can be saved to a file with `-o <file>`
143
+ 5. Encrypted file can be later decrypted with `sym -d [key-option] [data-option]`
144
+
145
+ Sample session that uses Mac OS-X Keychain to store the password-protected key.
146
+
147
+ ```bash
148
+ ❯ sym -gpx my-new-key
149
+ New Password : •••••••••
150
+ Confirm Password : •••••••••
151
+ BAhTOh1TeW06OkRhdGE6OldyYXBwZXJTdH.....
152
+
153
+ ❯ sym -ex my-new-key -s 'My secret data' -o secret.enc
154
+ Coin::Vault listening at: druby://127.0.0.1:24924
155
+ Password: •••••••••
156
+
157
+ ❯ cat secret.enc
158
+ BAhTOh1TeW06OkRhdGE6OldyYXBFefDFFD.....
159
+
160
+ ❯ sym -dx my-new-key -f secret.enc
161
+ My secret data
162
+ ```
34
163
 
35
- ### Features
164
+ The line that says `Coin::Vault listening at: druby://127.0.0.1:24924` is the indication that the local dRB server used for caching passwords has been started. Password caching can be easily disabled with `-P` flag. In the example above, the decryption step fetched the password from the cache, and so the user was not required to re-enter the password.
36
165
 
37
- The `sym` executable as well as the Ruby API provide:
166
+ __Direct Editing Encrypted Files__
38
167
 
39
- * Symmetric data encryption with:
40
- * the cipher `AES-256-CBC` used by the US Government
41
- * 256-bit private key
42
- * which can be auto-generated, and is a *base64-encoded* string which is 45 characters long. The *decoded* secret is always 32 characters long (or 256 bytes long).
43
- * which can be optionally password-encrypted using 128-bit key.
44
- * which is automatically detected when the key is read
45
- * Rich command line interface with some innovative features, such as inline editing of an encrypted file, using your favorite `$EDITOR`.
46
- * Data handling:
47
- * Automatic compression of the data upon encryption
48
- * Automatic base64 encryption to make all encrypted strings fit onto a single line.
49
- * This makes the format suitable for YAML or JSON configuration files, where only the values are encrypted.
50
- * Rich Ruby API
51
- * (OS-X Only): Ability to create, add and delete generic password entries from the Mac OS-X KeyChain, and to leverage the KeyChain to store sensitive private keys.
168
+ Instead of decrypting data anytime you need to change it, you can use the shortcut flag `-t` (for "edi__T__"), which decrypts your data into a temporary file, automatically opening it with an `$EDITOR`.
169
+
170
+ Example:
52
171
 
53
- ### Symmetric Encryption
172
+ sym -t -f config/application/secrets.yml.enc -K ~/.key
173
+
174
+ > This is one of those time-saving features that can make a difference in making encryption feel easy and transparent.
54
175
 
55
- Symmetric encryption simply means that we are using the same private key to encrypt and decrypt.
56
- In addition to the private key, the encryption uses an IV vector. The library completely hides `iv` from the user, generates one random `iv` per encryption, and stores it together with the field itself (*base64-encoded*).
176
+ For more information see the section on [inline editing](#inline).
57
177
 
58
178
  ## Installation
59
179
 
60
- If you plan on using the library in your ruby project with Bundler managing its dependencies, just include the following line in your `Gemfile`:
180
+ If you plan on using the library in your Ruby project with Bundler managing its dependencies, just include the following line in your `Gemfile`:
61
181
 
62
182
  gem 'sym'
63
183
 
@@ -69,95 +189,95 @@ Or install it into the global namespace with `gem install` command:
69
189
  $ sym -h
70
190
  $ sym -E # see examples
71
191
 
72
- ### BASH Completion (Optional Step)
192
+ __BASH Completion__
73
193
 
74
- After gem installation, an message will tell you to install bash completion into to your `~/.bashrc` or equivalent:
194
+ Optionally, after gem installation, you can also install bash-completion of gem's command line options, but running the following command (and feel free to use any of the "dot" files you prefer):
75
195
 
76
196
  sym --bash-completion ~/.bashrc
77
197
 
78
- 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.
198
+ 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 of the supported flags.
79
199
 
80
- ## Usage
200
+ <a name="#cli"></a>
81
201
 
82
- ### Private Keys
83
-
84
- This library relies on the existance of the 32-byte private key (aka, *a secret*) to perform encryption and decryption.
202
+ ## Using `sym` with the Command Line
85
203
 
86
- The key can be easily:
87
-
88
- * generated by this gem and displayed, or saved to Mac OS-X KeyChain
89
- * one way or another must be kept very well protected and secure from attackers
90
- * can be fetched from the the Keychain in subsequent encryption/decryption steps
91
- * password-protected, which you can enable during the generation with the `-p` flag.
92
- * NOTE: right now there is no way to add a password to an existing key, only generate a new one.
204
+ ### Private Keys
93
205
 
94
- Unencrypted private key will be in the form of a base64-encoded string, 45 characters long.
206
+ The private key is the cornerstone of the symmetric encryption. Using `sym`, the key can be:
95
207
 
96
- Encrypted private key will be considerably longer, perhaps 200-300 characters long.
208
+ * generated and printed to STDOUT, or saved to Mac OS-X KeyChain or a file
209
+ * fetched from the Keychain in subsequent operations
210
+ * password-protected during generation (or import) with the `-p` flag.
211
+ * must be kept very well protected and secure from attackers.
97
212
 
98
- When the private key is encrypted, `sym` will request the password every time it is used. We are looking at adding a caching layer with a configuerable timeout, so that the password is only re-entered once per given period.
213
+ The __unencrypted private__ key will be in the form of a base64-encoded string, 45 characters long.
99
214
 
100
- ### Command Line (CLI)
215
+ __Encrypted (with password) private key__ will be considerably longer, perhaps 200-300 characters long.
101
216
 
102
- You can generate using the command line, or in a programmatic way. First we'll discuss the command line usage, and in a later section we'll discuss Ruby API provided by the gem.
217
+ When the private key is encrypted, `sym` will request the password only once per 15 minute period. The password is cached using a local dRB server, but this caching can be disabled with `-P` flag.
103
218
 
104
- #### Generating and Using Private Keys
219
+ #### Generating Private Keys
105
220
 
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 (using `pbcopy` command on Mac OS-X):
221
+ Let's generate a new key, and copy it to the clipboard (using `pbcopy` command on Mac OS-X):
107
222
 
108
223
  sym -g | pbcopy
109
224
 
110
225
  Or save a new key into a bash variable
111
226
 
112
- SECRET=$(sym -g)
227
+ KEY=$(sym -g)
113
228
 
114
229
  Or save it to a file:
115
230
 
231
+ sym -g -o ~/.key
116
232
  sym -go ~/.key
117
233
 
118
- Or create a password-protected key, and save it to a file:
234
+ Or create a password-protected key (`-p`), and save it to a file (`-o`), and skip printing the new key to STDOUT (`-q` for quiet):
119
235
 
120
- sym -gp -o ~/.secret
121
- # New Password: ••••••••••
122
- # Confirm Password: ••••••••••
236
+ sym -gpqo ~/.secret
237
+ New Password: ••••••••••
238
+ Confirm Password: ••••••••••
123
239
 
124
- You can subsequently use the private key by either:
240
+ You can subsequently use the private key by passing either:
125
241
 
126
- 1. passing the `-k [key value]` flag
127
- 2. passing the `-K [key file]` flag3.
128
- 3. pasting or typing the key with the `-i` (interactive) flag
129
- 4. passing the `-x [keychain access entry name]` flag to read from Mac OS-X KeyChain Access's generic password field.
242
+ 1. the `-k key-string` flag
243
+ 2. the `-K key-file` flag
244
+ 3. the `-x key-keychain-name` flag to read the key from Mac OS-X KeyChain
245
+ 4. pasting or typing the key with the `-i` (interactive) flag
130
246
 
131
247
  #### Using KeyChain Access on Mac OS-X
132
248
 
133
- On Mac OS-X there is a third option using the Keychain Access Manager behind the scenes. Apple released a `security` command line tool, which this library uses to securely store a key/value pair of the key name and the actual private key in your OS-X KeyChain. The advantages of this method are numerous:
249
+ KeyChain storage is a huge time saver. It allows you to securely store the key the keychain, meaning the key can not be easily extracted by an attacker without a login to your account. Just having access to the disk is not enough.
250
+
251
+ Apple had released a `security` command line tool, which this library uses to securely store a key/value pair of the key name and the actual private key in your OS-X KeyChain. The advantages of this method are numerous:
134
252
 
135
253
  * The private key won't be lying around your file system unencrypted, so if your Mac is ever stolen, you don't need to worry about the keys running wild.
136
- * If you sync your keychain with iCloud you will have access to it on other machines
254
+ * If you sync your keychain with the iCloud you will have access to it on other machines
137
255
 
138
- To activate the KeyChain mode on the Mac, use `-x <keyname>` field instead of `-k` or `-K`, and add it to `-g` when generating a key. The `keyname` is what you name this particular key base on where it's going to be used. For example, you may call it `staging`, etc.
256
+ To activate the KeyChain mode on the Mac, use `-x <key-name>` field instead of `-k` or `-K`, and add it to `-g` when generating a key. The `key name` is what you call this particular key, based on how you plan to use it. For example, you may call it `staging`, etc.
139
257
 
140
258
  The following command generates the private key and immediately stores it in the KeyChain access under the name provided:
141
259
 
142
260
  sym -g -x staging
143
261
 
144
- Now, whenever you need to encrypt something, in addition to the `-k` and `-K` you can also choose `-x staging`. This will retrieve the key from the KeyChain access, and use it for encryption/decryption.
262
+ Now, whenever you need to encrypt something you can specify the key with `-x staging`.
145
263
 
146
264
  Finally, you can delete a key from KeyChain access by running:
147
265
 
148
266
  keychain <name> delete
149
267
 
268
+ Below we describe the purpose of the executable `keychain` shipped with sym.
269
+
150
270
  #### KeyChain Key Management
151
271
 
152
- `keychain` is an additional script installed with the gem, that can be used to read (find), update (add), and delete keychain entries used by `sym`.
272
+ `keychain` is an additional executable installed with the gem, which can be used to read (find), update (add), and delete keychain entries used by `sym`.
153
273
 
154
274
  It's help message is self-explanatory:
155
275
 
156
276
  Usage: keychain <name> [ add <contents> | find | delete ]
157
277
 
158
- #### Moving a Key to Keychain
278
+ #### Moving a Key to the Keychain
159
279
 
160
- You can easily move a key to a keychain by combinding -k or -K to read the key, and -x to write it.
280
+ You can easily move an existing key from a file or a string to a keychain by combining -k or -K to read the key, with -x to write it.
161
281
 
162
282
  sym -k $mykey -x mykey
163
283
 
@@ -167,64 +287,63 @@ You can add a password to a key by combining one of the key description flags (-
167
287
 
168
288
  sym -k $mykey -p -x moo
169
289
 
170
- The above example will take an unencrypted key passed in $k, ask for a password and save password protected key into the keychain with name "moo".
290
+ The above example will take an unencrypted key passed in `$mykey`, ask for a password and save password protected key into the keychain with name "moo."
171
291
 
172
- #### Encryption and Decryption
292
+ #### Encryption and Decryption
173
293
 
174
294
  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.
175
295
 
176
296
  ```
177
- Sym (2.0.0) – encrypt/decrypt data with a private key
297
+ Sym (2.1.1) – encrypt/decrypt data with a private key
178
298
 
179
299
  Usage:
180
300
  # Generate a new key:
181
- sym -g [ -c ] [ -p ] [ -x keychain ] [ -o keyfile | -q | ]
301
+ sym -g [ -p ] [ -x keychain ] [ -o keyfile | -q | ]
302
+
303
+ # Encrypt/Decrypt
304
+ sym [ -d | -e ] [ -f <file> | -s <string> ]
305
+ [ -k key | -K keyfile | -x keychain | -i ]
306
+ [ -o <output file> ]
307
+
308
+ # Edit an encrypted file in $EDITOR
309
+ sym -t -f <file> [ -b ][ -k key | -K keyfile | -x keychain | -i ]
182
310
 
183
- # Encrypt/Decrypt
184
- sym [ -d | -e ] [ -f <file> | -s <string> ]
185
- [ -k key | -K keyfile | -x keychain | -i ]
186
- [ -o <output file> ]
187
-
188
- # Edit an encrypted file in $EDITOR
189
- sym -t -f <file> [ -b ][ -k key | -K keyfile | -x keychain | -i ]
190
-
191
311
  Modes:
192
312
  -e, --encrypt encrypt mode
193
313
  -d, --decrypt decrypt mode
194
314
  -t, --edit decrypt, open an encr. file in an $EDITOR
195
-
196
- Create a private key:
315
+
316
+ Create a new private key:
197
317
  -g, --generate generate a new private key
198
318
  -p, --password encrypt the key with a password
199
- -c, --copy copy the new key to the clipboard
200
319
  -x, --keychain [key-name] add to (or read from) the OS-X Keychain
201
-
202
- Password Caching:
203
320
  -M, --password-timeout [timeout] when passwords expire (in seconds)
204
- -P, --no-password-cache disables key password caching
205
-
206
- Provide a private key:
321
+ -P, --no-password-cache disables caching of key passwords
322
+
323
+ Read existing private key from:
207
324
  -i, --interactive Paste or type the key interactively
208
325
  -k, --private-key [key] private key as a string
209
326
  -K, --keyfile [key-file] private key from a file
210
-
211
- Data:
327
+
328
+ Data to Encrypt/Decrypt:
212
329
  -s, --string [string] specify a string to encrypt/decrypt
213
330
  -f, --file [file] filename to read from
214
331
  -o, --output [file] filename to write to
215
-
332
+
216
333
  Flags:
217
- --keychain-del [key-name] delete keychain entry with that name
218
334
  -b, --backup create a backup file in the edit mode
219
335
  -v, --verbose show additional information
220
336
  -T, --trace print a backtrace of any errors
337
+ -D, --debug print debugging information
221
338
  -q, --quiet silence all output
222
339
  -V, --version print library version
223
340
  -N, --no-color disable color output
224
-
341
+
342
+ Utility:
343
+ -a, --bash-completion [file] append shell completion to a file
344
+
225
345
  Help & Examples:
226
346
  -E, --examples show several examples
227
- -L, --language natural language examples
228
347
  -h, --help show help
229
348
  ```
230
349
 
@@ -240,7 +359,7 @@ Generate a new private key into an environment variable:
240
359
 
241
360
  Generate a new password-protected key & save to a file:
242
361
 
243
- sym -gp -o ~/.key
362
+ sym -gpqo ~/.key
244
363
  New Password : ••••••••••
245
364
  Confirm Password : ••••••••••
246
365
 
@@ -255,7 +374,7 @@ Decrypt a previously encrypted string:
255
374
  sym -d -s $(cat file.enc) -k $KEY
256
375
  # => secret string
257
376
 
258
- Encrypt a file and save it to sym.enc:
377
+ Encrypt a file and save it to `sym.enc`:
259
378
 
260
379
  sym -e -f app-sym.yml -o app-sym.enc -k $KEY
261
380
 
@@ -263,10 +382,15 @@ Decrypt an encrypted file and print it to STDOUT:
263
382
 
264
383
  sym -df app-sym.enc -k $KEY
265
384
 
266
- ##### Inline Editing
385
+ <a name="inline"></a>
267
386
 
268
- The `sym` CLI tool supports one interesting mode where you can open an encrypted file in an `$EDITOR`, and edit it's unencrypted version (stored temporarily in a temp file), and upon saving and exiting the gem will automatically diff the new and old content, and if different – will save encrypt it and overwrite the original file.
387
+ #### Inline Editing
269
388
 
389
+ The `sym` CLI tool supports one particularly interesting mode, that streamlines handling of encrypted files. The mode is called __edit mode__, and is activated with the `-t` flag.
390
+
391
+ In this mode `sym` can decrypt the file, and open the result in an `$EDITOR`. Once you make any changes, and save it (exiting the editor), `sym` will automatically diff the new and old content, and if different – will save encrypt it and overwrite the original file.
392
+
393
+ > NOTE: this mode does not seem to work with GUI editors such as Atom or TextMate. Since `sym` waits for the editor process to complete, GUI editors "complete" immediately upon starting a windowed application.
270
394
  In this mode several flags are of importance:
271
395
 
272
396
  -b (--backup) – will create a backup of the original file
@@ -274,9 +398,7 @@ In this mode several flags are of importance:
274
398
 
275
399
  Here is a full command that opens a file specified by `-f | --file`, using the key specified in `-K | --keyfile`, in the editor defined by the `$EDITOR` environment variable (or if not set – defaults to `/bin/vi`)".
276
400
 
277
- NOTE: while much effort has been made to ensure that the gem is bug free, the reality is that no software is bug free. Please make sure to backup your encrypted file before doing it for the first few times to get familiar with the command.
278
-
279
- To edit an encrypted file in $EDITOR, while asking to paste the key (`-i | --interactive`), while creating a backup file (`-b | --backup`):
401
+ To edit an encrypted file in `$EDITOR`, while asking to paste the key (`-i | --interactive`), while creating a backup file (`-b | --backup`):
280
402
 
281
403
  sym -tibf data.enc
282
404
  # => Private Key: ••••••••••••••••••••••••••••••••••••••••••••
@@ -287,13 +409,15 @@ To edit an encrypted file in $EDITOR, while asking to paste the key (`-i | --int
287
409
  # ---
288
410
  # # (c) 2016 Konstantin Gredeskoul. All rights reserved.
289
411
 
290
- ### Ruby API
412
+ <a name="#ruby-api"></a>
413
+
414
+ ## Ruby API
291
415
 
292
- To use this library you must include the main `Sym` module into your library.
416
+ To use this library, you must include the main `Sym` module into your library.
293
417
 
294
418
  Any class including `Sym` will be decorated with new class methods `#private_key` and `#create_private_key`, as well as instance methods `#encr`, and `#decr`.
295
419
 
296
- `#create_private_key` will generate a new key each time it's called, while `#private_key` will either assign an existing key (if a value is passed), or generate and save a new key in the class instance variable. Therefore each class including `Sym` will use it's own key (unless the key is assigned).
420
+ `#create_private_key` will generate a new key each time it's called, while `#private_key` will either assign an existing key (if a value is passed) or generate and save a new key in the class instance variable. Therefore each class including `Sym` will use its key (unless the key is assigned).
297
421
 
298
422
  The following example illustrates this point:
299
423
 
@@ -315,9 +439,9 @@ end
315
439
  @key.eql?(SomeClass.private_key) # => true (it was assigned)
316
440
  ```
317
441
 
318
- #### Encryption and Decryption
442
+ ### Encryption and Decryption Operations
319
443
 
320
- So how would we use this library from another ruby project to encrypt and decrypt values?
444
+ So how would we use this library from another Ruby project to encrypt and decrypt values?
321
445
 
322
446
  After including the `Sym` module in a ruby class, the class will now have the `#encr` and `#decr` instance methods, as well as `#secret` and `#create_private_key class methods.
323
447
 
@@ -338,7 +462,7 @@ class TestClass
338
462
  end
339
463
  ```
340
464
 
341
- #### Full Application API
465
+ ### Full Application API
342
466
 
343
467
  Since the command line interface offers more than just encryption/decryption, it is available via `Sym::Application` class.
344
468
 
@@ -355,10 +479,11 @@ key = Sym::Application.new(generate: true).execute
355
479
 
356
480
  ### Configuration
357
481
 
358
- The library offers a typical `Sym::Configuration` class which can be used to tweak some of the internals of the gem. This is really meant for a very advanced user who knows what she is doing. The following snippet is actually part of the Configuration class itself, but can be overridden by your code that uses and initializes this library. `Configuration` is a singleton, so changes to it will propagate to any subsequent calls to the gem.
482
+ The library offers a typical `Sym::Configuration` class which can be used to tweak some of the internals of the gem. Its meant for an advanced user who knows what he or she is doing. The code snippet shown below is an actual part of the Configuration class, but you can override it by including it in your code that uses and initializes this library, right after the `require.` The `Configuration` class is a Singleton, so changes to it will propagate to any subsequent calls to the gem.
359
483
 
360
484
  ```ruby
361
485
  require 'zlib'
486
+ require 'sym'
362
487
  Sym::Configuration.configure do |config|
363
488
  config.password_cipher = 'AES-128-CBC' #
364
489
  config.data_cipher = 'AES-256-CBC'
@@ -368,27 +493,55 @@ Sym::Configuration.configure do |config|
368
493
  end
369
494
  ```
370
495
 
371
- As you can see, it's possible to change the default cipher typem, although not all ciphers will be code-compatible with the current algorithm, and may require additional code changes.
496
+ As you can see, it's possible to change the default cipher type, although not all ciphers will be code-compatible with the current algorithm, and may require additional code changes.
497
+
498
+ ## Encryption Features & Cipher Used
372
499
 
373
- ## Managing Keys
500
+ The `sym` executable as well as the Ruby API provide:
374
501
 
375
- There is a separate discussion about ways to securely store private keys in [MANAGING-KEYS.md](https://github.com/kigster/sym/blob/master/MANAGING-KEYS.md).
502
+ * Symmetric data encryption with:
503
+ * the Cipher `AES-256-CBC` used by the US Government
504
+ * 256-bit private key, that
505
+ * can be generated and is a *base64-encoded* string about 45 characters long. The *decoded* key is always 32 characters (or 256 bytes) long.
506
+ * can be optionally password-encrypted using the 128-bit key, and then be automatically detected (and password requested) when the key is used
507
+ * can have its password cached for 15 minutes locally on the machine using dRB server (or used without the cache with `-P` flag).
508
+ * Rich command line interface with some innovative features, such as inline editing of an encrypted file, using your favorite `$EDITOR`.
509
+ * Data handling:
510
+ * Automatic compression of the data upon encryption
511
+ * Automatic base64 encryption to make all encrypted strings fit onto a single line.
512
+ * This makes the format suitable for YAML or JSON configuration files, where only the values are encrypted.
513
+ * Rich Ruby API
514
+ * (OS-X Only): Ability to create, add and delete generic password entries from the Mac OS-X KeyChain, and to leverage the KeyChain to store sensitive private keys.
376
515
 
377
516
  ## Development
378
517
 
379
518
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
380
519
 
381
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
520
+ To install this gem onto your local machine, run `bundle exec rake install`.
382
521
 
383
- ## Contributing
522
+ To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
384
523
 
385
- Bug reports and pull requests are welcome on GitHub at (https://github.com/kigster/sym)[https://github.com/kigster/sym].
524
+ ### Contributing
525
+
526
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/kigster/sym](https://github.com/kigster/sym).
386
527
 
387
528
  ## License
388
529
 
530
+ `Sym` library is &copy; 2016-2017 Konstantin Gredeskoul.
531
+
389
532
  The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
390
533
 
391
- ## Author
534
+ The library is designed to be a layer on top of [`OpenSSL`](https://www.openssl.org/), distributed under the [Apache Style license](https://www.openssl.org/source/license.txt).
535
+
536
+ ## Acknowledgements
537
+
538
+ [Konstantin Gredeskoul](http:/kig.re) is the primary developer of this library. Contributions from others are strongly encouraged and very welcome. Any pull requests will be reviewed promptly.
392
539
 
393
- This library is the work of [Konstantin Gredeskoul](http:/kig.re), &copy; 2016-2017, distributed under the MIT license.
540
+ Contributors:
541
+
542
+ * Wissam Jarjoui (Shippo)
543
+ * Megan Mathews
544
+ * Barry Anderson
545
+
546
+
394
547
 
@@ -7,7 +7,6 @@ module Sym
7
7
  required_options [:bash_completion]
8
8
  try_after :generate_key, :open_editor, :encrypt_decrypt
9
9
 
10
-
11
10
  def execute
12
11
  install_completion_file
13
12
  file = opts[:bash_completion]
@@ -1,3 +1,15 @@
1
1
  module Sym
2
- VERSION = '2.1.1'
2
+ VERSION = '2.1.2'
3
+ DESCRIPTION = <<-eof
4
+ Sym is a command line utility and a Ruby API that makes it trivial to encrypt and decrypt
5
+ sensitive data. Unlike many other existing encryption tools, sym focuses on usability and
6
+ streamlined interface (CLI), with the goal of making encryption easy and transparent.
7
+ The result? There is no excuse for keeping your application secrets unencrypted :)
8
+
9
+ You can password-protect the key for an additional layer of security, and store the key in the
10
+ OS-X keychain. Use the key to reliably encrypt, decrypt and re-encrypt your application
11
+ secrets. Use the -t CLI switch to transparently edit an encrypted file in an editor of your choice.
12
+
13
+ Sym uses a symmetric aes-256-cbc cipher with a private key and an IV vector.
14
+ eof
3
15
  end
@@ -1,79 +1,128 @@
1
- ## Sym
2
1
 
3
- > Sym is a versatile encryption gem, based on the symmetric encryption cipher provided by the OpenSSL. It provides easy to remember commands to manage encryption key: you can generate a key, import an existing key, password protect an open key, store the key in OS-X KeyChain, and use it for encryption/decryption later. The key is used to encrypt, decrypt and edit any sensitive information, such application secrets.
2
+ # Sym
4
3
 
5
- ### Complete Usage
4
+ ## Table of Contents
5
+
6
+ [TOC]
7
+
8
+ __Sym__ is a versatile encryption gem, based on the symmetric encryption cipher provided by the OpenSSL. It provides easy to remember commands to manage encryption key: you can generate a key, import an existing key, password protect an open key, store the key in OS-X KeyChain, and use it for encryption/decryption later. The key is used to encrypt, decrypt and edit any sensitive information, such application secrets.
9
+
10
+ ## Usage
6
11
 
7
12
  sym [ global options ] [ sub command ] [ command options ]
8
13
 
9
- ##### Global Options
14
+ ## Global Options
10
15
 
11
16
  ```bash
12
- -M, ——password-timeout [timeout] when passwords expire (in seconds)
13
- -P, ——no-password-cache disables caching of key passwords
14
- -v, ——verbose show additional information
15
- -T, ——trace print a backtrace of any errors
16
- -q, ——quiet silence all output
17
- -V, ——version print library version
18
- -N, ——no-color disable color output
17
+ -t, --password-timeout [timeout] when passwords expire (in seconds)
18
+ -p, --no-password-cache disables caching of key passwords
19
+ -v, --verbose show additional information
20
+ -T, --trace print a backtrace of any errors
21
+ -q, --quiet silence all output
22
+ -V, --version print library version
23
+ -N, --no-color disable color output
19
24
  ```
20
25
 
21
- ##### Help & Examples:
26
+ ## Help & Examples:
22
27
 
23
28
  ```bash
24
- -h, ——help show help
25
- -l, ——long show help and detailed examples
29
+ -h, --help show help
30
+ -l, --long show help and detailed examples
26
31
  ```
27
32
 
28
- ##### Commands
33
+ ## Commands
29
34
 
30
- # Genereate new key
31
- sym key ——save [ key-source ]
32
-
33
- # Copy existing key, optionally password-protected:
34
- sym key ——save [ key-source ] ——key [ key-source ] [ -p ]
35
-
36
- # Delete existing key:
37
- sym key ——rm [ key-source ]
35
+ ### Genereate a new key
36
+ ```bash
37
+ sym key [ [ --out | -o ] uri ] # or STDOUT by default
38
+ # eg.
39
+ > sym key -o stdout
40
+ > sym key -o file://~/.key
41
+ ```
38
42
 
39
- sym decrypt ——key | -k key-source
40
- ——data | -d data-source
41
- ——to | -t data-source | ——in-place
42
-
43
- sym encrypt ——key | -k key-source
44
- ——data | -d data-source
45
- ——to | -t data-source | ——in-place
46
-
47
- sym edit ——data | -d data-source
48
- ——key | -k key-source
49
- ——bak | -b data-backup-source
50
-
51
- sym recrypt ——data | -d data-source
52
- ——key | -k key-source
53
- ——save | -s key-source
54
-
55
- sym install bash-completion
56
-
57
- sym --help | -h
58
-
59
- sym command --help | -h
60
-
61
- sym examples
43
+ ### Copy or Re-Import a Key
44
+
45
+ Typically applied to an existing key, optionally password-protecting it:
46
+
47
+ ```bash
48
+ sym key [ --in | -k ] uri
49
+ [ [ --out | -o ] uri ] # or STDOUT by default
50
+ [ --password | -p ]
51
+ # eg.
52
+ > sym key -k file://~/.key -o keychain://mykey -p
53
+
54
+ > sym key -k stdin -o keychain://mykey -p
55
+ Please enter the encryption key: 75ngenJpB6zL47/8Wo7Ne6JN1pnOsqNEcIqblItpfg4=
56
+ Please enter new password:
57
+ Please confirm the new password:
58
+ ```
59
+
60
+ ### Delete an existing key (assuming URI supports deletion):
61
+
62
+ ```bash
63
+ sym key [ --delete | -d ] uri
64
+
65
+ # eg.
66
+ > sym key -d keychain://mykey
67
+ > sym key -d redis://127.0.0.1:6379/1/symkey
68
+ ```
69
+
70
+ ### Encrypt or Decrypt a Resource
62
71
 
72
+ ```bash
73
+ sym decrypt [ --key | -k ] uri
74
+ [ --data | -d ] uri
75
+ [ [ --out | -o ] uri ]
63
76
 
64
- ##### Arguments via Environment
77
+ sym encrypt [ --key | -k ] uri
78
+ [ --data | -d ] uri
79
+ [ [ --out | -o ] uri ]
80
+ ```
65
81
 
66
- export SYM_ARGS_KEY='@file "~/.sym.key"'
67
- export SYM_ARGS_DATA='@file "~/.sym.key"'
82
+ ### Open Encrypted Resource in an Editor
68
83
 
69
- ##### Subcommands
84
+ ```bash
85
+ sym edit [ --key | -k ] uri
86
+ [ --data | -d ] uri
87
+ [ [ --backup | -b ] data-backup-uri
88
+ ```
89
+ ### Re-encrypt data, and rotate the key
70
90
 
71
- When loading the commands, we use the hierarchical loading:
91
+ For key and data URIs that support update operation (eg, `file://`, `keychain://`)
92
+ this operation decrypts the resource with the current key, generates
93
+ a new key, re-encrypts the data, and updates both the resource and the
94
+ key URIs.
72
95
 
73
- require 'sym/app/cmd'
74
- require 'sym/app/cmd/bash'
75
- require 'sym/app/cmd/bash/completion'
96
+ ```bash
97
+ sym cycle [ --key | -k ] uri
98
+ [ --data | -d ] uri
99
+ [ [ --out | -o ] uri ]
100
+ # eg:
101
+ sym cycle -k file://~/.key -d file://./secrets.yml
102
+ ```
76
103
 
104
+ ### Installation, Help, and Other Commands
105
+
106
+ ```bash
107
+ sym install bash-completion
108
+
109
+ sym --help | -h
110
+
111
+ sym command --help | -h
112
+
113
+ sym examples
114
+ ```
115
+
116
+ ### Arguments via Environment
117
+
118
+ Common arguments can be passed in an environment variable called `SYM_ARGS`:
119
+
120
+ export SYM_ARGS='-k file://~/.sym.key'
121
+
122
+ The name of the variable can be read from the `-B <name>` argument, eg:
123
+
124
+ SYM_ARGUMENTS='-k 75ngenJpB6zL47/8Wo7Ne6JN1pnOsqNEcIqblItpfg4'
125
+ sym -B SYM_ARGUMENS -d file://file.enc
77
126
 
78
127
  ### Reading and Writing Data and Keys
79
128
 
@@ -84,13 +133,17 @@ Each URI type is supported by a corresponding plugin, and new ones can be easily
84
133
  Some examples:
85
134
 
86
135
  ```bash
87
- ——key-in string://234234234 # read from the literal data
88
- ——key-out file://home/kig/.mykey # read/write from/to file
89
- ——key-in env://MY_VARIABLE # read from environment variable
90
- ——key-out stdio:// # read/write using stdin/out
91
-
92
- --data-in https://mysite.com/remote/secrets.json.enc
93
- --data-out file:///usr/local/etc/secrets.json
136
+ string://234234234 # read from the literal data
137
+ env://MY_VARIABLE # read from environment variable
138
+
139
+ file://home/kig/.mykey # read/write from/to file
140
+ stdio:// # read/write using stdin/out
141
+
142
+ # Real URLs could potentially support writes with PUT or POST
143
+ https://mysite.com/remote/secrets.json.enc
144
+
145
+ # Files support read/write
146
+ file:///usr/local/etc/secrets.json
94
147
  ```
95
148
 
96
149
  Below is the list of supported types planned for 3.0:
@@ -110,4 +163,6 @@ Below is the list of supported types planned for 3.0:
110
163
  memcached://127.0.0.1:11211/mykey yes yes yes
111
164
  scp://user@host/path/file yes yes yes
112
165
  http[s]://user@host/path/file yes yes yes
166
+ ftp[s]://user@host/path/file yes yes yes
167
+
113
168
  ```
@@ -2,23 +2,16 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'sym/version'
5
+
5
6
  Gem::Specification.new do |spec|
6
7
  spec.name = 'sym'
7
8
  spec.version = Sym::VERSION
8
9
  spec.authors = ['Konstantin Gredeskoul']
9
10
  spec.email = %w(kigster@gmail.com)
10
11
 
11
- spec.summary = %q{Easy to use symmetric encryption library & CLI with a strong aes-256-cbc cipher used by the US Government.}
12
+ spec.summary = %q{Super easy to use encryption library & a CLI with a strong aes-256-cbc cipher that can be used to transparently encrypt/decrypt/edit application secrets.}
12
13
 
13
- spec.description = <<-EOF
14
- Sym is a versatile command line utility and a library, that streamlines access to a
15
- symmetric encryption offered by OpenSSL library. Use its rich CLI interface, or the Ruby
16
- API to generate a key used for both encryption and decryption. You can
17
- additionally password protect the key, and optionally store the key in the named
18
- OS-X keychain. Use the key to reliably encrypt, decrypt and re-encrypt your application
19
- secrets. Use the -t CLI switch to open an encrypted file in an editor of your choice.
20
- Sym uses a symmetric aes-256-cbc cipher with a private key and an IV vector.
21
- EOF
14
+ spec.description = Sym::DESCRIPTION
22
15
 
23
16
  spec.homepage = 'https://github.com/kigster/sym'
24
17
 
@@ -40,7 +33,7 @@ command, which appends sym's shell completion to the specified file:
40
33
  Thank you for checking out Sym and happy crypting :)
41
34
  -- KG ( github.com/kigster | twitter.com/kig )
42
35
  EOF
43
- spec.add_dependency 'colored2', '~> 2.0'
36
+ spec.add_dependency 'colored2', '~> 3'
44
37
  spec.add_dependency 'slop', '~> 4.3'
45
38
  spec.add_dependency 'activesupport'
46
39
  spec.add_dependency 'highline', '~> 1.7'
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.1.1
4
+ version: 2.1.2
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-02-05 00:00:00.000000000 Z
11
+ date: 2017-02-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: '3'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: '3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: slop
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -178,14 +178,16 @@ dependencies:
178
178
  - - ">="
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
- description: " Sym is a versatile command line utility and a library, that streamlines
182
- access to a \n symmetric encryption offered by OpenSSL library. Use its rich
183
- CLI interface, or the Ruby \n API to generate a key used for both encryption
184
- and decryption. You can \n additionally password protect the key, and optionally
185
- store the key in the named \n OS-X keychain. Use the key to reliably encrypt,
186
- decrypt and re-encrypt your application \n secrets. Use the -t CLI switch to
187
- open an encrypted file in an editor of your choice. \n Sym uses a symmetric aes-256-cbc
188
- cipher with a private key and an IV vector.\n"
181
+ description: " Sym is a command line utility and a Ruby API that makes it trivial
182
+ to encrypt and decrypt \n sensitive data. Unlike many other existing encryption
183
+ tools, sym focuses on usability and \n streamlined interface (CLI), with the
184
+ goal of making encryption easy and transparent. \n The result? There is no excuse
185
+ for keeping your application secrets unencrypted :)\n\n You can password-protect
186
+ the key for an additional layer of security, and store the key in the \n OS-X
187
+ keychain. Use the key to reliably encrypt, decrypt and re-encrypt your application
188
+ \n secrets. Use the -t CLI switch to transparently edit an encrypted file in
189
+ an editor of your choice.\n \n Sym uses a symmetric aes-256-cbc cipher with a
190
+ private key and an IV vector.\n"
189
191
  email:
190
192
  - kigster@gmail.com
191
193
  executables:
@@ -280,6 +282,6 @@ rubyforge_project:
280
282
  rubygems_version: 2.6.8
281
283
  signing_key:
282
284
  specification_version: 4
283
- summary: Easy to use symmetric encryption library & CLI with a strong aes-256-cbc
284
- cipher used by the US Government.
285
+ summary: Super easy to use encryption library & a CLI with a strong aes-256-cbc cipher
286
+ that can be used to transparently encrypt/decrypt/edit application secrets.
285
287
  test_files: []