createi2prmdb.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. require "openssl"
  2. require "socket"
  3. require "gdbm"
  4. def randomname len=5
  5. symbols = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
  6. res = ""
  7. rnd = Random.new
  8. for i in 0...len
  9. res += symbols[rnd.rand(0...symbols.length)]
  10. end
  11. return res
  12. end
  13. def createdatabase cli
  14. fn = "i2prm.gdbm-#{randomname}"
  15. fn = "i2prm.gdbm-#{randomname}" while File.exist? fn
  16. db = GDBM.new fn
  17. puts "Create new OpenSSL RSA keys"
  18. privkey = OpenSSL::PKey::RSA.new 4096
  19. puts "Save private key to database"
  20. db["keypair-privkey"] = privkey.to_s.chars.map { |c| c == "\n" ? "|" : c }.join
  21. puts "Create new I2P keys"
  22. cli.puts "newkeys"
  23. cli.gets
  24. cli.puts "getkeys"
  25. puts "Save I2P keys to database"
  26. db["i2p-keys"] = cli.gets.chomp[3..-1]
  27. puts "Close database"
  28. db.close
  29. end
  30. if ARGV.length == 0
  31. puts "Please call #{__FILE__} [NUMBER OF DATABASES]"
  32. puts "Example: #{__FILE__} 2"
  33. exit
  34. end
  35. z = ARGV[0].to_i
  36. exit if z == 0
  37. puts "Open connection to BOB API"
  38. cli = TCPSocket.new "127.0.0.1", 2827
  39. puts "BOB API: #{cli.gets}"
  40. puts "BOB API: #{cli.gets}"
  41. cli.puts "setnick onlyforcreatekeys"
  42. puts "BOB API: #{cli.gets}"
  43. for i in 1..z
  44. puts "---- #{i}/#{z} ----"
  45. createdatabase cli
  46. sleep 0.5
  47. end
  48. cli.puts "quit"
  49. puts "\nClose connection to BOB API"
  50. puts "BOB API: #{cli.gets}"
  51. cli.close