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 +4 -4
- data/README.md +275 -122
- data/lib/sym/app/commands/bash_completion.rb +0 -1
- data/lib/sym/version.rb +13 -1
- data/sym-3.0-cli.md +116 -61
- data/sym.gemspec +4 -11
- metadata +16 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6529381babbcb57ee7ca039a9d01dbafe4d8fe9f
|
4
|
+
data.tar.gz: 9b48b1a55b06dd5870a3f0d25bc0b862c3f64502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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'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 & 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.
|
27
|
-
2.
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
-
|
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
|
-
|
166
|
+
__Direct Editing Encrypted Files__
|
38
167
|
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
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
|
-
|
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
|
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
|
-
|
192
|
+
__BASH Completion__
|
73
193
|
|
74
|
-
|
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
|
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
|
-
|
200
|
+
<a name="#cli"></a>
|
81
201
|
|
82
|
-
|
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
|
-
|
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
|
-
|
206
|
+
The private key is the cornerstone of the symmetric encryption. Using `sym`, the key can be:
|
95
207
|
|
96
|
-
|
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
|
-
|
213
|
+
The __unencrypted private__ key will be in the form of a base64-encoded string, 45 characters long.
|
99
214
|
|
100
|
-
|
215
|
+
__Encrypted (with password) private key__ will be considerably longer, perhaps 200-300 characters long.
|
101
216
|
|
102
|
-
|
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
|
219
|
+
#### Generating Private Keys
|
105
220
|
|
106
|
-
|
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
|
-
|
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 -
|
121
|
-
|
122
|
-
|
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.
|
127
|
-
2.
|
128
|
-
3.
|
129
|
-
4.
|
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
|
-
|
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 <
|
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
|
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
|
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
|
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
|
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
|
-
####
|
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.
|
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 [ -
|
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
|
205
|
-
|
206
|
-
|
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 -
|
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
|
-
|
385
|
+
<a name="inline"></a>
|
267
386
|
|
268
|
-
|
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
|
-
|
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
|
-
|
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)
|
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
|
-
|
442
|
+
### Encryption and Decryption Operations
|
319
443
|
|
320
|
-
So how would we use this library from another
|
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
|
-
|
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.
|
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
|
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
|
-
|
500
|
+
The `sym` executable as well as the Ruby API provide:
|
374
501
|
|
375
|
-
|
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`.
|
520
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
382
521
|
|
383
|
-
|
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
|
-
|
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 © 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
|
-
|
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
|
-
|
540
|
+
Contributors:
|
541
|
+
|
542
|
+
* Wissam Jarjoui (Shippo)
|
543
|
+
* Megan Mathews
|
544
|
+
* Barry Anderson
|
545
|
+
|
546
|
+
|
394
547
|
|
data/lib/sym/version.rb
CHANGED
@@ -1,3 +1,15 @@
|
|
1
1
|
module Sym
|
2
|
-
VERSION = '2.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
|
data/sym-3.0-cli.md
CHANGED
@@ -1,79 +1,128 @@
|
|
1
|
-
## Sym
|
2
1
|
|
3
|
-
|
2
|
+
# Sym
|
4
3
|
|
5
|
-
|
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
|
-
|
14
|
+
## Global Options
|
10
15
|
|
11
16
|
```bash
|
12
|
-
-
|
13
|
-
-
|
14
|
-
-v,
|
15
|
-
-T,
|
16
|
-
-q,
|
17
|
-
-V,
|
18
|
-
-N,
|
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
|
-
|
26
|
+
## Help & Examples:
|
22
27
|
|
23
28
|
```bash
|
24
|
-
-h,
|
25
|
-
-l,
|
29
|
+
-h, --help show help
|
30
|
+
-l, --long show help and detailed examples
|
26
31
|
```
|
27
32
|
|
28
|
-
|
33
|
+
## Commands
|
29
34
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
77
|
+
sym encrypt [ --key | -k ] uri
|
78
|
+
[ --data | -d ] uri
|
79
|
+
[ [ --out | -o ] uri ]
|
80
|
+
```
|
65
81
|
|
66
|
-
|
67
|
-
export SYM_ARGS_DATA='@file "~/.sym.key"'
|
82
|
+
### Open Encrypted Resource in an Editor
|
68
83
|
|
69
|
-
|
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
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
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
|
```
|
data/sym.gemspec
CHANGED
@@ -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{
|
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
|
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', '~>
|
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.
|
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-
|
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: '
|
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: '
|
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
|
182
|
-
|
183
|
-
|
184
|
-
and
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
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:
|
284
|
-
|
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: []
|