Repository where nkls researches and experiments with building mixnet stuff using libtorrent
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.8 KiB

  1. #include <stdio.h>
  2. #include <iostream>
  3. #include <cstring>
  4. #include <fstream>
  5. #include <openssl/rsa.h>
  6. #include <openssl/pem.h>
  7. #include <openssl/err.h>
  8. #include <exception>
  9. #include <gpgme.h>
  10. #include <boost/program_options.hpp>
  11. namespace po=boost::program_options;
  12. class mix
  13. {
  14. public:
  15. int id;
  16. std::string name;
  17. char *privkey;
  18. char *pubkey;
  19. gpgme_data_t keydata;
  20. gpgme_ctx_t context;
  21. gpgme_error_t error;
  22. gpgme_key_t key;
  23. void init()
  24. {
  25. std::cout << "Mix starting..." << std::endl;
  26. if(std::ifstream("mix.conf"))
  27. {
  28. std::cout << "Config file existing" << std::endl;
  29. this->read_settings();
  30. std::cout << "name = " << name << std::endl;
  31. std::cout << "id = " << id << std::endl;
  32. read_keys();
  33. }
  34. else
  35. {
  36. std::cout << "Config file does not exist. Exiting." << std::endl;
  37. std::exit(1);
  38. }
  39. }
  40. void read_settings()
  41. {
  42. po::options_description desc("Options");
  43. desc.add_options() ("name", po::value<std::string>(&name), "name");
  44. desc.add_options() ("id", po::value<int>(&id), "id");
  45. po::variables_map vm;
  46. std::ifstream settings_file("mix.conf");
  47. vm = po::variables_map();
  48. po::store(po::parse_config_file(settings_file , desc), vm);
  49. po::notify(vm);
  50. }
  51. void read_keys()
  52. {
  53. gpgme_data_new_from_file(&keydata, "keys.gpg", 1);
  54. gpgme_check_version(NULL);
  55. gpgme_new(&context);
  56. gpgme_op_import(context, keydata);
  57. gpgme_op_keylist_start (context, "mix", 0);
  58. while(!error)
  59. {
  60. error = gpgme_op_keylist_next (context, &key);
  61. if (error){break;}
  62. std::cout << key->subkeys->keyid << std::endl;
  63. if (key->uids && key->uids->name)
  64. {
  65. std::cout << key->uids->name << std::endl;
  66. }
  67. if (key->uids && key->uids->email)
  68. {
  69. std::cout << key->uids->email << std::endl;
  70. }
  71. }
  72. }
  73. };
  74. int main()
  75. {
  76. mix mix1;
  77. mix1.init();
  78. }