checki2prmdb.rb 762 B

12345678910111213141516171819202122232425262728293031323334353637
  1. require "gdbm"
  2. require "openssl"
  3. require "socket"
  4. if ARGV.length == 0
  5. puts "Please call #{__FILE__} [GDBM DATABASE]"
  6. puts "Example: #{__FILE__} i2prm.gdbm"
  7. exit
  8. elsif ! File.exist? ARGV[0]
  9. puts "\"#{ARGV[0]}\" not found."
  10. exit
  11. end
  12. db = GDBM.new ARGV[0], 0555, GDBM::READER
  13. begin
  14. OpenSSL::PKey::RSA.new db["keypair-privkey"].chars.map { |c| c == "|" ? "\n" : c }.join
  15. rescue OpenSSL::PKey::RSAError => rsaerror
  16. puts "Invalid private key: #{rsaerror.message}"
  17. else
  18. puts "Valid private key."
  19. end
  20. cli = TCPSocket.new "127.0.0.1", 2827
  21. cli.gets; cli.gets
  22. cli.puts "verify #{db["i2p-keys"]}"
  23. ans = cli.gets.chomp
  24. if ans[0...2] == "OK"
  25. puts "Valid i2p keys."
  26. else
  27. puts "Invalid i2p keys: #{ans[6..-1]}"
  28. end
  29. cli.puts "quit"; cli.gets
  30. cli.close