Class: Kyle
- Inherits:
-
Object
- Object
- Kyle
- Defined in:
- lib/kyle.rb
Class Method Summary collapse
- .di_hash(val) ⇒ Object
- .enc_it(alg, val, key) ⇒ Object
- .generate(hostname, account, port, key) ⇒ Object
- .getkey ⇒ Object
- .hash2pass(val) ⇒ Object
- .hash_it(alg, val) ⇒ Object
- .iterative_enc(val, key) ⇒ Object
- .iterative_hash(val) ⇒ Object
- .run(args) ⇒ Object
- .sha512ize(val) ⇒ Object
- .test_it ⇒ Object
- .to_hex(s) ⇒ Object
Class Method Details
.di_hash(val) ⇒ Object
96 97 98 |
# File 'lib/kyle.rb', line 96 def self.di_hash(val) iterative_hash(iterative_hash(val)) end |
.enc_it(alg, val, key) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/kyle.rb', line 57 def self.enc_it(alg,val,key) #puts "enc_it #{alg} #{to_hex(val)} #{to_hex(key)}" begin cipher = OpenSSL::Cipher::Cipher.new(alg) cipher.key = OpenSSL::PKCS5.pbkdf2_hmac_sha1(key, "kyle", 10000, 32) cipher.iv = sha512ize(key) cipher.encrypt return cipher.update(val) + cipher.final rescue OpenSSL::Cipher::CipherError => e puts "Error: #{e.}" end end |
.generate(hostname, account, port, key) ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/kyle.rb', line 115 def self.generate(hostname,account,port,key) ret = Array.new harr = [ di_hash(hostname), di_hash(account), di_hash(port), di_hash(key) ] v1 = iterative_enc(harr[0],harr[1]) v2 = iterative_enc(harr[2],harr[3]) v = iterative_enc(v1,v2) c = v $animalnames.each do |animal| c = OpenSSL::PKCS5.pbkdf2_hmac_sha1(c, v, 10000, 32) ret << hash2pass(c) end return ret end |
.getkey ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/kyle.rb', line 172 def self.getkey() key = "a" key2 = "b" while (key != key2) key = ask("Key:") { |q| q.echo = false } key2 = ask("Key (again):") { |q| q.echo = false } if (key != key2) puts "Passes do not match!!" end end return key end |
.hash2pass(val) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/kyle.rb', line 100 def self.hash2pass(val) ret = "" # to be sure it is long enough h = sha512ize(val) h.each_byte do |c| ret += $passctable[c % ($passctable.size)] end return ret[0..15] end |
.hash_it(alg, val) ⇒ Object
79 80 81 82 |
# File 'lib/kyle.rb', line 79 def self.hash_it(alg,val) #puts "hash_it #{alg} - #{to_hex(val)}" OpenSSL::Digest.digest(alg,val) end |
.iterative_enc(val, key) ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/kyle.rb', line 70 def self.iterative_enc(val, key) ret = val val.each_byte do |c| ret = enc_it($ENC_ALGS[c % ($ENC_ALGS.size)], ret, key) end return ret end |
.iterative_hash(val) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/kyle.rb', line 84 def self.iterative_hash(val) ret = val val.each_byte do |c| ret = hash_it($HSH_ALGS[c % ($HSH_ALGS.size)], ret) end return ret end |
.run(args) ⇒ Object
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/kyle.rb', line 190 def self.run(args) puts "Kyle - A password manager for paranoids. ( 0.0.4 )" puts "" if (args.size > 0 && args[0] == "test") test_it() elsif (args.size == 3 && args[0].to_s.downcase == "-b" && args[1] != nil && args[2] != nil) # Batch MODE # -b record_file favourite_animal_name key = getkey() text=File.open(args[1]).read text.gsub!(/\r\n?/, "\n") text.each_line do |line| hostname, account, port = line.split(';') port = port.gsub(/\n/,"") vals = generate(hostname,account,port,key) $animalnames.each.with_index(0) do |animal,i| puts "#{hostname}:#{account}:#{port} = #{vals[i]}" if (animal.downcase == args[2].downcase) end end else hostname = "" account = "" port = "" # Record given parameters to .kyle file at home kyle_r_path = File.join(Dir.home,".kyle") if (args.size > 0 && args[0].to_s.downcase == "-a") recs = [] iA = 0 File.open(kyle_r_path).each do |line| recs << line.rstrip! puts "#{iA} - #{line}" iA+=1 end puts("") idx = ask("Selection:") r = recs[idx.to_i].split(";") hostname = r[0] account = r[1] port = r[2] else hostname = ask("Hostname:") account = ask("Account:") port = ask("Port:") end key = getkey() if (args.size > 0 && args[0].to_s.downcase == "-r") line_to_add = "#{hostname};#{account};#{port}" File.open(kyle_r_path, 'a') do |file| file.puts line_to_add end end puts "Calculating..." vals = generate(hostname,account,port,key) $animalnames.each.with_index(0) do |animal,i| puts "#{animal}\t#{vals[i]}" end end end |
.sha512ize(val) ⇒ Object
92 93 94 |
# File 'lib/kyle.rb', line 92 def self.sha512ize(val) hash_it("sha512",val) end |
.test_it ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/kyle.rb', line 156 def self.test_it() puts "Testing..." failed = false (0..1).each do |idx| vals = generate($testarr[idx][0],$testarr[idx][1],$testarr[idx][2],$testarr[idx][3]) vals.each.with_index(0) do |v,i| if ($testarr[idx][i+4] != v) puts "Test failed: #{$testarr[idx][i+4]} <> #{v}" failed = true end end end puts "Finished #{failed ? "and Failed" : "successfully"}" end |
.to_hex(s) ⇒ Object
52 53 54 |
# File 'lib/kyle.rb', line 52 def self.to_hex(s) s.each_byte.map { |b| b.to_s(16) }.join end |