From 00c1bfcf5467d1338ee602402cb083b02c89cab7 Mon Sep 17 00:00:00 2001 From: chrisparker126 Date: Sun, 15 May 2011 12:01:23 +0000 Subject: [PATCH] fixed bug related to opening cache hist file in text mode for windows added cleaning of cipher context to authssl encrypt decrypt functions added header to trustview which caused compilation error git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4199 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/pqi/authssl.cc | 9 +++++++-- libretroshare/src/services/p3distrib.cc | 6 ++++-- retroshare-gui/src/gui/TrustView.cpp | 2 ++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libretroshare/src/pqi/authssl.cc b/libretroshare/src/pqi/authssl.cc index 37da827f7..95865de07 100644 --- a/libretroshare/src/pqi/authssl.cc +++ b/libretroshare/src/pqi/authssl.cc @@ -1026,6 +1026,8 @@ bool AuthSSLimpl::encrypt(void *&out, int &outlen, const void *in, int inlen, // free encrypted key data free(ek); + EVP_CIPHER_CTX_cleanup(&ctx); + outlen = out_offset; #ifdef DISTRIB_DEBUG @@ -1052,7 +1054,8 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen) int eklen = 0, net_ekl = 0; unsigned char *ek = NULL; unsigned char iv[EVP_MAX_IV_LENGTH]; - ek = (unsigned char*)malloc(EVP_PKEY_size(mOwnPrivateKey)); + int ek_mkl = EVP_PKEY_size(mOwnPrivateKey); + ek = (unsigned char*)malloc(ek_mkl); EVP_CIPHER_CTX_init(&ctx); int in_offset = 0, out_currOffset = 0; @@ -1085,7 +1088,7 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen) const EVP_CIPHER* cipher = EVP_aes_128_cbc(); - if(!EVP_OpenInit(&ctx, cipher, ek, eklen, iv, mOwnPrivateKey)) { + if(0 == EVP_OpenInit(&ctx, cipher, ek, eklen, iv, mOwnPrivateKey)) { free(ek); return false; } @@ -1114,6 +1117,8 @@ bool AuthSSLimpl::decrypt(void *&out, int &outlen, const void *in, int inlen) if(ek != NULL) free(ek); + EVP_CIPHER_CTX_cleanup(&ctx); + #ifdef AUTHSSL_DEBUG std::cerr << "AuthSSLimpl::decrypt() finished with outlen : " << outlen << std::endl; #endif diff --git a/libretroshare/src/services/p3distrib.cc b/libretroshare/src/services/p3distrib.cc index cf8687cf3..391cd012e 100644 --- a/libretroshare/src/services/p3distrib.cc +++ b/libretroshare/src/services/p3distrib.cc @@ -51,6 +51,7 @@ #define FAILED_CACHE_CONT "failedcachegrp" // cache id which have failed are stored under a node of this name/grpid #define HIST_CACHE_FNAME "grp_history.xml" +#define ENABLE_CACHE_OPT /***** * #define DISTRIB_DEBUG 1 @@ -786,7 +787,7 @@ void p3GroupDistrib::locked_getHistoryCacheData(const std::string& grpId, std::l bool p3GroupDistrib::locked_loadHistoryCacheFile() { std::string hFileName = mKeyBackUpDir + "/" + HIST_CACHE_FNAME; - std::ifstream hFile(hFileName.c_str()); + std::ifstream hFile(hFileName.c_str(), std::ios::binary | std::ios::in); int fileLength; char* fileLoadBuffer = NULL; char* decryptedCacheFile = NULL; @@ -812,6 +813,7 @@ bool p3GroupDistrib::locked_loadHistoryCacheFile() char* buffer = static_cast(pugi::get_memory_allocation_function()(outlen)); if(ok){ + memcpy(buffer, decryptedCacheFile, outlen); if(decryptedCacheFile != NULL) @@ -834,7 +836,7 @@ bool p3GroupDistrib::locked_saveHistoryCacheFile() return false; std::string hFileName = mKeyBackUpDir + "/" + HIST_CACHE_FNAME; - std::ofstream hFile(hFileName.c_str()); + std::ofstream hFile(hFileName.c_str(), std::ios::binary | std::ios::out); std::ostringstream cacheStream; char* fileBuffer = NULL; int streamLength; diff --git a/retroshare-gui/src/gui/TrustView.cpp b/retroshare-gui/src/gui/TrustView.cpp index aeed0cad2..c64c0cfd7 100644 --- a/retroshare-gui/src/gui/TrustView.cpp +++ b/retroshare-gui/src/gui/TrustView.cpp @@ -8,6 +8,8 @@ #include #include "TrustView.h" +#include + using namespace std ; TrustView::TrustView()