ohlol-nachos 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +46 -6
- data/VERSION +1 -1
- data/lib/nachos.rb +29 -15
- data/nachos.gemspec +2 -2
- metadata +2 -2
data/README.markdown
CHANGED
@@ -3,23 +3,63 @@ NACHOS
|
|
3
3
|
|
4
4
|
Nachos keeps people from taking your stuff. It's mine, nachos!
|
5
5
|
|
6
|
+
I recently needed the ability to programatically encrypt and decrypt data on
|
7
|
+
the fly for operations support purposes (code releases, etc). I considered
|
8
|
+
writing a script, but it just didn't seem very clean. Plus, the main reason I
|
9
|
+
needed it was for software deployment, which I execute in Rake tasks.
|
10
|
+
|
11
|
+
It uses two levels of encryption:
|
12
|
+
|
13
|
+
1. AES-256 CBC encryption of the data with a secret key and an IV
|
14
|
+
2. PKI encryption (private key is 3DES encrypted, too!) of the secret key
|
15
|
+
and IV
|
16
|
+
|
17
|
+
While it's arguably unnecessary to encrypt the IV, I did want to be able to
|
18
|
+
store my secret key without worrying about it getting compromised. This allows
|
19
|
+
me to keep all of my keystores where ever I want, including a SCM. For stuff
|
20
|
+
like code releases, this is huge.
|
21
|
+
|
22
|
+
Another really cool facet of this is that I can keep revisioned copies of not
|
23
|
+
only my sensitive data, but also my keystores! Oh yeah.
|
24
|
+
|
6
25
|
You need to generate a public and private key to bootstrap it.
|
7
26
|
|
27
|
+
For more info, check here: http://ohlol.net/2009/07/announcing-nachos.html
|
28
|
+
|
29
|
+
INSTALL
|
30
|
+
-------
|
31
|
+
|
32
|
+
% sudo gem sources -a http://gems.github.com
|
33
|
+
% sudo gem install ohlol-nachos
|
34
|
+
|
35
|
+
SETUP/BOOTSTRAP
|
36
|
+
---------------
|
37
|
+
|
38
|
+
% openssl genrsa -des3 -out config/private.pem 2048
|
39
|
+
<enter passphrase>
|
40
|
+
<repeat passphrase>
|
41
|
+
% openssl rsa -in config/private.pem -pubout -out config/public.pem
|
42
|
+
|
8
43
|
EXAMPLE USAGE
|
9
44
|
-------------
|
10
45
|
|
11
|
-
|
46
|
+
to store:
|
12
47
|
|
13
|
-
require '
|
48
|
+
require 'nachos'
|
14
49
|
|
50
|
+
|
51
|
+
config = {
|
52
|
+
:public_key => 'config/public.pem',
|
53
|
+
:private_key => 'config/private.pem',
|
54
|
+
:secret_key => 'config/secret-key.yml',
|
55
|
+
:data_store => 'config/secret-data.enc'
|
56
|
+
}
|
57
|
+
|
15
58
|
e = Nachos::Encryptor('password')
|
16
59
|
e.clear_data = 'foo bar baz'
|
17
60
|
e.save_data
|
18
61
|
|
19
|
-
|
62
|
+
to load:
|
20
63
|
|
21
|
-
require 'ohlol-nachos'
|
22
|
-
|
23
|
-
e = Nachos::Encryptor('password)'
|
24
64
|
e.load_data
|
25
65
|
puts e.clear_data
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/nachos.rb
CHANGED
@@ -50,8 +50,6 @@ class Nachos::Encryptor
|
|
50
50
|
@public_key = OpenSSL::PKey::RSA.new(File.open(self.config[:public_key]))
|
51
51
|
@private_key =
|
52
52
|
OpenSSL::PKey::RSA.new(File.open(self.config[:private_key]), password)
|
53
|
-
@cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
54
|
-
|
55
53
|
@keystore = Nachos::KeyStore.new
|
56
54
|
|
57
55
|
keypair
|
@@ -69,11 +67,15 @@ class Nachos::Encryptor
|
|
69
67
|
def keypair
|
70
68
|
if @keystore.secret_key.empty? || @keystore.secret_iv.empty?
|
71
69
|
begin
|
72
|
-
|
73
|
-
|
70
|
+
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
71
|
+
|
72
|
+
@clear_secret_key = cipher.random_key
|
73
|
+
@clear_secret_iv = cipher.random_iv
|
74
74
|
|
75
|
-
@secret_key = @keystore.secret_key =
|
76
|
-
|
75
|
+
@secret_key = @keystore.secret_key =
|
76
|
+
@public_key.public_encrypt(@clear_secret_key)
|
77
|
+
@secret_iv = @keystore.secret_iv =
|
78
|
+
@public_key.public_encrypt(@clear_secret_iv)
|
77
79
|
@keystore.save_secrets
|
78
80
|
rescue => e
|
79
81
|
raise Nachos::EncryptorException, "There was a problem generating " +
|
@@ -84,8 +86,8 @@ class Nachos::Encryptor
|
|
84
86
|
@secret_iv = @keystore.secret_iv
|
85
87
|
end
|
86
88
|
|
87
|
-
@clear_secret_key =
|
88
|
-
@clear_secret_iv =
|
89
|
+
@clear_secret_key = @private_key.private_decrypt(@secret_key)
|
90
|
+
@clear_secret_iv = @private_key.private_decrypt(@secret_iv)
|
89
91
|
end
|
90
92
|
|
91
93
|
def encrypt(str)
|
@@ -93,8 +95,14 @@ class Nachos::Encryptor
|
|
93
95
|
raise Nachos::EncryptorException, "What do you want to encrypt?"
|
94
96
|
else
|
95
97
|
begin
|
96
|
-
|
97
|
-
|
98
|
+
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
99
|
+
|
100
|
+
cipher.encrypt
|
101
|
+
cipher.key = @clear_secret_key
|
102
|
+
cipher.iv = @clear_secret_iv
|
103
|
+
|
104
|
+
str_e = cipher.update(str)
|
105
|
+
str_e << cipher.final
|
98
106
|
rescue => e
|
99
107
|
raise Nachos::EncryptorException, "Couldn't encrypt the data! (#{e})"
|
100
108
|
end
|
@@ -106,10 +114,16 @@ class Nachos::Encryptor
|
|
106
114
|
raise Nachos::EncryptorException, "What do you want to decrypt?"
|
107
115
|
else
|
108
116
|
begin
|
109
|
-
|
110
|
-
|
117
|
+
cipher = OpenSSL::Cipher::Cipher.new('aes-256-cbc')
|
118
|
+
|
119
|
+
cipher.decrypt
|
120
|
+
cipher.key = @clear_secret_key
|
121
|
+
cipher.iv = @clear_secret_iv
|
122
|
+
|
123
|
+
str_d = cipher.update(str)
|
124
|
+
str_d << cipher.final
|
111
125
|
rescue => e
|
112
|
-
raise Nachos::
|
126
|
+
raise Nachos::EncryptorException, "Couldn't decrypt the data! (#{e})"
|
113
127
|
end
|
114
128
|
end
|
115
129
|
end
|
@@ -123,7 +137,7 @@ class Nachos::Encryptor
|
|
123
137
|
end
|
124
138
|
|
125
139
|
@encrypted_data.chomp!
|
126
|
-
@clear_data = decrypt(@encrypted_data)
|
140
|
+
@clear_data = decrypt(Base64.decode64(@encrypted_data))
|
127
141
|
rescue Errno::ENOENT
|
128
142
|
rescue => e
|
129
143
|
raise Nachos::EncryptorException, "There was a problem reading the " +
|
@@ -138,7 +152,7 @@ class Nachos::Encryptor
|
|
138
152
|
|
139
153
|
begin
|
140
154
|
File.open(self.config[:data_store], 'w') do |f|
|
141
|
-
f.puts @encrypted_data
|
155
|
+
f.puts Base64.encode64(@encrypted_data)
|
142
156
|
end
|
143
157
|
rescue
|
144
158
|
raise Nachos::EncryptorException, "There was a problem saving the data " +
|
data/nachos.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{nachos}
|
5
|
-
s.version = "0.3.
|
5
|
+
s.version = "0.3.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Scott Smith"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-17}
|
10
10
|
s.description = %q{Nachos is a Ruby library for managing an encrypted data store.}
|
11
11
|
s.email = %q{scott@ohlol.net}
|
12
12
|
s.extra_rdoc_files = [
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ohlol-nachos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Smith
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-17 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|