opensecret 0.0.941 → 0.0.946
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/crypto/amalgam.rb +22 -159
- data/lib/crypto/blowfish.rb +85 -0
- data/lib/crypto/collect.rb +1 -0
- data/lib/crypto/engineer.rb +27 -147
- data/lib/crypto/open.bcrypt.rb +170 -0
- data/lib/crypto/verify.rb +1 -1
- data/lib/{session/exceptions.rb → exception/cli.error.rb} +2 -2
- data/lib/exception/errors/cli.errors.rb +31 -0
- data/lib/factbase/facts.opensecret.io.ini +1 -1
- data/lib/notepad/blow.rb +14 -0
- data/lib/opensecret.rb +11 -3
- data/lib/opensecret/commons/eco.system.rb +1 -1
- data/lib/opensecret/executors/crypt.keys/crypt.keys.rb +1 -1
- data/lib/opensecret/executors/decrypt/decrypt.rb +1 -1
- data/lib/opensecret/executors/encrypt/encrypt.rb +1 -1
- data/lib/plugins/cipher.rb +179 -0
- data/lib/plugins/ciphers/aes-256.rb +162 -0
- data/lib/plugins/ciphers/blowfish.rb +223 -0
- data/lib/plugins/stores/store.rb +4 -0
- data/lib/{usecase → plugins}/usecase.rb +3 -12
- data/lib/{usecase → plugins}/usecases/init.rb +29 -41
- data/lib/{usecase → plugins}/usecases/on.rb +0 -0
- data/lib/{usecase → plugins}/usecases/safe.rb +2 -4
- data/lib/session/require.gem.rb +107 -0
- data/lib/version.rb +1 -1
- metadata +16 -8
- data/lib/config.opensecret.ini +0 -14
@@ -0,0 +1,162 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
module OpenSecret
|
5
|
+
|
6
|
+
# Aes256 is a symmetric encryption cipher which inherits extends the
|
7
|
+
# {OpenSecret::Cipher} base class in order to implement plug and play
|
8
|
+
# symmetric encryption.
|
9
|
+
#
|
10
|
+
# == Aes256 Symmetric Encrypt/Decrypt Dictionary
|
11
|
+
#
|
12
|
+
# To facilitate decryption - this cipher produces a key/value pair
|
13
|
+
# dictionary which will be stored along with the ciphertext itself.
|
14
|
+
# The dictionary includes
|
15
|
+
#
|
16
|
+
# - <tt>symmetric.cipher</tt> - the algorithm used to encrypt and decrypt
|
17
|
+
# - <tt>encryption.key</tt> - hex encoded key for encrypting and decrypting
|
18
|
+
# - <tt>initialize.vector</tt> - the initialization vector known as a IV (four)
|
19
|
+
#
|
20
|
+
# == Aes256 Implemented Methods
|
21
|
+
#
|
22
|
+
# This cipher brings the cryptographic mathematics and implementation algorithms
|
23
|
+
# for the 256Bit Advanced Encryption Standard. No serious practical (nor theoretical)
|
24
|
+
# challenge has ever been mounted against this algorithm (or this implementation).
|
25
|
+
#
|
26
|
+
# This class implements the below methods
|
27
|
+
#
|
28
|
+
# - <tt>do_symmetric_encryption(plain_text)</tt> - resulting in ciphertext
|
29
|
+
# - <tt>do_symmetric_decryption(ciphertext, encryption_dictionary)</tt> » plaintext
|
30
|
+
#
|
31
|
+
# and it also sets the <tt>@encryption_dictionary</tt> hash (map) of pertinent
|
32
|
+
# key/value pairs including the +encryption algorithm+ and +encryption key+.
|
33
|
+
#
|
34
|
+
# That's It. Cipher children can rely on the {OpenSecret::Cipher} parent to
|
35
|
+
# do the nitty gritty of file-handling plus managing stores and paths.
|
36
|
+
|
37
|
+
class Aes256 < OpenSecret::Cipher
|
38
|
+
|
39
|
+
@@initialize_vector_keyname = "initialize.vector"
|
40
|
+
|
41
|
+
# Use the AES 256 bit block cipher and a robust strong random key plus
|
42
|
+
# initialization vector (IV) to symmetrically encrypt the plain text.
|
43
|
+
#
|
44
|
+
# Add these key/value pairs to @encryption_dictionary instance map.
|
45
|
+
#
|
46
|
+
# - <tt>symmetric.cipher</tt> - the algorithm used to encrypt and decrypt
|
47
|
+
# - <tt>encryption.key</tt> - hex encoded key for encrypting and decrypting
|
48
|
+
# - <tt>initialize.vector</tt> - the initialization vector known as a IV (four)
|
49
|
+
#
|
50
|
+
# @param plain_text [String] the plain (or base64 encoded) text to encrypt
|
51
|
+
# @return [String] the symmetrically encrypted cipher text
|
52
|
+
def do_symmetric_encryption plain_text
|
53
|
+
|
54
|
+
@cipher_name = "aes-256-cbc"
|
55
|
+
|
56
|
+
crypt_cipher = OpenSSL::Cipher.new @cipher_name
|
57
|
+
crypt_cipher.encrypt( plain_text )
|
58
|
+
|
59
|
+
@encryption_dictionary = {
|
60
|
+
@@symmetric_cipher_keyname => @cipher_name,
|
61
|
+
@@encryption_key_keyname => crypt_cipher.random_key.unpack("H*").first,
|
62
|
+
@@initialize_vector_keyname => crypt_cipher.random_iv.unpack("H*").first
|
63
|
+
}
|
64
|
+
|
65
|
+
Base64.encode64( crypt_cipher.update + crypt_cipher.final )
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Use the AES 256 bit block cipher together with the encryption key
|
71
|
+
# and initialization vector (iv) sitting in the encryption_dictionary,
|
72
|
+
# to symmetrically decrypt the parameter cipher text.
|
73
|
+
#
|
74
|
+
# == Pre-Condition | Encryption Dictionary
|
75
|
+
#
|
76
|
+
# This method requires the <tt>@encryption_dictionary</tt> instance
|
77
|
+
# variable to have been set and to contain (amongst others)
|
78
|
+
#
|
79
|
+
# - the <tt>encryption.key</tt> - hex encoded key for encrypting and decrypting
|
80
|
+
# - and <tt>initialize.vector</tt> - the initialization vector known as a IV (four)
|
81
|
+
#
|
82
|
+
# @param cipher_text [String] the base64 encoded cipher text to decrypt
|
83
|
+
# @return [String] decrypted plain text from symmetric key and cipher text
|
84
|
+
def do_symmetric_decryption cipher_text
|
85
|
+
|
86
|
+
abort "Implement AES 256 decryption in aes-256"
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
|
91
|
+
|
92
|
+
=begin
|
93
|
+
encode_cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
94
|
+
encode_cipher.encrypt # We are encrypting
|
95
|
+
key = encode_cipher.random_key
|
96
|
+
iv = encode_cipher.random_iv
|
97
|
+
hex_key = key.unpack("H*").first
|
98
|
+
hex_iv = iv.unpack("H*").first
|
99
|
+
|
100
|
+
line1 = "1>> This is secret number one over here with at @ and squiggle~ and round brakets().\n"
|
101
|
+
line2 = "2>> secret number two with colon and semi :; angular <> qmarks ??.\n"
|
102
|
+
line3 = "3>> secret number 3 fwd slash / and backslash twice \\ and pipe || and excla !!\n"
|
103
|
+
line4 = "4>> secret 4 with pound ££ dollar $$ percent %% hat ^^ ampr && stars **\n"
|
104
|
+
line5 = "5>> secret 5 with hyphens - and underscore __ and plus ++ and equal == and sqBs [[]].\n"
|
105
|
+
line6 = "6>> secret 6 with double quote \"from here to here\" and \' single quotes\'.\n"
|
106
|
+
line7 = "7>> secret 7 with periods .... and hashes #####\n"
|
107
|
+
|
108
|
+
crypt_text = ""
|
109
|
+
crypt_text += encode_cipher.update line1
|
110
|
+
crypt_text += encode_cipher.update line2
|
111
|
+
crypt_text += encode_cipher.update line3
|
112
|
+
crypt_text += encode_cipher.update line4
|
113
|
+
crypt_text += encode_cipher.update line5
|
114
|
+
crypt_text += encode_cipher.update line6
|
115
|
+
crypt_text += encode_cipher.update line7
|
116
|
+
crypt_text += encode_cipher.final
|
117
|
+
coded_crypt_text = Base64.encode64(crypt_text)
|
118
|
+
|
119
|
+
puts ""
|
120
|
+
puts "The key is #{hex_key}"
|
121
|
+
puts "The IV is #{hex_iv}"
|
122
|
+
puts "========================"
|
123
|
+
puts "The Cipher Text is Below"
|
124
|
+
puts "========================"
|
125
|
+
puts coded_crypt_text
|
126
|
+
puts "========================"
|
127
|
+
puts crypt_text
|
128
|
+
puts "========================"
|
129
|
+
puts "========================"
|
130
|
+
puts "========================"
|
131
|
+
puts line1 + line2 + line3 + line4 + line5 + line6 + line7
|
132
|
+
puts "========================"
|
133
|
+
puts "========================"
|
134
|
+
puts "========================"
|
135
|
+
puts ""
|
136
|
+
puts ""
|
137
|
+
|
138
|
+
unencoded_crypt_text = Base64.decode64(coded_crypt_text)
|
139
|
+
decode_cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
140
|
+
|
141
|
+
decode_cipher.decrypt
|
142
|
+
decode_cipher.key = [hex_key].pack("H*")
|
143
|
+
decode_cipher.iv = [hex_iv].pack("H*")
|
144
|
+
first_part = decode_cipher.update( Base64.decode64(coded_crypt_text) )
|
145
|
+
second_part = ""
|
146
|
+
second_part << decode_cipher.final
|
147
|
+
|
148
|
+
puts "========================"
|
149
|
+
puts "Decrypted Text is Below"
|
150
|
+
puts "========================"
|
151
|
+
puts first_part
|
152
|
+
puts "========================"
|
153
|
+
puts second_part
|
154
|
+
puts "========================"
|
155
|
+
puts ""
|
156
|
+
=end
|
157
|
+
|
158
|
+
|
159
|
+
end
|
160
|
+
|
161
|
+
|
162
|
+
end
|
@@ -0,0 +1,223 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
# coding: utf-8
|
3
|
+
|
4
|
+
module OpenSecret
|
5
|
+
|
6
|
+
# Blowfish is a symmetric encryption cipher which inherits extends the
|
7
|
+
# {OpenSecret::Cipher} base class in order to implement plug and play
|
8
|
+
# symmetric encryption.
|
9
|
+
#
|
10
|
+
# Blowfish is still uncrackable - however its successor (TwoFish) has
|
11
|
+
# been reinforced to counter the growth of super-computer brute force
|
12
|
+
# resources.
|
13
|
+
class Blowfish < OpenSecret::Cipher
|
14
|
+
|
15
|
+
|
16
|
+
# The blowfish cipher id constant is used to +initialize+
|
17
|
+
# an {OpenSSL::Cipher} class instance.
|
18
|
+
BLOWFISH_CIPHER_ID = "BF-ECB"
|
19
|
+
|
20
|
+
|
21
|
+
# Blowfish constrains the length of +incoming plain text+ forcing it
|
22
|
+
# to be a multiple of eight (8).
|
23
|
+
BLOWFISH_BLOCK_LEN = 8
|
24
|
+
|
25
|
+
|
26
|
+
# This method provides the Blowfish algorithm but we reserve the
|
27
|
+
# right to enforce upon it - an encryption key of our choosing.
|
28
|
+
#
|
29
|
+
# The key length need not be a multiple of 8 - however it is advisable
|
30
|
+
# to use {Digest::SHA256.digest} to produce a strong 32 character key.
|
31
|
+
#
|
32
|
+
# == Multiples of 8 | Plain Text Length
|
33
|
+
#
|
34
|
+
# Blowfish constrains plain text lengths to multiples of 8 but we
|
35
|
+
# do NOT walk the common +space padding+ road.
|
36
|
+
#
|
37
|
+
# == No Space Padding? | Why Not?
|
38
|
+
#
|
39
|
+
# Many ciphers (like Blowfish) constrains plain text lengths to multiples
|
40
|
+
# of 8 (or 16) and a common +right pad with spaces+ strategy is employed
|
41
|
+
# as a workaround.
|
42
|
+
#
|
43
|
+
# If opensecret padded plaintext (ending in one or more spaces) with
|
44
|
+
# spaces, the decrypt phase (after right stripping spaces) would return
|
45
|
+
# plain text string +shorter than the original+.
|
46
|
+
#
|
47
|
+
# == So How is Padding Done?
|
48
|
+
#
|
49
|
+
# Instead of single space padding - opensecret uses an unlikely 7 character
|
50
|
+
# delimiter which is repeated until the multiple is reached.
|
51
|
+
#
|
52
|
+
# Please see {OpenSecret::Cipher::PLAIN_TEXT_DELIMITER} for the definition
|
53
|
+
# of the constant delimiter.
|
54
|
+
#
|
55
|
+
# == Key Length Error
|
56
|
+
#
|
57
|
+
# Short keys receive a <tt>key length too short</tt> error from the
|
58
|
+
# {OpenSSL::Cipher} class namely {OpenSSL::Cipher::CipherError}.
|
59
|
+
#
|
60
|
+
# @param plain_text [String] the text to encrypt using Blowfish
|
61
|
+
# @param encryption_key [String] strong unencoded (32 character key)
|
62
|
+
#
|
63
|
+
# @return [String] base64 representation of blowfish crypted ciphertext
|
64
|
+
def do_encrypt_with_key plain_text, encryption_key
|
65
|
+
|
66
|
+
shortkey_msg = "The #{encryption_key.length} character encryption key is too short."
|
67
|
+
raise ArgumentError, shortkey_msg unless encryption_key.length > 8
|
68
|
+
log.info(x) { "os blowfish request to encrypt plain text with provided key." }
|
69
|
+
|
70
|
+
block_txt = plain_text
|
71
|
+
block_txt += ::Cipher::TEXT_PADDER until block_txt.bytesize % OpenSecret::Blowfish::BLOWFISH_BLOCK_LEN == 0
|
72
|
+
raw_stretched_key = Digest::SHA256.digest(encryption_key)
|
73
|
+
|
74
|
+
blowfish_encryptor = OpenSSL::Cipher.new(OpenSecret::Blowfish::BLOWFISH_CIPHER_ID).encrypt
|
75
|
+
blowfish_encryptor.key = raw_stretched_key
|
76
|
+
|
77
|
+
Base64.encode64( blowfish_encryptor.update(block_txt) << blowfish_encryptor.final )
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
=begin
|
83
|
+
puts "Plain Text => #{sentence}"
|
84
|
+
puts "Plain Text Length => #{sentence.length}"
|
85
|
+
puts "Multiple 8 Text => [#{multiple8}]"
|
86
|
+
puts "Multiple 8 Length => [#{multiple8.length}]"
|
87
|
+
puts "Encrypted Text Length => #{encrypted_text.length}"
|
88
|
+
######### puts "Encrypted Text => #{encrypted_text}"
|
89
|
+
puts "Base64 Encrypted Text => #{base64_encrypted_text}"
|
90
|
+
|
91
|
+
dbf = OpenSSL::Cipher.new("BF-ECB").decrypt
|
92
|
+
dbf.key = the_key
|
93
|
+
debase64_text = Base64.decode64( base64_encrypted_text )
|
94
|
+
decrypted_text = dbf.update(debase64_text) << dbf.final
|
95
|
+
|
96
|
+
puts "Decrypted Text => #{decrypted_text}"
|
97
|
+
=end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
# Use the AES 256 bit block cipher and a robust strong random key plus
|
103
|
+
# initialization vector (IV) to symmetrically encrypt the plain text.
|
104
|
+
#
|
105
|
+
# Add these key/value pairs to @encryption_dictionary instance map.
|
106
|
+
#
|
107
|
+
# - <tt>symmetric.cipher</tt> - the algorithm used to encrypt and decrypt
|
108
|
+
# - <tt>encryption.key</tt> - hex encoded key for encrypting and decrypting
|
109
|
+
# - <tt>initialize.vector</tt> - the initialization vector known as a IV (four)
|
110
|
+
#
|
111
|
+
# @param plain_text [String] the plain (or base64 encoded) text to encrypt
|
112
|
+
# @return [String] the symmetrically encrypted cipher text
|
113
|
+
def do_symmetric_encryption plain_text
|
114
|
+
|
115
|
+
@cipher_name = "aes-256-cbc"
|
116
|
+
|
117
|
+
crypt_cipher = OpenSSL::Cipher.new @cipher_name
|
118
|
+
crypt_cipher.encrypt( plain_text )
|
119
|
+
|
120
|
+
@encryption_dictionary = {
|
121
|
+
@@symmetric_cipher_keyname => @cipher_name,
|
122
|
+
@@encryption_key_keyname => crypt_cipher.random_key.unpack("H*").first,
|
123
|
+
@@initialize_vector_keyname => crypt_cipher.random_iv.unpack("H*").first
|
124
|
+
}
|
125
|
+
|
126
|
+
Base64.encode64( crypt_cipher.update + crypt_cipher.final )
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
|
131
|
+
# Use the AES 256 bit block cipher together with the encryption key
|
132
|
+
# and initialization vector (iv) sitting in the encryption_dictionary,
|
133
|
+
# to symmetrically decrypt the parameter cipher text.
|
134
|
+
#
|
135
|
+
# == Pre-Condition | Encryption Dictionary
|
136
|
+
#
|
137
|
+
# This method requires the <tt>@encryption_dictionary</tt> instance
|
138
|
+
# variable to have been set and to contain (amongst others)
|
139
|
+
#
|
140
|
+
# - the <tt>encryption.key</tt> - hex encoded key for encrypting and decrypting
|
141
|
+
# - and <tt>initialize.vector</tt> - the initialization vector known as a IV (four)
|
142
|
+
#
|
143
|
+
# @param cipher_text [String] the base64 encoded cipher text to decrypt
|
144
|
+
# @return [String] decrypted plain text from symmetric key and cipher text
|
145
|
+
def do_symmetric_decryption cipher_text
|
146
|
+
|
147
|
+
abort "Implement AES 256 decryption in aes-256"
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
=begin
|
154
|
+
encode_cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
155
|
+
encode_cipher.encrypt # We are encrypting
|
156
|
+
key = encode_cipher.random_key
|
157
|
+
iv = encode_cipher.random_iv
|
158
|
+
hex_key = key.unpack("H*").first
|
159
|
+
hex_iv = iv.unpack("H*").first
|
160
|
+
|
161
|
+
line1 = "1>> This is secret number one over here with at @ and squiggle~ and round brakets().\n"
|
162
|
+
line2 = "2>> secret number two with colon and semi :; angular <> qmarks ??.\n"
|
163
|
+
line3 = "3>> secret number 3 fwd slash / and backslash twice \\ and pipe || and excla !!\n"
|
164
|
+
line4 = "4>> secret 4 with pound ££ dollar $$ percent %% hat ^^ ampr && stars **\n"
|
165
|
+
line5 = "5>> secret 5 with hyphens - and underscore __ and plus ++ and equal == and sqBs [[]].\n"
|
166
|
+
line6 = "6>> secret 6 with double quote \"from here to here\" and \' single quotes\'.\n"
|
167
|
+
line7 = "7>> secret 7 with periods .... and hashes #####\n"
|
168
|
+
|
169
|
+
crypt_text = ""
|
170
|
+
crypt_text += encode_cipher.update line1
|
171
|
+
crypt_text += encode_cipher.update line2
|
172
|
+
crypt_text += encode_cipher.update line3
|
173
|
+
crypt_text += encode_cipher.update line4
|
174
|
+
crypt_text += encode_cipher.update line5
|
175
|
+
crypt_text += encode_cipher.update line6
|
176
|
+
crypt_text += encode_cipher.update line7
|
177
|
+
crypt_text += encode_cipher.final
|
178
|
+
coded_crypt_text = Base64.encode64(crypt_text)
|
179
|
+
|
180
|
+
puts ""
|
181
|
+
puts "The key is #{hex_key}"
|
182
|
+
puts "The IV is #{hex_iv}"
|
183
|
+
puts "========================"
|
184
|
+
puts "The Cipher Text is Below"
|
185
|
+
puts "========================"
|
186
|
+
puts coded_crypt_text
|
187
|
+
puts "========================"
|
188
|
+
puts crypt_text
|
189
|
+
puts "========================"
|
190
|
+
puts "========================"
|
191
|
+
puts "========================"
|
192
|
+
puts line1 + line2 + line3 + line4 + line5 + line6 + line7
|
193
|
+
puts "========================"
|
194
|
+
puts "========================"
|
195
|
+
puts "========================"
|
196
|
+
puts ""
|
197
|
+
puts ""
|
198
|
+
|
199
|
+
unencoded_crypt_text = Base64.decode64(coded_crypt_text)
|
200
|
+
decode_cipher = OpenSSL::Cipher.new('aes-256-cbc')
|
201
|
+
|
202
|
+
decode_cipher.decrypt
|
203
|
+
decode_cipher.key = [hex_key].pack("H*")
|
204
|
+
decode_cipher.iv = [hex_iv].pack("H*")
|
205
|
+
first_part = decode_cipher.update( Base64.decode64(coded_crypt_text) )
|
206
|
+
second_part = ""
|
207
|
+
second_part << decode_cipher.final
|
208
|
+
|
209
|
+
puts "========================"
|
210
|
+
puts "Decrypted Text is Below"
|
211
|
+
puts "========================"
|
212
|
+
puts first_part
|
213
|
+
puts "========================"
|
214
|
+
puts second_part
|
215
|
+
puts "========================"
|
216
|
+
puts ""
|
217
|
+
=end
|
218
|
+
|
219
|
+
|
220
|
+
end
|
221
|
+
|
222
|
+
|
223
|
+
end
|
@@ -17,14 +17,6 @@
|
|
17
17
|
module OpenSession
|
18
18
|
|
19
19
|
|
20
|
-
require "session/exceptions"
|
21
|
-
require "session/fact.finder"
|
22
|
-
|
23
|
-
require "extension/array"
|
24
|
-
require "extension/dir"
|
25
|
-
require "extension/string"
|
26
|
-
|
27
|
-
|
28
20
|
# An opensession use case is designed to be extended and does preparatory
|
29
21
|
# work to create favourable and useful conditions to make use cases readable,
|
30
22
|
# less repetitive, simpler and concise.
|
@@ -59,7 +51,7 @@ module OpenSession
|
|
59
51
|
|
60
52
|
pre_validation
|
61
53
|
|
62
|
-
rescue
|
54
|
+
rescue OpenError::Error => e
|
63
55
|
|
64
56
|
puts ""
|
65
57
|
puts "Your command did not complete successfully."
|
@@ -83,11 +75,12 @@ module OpenSession
|
|
83
75
|
# post execution (post condition) checks in it and then
|
84
76
|
# make a call to this method through the "super" keyword.
|
85
77
|
def check_post_conditions
|
78
|
+
|
86
79
|
begin
|
87
80
|
|
88
81
|
post_validation
|
89
82
|
|
90
|
-
rescue
|
83
|
+
rescue OpenError::Error => e
|
91
84
|
|
92
85
|
puts ""
|
93
86
|
puts "Your command did not complete successfully."
|
@@ -99,8 +92,6 @@ module OpenSession
|
|
99
92
|
abort e.message
|
100
93
|
end
|
101
94
|
|
102
|
-
|
103
|
-
|
104
95
|
end
|
105
96
|
|
106
97
|
|
@@ -18,23 +18,6 @@ module OpenSecret
|
|
18
18
|
# --> require 'nokogiri'
|
19
19
|
# --> require 'io/console'
|
20
20
|
|
21
|
-
require "session/exceptions"
|
22
|
-
require "crypto/collect"
|
23
|
-
|
24
|
-
# Throw this error if the configured safe directory points to a file.
|
25
|
-
class SafeDirectoryIsFile < OpenSession::OpenSessionError; end;
|
26
|
-
# Throw this error if safe directory path is either nil or empty.
|
27
|
-
class SafeDirNotConfigured < OpenSession::OpenSessionError; end;
|
28
|
-
# Throw this error if the email address is nil, empty or less than 5 characters.
|
29
|
-
class EmailAddrNotConfigured < OpenSession::OpenSessionError; end;
|
30
|
-
# Throw this error if the store url is either nil or empty.
|
31
|
-
class StoreUrlNotConfigured < OpenSession::OpenSessionError; end;
|
32
|
-
# Throw if "prime folder" name occurs 2 or more times in the path.
|
33
|
-
class SafePrimeNameRepeated < OpenSession::OpenSessionError; end;
|
34
|
-
# Throw if "prime folder" name occurs 2 or more times in the path.
|
35
|
-
class SafePrimeNameNotAtEnd < OpenSession::OpenSessionError; end;
|
36
|
-
|
37
|
-
|
38
21
|
# The <tt>init use case</tt> initializes +opensecret+ thus preparing it
|
39
22
|
# for the ability to lock secrets, unlock them, transport their keys and
|
40
23
|
# much more.
|
@@ -54,7 +37,6 @@ module OpenSecret
|
|
54
37
|
# +No cloud or other external access+ occurs as per the opensecret policy.
|
55
38
|
class Init < OpenSession::UseCase
|
56
39
|
|
57
|
-
|
58
40
|
attr_writer :safe_path, :email_addr, :store_url
|
59
41
|
@@context_name = "opensecret"
|
60
42
|
|
@@ -70,7 +52,8 @@ module OpenSecret
|
|
70
52
|
# - +manufacture workstation key+ that will be encrypted b4 it rests on machine
|
71
53
|
# - +create amalgamated human/workstation password+ for locking the private key
|
72
54
|
# - +create a long cryptographically strong symmetric encryption key+
|
73
|
-
# - +encrypt workstation key+ into <tt>.opensecret/<email>/
|
55
|
+
# - +encrypt workstation key+ into <tt>.opensecret/<email>/workstation.key.osx.txt</tt>
|
56
|
+
|
74
57
|
# - +encrypt workstation encryption key+ with human password and email address
|
75
58
|
# - then write into <tt>safe</tt> under <tt>machine.password.key.cipher.txt</tt>
|
76
59
|
# - +create a super 8,192 bit private/public key pair+
|
@@ -109,35 +92,40 @@ module OpenSecret
|
|
109
92
|
#
|
110
93
|
# This action thwarts (usb key) switch attacks where the attacker knows the human
|
111
94
|
# password and has access to the USB key for a time.
|
112
|
-
#
|
113
95
|
def execute
|
114
96
|
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
##########------------> START FROM HERE (aside from prompt bug (check facts) all good.
|
127
|
-
##########------------> START FROM HERE (aside from prompt bug (check facts) all good.
|
128
|
-
##########------------> START FROM HERE (aside from prompt bug (check facts) all good.
|
129
|
-
##########------------> START FROM HERE (aside from prompt bug (check facts) all good.
|
130
|
-
machine_password = Crypto.get_machine_password natural_password.length, @p[:ratio]
|
131
|
-
amalgam_password = Crypto.get_amalgam_password natural_password, machine_password, @p[:ratio]
|
132
|
-
|
133
|
-
asymmetric_keys = OpenSSL::PKey::RSA.new @p[:bit_key_size]
|
134
|
-
secured_keytext = asymmetric_keys.export @p[:key_cipher], amalgam_password
|
97
|
+
human_password = Collect.secret_text(
|
98
|
+
@c[:global][:min_passwd_len],
|
99
|
+
true,
|
100
|
+
@c[:global][:prompt_1],
|
101
|
+
@c[:global][:prompt_2]
|
102
|
+
)
|
103
|
+
|
104
|
+
machine_key = Engineer.machine_key human_password.length, @c[:global][:ratio]
|
105
|
+
amalgam_key = Amalgam.passwords human_password, machine_key, @c[:global][:ratio]
|
106
|
+
asymmetric_keys = OpenSSL::PKey::RSA.new @c[:global][:bit_key_size]
|
107
|
+
secured_keytext = asymmetric_keys.export @c[:global][:key_cipher], amalgam_key
|
135
108
|
public_key_text = asymmetric_keys.public_key.to_pem
|
136
109
|
|
110
|
+
machine_key_crypt_key = human_password + "%$os$%" + @email_addr
|
111
|
+
blowfish_cipher = OpenSecret::Blowfish.new()
|
112
|
+
machine_key_crypted = blowfish_cipher.do_encrypt_with_key machine_key, machine_key_crypt_key
|
113
|
+
|
114
|
+
puts ""
|
115
|
+
puts "public key => #{public_key_text}"
|
116
|
+
puts "Carry on development in init.rb"
|
117
|
+
puts ""
|
118
|
+
puts "Machine Key Plain Text => #{machine_key}"
|
119
|
+
puts "Machine Key Crypt Key => #{machine_key_crypt_key}"
|
120
|
+
puts "Machine Key Cipher Text => #{machine_key_crypted}"
|
121
|
+
puts ""
|
122
|
+
exit
|
123
|
+
|
124
|
+
|
137
125
|
Dir.mkdir @p[:secret_keydir] unless File.exists? @p[:secret_keydir]
|
138
126
|
File.write @p[:secret_keypath], secured_keytext
|
139
127
|
|
140
|
-
Crypto.print_secret_env_var @p[:env_var_name],
|
128
|
+
Crypto.print_secret_env_var @p[:env_var_name], machine_key
|
141
129
|
|
142
130
|
GitFlow.do_clone_repo @p[:public_gitrepo], @p[:local_gitrepo]
|
143
131
|
FileUtils.mkdir_p @p[:public_keydir]
|