mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
moved PGP id types into rsid.h, and renamed them with a more appropriate name
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6985 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
91291a9920
commit
4ce8ea73d2
@ -813,7 +813,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
|
|||||||
import_error = "File does not contain a public and a private key. Sorry." ;
|
import_error = "File does not contain a public and a private key. Sorry." ;
|
||||||
return false ;
|
return false ;
|
||||||
}
|
}
|
||||||
if(memcmp(pubkey->fingerprint.fingerprint,seckey->fingerprint.fingerprint,KEY_FINGERPRINT_SIZE) != 0)
|
if(memcmp(pubkey->fingerprint.fingerprint,seckey->fingerprint.fingerprint,PGP_KEY_FINGERPRINT_SIZE) != 0)
|
||||||
{
|
{
|
||||||
import_error = "Public and private keys do nt have the same fingerprint. Sorry!" ;
|
import_error = "Public and private keys do nt have the same fingerprint. Sorry!" ;
|
||||||
return false ;
|
return false ;
|
||||||
@ -840,7 +840,7 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
|
|||||||
bool found = false ;
|
bool found = false ;
|
||||||
|
|
||||||
for(uint32_t i=0;i<result->valid_count;++i)
|
for(uint32_t i=0;i<result->valid_count;++i)
|
||||||
if(!memcmp((unsigned char*)result->valid_sigs[i].signer_id,pubkey->key_id,KEY_ID_SIZE))
|
if(!memcmp((unsigned char*)result->valid_sigs[i].signer_id,pubkey->key_id,PGP_KEY_ID_SIZE))
|
||||||
{
|
{
|
||||||
found = true ;
|
found = true ;
|
||||||
break ;
|
break ;
|
||||||
@ -988,7 +988,7 @@ bool PGPHandler::LoadCertificateFromString(const std::string& pgp_cert,PGPIdType
|
|||||||
bool found = false ;
|
bool found = false ;
|
||||||
|
|
||||||
for(uint32_t i=0;i<result->valid_count;++i)
|
for(uint32_t i=0;i<result->valid_count;++i)
|
||||||
if(!memcmp((unsigned char*)result->valid_sigs[i].signer_id,keydata->key_id,KEY_ID_SIZE))
|
if(!memcmp((unsigned char*)result->valid_sigs[i].signer_id,keydata->key_id,PGP_KEY_ID_SIZE))
|
||||||
{
|
{
|
||||||
found = true ;
|
found = true ;
|
||||||
break ;
|
break ;
|
||||||
@ -1065,7 +1065,7 @@ bool PGPHandler::locked_addOrMergeKey(ops_keyring_t *keyring,std::map<std::strin
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(memcmp(existing_key->fingerprint.fingerprint, keydata->fingerprint.fingerprint,KEY_FINGERPRINT_SIZE))
|
if(memcmp(existing_key->fingerprint.fingerprint, keydata->fingerprint.fingerprint,PGP_KEY_FINGERPRINT_SIZE))
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) attempt to merge key with identical id, but different fingerprint!" << std::endl;
|
std::cerr << "(EE) attempt to merge key with identical id, but different fingerprint!" << std::endl;
|
||||||
return false ;
|
return false ;
|
||||||
@ -1642,7 +1642,7 @@ bool PGPHandler::privateTrustCertificate(const PGPIdType& id,int trustlvl)
|
|||||||
|
|
||||||
struct PrivateTrustPacket
|
struct PrivateTrustPacket
|
||||||
{
|
{
|
||||||
unsigned char user_id[KEY_ID_SIZE] ; // pgp id in unsigned char format.
|
unsigned char user_id[PGP_KEY_ID_SIZE] ; // pgp id in unsigned char format.
|
||||||
uint8_t trust_level ; // trust level. From 0 to 6.
|
uint8_t trust_level ; // trust level. From 0 to 6.
|
||||||
uint32_t time_stamp ; // last time the cert was ever used, in seconds since the epoch. 0 means not initialized.
|
uint32_t time_stamp ; // last time the cert was ever used, in seconds since the epoch. 0 means not initialized.
|
||||||
};
|
};
|
||||||
@ -1706,7 +1706,7 @@ bool PGPHandler::locked_writePrivateTrustDatabase()
|
|||||||
|
|
||||||
for(std::map<std::string,PGPCertificateInfo>::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it)
|
for(std::map<std::string,PGPCertificateInfo>::iterator it = _public_keyring_map.begin();it!=_public_keyring_map.end() ;++it)
|
||||||
{
|
{
|
||||||
memcpy(trustpacket.user_id,PGPIdType(it->first).toByteArray(),KEY_ID_SIZE) ;
|
memcpy(trustpacket.user_id,PGPIdType(it->first).toByteArray(),PGP_KEY_ID_SIZE) ;
|
||||||
trustpacket.trust_level = it->second._trustLvl ;
|
trustpacket.trust_level = it->second._trustLvl ;
|
||||||
trustpacket.time_stamp = it->second._time_stamp ;
|
trustpacket.time_stamp = it->second._time_stamp ;
|
||||||
|
|
||||||
|
@ -16,14 +16,8 @@ extern "C" {
|
|||||||
#include <openpgpsdk/keyring_local.h>
|
#include <openpgpsdk/keyring_local.h>
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int KEY_ID_SIZE = 8 ;
|
|
||||||
static const int KEY_FINGERPRINT_SIZE = 20 ;
|
|
||||||
|
|
||||||
typedef std::string (*PassphraseCallback)(void *data, const char *uid_hint, const char *passphrase_info, int prev_was_bad) ;
|
typedef std::string (*PassphraseCallback)(void *data, const char *uid_hint, const char *passphrase_info, int prev_was_bad) ;
|
||||||
|
|
||||||
typedef t_RsGenericIdType<KEY_ID_SIZE> PGPIdType;
|
|
||||||
typedef t_RsGenericIdType<KEY_FINGERPRINT_SIZE> PGPFingerprintType ;
|
|
||||||
|
|
||||||
class PGPCertificateInfo
|
class PGPCertificateInfo
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -3498,14 +3498,14 @@ bool p3ChatService::createDistantChatInvite(const std::string& pgp_id,time_t tim
|
|||||||
//
|
//
|
||||||
// retroshare://chat?time_stamp=3243242&private_data=[radix64 string]
|
// retroshare://chat?time_stamp=3243242&private_data=[radix64 string]
|
||||||
|
|
||||||
uint32_t header_size = DISTANT_CHAT_AES_KEY_SIZE + DISTANT_CHAT_HASH_SIZE + KEY_ID_SIZE;
|
uint32_t header_size = DISTANT_CHAT_AES_KEY_SIZE + DISTANT_CHAT_HASH_SIZE + PGP_KEY_ID_SIZE;
|
||||||
unsigned char *data = new unsigned char[header_size+800] ;
|
unsigned char *data = new unsigned char[header_size+800] ;
|
||||||
|
|
||||||
PGPIdType OwnId(AuthGPG::getAuthGPG()->getGPGOwnId());
|
PGPIdType OwnId(AuthGPG::getAuthGPG()->getGPGOwnId());
|
||||||
|
|
||||||
memcpy(data ,hash_bytes ,DISTANT_CHAT_HASH_SIZE) ;
|
memcpy(data ,hash_bytes ,DISTANT_CHAT_HASH_SIZE) ;
|
||||||
memcpy(data+DISTANT_CHAT_HASH_SIZE ,invite.aes_key ,DISTANT_CHAT_AES_KEY_SIZE) ;
|
memcpy(data+DISTANT_CHAT_HASH_SIZE ,invite.aes_key ,DISTANT_CHAT_AES_KEY_SIZE) ;
|
||||||
memcpy(data+DISTANT_CHAT_HASH_SIZE+DISTANT_CHAT_AES_KEY_SIZE,OwnId.toByteArray(),KEY_ID_SIZE) ;
|
memcpy(data+DISTANT_CHAT_HASH_SIZE+DISTANT_CHAT_AES_KEY_SIZE,OwnId.toByteArray(),PGP_KEY_ID_SIZE) ;
|
||||||
|
|
||||||
#ifdef DEBUG_DISTANT_CHAT
|
#ifdef DEBUG_DISTANT_CHAT
|
||||||
std::cerr << "Performing signature " << std::endl;
|
std::cerr << "Performing signature " << std::endl;
|
||||||
@ -3573,7 +3573,7 @@ bool p3ChatService::initiateDistantChatConnexion(const std::string& encrypted_st
|
|||||||
std::cerr << "Chat invite was successfuly decrypted!" << std::endl;
|
std::cerr << "Chat invite was successfuly decrypted!" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint32_t header_size = DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE + KEY_ID_SIZE ;
|
uint32_t header_size = DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE + PGP_KEY_ID_SIZE ;
|
||||||
|
|
||||||
PGPIdType pgp_id( data + DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE ) ;
|
PGPIdType pgp_id( data + DISTANT_CHAT_HASH_SIZE + DISTANT_CHAT_AES_KEY_SIZE ) ;
|
||||||
|
|
||||||
|
@ -1772,7 +1772,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
// 0 - append own id to the data.
|
// 0 - append own id to the data.
|
||||||
//
|
//
|
||||||
uint32_t rssize = _serialiser->size(item) ;
|
uint32_t rssize = _serialiser->size(item) ;
|
||||||
unsigned char *data = (unsigned char *)malloc(1+rssize+KEY_ID_SIZE) ;
|
unsigned char *data = (unsigned char *)malloc(1+rssize+PGP_KEY_ID_SIZE) ;
|
||||||
|
|
||||||
// -1 - setup protocol version
|
// -1 - setup protocol version
|
||||||
//
|
//
|
||||||
@ -1784,7 +1784,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
#ifdef DEBUG_DISTANT_MSG
|
#ifdef DEBUG_DISTANT_MSG
|
||||||
std::cerr << " adding own key ID " << AuthGPG::getAuthGPG()->getGPGOwnId() << std::endl;
|
std::cerr << " adding own key ID " << AuthGPG::getAuthGPG()->getGPGOwnId() << std::endl;
|
||||||
#endif
|
#endif
|
||||||
memcpy(&data[1], PGPIdType(AuthGPG::getAuthGPG()->getGPGOwnId()).toByteArray(), KEY_ID_SIZE) ;
|
memcpy(&data[1], PGPIdType(AuthGPG::getAuthGPG()->getGPGOwnId()).toByteArray(), PGP_KEY_ID_SIZE) ;
|
||||||
|
|
||||||
// 1 - serialise the whole message item into a binary chunk.
|
// 1 - serialise the whole message item into a binary chunk.
|
||||||
//
|
//
|
||||||
@ -1792,7 +1792,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
#ifdef DEBUG_DISTANT_MSG
|
#ifdef DEBUG_DISTANT_MSG
|
||||||
std::cerr << " serialising item..." << std::endl;
|
std::cerr << " serialising item..." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if(!_serialiser->serialise(item,&data[1+KEY_ID_SIZE],&rssize))
|
if(!_serialiser->serialise(item,&data[1+PGP_KEY_ID_SIZE],&rssize))
|
||||||
{
|
{
|
||||||
std::cerr << "(EE) p3MsgService::encryptMessage(): Serialization error." << std::endl;
|
std::cerr << "(EE) p3MsgService::encryptMessage(): Serialization error." << std::endl;
|
||||||
free(data) ;
|
free(data) ;
|
||||||
@ -1812,7 +1812,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
signature_length = 2000 ;
|
signature_length = 2000 ;
|
||||||
signature_data = new unsigned char[signature_length] ;
|
signature_data = new unsigned char[signature_length] ;
|
||||||
|
|
||||||
if(!AuthGPG::getAuthGPG()->SignDataBin(data,1+rssize+KEY_ID_SIZE,signature_data,&signature_length))
|
if(!AuthGPG::getAuthGPG()->SignDataBin(data,1+rssize+PGP_KEY_ID_SIZE,signature_data,&signature_length))
|
||||||
{
|
{
|
||||||
free(data) ;
|
free(data) ;
|
||||||
std::cerr << "Signature failed!" << std::endl;
|
std::cerr << "Signature failed!" << std::endl;
|
||||||
@ -1823,7 +1823,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_DISTANT_MSG
|
#ifdef DEBUG_DISTANT_MSG
|
||||||
std::cerr << " total decrypted size = " << KEY_ID_SIZE + 1 + rssize + signature_length << std::endl;
|
std::cerr << " total decrypted size = " << PGP_KEY_ID_SIZE + 1 + rssize + signature_length << std::endl;
|
||||||
#endif
|
#endif
|
||||||
// 3 - append the signature to the serialized data.
|
// 3 - append the signature to the serialized data.
|
||||||
|
|
||||||
@ -1832,19 +1832,19 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
#ifdef DEBUG_DISTANT_MSG
|
#ifdef DEBUG_DISTANT_MSG
|
||||||
std::cerr << " Appending signature." << std::endl;
|
std::cerr << " Appending signature." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
data = (uint8_t*)realloc(data,1+rssize+signature_length+KEY_ID_SIZE) ;
|
data = (uint8_t*)realloc(data,1+rssize+signature_length+PGP_KEY_ID_SIZE) ;
|
||||||
memcpy(&data[1+rssize+KEY_ID_SIZE],signature_data,signature_length) ;
|
memcpy(&data[1+rssize+PGP_KEY_ID_SIZE],signature_data,signature_length) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2 - pgp-encrypt the whole chunk with the user-supplied public key.
|
// 2 - pgp-encrypt the whole chunk with the user-supplied public key.
|
||||||
//
|
//
|
||||||
uint32_t encrypted_size = 1+rssize + KEY_ID_SIZE + signature_length + 1000 ;
|
uint32_t encrypted_size = 1+rssize + PGP_KEY_ID_SIZE + signature_length + 1000 ;
|
||||||
unsigned char *encrypted_data = new unsigned char[encrypted_size] ;
|
unsigned char *encrypted_data = new unsigned char[encrypted_size] ;
|
||||||
|
|
||||||
#ifdef DEBUG_DISTANT_MSG
|
#ifdef DEBUG_DISTANT_MSG
|
||||||
std::cerr << " Encrypting for Key ID " << pgp_id << std::endl;
|
std::cerr << " Encrypting for Key ID " << pgp_id << std::endl;
|
||||||
#endif
|
#endif
|
||||||
if(!AuthGPG::getAuthGPG()->encryptDataBin(pgp_id,data,1+rssize+signature_length+KEY_ID_SIZE,encrypted_data,&encrypted_size))
|
if(!AuthGPG::getAuthGPG()->encryptDataBin(pgp_id,data,1+rssize+signature_length+PGP_KEY_ID_SIZE,encrypted_data,&encrypted_size))
|
||||||
{
|
{
|
||||||
free(data) ;
|
free(data) ;
|
||||||
delete[] encrypted_data ;
|
delete[] encrypted_data ;
|
||||||
@ -1854,7 +1854,7 @@ bool p3MsgService::encryptMessage(const std::string& pgp_id,RsMsgItem *item)
|
|||||||
free(data) ;
|
free(data) ;
|
||||||
|
|
||||||
#ifdef DEBUG_DISTANT_MSG
|
#ifdef DEBUG_DISTANT_MSG
|
||||||
std::cerr << " Decrypted size = " << 1+rssize+signature_length+KEY_ID_SIZE << std::endl;
|
std::cerr << " Decrypted size = " << 1+rssize+signature_length+PGP_KEY_ID_SIZE << std::endl;
|
||||||
std::cerr << " Encrypted size = " << encrypted_size << std::endl;
|
std::cerr << " Encrypted size = " << encrypted_size << std::endl;
|
||||||
std::cerr << " First bytes of encrypted data: " << std::hex << (int)encrypted_data[0] << " " << (int)encrypted_data[1] << " " << (int)encrypted_data[2] << std::dec << std::endl;
|
std::cerr << " First bytes of encrypted data: " << std::hex << (int)encrypted_data[0] << " " << (int)encrypted_data[1] << " " << (int)encrypted_data[2] << std::dec << std::endl;
|
||||||
std::cerr << " Encrypted data hash = " << RsDirUtil::sha1sum(encrypted_data,encrypted_size).toStdString() << std::endl;
|
std::cerr << " Encrypted data hash = " << RsDirUtil::sha1sum(encrypted_data,encrypted_size).toStdString() << std::endl;
|
||||||
@ -1963,7 +1963,7 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||||||
std::cerr << " Deserializing..." << std::endl;
|
std::cerr << " Deserializing..." << std::endl;
|
||||||
#endif
|
#endif
|
||||||
uint32_t item_size = decrypted_size ; // just needs to be larger than the actual size.
|
uint32_t item_size = decrypted_size ; // just needs to be larger than the actual size.
|
||||||
RsMsgItem *item = dynamic_cast<RsMsgItem*>(_serialiser->deserialise(&decrypted_data[1+KEY_ID_SIZE],&item_size)) ;
|
RsMsgItem *item = dynamic_cast<RsMsgItem*>(_serialiser->deserialise(&decrypted_data[1+PGP_KEY_ID_SIZE],&item_size)) ;
|
||||||
|
|
||||||
if(item == NULL)
|
if(item == NULL)
|
||||||
{
|
{
|
||||||
@ -1976,7 +1976,7 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||||||
bool signature_present = false ;
|
bool signature_present = false ;
|
||||||
bool signature_ok = false ;
|
bool signature_ok = false ;
|
||||||
|
|
||||||
if(1+item_size + KEY_ID_SIZE < decrypted_size)
|
if(1+item_size + PGP_KEY_ID_SIZE < decrypted_size)
|
||||||
{
|
{
|
||||||
std::cerr << " Signature is present. Verifying it..." << std::endl;
|
std::cerr << " Signature is present. Verifying it..." << std::endl;
|
||||||
|
|
||||||
@ -1989,9 +1989,9 @@ bool p3MsgService::decryptMessage(const std::string& mId)
|
|||||||
std::cerr << " Fingerprint = " << fingerprint.toStdString() << std::endl;
|
std::cerr << " Fingerprint = " << fingerprint.toStdString() << std::endl;
|
||||||
|
|
||||||
signature_present = true ;
|
signature_present = true ;
|
||||||
signature_ok = AuthGPG::getAuthGPG()->VerifySignBin(decrypted_data, 1+KEY_ID_SIZE+item_size, &decrypted_data[1+KEY_ID_SIZE+item_size], decrypted_size - KEY_ID_SIZE - item_size - 1, fingerprint.toStdString()) ;
|
signature_ok = AuthGPG::getAuthGPG()->VerifySignBin(decrypted_data, 1+PGP_KEY_ID_SIZE+item_size, &decrypted_data[1+PGP_KEY_ID_SIZE+item_size], decrypted_size - PGP_KEY_ID_SIZE - item_size - 1, fingerprint.toStdString()) ;
|
||||||
}
|
}
|
||||||
else if(1 + item_size + KEY_ID_SIZE == decrypted_size)
|
else if(1 + item_size + PGP_KEY_ID_SIZE == decrypted_size)
|
||||||
std::cerr << " No signature in this packet" << std::endl;
|
std::cerr << " No signature in this packet" << std::endl;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2120,14 +2120,23 @@ void p3MsgService::enableDistantMessaging(bool b)
|
|||||||
invite.time_of_validity = time(NULL) + 10*365*86400; // 10 years from now
|
invite.time_of_validity = time(NULL) + 10*365*86400; // 10 years from now
|
||||||
_messenging_invites[hash] = invite ;
|
_messenging_invites[hash] = invite ;
|
||||||
mDistantMessagingEnabled = true ;
|
mDistantMessagingEnabled = true ;
|
||||||
|
#ifdef GROUTER
|
||||||
|
std::cerr << "Notifying the global router." << std::endl;
|
||||||
|
|
||||||
|
std::string pname = rsPeers->getPeerName(mLinkMgr->getOwnId()) ;
|
||||||
|
Sha1CheckSum grouter_hash = RsDirUtil::sha1sum((uint8_t*)mLinkMgr->getOwnId().c_str(),16);
|
||||||
|
|
||||||
|
mGRouter->registerKey(grouter_hash, RS_SERVICE_TYPE_MSG, std::string("Contact address for ")+pname) ;
|
||||||
|
#endif
|
||||||
cchanged = true ;
|
cchanged = true ;
|
||||||
}
|
}
|
||||||
if((!b) && it != _messenging_invites.end())
|
if((!b) && it != _messenging_invites.end())
|
||||||
{
|
{
|
||||||
_messenging_invites.erase(it) ;
|
_messenging_invites.erase(it) ;
|
||||||
mDistantMessagingEnabled = false ;
|
mDistantMessagingEnabled = false ;
|
||||||
|
#ifdef GROUTER
|
||||||
|
mGRouter->unregisterKey(GRouterKeyId(hash)) ;
|
||||||
|
#endif
|
||||||
cchanged = true ;
|
cchanged = true ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,11 @@ template<uint32_t ID_SIZE_IN_BYTES> t_RsGenericIdType<ID_SIZE_IN_BYTES>::t_RsGen
|
|||||||
memcpy(bytes,mem,ID_SIZE_IN_BYTES) ;
|
memcpy(bytes,mem,ID_SIZE_IN_BYTES) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const int SSL_ID_SIZE = 16 ;
|
static const int SSL_ID_SIZE = 16 ;
|
||||||
|
static const int PGP_KEY_ID_SIZE = 8 ;
|
||||||
|
static const int PGP_KEY_FINGERPRINT_SIZE = 20 ;
|
||||||
|
|
||||||
typedef t_RsGenericIdType<SSL_ID_SIZE> SSLIdType ;
|
typedef t_RsGenericIdType<SSL_ID_SIZE> SSLIdType ;
|
||||||
|
typedef t_RsGenericIdType<PGP_KEY_ID_SIZE> PGPIdType;
|
||||||
|
typedef t_RsGenericIdType<PGP_KEY_FINGERPRINT_SIZE> PGPFingerprintType ;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user