From 91ba50b8367a11d99bfd0c036db8d8b407ac1a56 Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Mon, 7 Oct 2013 22:59:23 -0300 Subject: [PATCH] try to decrypt DM in acceptSignedPost (it works!) --- src/twister.cpp | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/twister.cpp b/src/twister.cpp index 11014505..86018e53 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -600,6 +600,27 @@ bool acceptSignedPost(char const *data, int data_size, std::string username, int lazy_entry const* dm = post->dict_find_dict("dm"); if( dm && flags ) { (*flags) |= USERPOST_FLAG_DM; + + ecies_secure_t sec; + sec.key = dm->dict_find_string_value("key"); + sec.mac = dm->dict_find_string_value("mac"); + sec.orig = dm->dict_find_int_value("orig"); + sec.body = dm->dict_find_string_value("body"); + + BOOST_FOREACH(const PAIRTYPE(CKeyID, CKeyMetadata)& item, pwalletMain->mapKeyMetadata) + { + CKey key; + if (!pwalletMain->GetKey(item.first, key)) { + printf("acceptSignedPost: private key not available trying to decrypt DM.\n"); + } else { + std::string textOut; + if( key.Decrypt(sec, textOut) ) { + printf("Received DM for user '%s' text = '%s'\n", + item.second.username.c_str(), + textOut.c_str()); + } + } + } } } } @@ -905,7 +926,7 @@ Value newdirectmsg(const Array& params, bool fHelp) { if (fHelp || params.size() != 4) throw runtime_error( - "newdirectmessage \n" + "newdirectmsg \n" "Post a new dm to swarm"); EnsureWalletIsUnlocked();