mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
- added creation of chat link info
- added binary data encryption to PGPHandler git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-GenericTunneling@6301 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
f12ad9583d
commit
43b9117293
@ -952,6 +952,49 @@ bool PGPHandler::encryptTextToFile(const PGPIdType& key_id,const std::string& te
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::encryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
||||
const ops_keydata_t *public_key = getPublicKey(key_id) ;
|
||||
|
||||
if(public_key == NULL)
|
||||
{
|
||||
std::cerr << "Cannot get public key of id " << key_id.toStdString() << std::endl;
|
||||
return false ;
|
||||
}
|
||||
|
||||
if(public_key->type != OPS_PTAG_CT_PUBLIC_KEY)
|
||||
{
|
||||
std::cerr << "PGPHandler::encryptTextToFile(): ERROR: supplied id did not return a public key!" << std::endl;
|
||||
return false ;
|
||||
}
|
||||
ops_create_info_t *info;
|
||||
ops_memory_t *buf = NULL ;
|
||||
ops_setup_memory_write(&info, &buf, 0);
|
||||
|
||||
ops_encrypt_stream(info, public_key, NULL, ops_false, ops_false);
|
||||
|
||||
ops_write(data,len,info);
|
||||
ops_writer_close(info);
|
||||
ops_create_info_delete(info);
|
||||
|
||||
int tlen = ops_memory_get_length(buf) ;
|
||||
memcpy(encrypted_data,ops_memory_get_data(buf),tlen) ;
|
||||
*encrypted_data_len = tlen ;
|
||||
|
||||
ops_memory_release(buf) ;
|
||||
free(buf) ;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool PGPHandler::decryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *encrypted_data, unsigned int *encrypted_data_len)
|
||||
{
|
||||
throw std::runtime_error("Not implemented!") ;
|
||||
return false ;
|
||||
}
|
||||
|
||||
bool PGPHandler::decryptTextFromFile(const PGPIdType&,std::string& text,const std::string& inputfile)
|
||||
{
|
||||
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
|
||||
|
@ -92,6 +92,9 @@ class PGPHandler
|
||||
bool VerifySignBin(const void *data, uint32_t data_len, unsigned char *sign, unsigned int sign_len, const PGPFingerprintType& withfingerprint) ;
|
||||
bool privateSignCertificate(const PGPIdType& own_id,const PGPIdType& id_of_key_to_sign) ;
|
||||
|
||||
bool encryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) ;
|
||||
bool decryptDataBin(const PGPIdType& key_id,const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen) ;
|
||||
|
||||
bool encryptTextToFile(const PGPIdType& key_id,const std::string& text,const std::string& outfile) ;
|
||||
bool decryptTextFromFile(const PGPIdType& key_id,std::string& text,const std::string& inputfile) ;
|
||||
|
||||
|
@ -629,6 +629,15 @@ bool AuthGPG::TrustCertificate(const std::string &id, int trustlvl)
|
||||
return privateTrustCertificate(id, trustlvl) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::encryptDataBin(const std::string& pgp_id,const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
{
|
||||
return PGPHandler::encryptDataBin(PGPIdType(pgp_id),data,datalen,sign,signlen) ;
|
||||
}
|
||||
|
||||
bool AuthGPG::decryptDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
{
|
||||
return PGPHandler::decryptDataBin(mOwnGpgId,data,datalen,sign,signlen) ;
|
||||
}
|
||||
bool AuthGPG::SignDataBin(const void *data, unsigned int datalen, unsigned char *sign, unsigned int *signlen)
|
||||
{
|
||||
return DoOwnSignature(data, datalen, sign, signlen);
|
||||
|
@ -215,6 +215,9 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
|
||||
virtual bool SignDataBin(const void *data, const uint32_t len, unsigned char *sign, unsigned int *signlen);
|
||||
virtual bool VerifySignBin(const void*, uint32_t, unsigned char*, unsigned int, const std::string &withfingerprint);
|
||||
|
||||
virtual bool encryptDataBin(const std::string& pgp_id,const void *data, const uint32_t len, unsigned char *encr, unsigned int *encrlen);
|
||||
virtual bool decryptDataBin(const void *data, const uint32_t len, unsigned char *decr, unsigned int *decrlen);
|
||||
|
||||
virtual bool decryptTextFromFile( std::string& text,const std::string& filename);
|
||||
virtual bool encryptTextToFile (const std::string& text,const std::string& filename);
|
||||
|
||||
|
@ -26,7 +26,9 @@
|
||||
|
||||
#include "openssl/rand.h"
|
||||
#include "pgp/rscertificate.h"
|
||||
#include "pqi/authgpg.h"
|
||||
#include "util/rsdir.h"
|
||||
#include "util/radix64.h"
|
||||
#include "util/rsaes.h"
|
||||
#include "util/rsrandom.h"
|
||||
#include "util/rsstring.h"
|
||||
@ -2937,7 +2939,7 @@ void p3ChatService::sendTurtleData(RsChatItem *item, const std::string& virtual_
|
||||
mTurtle->sendTurtleData(virtual_peer_id,gitem) ;
|
||||
}
|
||||
|
||||
bool p3ChatService::createDistantChatInvite(PGPIdType pgp_id,time_t time_of_validity,TurtleFileHash& hash)
|
||||
bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash)
|
||||
{
|
||||
// create the invite
|
||||
|
||||
@ -2957,11 +2959,6 @@ bool p3ChatService::createDistantChatInvite(PGPIdType pgp_id,time_t time_of_vali
|
||||
|
||||
hash = SSLIdType(hash_bytes).toStdString() ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
_distant_chat_invites[hash] = invite ;
|
||||
}
|
||||
|
||||
std::cerr << "Created new distant chat invite: " << std::endl;
|
||||
std::cerr << " creation time stamp = " << invite.time_of_creation << std::endl;
|
||||
std::cerr << " validity time stamp = " << invite.time_of_validity << std::endl;
|
||||
@ -2971,6 +2968,51 @@ bool p3ChatService::createDistantChatInvite(PGPIdType pgp_id,time_t time_of_vali
|
||||
for(uint32_t j = 0; j < 16; j++) { std::cerr << outl[ (invite.aes_key[j]>>4) ] ; std::cerr << outl[ invite.aes_key[j] & 0xf ] ; }
|
||||
std::cerr << std::endl;
|
||||
|
||||
// Now encrypt the data to create the link info. We need
|
||||
//
|
||||
// [E] - the hash
|
||||
// [E] - the aes key
|
||||
// [E] - the signature
|
||||
// - pgp id
|
||||
// - timestamp
|
||||
//
|
||||
// The link will be
|
||||
//
|
||||
// retroshare://chat?time_stamp=3243242&private_data=[radix64 string]
|
||||
|
||||
unsigned char *data = new unsigned char[16+16+400] ;
|
||||
memcpy(data ,hash_bytes ,16) ;
|
||||
memcpy(data+16,invite.aes_key ,16) ;
|
||||
|
||||
PGPIdType own_gpg_id( rsPeers->getOwnId() ) ;
|
||||
uint32_t signlen = 400;
|
||||
|
||||
if(!AuthGPG::getAuthGPG()->SignDataBin(data,32,data+32,&signlen))
|
||||
return false ;
|
||||
|
||||
std::cerr << "Performing signature with id = " << own_gpg_id.toStdString() << std::endl;
|
||||
std::cerr << "Signature length = " << signlen << std::endl;
|
||||
|
||||
// Then encrypt the whole data into a single string.
|
||||
|
||||
unsigned char *encrypted_data = NULL ;
|
||||
uint32_t encrypted_size = 0 ;
|
||||
|
||||
if(!AuthGPG::getAuthGPG()->encryptDataBin(pgp_id,(unsigned char *)data,signlen+32,encrypted_data,&encrypted_size))
|
||||
return false ;
|
||||
|
||||
std::cerr << "Encrypted data size: " << encrypted_size << std::endl;
|
||||
|
||||
std::string encrypted_radix64_string ;
|
||||
Radix64::encode((const char *)encrypted_data,encrypted_size,invite.encrypted_radix64_string) ;
|
||||
|
||||
{
|
||||
RsStackMutex stack(mChatMtx); /********** STACK LOCKED MTX ******/
|
||||
_distant_chat_invites[hash] = invite ;
|
||||
}
|
||||
|
||||
std::cerr << "Encrypted radix64 string: " << invite.encrypted_radix64_string << std::endl;
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
@ -310,6 +310,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
||||
struct DistantChatInvite
|
||||
{
|
||||
unsigned char aes_key[16] ;
|
||||
std::string encrypted_radix64_string ;
|
||||
time_t time_of_validity ;
|
||||
time_t time_of_creation ;
|
||||
time_t last_hit_time ;
|
||||
@ -332,7 +333,7 @@ class p3ChatService: public p3Service, public p3Config, public pqiMonitor, publi
|
||||
// Creates the invite if the public key of the distant peer is available.
|
||||
// Om success, stores the invite in the map above, so that we can respond to tunnel requests.
|
||||
//
|
||||
bool createDistantChatInvite(PGPIdType pgp_id,time_t time_of_validity,TurtleFileHash& hash) ;
|
||||
bool createDistantChatInvite(const std::string& pgp_id,time_t time_of_validity,TurtleFileHash& hash) ;
|
||||
|
||||
// Overloaded from RsTurtleClientService
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user