Merge pull request #417 from csoler/v0.6-SecurityKeys

V0.6 security keys
This commit is contained in:
Cyril Soler 2016-06-17 22:53:05 -04:00 committed by GitHub
commit 7627bd96ca
71 changed files with 946 additions and 869 deletions

View File

@ -316,7 +316,7 @@ std::string ApiServer::handleRequest(Request &request)
task = mRouter.handleRequest(request, resp);
}
time_t start = time(NULL);
//time_t start = time(NULL);
bool morework = true;
while(task && morework)
{

View File

@ -424,7 +424,7 @@ static void sendMessage(MHD_Connection *connection, unsigned int status, std::st
static std::string escape_html(std::string in)
{
std::string out;
for(int i = 0; i < in.size(); i++)
for(uint32_t i = 0; i < in.size(); i++)
{
char a = (in[i]&0xF0)>>4;
a = a < 10? a+'0': a-10+'A';

View File

@ -218,7 +218,7 @@ ResponseTask* IdentityHandler::handleOwn(Request & /* req */, Response &resp)
return 0;
}
ResponseTask* IdentityHandler::handleCreateIdentity(Request &req, Response &resp)
ResponseTask* IdentityHandler::handleCreateIdentity(Request & /* req */, Response & /* resp */)
{
return new CreateIdentityTask(mRsIdentity);
}

View File

@ -72,7 +72,7 @@ PeersHandler::~PeersHandler()
mStateTokenServer->unregisterTickClient(this);
}
void PeersHandler::notifyListChange(int list, int type)
void PeersHandler::notifyListChange(int list, int /* type */)
{
RsStackMutex stack(mMtx); /********** STACK LOCKED MTX ******/
if(list == NOTIFY_LIST_FRIENDS)

View File

@ -12,7 +12,7 @@ public:
{
addResourceHandler("eins", this, &TestResource::eins);
}
ResponseTask* eins(Request& req, Response& resp)
ResponseTask* eins(Request& /* req */, Response& /* resp */)
{
return 0;
}

View File

@ -55,7 +55,7 @@ bool RsControlModule::processShouldExit()
return mProcessShouldExit;
}
bool RsControlModule::askForPassword(const std::string &key_details, bool prev_is_bad, std::string &password, bool& cancelled)
bool RsControlModule::askForPassword(const std::string &key_details, bool /* prev_is_bad */, std::string &password, bool& cancelled)
{
cancelled = false ;
{

View File

@ -42,7 +42,7 @@ void TransfersHandler::tick()
}
}
void TransfersHandler::handleWildcard(Request &req, Response &resp)
void TransfersHandler::handleWildcard(Request & /*req*/, Response & /*resp*/)
{
}
@ -108,7 +108,7 @@ void TransfersHandler::handleControlDownload(Request &req, Response &resp)
resp.setFail("error: action not handled");
}
void TransfersHandler::handleDownloads(Request &req, Response &resp)
void TransfersHandler::handleDownloads(Request & /* req */, Response &resp)
{
tick();
resp.mStateToken = mStateToken;

View File

@ -525,7 +525,7 @@ std::string SerializeValue(const Value& v)
// json expets decimal points, so replace all commas with decimal points
if(v.GetType() == FloatVal || v.GetType() == DoubleVal)
{
for(int i = 0; i < str.size(); i++)
for(unsigned int i = 0; i < str.size(); i++)
if(str[i] == ',')
str[i] = '.';
}

View File

@ -406,7 +406,7 @@ class RsChatDHPublicKeyItem: public RsChatItem
BIGNUM *public_key ;
RsTlvKeySignature signature ; // signs the public key in a row.
RsTlvSecurityKey gxs_key ; // public key of the signer
RsTlvPublicRSAKey gxs_key ; // public key of the signer
private:
RsChatDHPublicKeyItem(const RsChatDHPublicKeyItem&) : RsChatItem(RS_PKT_SUBTYPE_DISTANT_CHAT_DH_PUBLIC_KEY) {} // make the object non copy-able

View File

@ -1958,8 +1958,6 @@ bool p3GRouter::signDataItem(RsGRouterAbstractMsgItem *item,const RsGxsId& signi
{
try
{
RsTlvSecurityKey signature_key ;
#ifdef GROUTER_DEBUG
std::cerr << "p3GRouter::signDataItem()" << std::endl;
std::cerr << " Key ID = " << signing_id << std::endl;

View File

@ -39,6 +39,20 @@ static const uint32_t MULTI_ENCRYPTION_FORMAT_v001_HEADER_SIZE = 2 ;
static const uint32_t MULTI_ENCRYPTION_FORMAT_v001_NUMBER_OF_KEYS_SIZE = 2 ;
static const uint32_t MULTI_ENCRYPTION_FORMAT_v001_ENCRYPTED_KEY_SIZE = 256 ;
static RsGxsId getRsaKeyFingerprint_old_insecure_method(RSA *pubkey)
{
int lenn = BN_num_bytes(pubkey -> n);
RsTemporaryMemory tmp(lenn) ;
BN_bn2bin(pubkey -> n, tmp);
// Copy first CERTSIGNLEN bytes from the hash of the public modulus and exponent
// We should not be using strings here, but a real ID. To be done later.
assert(lenn >= CERTSIGNLEN) ;
return RsGxsId((unsigned char*)tmp) ;
}
static RsGxsId getRsaKeyFingerprint(RSA *pubkey)
{
int lenn = BN_num_bytes(pubkey -> n);
@ -59,7 +73,7 @@ static RsGxsId getRsaKeyFingerprint(RSA *pubkey)
return RsGxsId(s.toStdString().substr(0,2*CERTSIGNLEN));
}
static RSA *extractPrivateKey(const RsTlvSecurityKey & key)
static RSA *extractPrivateKey(const RsTlvPrivateRSAKey& key)
{
assert(key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
@ -72,7 +86,7 @@ static RSA *extractPrivateKey(const RsTlvSecurityKey & key)
return rsakey;
}
static RSA *extractPublicKey(const RsTlvSecurityKey& key)
static RSA *extractPublicKey(const RsTlvPublicRSAKey& key)
{
assert(!(key.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
@ -84,18 +98,39 @@ static RSA *extractPublicKey(const RsTlvSecurityKey& key)
return rsakey;
}
static void setRSAPublicKeyData(RsTlvSecurityKey & key, RSA *rsa_pub)
static void setRSAPublicKeyData(RsTlvPublicRSAKey& key, RSA *rsa_pub)
{
assert(!(key.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
unsigned char *data = NULL ; // this works for OpenSSL > 0.9.7
int reqspace = i2d_RSAPublicKey(rsa_pub, &data);
key.keyData.setBinData(data, reqspace);
key.keyId = getRsaKeyFingerprint(rsa_pub);
free(data) ;
free(data) ;
}
bool GxsSecurity::checkPrivateKey(const RsTlvSecurityKey& key)
static void setRSAPrivateKeyData(RsTlvPrivateRSAKey& key, RSA *rsa_priv)
{
assert(key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
unsigned char *data = NULL ; // this works for OpenSSL > 0.9.7
int reqspace = i2d_RSAPrivateKey(rsa_priv, &data);
key.keyData.setBinData(data, reqspace);
key.keyId = getRsaKeyFingerprint(rsa_priv);
free(data) ;
}
bool GxsSecurity::checkFingerprint(const RsTlvPublicRSAKey& key)
{
RSA *rsa_pub = ::extractPublicKey(key) ;
bool res = (key.keyId == getRsaKeyFingerprint(rsa_pub)) ;
RSA_free(rsa_pub) ;
return res ;
}
bool GxsSecurity::checkPrivateKey(const RsTlvPrivateRSAKey& key)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "Checking private key " << key.keyId << " ..." << std::endl;
@ -122,17 +157,33 @@ bool GxsSecurity::checkPrivateKey(const RsTlvSecurityKey& key)
return false ;
}
RsGxsId recomputed_key_id = getRsaKeyFingerprint(rsa_pub) ;
RSA_free(rsa_pub) ;
if(recomputed_key_id != key.keyId)
{
std::cerr << "(WW) GxsSecurity::checkPrivateKey(): key " << key.keyId << " has wrong fingerprint " << recomputed_key_id << "! This is unexpected." << std::endl;
return false ;
if(key.keyId == getRsaKeyFingerprint_old_insecure_method(rsa_pub))
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "(WW) fingerprint of key " << key.keyId << " was derived using old---insecure---format. It can be faked easily. You should get rid of this key!" << std::endl;
#endif
RSA_free(rsa_pub) ;
// The policy is to *accept* these private keys, but the public key that corresponds will be rejected anyway, as it can easily be faked.
return true ;
}
else
{
std::cerr << "(WW) GxsSecurity::checkPrivateKey(): key " << key.keyId << " has wrong fingerprint " << recomputed_key_id << std::endl;
RSA_free(rsa_pub) ;
return false ;
}
}
RSA_free(rsa_pub) ;
return true ;
}
bool GxsSecurity::checkPublicKey(const RsTlvSecurityKey& key)
bool GxsSecurity::checkPublicKey(const RsTlvPublicRSAKey &key)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "Checking public key " << key.keyId << " ..." << std::endl;
@ -143,6 +194,19 @@ bool GxsSecurity::checkPublicKey(const RsTlvSecurityKey& key)
std::cerr << "(WW) GxsSecurity::checkPublicKey(): public key has wrong flags " << std::hex << (key.keyFlags & RSTLV_KEY_TYPE_MASK) << std::dec << ". This is unexpected." << std::endl;
return false ;
}
// try to extract private key
const unsigned char *keyptr = (const unsigned char *) key.keyData.bin_data;
long keylen = key.keyData.bin_len;
RSA *rsa_prv = d2i_RSAPrivateKey(NULL, &(keyptr), keylen);
if(rsa_prv != NULL)
{
std::cerr << "(SS) GxsSecurity::checkPublicKey(): public key with ID " << key.keyId << " actually is a Private key!!!" << std::endl;
RSA_free(rsa_prv) ;
return false ;
}
RSA *rsa_pub = ::extractPublicKey(key) ;
if(rsa_pub == NULL)
@ -151,53 +215,63 @@ bool GxsSecurity::checkPublicKey(const RsTlvSecurityKey& key)
return false ;
}
RsGxsId recomputed_key_id = getRsaKeyFingerprint(rsa_pub) ;
RSA_free(rsa_pub) ;
if(recomputed_key_id != key.keyId)
{
std::cerr << "(WW) GxsSecurity::checkPublicKey(): key " << key.keyId << " has wrong fingerprint " << recomputed_key_id << "! This is unexpected." << std::endl;
if(key.keyId == getRsaKeyFingerprint_old_insecure_method(rsa_pub))
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "(WW) fingerprint was derived using old---insecure---format. It can be faked easily." << std::endl;
#endif
RSA_free(rsa_pub) ;
// The policy is to accept these public keys, but warn the owner, since they might be fake keys. They will be soon rejected here, by replacing
// the return value by false.
return true ;
}
else
std::cerr << "(WW) GxsSecurity::checkPublicKey(): key " << key.keyId << " has wrong fingerprint " << recomputed_key_id << "! Key will be discarded." << std::endl;
RSA_free(rsa_pub) ;
return false ;
}
RSA_free(rsa_pub) ;
return true ;
}
static void setRSAPrivateKeyData(RsTlvSecurityKey & key, RSA *rsa_priv)
{
unsigned char *data = NULL ;
int reqspace = i2d_RSAPrivateKey(rsa_priv, &data);
key.keyData.setBinData(data, reqspace);
key.keyId = getRsaKeyFingerprint(rsa_priv);
free(data) ;
}
bool GxsSecurity::generateKeyPair(RsTlvSecurityKey& public_key,RsTlvSecurityKey& private_key)
bool GxsSecurity::generateKeyPair(RsTlvPublicRSAKey& public_key,RsTlvPrivateRSAKey& private_key)
{
// admin keys
RSA *rsa = RSA_generate_key(2048, 65537, NULL, NULL);
RSA *rsa_pub = RSAPublicKey_dup(rsa);
public_key.keyFlags = RSTLV_KEY_TYPE_PUBLIC_ONLY ;
private_key.keyFlags = RSTLV_KEY_TYPE_FULL ;
setRSAPublicKeyData(public_key, rsa_pub);
setRSAPrivateKeyData(private_key, rsa);
public_key.startTS = time(NULL);
public_key.endTS = public_key.startTS + 60 * 60 * 24 * 365 * 5; /* approx 5 years */
public_key.keyFlags = RSTLV_KEY_TYPE_PUBLIC_ONLY ;
private_key.startTS = public_key.startTS;
private_key.endTS = 0; /* no end */
private_key.keyFlags = RSTLV_KEY_TYPE_FULL ;
// clean up
RSA_free(rsa);
RSA_free(rsa_pub);
return true ;
if(!(private_key.checkKey() && public_key.checkKey()))
{
std::cerr << "(EE) ERROR while generating keys. Something inconsistent in flags. This is probably a bad sign!" << std::endl;
return false ;
}
return true ;
}
bool GxsSecurity::extractPublicKey(const RsTlvSecurityKey& private_key,RsTlvSecurityKey& public_key)
bool GxsSecurity::extractPublicKey(const RsTlvPrivateRSAKey &private_key, RsTlvPublicRSAKey &public_key)
{
public_key.TlvClear() ;
@ -241,30 +315,30 @@ bool GxsSecurity::extractPublicKey(const RsTlvSecurityKey& private_key,RsTlvSecu
return true ;
}
bool GxsSecurity::getSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& privKey, RsTlvKeySignature& sign)
bool GxsSecurity::getSignature(const char *data, uint32_t data_len, const RsTlvPrivateRSAKey &privKey, RsTlvKeySignature& sign)
{
RSA* rsa_pub = extractPrivateKey(privKey);
RSA* rsa_priv = extractPrivateKey(privKey);
if(!rsa_pub)
if(!rsa_priv)
{
std::cerr << "GxsSecurity::getSignature(): Cannot create signature. Keydata is incomplete." << std::endl;
return false ;
}
EVP_PKEY *key_pub = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key_pub, rsa_pub);
EVP_PKEY *key_priv = EVP_PKEY_new();
EVP_PKEY_assign_RSA(key_priv, rsa_priv);
/* calc and check signature */
EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
bool ok = EVP_SignInit(mdctx, EVP_sha1()) == 1;
ok &= EVP_SignUpdate(mdctx, data, data_len) == 1;
unsigned int siglen = EVP_PKEY_size(key_pub);
unsigned int siglen = EVP_PKEY_size(key_priv);
unsigned char sigbuf[siglen];
ok &= EVP_SignFinal(mdctx, sigbuf, &siglen, key_pub) == 1;
ok &= EVP_SignFinal(mdctx, sigbuf, &siglen, key_priv) == 1;
// clean up
EVP_MD_CTX_destroy(mdctx);
EVP_PKEY_free(key_pub);
EVP_PKEY_free(key_priv);
sign.signData.setBinData(sigbuf, siglen);
sign.keyId = RsGxsId(privKey.keyId);
@ -272,12 +346,11 @@ bool GxsSecurity::getSignature(const char *data, uint32_t data_len, const RsTlvS
return ok;
}
bool GxsSecurity::validateSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& key, const RsTlvKeySignature& signature)
bool GxsSecurity::validateSignature(const char *data, uint32_t data_len, const RsTlvPublicRSAKey &key, const RsTlvKeySignature& signature)
{
RSA *tmpkey = (key.keyFlags & RSTLV_KEY_TYPE_FULL)?(::extractPrivateKey(key)):(::extractPublicKey(key)) ;
RSA *rsakey = RSAPublicKey_dup(tmpkey) ; // always extract public key
RSA_free(tmpkey) ;
assert(!(key.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
RSA *rsakey = ::extractPublicKey(key) ;
if(!rsakey)
{
@ -303,7 +376,7 @@ bool GxsSecurity::validateSignature(const char *data, uint32_t data_len, const R
return signOk;
}
bool GxsSecurity::validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& sign, const RsTlvSecurityKey& key)
bool GxsSecurity::validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& sign, const RsTlvPublicRSAKey& key)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "GxsSecurity::validateNxsMsg()";
@ -417,7 +490,7 @@ bool GxsSecurity::validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& s
return false;
}
bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvSecurityKey& key)
bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvPublicRSAKey& key)
{
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity::encrypt() " << std::endl;
@ -532,7 +605,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
return true;
}
bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvSecurityKey>& keys)
bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvPublicRSAKey> &keys)
{
#ifdef DISTRIB_DEBUG
std::cerr << "GxsSecurity::encrypt() " << std::endl;
@ -685,7 +758,7 @@ bool GxsSecurity::encrypt(uint8_t *& out, uint32_t &outlen, const uint8_t *in, u
}
}
bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in, uint32_t inlen, const RsTlvSecurityKey& key)
bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in, uint32_t inlen, const RsTlvPrivateRSAKey &key)
{
// Decrypts (in,inlen) into (out,outlen) using the given RSA public key.
// The format of the encrypted data (in) is:
@ -791,7 +864,7 @@ bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in,
return true;
}
bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvSecurityKey>& keys)
bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvPrivateRSAKey> &keys)
{
// Decrypts (in,inlen) into (out,outlen) using one of the given RSA public keys, trying them all in a row.
// The format of the encrypted data is:
@ -936,7 +1009,7 @@ bool GxsSecurity::decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in,
return false;
}
}
bool GxsSecurity::validateNxsGrp(const RsNxsGrp& grp, const RsTlvKeySignature& sign, const RsTlvSecurityKey& key)
bool GxsSecurity::validateNxsGrp(const RsNxsGrp& grp, const RsTlvKeySignature& sign, const RsTlvPublicRSAKey &key)
{
#ifdef GXS_SECURITY_DEBUG
std::cerr << "GxsSecurity::validateNxsGrp()";
@ -974,7 +1047,7 @@ bool GxsSecurity::validateNxsGrp(const RsNxsGrp& grp, const RsTlvKeySignature& s
#endif
/* extract admin key */
RSA *rsakey = (key.keyFlags & RSTLV_KEY_TYPE_FULL)? d2i_RSAPrivateKey(NULL, &(keyptr), keylen): d2i_RSAPublicKey(NULL, &(keyptr), keylen);
RSA *rsakey = d2i_RSAPublicKey(NULL, &(keyptr), keylen);
if (!rsakey)
{
@ -1049,4 +1122,21 @@ bool GxsSecurity::validateNxsGrp(const RsNxsGrp& grp, const RsTlvKeySignature& s
return false;
}
void GxsSecurity::createPublicKeysFromPrivateKeys(RsTlvSecurityKeySet& keyset)
{
for( std::map<RsGxsId, RsTlvPrivateRSAKey>::const_iterator it = keyset.private_keys.begin(); it != keyset.private_keys.end() ; ++it)
if(keyset.public_keys.find(it->second.keyId) == keyset.public_keys.end())
{
RsTlvPublicRSAKey pub_key ;
if(!extractPublicKey(it->second,pub_key))
{
std::cerr << "(EE) ERROR when trying to generate public key from private key for ID " << it->second.keyId << ". This is probably a bug with security implications." << std::endl;
continue ;
}
keyset.public_keys[it->second.keyId] = pub_key ;
std::cerr << "(II) Generated missing public key for ID " << it->second.keyId << " from private key." << std::endl;
}
}

View File

@ -45,7 +45,7 @@ class GxsSecurity
/*!
* Extracts a public key from a private key.
*/
static bool extractPublicKey(const RsTlvSecurityKey& private_key,RsTlvSecurityKey& public_key) ;
static bool extractPublicKey(const RsTlvPrivateRSAKey& private_key,RsTlvPublicRSAKey& public_key) ;
/*!
* Generates a public/private RSA keypair. To be used for all GXS purposes.
@ -53,7 +53,7 @@ class GxsSecurity
* @param RsTlvSecurityKey private RSA key
* @return true if the generate was successful, false otherwise.
*/
static bool generateKeyPair(RsTlvSecurityKey& public_key,RsTlvSecurityKey& private_key) ;
static bool generateKeyPair(RsTlvPublicRSAKey &public_key, RsTlvPrivateRSAKey &private_key) ;
/*!
* Encrypts data using envelope encryption (taken from open ssl's evp_sealinit )
@ -63,8 +63,8 @@ class GxsSecurity
*@param in
*@param inlen
*/
static bool encrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvSecurityKey& key) ;
static bool encrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvSecurityKey>& keys) ;
static bool encrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvPublicRSAKey& key) ;
static bool encrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvPublicRSAKey>& keys) ;
/**
* Decrypts data using evelope decryption (taken from open ssl's evp_sealinit )
@ -75,8 +75,8 @@ class GxsSecurity
* @param inlen
* @return false if encryption failed
*/
static bool decrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvSecurityKey& key) ;
static bool decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvSecurityKey>& keys);
static bool decrypt(uint8_t *&out, uint32_t &outlen, const uint8_t *in, uint32_t inlen, const RsTlvPrivateRSAKey& key) ;
static bool decrypt(uint8_t *& out, uint32_t & outlen, const uint8_t *in, uint32_t inlen, const std::vector<RsTlvPrivateRSAKey>& keys);
/*!
* uses grp signature to check if group has been
@ -86,7 +86,7 @@ class GxsSecurity
* @param key the public key to use to check signature
* @return true if group valid false otherwise
*/
static bool validateNxsGrp(const RsNxsGrp& grp, const RsTlvKeySignature& sign, const RsTlvSecurityKey& key);
static bool validateNxsGrp(const RsNxsGrp& grp, const RsTlvKeySignature& sign, const RsTlvPublicRSAKey& key);
/*!
* Validate a msg's signature using the given public key
@ -95,7 +95,7 @@ class GxsSecurity
* @param key the public key to use to check signature
* @return false if verfication of signature is not passed
*/
static bool validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& sign, const RsTlvSecurityKey& key);
static bool validateNxsMsg(const RsNxsMsg& msg, const RsTlvKeySignature& sign, const RsTlvPublicRSAKey &key);
/*!
@ -105,7 +105,7 @@ class GxsSecurity
* @param sign the signature is stored here
* @return false if signature creation failed, true is signature created
*/
static bool getSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& privKey, RsTlvKeySignature& sign);
static bool getSignature(const char *data, uint32_t data_len, const RsTlvPrivateRSAKey& privKey, RsTlvKeySignature& sign);
/*!
* @param data data that has been signed
@ -114,7 +114,7 @@ class GxsSecurity
* @param sign Signature for the data
* @return true if signature checks
*/
static bool validateSignature(const char *data, uint32_t data_len, const RsTlvSecurityKey& pubKey, const RsTlvKeySignature& sign);
static bool validateSignature(const char *data, uint32_t data_len, const RsTlvPublicRSAKey& pubKey, const RsTlvKeySignature& sign);
/*!
* Checks that the public key has correct fingerprint and correct flags.
@ -123,8 +123,18 @@ class GxsSecurity
* @return false if the key is invalid.
*/
static bool checkPublicKey(const RsTlvSecurityKey &key);
static bool checkPrivateKey(const RsTlvSecurityKey &key);
static bool checkPublicKey(const RsTlvPublicRSAKey &key);
static bool checkPrivateKey(const RsTlvPrivateRSAKey &key);
static bool checkFingerprint(const RsTlvPublicRSAKey& key); // helper function to only check the fingerprint
/*!
* Adds possibly missing public keys when private keys are present.
*
* \brief createPublicKeysForPrivateKeys
* \param set set of keys to consider
* \return
*/
static void createPublicKeysFromPrivateKeys(RsTlvSecurityKeySet& set) ;
};
#endif // GXSSECURITY_H

View File

@ -63,8 +63,8 @@ static const uint32_t INDEX_AUTHEN_ADMIN = 0x00000040; // admin key
//#define GEN_EXCH_DEBUG 1
#define MSG_CLEANUP_PERIOD 60*5 // 5 minutes
#define INTEGRITY_CHECK_PERIOD 60*30 // 30 minutes
#define MSG_CLEANUP_PERIOD 60*59 // 59 minutes
#define INTEGRITY_CHECK_PERIOD 60*31 // 31 minutes
RsGenExchange::RsGenExchange(RsGeneralDataService *gds, RsNetworkExchangeService *ns,
RsSerialType *serviceSerialiser, uint16_t servType, RsGixs* gixs,
@ -108,41 +108,6 @@ void RsGenExchange::setNetworkExchangeService(RsNetworkExchangeService *ns)
mNetService = ns ;
}
#ifdef TO_BE_DELETED_IF_NOT_USEFUL
// This class has been tested so as to see where the database gets modified.
class RsDataBaseTester
{
public:
RsDataBaseTester(RsGeneralDataService *store,const RsGxsGroupId& grpId,const std::string& info)
:_grpId(grpId),_store(store),_info(info)
{
//std::cerr << "RsDataBaseTester: (" << _info << ") retrieving messages for group " << grpId << std::endl;
_store->retrieveMsgIds(_grpId, _msgIds1) ;
}
~RsDataBaseTester()
{
//std::cerr << "RsDataBaseTester: (" << _info << ") testing messages for group " << _grpId << std::endl;
_store->retrieveMsgIds(_grpId, _msgIds2) ;
bool all_idendical = true ;
std::cerr << std::dec ;
if(_msgIds1.size() != _msgIds2.size())
std::cerr << " " << _info << " (EE) The two arrays are different (size1=" << _msgIds1.size() << ", size2=" << _msgIds2.size() << ") !!" << std::endl;
else
for(uint32_t i=0;i<_msgIds1.size();++i)
if(_msgIds1[i] != _msgIds2[i])
std::cerr << " " << _info << " (EE) The two arrays are different for i=" << i << " !!" << std::endl;
}
RsGxsGroupId _grpId ;
RsGeneralDataService *_store ;
std::vector<RsGxsMessageId> _msgIds1 ;
std::vector<RsGxsMessageId> _msgIds2 ;
std::string _info ;
};
#endif
RsGenExchange::~RsGenExchange()
{
// need to destruct in a certain order (bad thing, TODO: put down instance ownership rules!)
@ -341,47 +306,39 @@ bool RsGenExchange::acknowledgeTokenGrp(const uint32_t& token, RsGxsGroupId& grp
return true;
}
void RsGenExchange::generateGroupKeys(RsTlvSecurityKeySet& privatekeySet, RsTlvSecurityKeySet& publickeySet, bool genPublishKeys)
void RsGenExchange::generateGroupKeys(RsTlvSecurityKeySet& keySet, bool genPublishKeys)
{
/* create Keys */
RsTlvSecurityKey adminKey, privAdminKey;
GxsSecurity::generateKeyPair(adminKey,privAdminKey) ;
/* create Keys */
RsTlvPublicRSAKey pubAdminKey ;
RsTlvPrivateRSAKey privAdminKey;
// for now all public
adminKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_PUBLIC_ONLY;
privAdminKey.keyFlags = RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL;
GxsSecurity::generateKeyPair(pubAdminKey,privAdminKey) ;
publickeySet.keys[adminKey.keyId] = adminKey;
privatekeySet.keys[privAdminKey.keyId] = privAdminKey;
// for now all public
pubAdminKey.keyFlags |= RSTLV_KEY_DISTRIB_ADMIN ;
privAdminKey.keyFlags |= RSTLV_KEY_DISTRIB_ADMIN ;
if(genPublishKeys)
{
/* set publish keys */
RsTlvSecurityKey publishKey, privPublishKey;
GxsSecurity::generateKeyPair(publishKey,privPublishKey) ;
keySet.public_keys[pubAdminKey.keyId] = pubAdminKey;
keySet.private_keys[privAdminKey.keyId] = privAdminKey;
// for now all public
publishKey.keyFlags = RSTLV_KEY_DISTRIB_PUBLISH | RSTLV_KEY_TYPE_PUBLIC_ONLY;
privPublishKey.keyFlags = RSTLV_KEY_DISTRIB_PUBLISH | RSTLV_KEY_TYPE_FULL;
if(genPublishKeys)
{
/* set publish keys */
RsTlvPublicRSAKey pubPublishKey ;
RsTlvPrivateRSAKey privPublishKey;
publickeySet.keys[publishKey.keyId] = publishKey;
privatekeySet.keys[privPublishKey.keyId] = privPublishKey;
}
GxsSecurity::generateKeyPair(pubPublishKey,privPublishKey) ;
// for now all public
pubPublishKey.keyFlags |= RSTLV_KEY_DISTRIB_PUBLISH ;
privPublishKey.keyFlags |= RSTLV_KEY_DISTRIB_PUBLISH ;
keySet.public_keys[pubPublishKey.keyId] = pubPublishKey;
keySet.private_keys[privPublishKey.keyId] = privPublishKey;
}
}
void RsGenExchange::generatePublicFromPrivateKeys(const RsTlvSecurityKeySet &privatekeySet, RsTlvSecurityKeySet &publickeySet)
{
// actually just copy settings of one key except mark its key flags public
publickeySet = RsTlvSecurityKeySet() ;
RsTlvSecurityKey pubkey ;
for(std::map<RsGxsId, RsTlvSecurityKey>::const_iterator cit=privatekeySet.keys.begin(); cit != privatekeySet.keys.end(); ++cit)
if(GxsSecurity::extractPublicKey(cit->second,pubkey))
publickeySet.keys.insert(std::make_pair(pubkey.keyId, pubkey));
}
uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet)
uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& keySet)
{
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::createGroup()";
@ -393,19 +350,18 @@ uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKe
/* add public admin and publish keys to grp */
// find private admin key
RsTlvSecurityKey privAdminKey;
std::map<RsGxsId, RsTlvSecurityKey>::iterator mit = privateKeySet.keys.begin();
RsTlvPrivateRSAKey privAdminKey;
bool privKeyFound = false; // private admin key
for(; mit != privateKeySet.keys.end(); ++mit)
for( std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit = keySet.private_keys.begin(); mit != keySet.private_keys.end(); ++mit)
{
RsTlvSecurityKey& key = mit->second;
RsTlvPrivateRSAKey& key = mit->second;
if((key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN) && (key.keyFlags & RSTLV_KEY_TYPE_FULL))
{
privAdminKey = key;
privKeyFound = true;
break ;
break ;
}
}
@ -417,13 +373,17 @@ uint8_t RsGenExchange::createGroup(RsNxsGrp *grp, RsTlvSecurityKeySet& privateKe
return false;
}
meta->keys = publicKeySet; // only public keys are included to be transported
// only public keys are included to be transported. The 2nd line below is very important.
meta->keys = keySet;
meta->keys.private_keys.clear() ;
// group is self signing
// for the creation of group signature
// only public admin and publish keys are present in meta
uint32_t metaDataLen = meta->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
uint32_t allGrpDataLen = metaDataLen + grp->grp.bin_len;
char* metaData = new char[metaDataLen];
char* allGrpData = new char[allGrpDataLen]; // msgData + metaData
@ -503,12 +463,11 @@ int RsGenExchange::createGroupSignatures(RsTlvKeySignatureSet& signSet, RsTlvBin
if(haveKey)
{
RsTlvSecurityKey authorKey;
RsTlvPrivateRSAKey authorKey;
mGixs->getPrivateKey(grpMeta.mAuthorId, authorKey);
RsTlvKeySignature sign;
if(GxsSecurity::getSignature((char*)grpData.bin_data, grpData.bin_len,
authorKey, sign))
if(GxsSecurity::getSignature((char*)grpData.bin_data, grpData.bin_len, authorKey, sign))
{
id_ret = SIGN_SUCCESS;
mGixs->timeStampKey(grpMeta.mAuthorId) ;
@ -623,12 +582,12 @@ int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinar
if(needPublishSign)
{
// public and shared is publish key
RsTlvSecurityKeySet& keys = grpMeta.keys;
RsTlvSecurityKey* publishKey;
const RsTlvSecurityKeySet& keys = grpMeta.keys;
const RsTlvPrivateRSAKey *publishKey;
std::map<RsGxsId, RsTlvSecurityKey>::iterator mit =
keys.keys.begin(), mit_end = keys.keys.end();
std::map<RsGxsId, RsTlvPrivateRSAKey>::const_iterator mit = keys.private_keys.begin(), mit_end = keys.private_keys.end();
bool publish_key_found = false;
for(; mit != mit_end; ++mit)
{
@ -672,7 +631,7 @@ int RsGenExchange::createMsgSignatures(RsTlvKeySignatureSet& signSet, RsTlvBinar
if(haveKey)
{
RsTlvSecurityKey authorKey;
RsTlvPrivateRSAKey authorKey;
mGixs->getPrivateKey(msgMeta.mAuthorId, authorKey);
RsTlvKeySignature sign;
@ -841,13 +800,13 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
{
RsTlvKeySignature sign = metaData.signSet.keySignSet[INDEX_AUTHEN_PUBLISH];
std::map<RsGxsId, RsTlvSecurityKey>& keys = grpKeySet.keys;
std::map<RsGxsId, RsTlvSecurityKey>::iterator mit = keys.begin();
std::map<RsGxsId, RsTlvPublicRSAKey>& keys = grpKeySet.public_keys;
std::map<RsGxsId, RsTlvPublicRSAKey>::iterator mit = keys.begin();
RsGxsId keyId;
for(; mit != keys.end() ; ++mit)
{
RsTlvSecurityKey& key = mit->second;
RsTlvPublicRSAKey& key = mit->second;
if(key.keyFlags & RSTLV_KEY_DISTRIB_PUBLIC_deprecated)
{
@ -865,7 +824,7 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
if(!keyId.isNull())
{
RsTlvSecurityKey& key = keys[keyId];
RsTlvPublicRSAKey& key = keys[keyId];
publishValidate &= GxsSecurity::validateNxsMsg(*msg, sign, key);
}
else
@ -889,7 +848,7 @@ int RsGenExchange::validateMsg(RsNxsMsg *msg, const uint32_t& grpFlag, const uin
if(haveKey)
{
RsTlvSecurityKey authorKey;
RsTlvPublicRSAKey authorKey;
bool auth_key_fetched = mGixs->getKey(metaData.mAuthorId, authorKey) ;
if (auth_key_fetched)
@ -1008,7 +967,7 @@ int RsGenExchange::validateGrp(RsNxsGrp* grp)
std::cerr << " have ID key in cache: yes" << std::endl;
#endif
RsTlvSecurityKey authorKey;
RsTlvPublicRSAKey authorKey;
bool auth_key_fetched = mGixs->getKey(metaData.mAuthorId, authorKey) ;
if (auth_key_fetched)
@ -2157,20 +2116,23 @@ void RsGenExchange::processGroupUpdatePublish()
//gup.grpItem->meta = *meta;
GxsGrpPendingSign ggps(gup.grpItem, gup.mToken);
bool publishAndAdminPrivatePresent = checkKeys(meta->keys);
if(publishAndAdminPrivatePresent)
if(checkKeys(meta->keys))
{
ggps.mPrivateKeys = meta->keys;
generatePublicFromPrivateKeys(ggps.mPrivateKeys, ggps.mPublicKeys);
ggps.mKeys = meta->keys;
GxsSecurity::createPublicKeysFromPrivateKeys(ggps.mKeys) ;
ggps.mHaveKeys = true;
ggps.mStartTS = time(NULL);
ggps.mLastAttemptTS = 0;
ggps.mIsUpdate = true;
ggps.mToken = gup.mToken;
mGrpsToPublish.push_back(ggps);
}else
}
else
{
std::cerr << "(EE) publish group fails because RS cannot find the private publish and author keys" << std::endl;
delete gup.grpItem;
mDataAccess->updatePublicRequestStatus(gup.mToken, RsTokenService::GXS_REQUEST_V2_STATUS_FAILED);
}
@ -2293,14 +2255,15 @@ void RsGenExchange::processMessageDelete()
bool RsGenExchange::checkKeys(const RsTlvSecurityKeySet& keySet)
{
typedef std::map<RsGxsId, RsTlvSecurityKey> keyMap;
const keyMap& allKeys = keySet.keys;
typedef std::map<RsGxsId, RsTlvPrivateRSAKey> keyMap;
const keyMap& allKeys = keySet.private_keys;
keyMap::const_iterator cit = allKeys.begin();
bool adminFound = false, publishFound = false;
for(; cit != allKeys.end(); ++cit)
{
const RsTlvSecurityKey& key = cit->second;
if(key.keyFlags & RSTLV_KEY_TYPE_FULL)
const RsTlvPrivateRSAKey& key = cit->second;
if(key.keyFlags & RSTLV_KEY_TYPE_FULL) // this one is not useful. Just a security.
{
if(key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
adminFound = true;
@ -2309,6 +2272,11 @@ bool RsGenExchange::checkKeys(const RsTlvSecurityKeySet& keySet)
publishFound = true;
}
else if(key.keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY) // this one is not useful. Just a security.
{
std::cerr << "(EE) found a public only key in the private key list" << std::endl;
return false ;
}
}
// user must have both private and public parts of publish and admin keys
@ -2347,29 +2315,23 @@ void RsGenExchange::publishGrps()
RsNxsGrp* grp = new RsNxsGrp(mServType);
RsGxsGrpItem* grpItem = ggps.mItem;
RsTlvSecurityKeySet privatekeySet, publicKeySet;
RsTlvSecurityKeySet fullKeySet;
if(!(ggps.mHaveKeys))
{
generateGroupKeys(privatekeySet, publicKeySet, true);
generateGroupKeys(fullKeySet, true);
ggps.mHaveKeys = true;
ggps.mPrivateKeys = privatekeySet;
ggps.mPublicKeys = publicKeySet;
ggps.mKeys = fullKeySet;
}
else
{
privatekeySet = ggps.mPrivateKeys;
publicKeySet = ggps.mPublicKeys;
}
// find private admin key
RsTlvSecurityKey privAdminKey;
std::map<RsGxsId, RsTlvSecurityKey>::iterator mit_keys = privatekeySet.keys.begin();
fullKeySet = ggps.mKeys;
// find private admin key
RsTlvPrivateRSAKey privAdminKey;
bool privKeyFound = false;
for(; mit_keys != privatekeySet.keys.end(); ++mit_keys)
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit_keys = fullKeySet.private_keys.begin(); mit_keys != fullKeySet.private_keys.end(); ++mit_keys)
{
RsTlvSecurityKey& key = mit_keys->second;
RsTlvPrivateRSAKey& key = mit_keys->second;
if(key.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
{
@ -2385,8 +2347,7 @@ void RsGenExchange::publishGrps()
// get group id from private admin key id
grpItem->meta.mGroupId = grp->grpId = RsGxsGroupId(privAdminKey.keyId);
ServiceCreate_Return ret = service_CreateGroup(grpItem, privatekeySet);
ServiceCreate_Return ret = service_CreateGroup(grpItem, fullKeySet);
bool serialOk = false, servCreateOk;
@ -2414,7 +2375,7 @@ void RsGenExchange::publishGrps()
grp->metaData->mSubscribeFlags = GXS_SERV::GROUP_SUBSCRIBE_ADMIN | GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED
| GXS_SERV::GROUP_SUBSCRIBE_PUBLISH;
create = createGroup(grp, privatekeySet, publicKeySet);
create = createGroup(grp, fullKeySet);
#ifdef GEN_EXCH_DEBUG
std::cerr << "RsGenExchange::publishGrps() ";
@ -2426,15 +2387,22 @@ void RsGenExchange::publishGrps()
if(create == CREATE_SUCCESS)
{
// Here we need to make sure that no private keys are included. This is very important since private keys
// can be used to modify the group. Normally the private key set is whiped out by createGroup, but
grp->metaData->keys.private_keys.clear() ;
uint32_t mdSize = grp->metaData->serial_size(RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
char* metaData = new char[mdSize];
serialOk = grp->metaData->serialise(metaData, mdSize,RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
grp->meta.setBinData(metaData, mdSize);
delete[] metaData;
{
RsTemporaryMemory metaData(mdSize);
serialOk = grp->metaData->serialise(metaData, mdSize,RS_GXS_GRP_META_DATA_CURRENT_API_VERSION);
#warning TODO: grp->meta should be renamed grp->public_meta !
grp->meta.setBinData(metaData, mdSize);
}
// place back private keys for publisher
grp->metaData->keys = privatekeySet;
// Place back private keys for publisher and database storage
grp->metaData->keys.private_keys = fullKeySet.private_keys;
if(mDataStore->validSize(grp) && serialOk)
{
@ -2445,10 +2413,10 @@ void RsGenExchange::publishGrps()
if(ggps.mIsUpdate)
mDataAccess->updateGroupData(grp);
else
mDataAccess->addGroupData(grp);
if(mNetService!=NULL)
mNetService->subscribeStatusChanged(grpId,true) ;
mDataAccess->addGroupData(grp);
#warning this is bad: addGroupData/updateGroupData actially deletes grp. But it may be used below? grp should be a class object and not deleted manually!
if(mNetService!=NULL)
mNetService->subscribeStatusChanged(grpId,true) ;
}
else
{
@ -2568,29 +2536,30 @@ RsGeneralDataService* RsGenExchange::getDataStore()
bool RsGenExchange::getGroupKeys(const RsGxsGroupId &grpId, RsTlvSecurityKeySet &keySet)
{
if(grpId.isNull())
return false;
if(grpId.isNull())
return false;
RS_STACK_MUTEX(mGenMtx) ;
RS_STACK_MUTEX(mGenMtx) ;
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
grpMeta[grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMeta);
std::map<RsGxsGroupId, RsGxsGrpMetaData*> grpMeta;
grpMeta[grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMeta);
if(grpMeta.empty())
return false;
if(grpMeta.empty())
return false;
RsGxsGrpMetaData* meta = grpMeta[grpId];
RsGxsGrpMetaData* meta = grpMeta[grpId];
if(meta == NULL)
return false;
if(meta == NULL)
return false;
keySet = meta->keys;
keySet = meta->keys;
GxsSecurity::createPublicKeysFromPrivateKeys(keySet) ;
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator it=grpMeta.begin();it!=grpMeta.end();++it)
delete it->second ;
for(std::map<RsGxsGroupId, RsGxsGrpMetaData*>::iterator it=grpMeta.begin();it!=grpMeta.end();++it)
delete it->second ;
return true;
return true;
}
void RsGenExchange::shareGroupPublishKey(const RsGxsGroupId& grpId,const std::set<RsPeerId>& peers)
@ -3076,8 +3045,8 @@ bool RsGenExchange::updateValid(RsGxsGrpMetaData& oldGrpMeta, RsNxsGrp& newGrp)
RsTlvKeySignature adminSign = mit->second;
std::map<RsGxsId, RsTlvSecurityKey>& keys = oldGrpMeta.keys.keys;
std::map<RsGxsId, RsTlvSecurityKey>::iterator keyMit = keys.find(RsGxsId(oldGrpMeta.mGroupId));
std::map<RsGxsId, RsTlvPublicRSAKey>& keys = oldGrpMeta.keys.public_keys;
std::map<RsGxsId, RsTlvPublicRSAKey>::iterator keyMit = keys.find(RsGxsId(oldGrpMeta.mGroupId));
if(keyMit == keys.end())
{

View File

@ -79,8 +79,7 @@ public:
RsGxsGrpItem* mItem;
bool mHaveKeys; // mKeys->first == true if key present
bool mIsUpdate;
RsTlvSecurityKeySet mPrivateKeys;
RsTlvSecurityKeySet mPublicKeys;
RsTlvSecurityKeySet mKeys;
};
typedef std::map<RsGxsGroupId, std::vector<RsGxsMsgItem*> > GxsMsgDataMap;
@ -694,7 +693,7 @@ private:
* @return CREATE_SUCCESS for success, CREATE_FAIL for fail,
* CREATE_FAIL_TRY_LATER for Id sign key not avail (but requested)
*/
uint8_t createGroup(RsNxsGrp* grp, RsTlvSecurityKeySet& privateKeySet, RsTlvSecurityKeySet& publicKeySet);
uint8_t createGroup(RsNxsGrp* grp, RsTlvSecurityKeySet& keySet);
/*!
* This completes the creation of an instance on RsNxsMsg
@ -742,16 +741,7 @@ private:
* @param publickeySet contains public generated keys (counterpart of private)
* @param genPublicKeys should publish key pair also be generated
*/
void generateGroupKeys(RsTlvSecurityKeySet& privatekeySet, RsTlvSecurityKeySet& publickeySet, bool genPublishKeys);
/*!
* Generate public set of keys from their private counterparts
* No keys will be generated if one fails
* @param privatekeySet contains private generated keys
* @param publickeySet contains public generated keys (counterpart of private)
* @return false if key gen failed for a key set
*/
void generatePublicFromPrivateKeys(const RsTlvSecurityKeySet& privatekeySet, RsTlvSecurityKeySet& publickeySet);
void generateGroupKeys(RsTlvSecurityKeySet& keySet, bool genPublishKeys);
/*!
* Attempts to validate msg signatures

View File

@ -160,8 +160,8 @@ public:
* @return a pointer to a valid profile if successful, otherwise NULL
*
*/
virtual bool getKey(const RsGxsId &id, RsTlvSecurityKey &key) = 0;
virtual bool getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key) = 0; // For signing outgoing messages.
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey& key) = 0;
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey& key) = 0; // For signing outgoing messages.
virtual bool getIdDetails(const RsGxsId& id, RsIdentityDetails& details) = 0 ; // Proxy function so that we get p3Identity info from Gxs
};

View File

@ -3292,6 +3292,7 @@ void RsGxsNetService::locked_genSendGrpsTransaction(NxsTransaction* tr)
RsPeerId peerId = tr->mTransaction->PeerId();
for(;mit != grps.end(); ++mit)
{
#warning Should make sure that no private key information is sneaked in here for the grp
mit->second->PeerId(peerId); // set so it gets sent to right peer
mit->second->transactionNumber = transN;
newTr->mItems.push_back(mit->second);
@ -3691,11 +3692,11 @@ bool RsGxsNetService::encryptSingleNxsItem(RsNxsItem *item, const RsGxsCircleId&
#ifdef NXS_NET_DEBUG_7
GXSNETDEBUG_P_ (item->PeerId()) << " Dest Ids: " << std::endl;
#endif
std::vector<RsTlvSecurityKey> recipient_keys ;
std::vector<RsTlvPublicRSAKey> recipient_keys ;
for(std::list<RsGxsId>::const_iterator it(recipients.begin());it!=recipients.end();++it)
{
RsTlvSecurityKey pkey ;
RsTlvPublicRSAKey pkey ;
if(!mGixs->getKey(*it,pkey))
{
@ -3767,7 +3768,7 @@ bool RsGxsNetService::processTransactionForDecryption(NxsTransaction *tr)
#endif
std::list<RsNxsItem*> decrypted_items ;
std::vector<RsTlvSecurityKey> private_keys ;
std::vector<RsTlvPrivateRSAKey> private_keys ;
// get all private keys. Normally we should look into the circle name and only supply the keys that we have
@ -3803,13 +3804,13 @@ bool RsGxsNetService::processTransactionForDecryption(NxsTransaction *tr)
return true ;
}
bool RsGxsNetService::decryptSingleNxsItem(const RsNxsEncryptedDataItem *encrypted_item, RsNxsItem *& nxsitem,std::vector<RsTlvSecurityKey> *pprivate_keys)
bool RsGxsNetService::decryptSingleNxsItem(const RsNxsEncryptedDataItem *encrypted_item, RsNxsItem *& nxsitem,std::vector<RsTlvPrivateRSAKey> *pprivate_keys)
{
// if private_keys storage is supplied use/update them, otherwise, find which key should be used, and store them in a local std::vector.
nxsitem = NULL ;
std::vector<RsTlvSecurityKey> local_keys ;
std::vector<RsTlvSecurityKey>& private_keys = pprivate_keys?(*pprivate_keys):local_keys ;
std::vector<RsTlvPrivateRSAKey> local_keys ;
std::vector<RsTlvPrivateRSAKey>& private_keys = pprivate_keys?(*pprivate_keys):local_keys ;
// we need the private keys to decrypt the item. First load them in!
bool key_loading_failed = false ;
@ -3825,7 +3826,7 @@ bool RsGxsNetService::decryptSingleNxsItem(const RsNxsEncryptedDataItem *encrypt
for(std::list<RsGxsId>::const_iterator it(own_keys.begin());it!=own_keys.end();++it)
{
RsTlvSecurityKey private_key ;
RsTlvPrivateRSAKey private_key ;
if(mGixs->getPrivateKey(*it,private_key))
{
@ -4879,9 +4880,9 @@ void RsGxsNetService::sharePublishKeysPending()
const RsTlvSecurityKeySet& keys = grpMeta->keys;
std::map<RsGxsId, RsTlvSecurityKey>::const_iterator kit = keys.keys.begin(), kit_end = keys.keys.end();
std::map<RsGxsId, RsTlvPrivateRSAKey>::const_iterator kit = keys.private_keys.begin(), kit_end = keys.private_keys.end();
bool publish_key_found = false;
RsTlvSecurityKey publishKey ;
RsTlvPrivateRSAKey publishKey ;
for(; kit != kit_end && !publish_key_found; ++kit)
{
@ -4907,7 +4908,7 @@ void RsGxsNetService::sharePublishKeysPending()
publishKeyItem->clear();
publishKeyItem->grpId = mit->first;
publishKeyItem->key = publishKey ;
publishKeyItem->private_key = publishKey ;
publishKeyItem->PeerId(*it);
sendItem(publishKeyItem);
@ -4931,7 +4932,7 @@ void RsGxsNetService::sharePublishKeysPending()
void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
{
#ifdef NXS_NET_DEBUG_3
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << "RsGxsNetService::sharePublishKeys() " << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << "RsGxsNetService::sharePublishKeys() " << std::endl;
#endif
if (!item)
@ -4940,62 +4941,61 @@ void RsGxsNetService::handleRecvPublishKeys(RsNxsGroupPublishKeyItem *item)
RS_STACK_MUTEX(mNxsMutex) ;
#ifdef NXS_NET_DEBUG_3
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " PeerId : " << item->PeerId() << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " GrpId: " << item->grpId << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " Got key Item: " << item->key.keyId << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " PeerId : " << item->PeerId() << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " GrpId: " << item->grpId << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId) << " Got key Item: " << item->key.keyId << std::endl;
#endif
// Get the meta data for this group Id
//
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap;
grpMetaMap[item->grpId] = NULL;
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
// Get the meta data for this group Id
//
RsGxsMetaDataTemporaryMap<RsGxsGrpMetaData> grpMetaMap;
grpMetaMap[item->grpId] = NULL;
// update the publish keys in this group meta info
mDataStore->retrieveGxsGrpMetaData(grpMetaMap);
RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ;
// update the publish keys in this group meta info
// Check that the keys correspond, and that FULL keys are supplied, etc.
RsGxsGrpMetaData *grpMeta = grpMetaMap[item->grpId] ;
// Check that the keys correspond, and that FULL keys are supplied, etc.
#ifdef NXS_NET_DEBUG_3
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " Key received: " << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " Key received: " << std::endl;
#endif
bool admin = (item->key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN) && (item->key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
bool publi = (item->key.keyFlags & RSTLV_KEY_DISTRIB_PUBLISH) && (item->key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
bool admin = (item->private_key.keyFlags & RSTLV_KEY_DISTRIB_ADMIN) && (item->private_key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
bool publi = (item->private_key.keyFlags & RSTLV_KEY_DISTRIB_PUBLISH) && (item->private_key.keyFlags & RSTLV_KEY_TYPE_FULL) ;
#ifdef NXS_NET_DEBUG_3
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " Key id = " << item->key.keyId << " admin=" << admin << ", publish=" << publi << " ts=" << item->key.endTS << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " Key id = " << item->key.keyId << " admin=" << admin << ", publish=" << publi << " ts=" << item->key.endTS << std::endl;
#endif
if(!(!admin && publi))
{
std::cerr << " Key is not a publish private key. Discarding!" << std::endl;
return ;
}
// Also check that we don't already have full keys for that group.
std::map<RsGxsId,RsTlvSecurityKey>::iterator it = grpMeta->keys.keys.find(item->key.keyId) ;
if(!(!admin && publi))
{
std::cerr << " Key is not a publish private key. Discarding!" << std::endl;
return ;
}
// Also check that we don't already have full keys for that group.
if(it == grpMeta->keys.keys.end())
{
std::cerr << " (EE) Key not found in known group keys. This is an inconsistency." << std::endl;
return ;
}
if(grpMeta->keys.public_keys.find(item->private_key.keyId) == grpMeta->keys.public_keys.end())
{
std::cerr << " (EE) Key not found in known group keys. This is an inconsistency." << std::endl;
return ;
}
if((it->second.keyFlags & RSTLV_KEY_DISTRIB_PUBLISH) && (it->second.keyFlags & RSTLV_KEY_TYPE_FULL))
{
if(grpMeta->keys.private_keys.find(item->private_key.keyId) != grpMeta->keys.private_keys.end())
{
#ifdef NXS_NET_DEBUG_3
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " (EE) Publish key already present in database. Discarding message." << std::endl;
GXSNETDEBUG_PG(item->PeerId(),item->grpId)<< " (EE) Publish key already present in database. Discarding message." << std::endl;
#endif
return ;
}
return ;
}
// Store/update the info.
// Store/update the info.
it->second = item->key ;
bool ret = mDataStore->updateGroupKeys(item->grpId,grpMeta->keys, grpMeta->mSubscribeFlags | GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) ;
grpMeta->keys.private_keys[item->private_key.keyId] = item->private_key ;
bool ret = mDataStore->updateGroupKeys(item->grpId,grpMeta->keys, grpMeta->mSubscribeFlags | GXS_SERV::GROUP_SUBSCRIBE_PUBLISH) ;
if(ret)
{

View File

@ -457,7 +457,7 @@ private:
* encrypts/decrypts the transaction for the destination circle id.
*/
bool encryptSingleNxsItem(RsNxsItem *item, const RsGxsCircleId& destination_circle, const RsGxsGroupId &destination_group, RsNxsItem *& encrypted_item, uint32_t &status) ;
bool decryptSingleNxsItem(const RsNxsEncryptedDataItem *encrypted_item, RsNxsItem *&nxsitem, std::vector<RsTlvSecurityKey> *private_keys=NULL);
bool decryptSingleNxsItem(const RsNxsEncryptedDataItem *encrypted_item, RsNxsItem *&nxsitem, std::vector<RsTlvPrivateRSAKey> *private_keys=NULL);
bool processTransactionForDecryption(NxsTransaction *tr); // return false when the keys are not loaded => need retry later
void cleanRejectedMessages();

View File

@ -89,11 +89,14 @@ bool RsGxsMessageCleanUp::clean()
remove &= !(meta->mMsgStatus & GXS_SERV::GXS_MSG_STATUS_KEEP);
// if not subscribed remove messages (can optimise this really)
remove = remove || (grpMeta->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED);
remove = remove || (grpMeta->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED);
remove = remove || !(grpMeta->mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED);
if( remove )
{
req[grpId].push_back(meta->mMsgId);
std::cerr << "Scheduling msg id " << meta->mMsgId << " in grp " << grpId << " for removal." << std::endl;
}
delete meta;

View File

@ -890,7 +890,7 @@ void p3GxsTunnelService::handleRecvDHPublicKey(RsGxsTunnelDHPublicKeyItem *item)
RsTemporaryMemory data(pubkey_size) ;
BN_bn2bin(item->public_key, data) ;
RsTlvSecurityKey signature_key ;
RsTlvPublicRSAKey signature_key ;
// We need to get the key of the sender, but if the key is not cached, we
// need to get it first. So we let the system work for 2-3 seconds before
@ -1059,9 +1059,9 @@ bool p3GxsTunnelService::locked_sendDHPublicKey(const DH *dh,const RsGxsId& own_
// we should also sign the data and check the signature on the other end.
//
RsTlvKeySignature signature ;
RsTlvSecurityKey signature_key ;
RsTlvSecurityKey signature_key_public ;
RsTlvKeySignature signature ;
RsTlvPrivateRSAKey signature_key ;
RsTlvPublicRSAKey signature_key_public ;
uint32_t error_status ;

View File

@ -146,7 +146,7 @@ class RsGxsTunnelDHPublicKeyItem: public RsGxsTunnelItem
BIGNUM *public_key ;
RsTlvKeySignature signature ; // signs the public key in a row.
RsTlvSecurityKey gxs_key ; // public key of the signer
RsTlvPublicRSAKey gxs_key ; // public key of the signer
private:
// make the object non copy-able

View File

@ -266,7 +266,7 @@ int BinEncryptedFileInterface::readdata(void* data, int len)
}
if(len <= sizeData)
if((uint64_t)len <= sizeData)
{
memcpy(data, this->data, len);
cpyCount += len;

View File

@ -696,7 +696,7 @@ int pqistreamer::handleincoming_locked()
allocate_rpend_locked();
// enough space to read any packet.
int maxlen = mPkt_rpend_size;
uint32_t maxlen = mPkt_rpend_size;
void *block = mPkt_rpending;
// initial read size: basic packet.
@ -812,7 +812,7 @@ continue_packet:
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet state=" << mReading_state << std::endl ;
std::cerr << "[" << (void*)pthread_self() << "] " << "block 1 : " << RsUtil::BinToHex(block,8) << std::endl;
#endif
if (extralen > maxlen - blen)
if (extralen + (uint32_t)blen > maxlen)
{
pqioutput(PQL_ALERT, pqistreamerzone, "ERROR: Read Packet too Big!");

View File

@ -102,6 +102,7 @@ namespace GXS_SERV {
// GENERIC GXS MACROS
#define IS_MSG_NEW(status) (status & GXS_SERV::GXS_MSG_STATUS_GUI_NEW)
#define IS_MSG_UNREAD(status) (status & GXS_SERV::GXS_MSG_STATUS_GUI_UNREAD)
#define IS_MSG_UNPROCESSED(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
#define IS_GROUP_PGP_AUTHED(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_GPG)
#define IS_GROUP_MESSAGE_TRACKING(signFlags) (signFlags & GXS_SERV::FLAG_AUTHOR_AUTHENTICATION_TRACK_MESSAGES)
@ -111,7 +112,4 @@ namespace GXS_SERV {
#define IS_GROUP_SUBSCRIBED(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_SUBSCRIBED)
#define IS_GROUP_NOT_SUBSCRIBED(subscribeFlags) (subscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_NOT_SUBSCRIBED)
#define IS_MSG_UNPROCESSED(status) (status & GXS_SERV::GXS_MSG_STATUS_UNPROCESSED)
#endif // RSGXSFLAGS_H

View File

@ -69,6 +69,7 @@ static const uint32_t RS_IDENTITY_FLAGS_IS_A_CONTACT = 0x0001;
static const uint32_t RS_IDENTITY_FLAGS_PGP_LINKED = 0x0002;
static const uint32_t RS_IDENTITY_FLAGS_PGP_KNOWN = 0x0004;
static const uint32_t RS_IDENTITY_FLAGS_IS_OWN_ID = 0x0008;
static const uint32_t RS_IDENTITY_FLAGS_IS_DEPRECATED= 0x0010; // used to denote keys with deprecated fingerprint format.
class GxsReputation
{

View File

@ -1383,13 +1383,20 @@ FileSearchFlags p3Peers::computePeerPermissionFlags(const RsPeerId& peer_ssl_id,
RsPeerDetails::RsPeerDetails()
:isOnlyGPGdetail(false),
name(""),email(""),location(""),
org(""),authcode(""),
trustLvl(0), validLvl(0),ownsign(false),
hasSignedMe(false),accept_connection(false),
state(0),localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),vs_disc(0), vs_dht(0),
lastConnect(0),connectState(0),connectStateString(""),connectPeriod(0),
hiddenType(RS_HIDDEN_TYPE_NONE), foundDHT(false), wasDeniedConnection(false), deniedTS(0)
name(""),email(""),location(""),
org(""),authcode(""),
trustLvl(0), validLvl(0),ownsign(false),
hasSignedMe(false),accept_connection(false),
state(0),actAsServer(false),
connectPort(0),
isHiddenNode(false),
hiddenNodePort(0),
hiddenType(RS_HIDDEN_TYPE_NONE),
localAddr(""),localPort(0),extAddr(""),extPort(0),netMode(0),vs_disc(0), vs_dht(0),
lastConnect(0),lastUsed(0),connectState(0),connectStateString(""),
connectPeriod(0),
foundDHT(false), wasDeniedConnection(false), deniedTS(0),
linkType ( RS_NET_CONN_TRANS_TCP_UNKNOWN)
{
}

View File

@ -7,12 +7,15 @@
#if defined(HAS_GNOME_KEYRING) || defined(__FreeBSD__) || defined(__OpenBSD__)
#include <gnome-keyring-1/gnome-keyring.h>
GnomeKeyringPasswordSchema my_schema = {
GNOME_KEYRING_ITEM_ENCRYPTION_KEY_PASSWORD,
{
{ "RetroShare SSL Id", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ NULL, (GnomeKeyringAttributeType)0 }
}
GnomeKeyringPasswordSchema my_schema = {
GNOME_KEYRING_ITEM_ENCRYPTION_KEY_PASSWORD,
{
{ "RetroShare SSL Id", GNOME_KEYRING_ATTRIBUTE_TYPE_STRING },
{ NULL, (GnomeKeyringAttributeType)0 }
},
NULL,
NULL,
NULL
};
#endif

View File

@ -117,7 +117,7 @@ virtual void clear();
std::ostream &print(std::ostream &out, uint16_t indent = 0);
RsTlvServiceIdSet signing_classes;
RsTlvSecurityKey key; // has from->to, and flags.
RsTlvPublicRSAKey key; // has from->to, and flags.
RsTlvKeySignature sign;
};

View File

@ -403,7 +403,7 @@ bool RsNxsGroupPublishKeyItem::serialise(void *data, uint32_t& size) const
return false ;
ok &= grpId.serialise(data, size, offset) ;
ok &= key.SetTlv(data, size, &offset) ;
ok &= private_key.SetTlv(data, size, &offset) ;
if(offset != tlvsize)
{
@ -813,7 +813,7 @@ RsNxsGroupPublishKeyItem* RsNxsSerialiser::deserialNxsGroupPublishKeyItem(void *
RsNxsGroupPublishKeyItem* item = new RsNxsGroupPublishKeyItem(SERVICE_TYPE);
ok &= item->grpId.deserialise(data, *size, offset);
ok &= item->key.GetTlv(data, *size, &offset) ;
ok &= item->private_key.GetTlv(data, *size, &offset) ;
if (offset != *size)
{
@ -959,7 +959,7 @@ uint32_t RsNxsGroupPublishKeyItem::serial_size() const
uint32_t s = 8; // header size
s += grpId.serial_size() ;
s += key.TlvSize();
s += private_key.TlvSize();
return s;
}
@ -1093,7 +1093,7 @@ void RsNxsSyncGrpReqItem::clear()
}
void RsNxsGroupPublishKeyItem::clear()
{
key.TlvClear();
private_key.TlvClear();
}
void RsNxsSyncMsgReqItem::clear()
{
@ -1165,7 +1165,7 @@ std::ostream& RsNxsGroupPublishKeyItem::print(std::ostream &out, uint16_t indent
printIndent(out , int_Indent);
out << "GroupId: " << grpId << std::endl;
printIndent(out , int_Indent);
out << "keyId: " << key.keyId << std::endl;
out << "keyId: " << private_key.keyId << std::endl;
printRsItemEnd(out ,"RsNxsGroupPublishKeyItem", indent);
@ -1239,7 +1239,7 @@ RsNxsGrp* RsNxsGrp::clone() const {
if(this->metaData)
{
grp->metaData = new RsGxsGrpMetaData();
*(grp->metaData) = *(this->metaData);
// *(grp->metaData) = *(this->metaData);
}
return grp;

View File

@ -157,7 +157,7 @@ public:
virtual uint32_t serial_size() const;
RsGxsGroupId grpId ;
RsTlvSecurityKey key ;
RsTlvPrivateRSAKey private_key ;
};
@ -330,9 +330,12 @@ public:
* This should contains all data
* which is not specific to the Gxs service data
*/
// This is the binary data for the group meta that is sent to friends. It *should not* contain any private
// key parts. This is ensured in RsGenExchange
RsTlvBinaryData meta;
// deserialised metaData, this is not serialised
// Deserialised metaData, this is not serialised by the serialize() method. So it may contain private key parts in some cases.
RsGxsGrpMetaData* metaData;
};

View File

@ -207,12 +207,16 @@ const uint16_t TLV_TYPE_GXSCIRCLEIDSET= 0x1026;
const uint16_t TLV_TYPE_SERVICESET = 0x1030;
const uint16_t TLV_TYPE_SECURITYKEY = 0x1040;
const uint16_t TLV_TYPE_SECURITYKEYSET= 0x1041;
// *_deprectate should not be used anymore!!
// We use 1040 for both public and private keys, so that transmitting them still works (backward compatibility), and so that
// signatures are kept. But the two different classes will check that the flags are correct when deserialising.
const uint16_t TLV_TYPE_KEYSIGNATURE = 0x1050;
const uint16_t TLV_TYPE_SECURITY_KEY = 0x1040;
const uint16_t TLV_TYPE_SECURITYKEYSET = 0x1041;
const uint16_t TLV_TYPE_KEYSIGNATURE = 0x1050;
const uint16_t TLV_TYPE_KEYSIGNATURESET = 0x1051;
const uint16_t TLV_TYPE_KEYSIGNATURETYPE = 0x1052;
const uint16_t TLV_TYPE_KEYSIGNATURETYPE = 0x1052;
const uint16_t TLV_TYPE_IMAGE = 0x1060;

View File

@ -27,6 +27,8 @@
#include "rstlvkeys.h"
#include "rstlvbase.h"
#include "rsbaseserial.h"
#include "util/stacktrace.h"
#include "gxs/gxssecurity.h"
#include <iostream>
@ -37,13 +39,13 @@
/************************************* RsTlvSecurityKey ************************************/
RsTlvSecurityKey::RsTlvSecurityKey()
RsTlvRSAKey::RsTlvRSAKey()
:RsTlvItem(), keyFlags(0), startTS(0), endTS(0), keyData(TLV_TYPE_KEY_EVP_PKEY)
{
return;
}
void RsTlvSecurityKey::TlvClear()
void RsTlvRSAKey::TlvClear()
{
keyId.clear();
keyFlags = 0;
@ -53,7 +55,7 @@ void RsTlvSecurityKey::TlvClear()
}
/* clears keyData - but doesn't delete */
void RsTlvSecurityKey::ShallowClear()
void RsTlvRSAKey::ShallowClear()
{
keyId.clear();
keyFlags = 0;
@ -63,8 +65,7 @@ void RsTlvSecurityKey::ShallowClear()
keyData.bin_len = 0;
}
uint32_t RsTlvSecurityKey::TlvSize() const
uint32_t RsTlvRSAKey::TlvSize() const
{
uint32_t s = TLV_HEADER_SIZE; /* header + 4 for size */
@ -81,10 +82,9 @@ uint32_t RsTlvSecurityKey::TlvSize() const
s += keyData.TlvSize();
return s;
}
bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) const
bool RsTlvRSAKey::SetTlv(void *data, uint32_t size, uint32_t *offset) const
{
/* must check sizes */
uint32_t tlvsize = TlvSize();
@ -92,20 +92,17 @@ bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) cons
if (size < tlvend)
{
//#ifdef TLV_DEBUG
std::cerr << "RsTlvSecurityKey::SetTlv() Failed not enough space";
std::cerr << std::endl;
//#endif
return false; /* not enough space */
}
bool ok = true;
bool ok = checkKey(); // check before serialise, just in case
/* start at data[offset] */
/* add mandatory parts first */
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_SECURITYKEY, tlvsize);
ok &= SetTlvBase(data, tlvend, offset, TLV_TYPE_SECURITY_KEY, tlvsize);
#ifdef KEEP_OLD_SIGNATURE_SERIALISE_FORMAT
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEYID, keyId.toStdString());
#else
@ -120,8 +117,7 @@ bool RsTlvSecurityKey::SetTlv(void *data, uint32_t size, uint32_t *offset) cons
}
bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
bool RsTlvRSAKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
{
if (size < *offset + TLV_HEADER_SIZE)
return false;
@ -139,7 +135,7 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
return false; /* not enough space */
}
if (tlvtype != TLV_TYPE_SECURITYKEY) /* check type */
if (tlvtype != TLV_TYPE_SECURITY_KEY) /* check type */
{
#ifdef TLV_DEBUG
std::cerr << "RsTlvSecurityKey::GetTlv() Fail, wrong type";
@ -155,7 +151,6 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
/* skip the header */
(*offset) += TLV_HEADER_SIZE;
#ifdef KEEP_OLD_SIGNATURE_SERIALISE_FORMAT
std::string s ;
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_KEYID, s);
@ -167,7 +162,6 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
ok &= getRawUInt32(data, tlvend, offset, &(startTS));
ok &= getRawUInt32(data, tlvend, offset, &(endTS));
ok &= keyData.GetTlv(data, tlvend, offset);
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
@ -191,12 +185,10 @@ bool RsTlvSecurityKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
std::cerr << std::endl;
#endif
}
return ok;
return ok && checkKey() ;
}
std::ostream &RsTlvSecurityKey::print(std::ostream &out, uint16_t indent) const
std::ostream& RsTlvRSAKey::print(std::ostream &out, uint16_t indent) const
{
printBase(out, "RsTlvSecurityKey", indent);
uint16_t int_Indent = indent + 2;
@ -226,14 +218,25 @@ std::ostream &RsTlvSecurityKey::print(std::ostream &out, uint16_t indent) const
}
bool RsTlvPrivateRSAKey::checkKey() const
{
return bool(keyFlags & RSTLV_KEY_TYPE_FULL) && !bool(keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY) && GxsSecurity::checkPrivateKey(*this) ;
}
bool RsTlvPublicRSAKey::checkKey() const
{
return bool(keyFlags & RSTLV_KEY_TYPE_PUBLIC_ONLY) && !bool(keyFlags & RSTLV_KEY_TYPE_FULL) && GxsSecurity::checkPublicKey(*this) ;
}
/************************************* RsTlvSecurityKeySet ************************************/
void RsTlvSecurityKeySet::TlvClear()
{
groupId.clear();
keys.clear(); //empty list
#ifdef TODO
public_keys.clear(); //empty list
private_keys.clear(); //empty list
#endif
}
uint32_t RsTlvSecurityKeySet::TlvSize() const
@ -241,17 +244,13 @@ uint32_t RsTlvSecurityKeySet::TlvSize() const
uint32_t s = TLV_HEADER_SIZE; /* header */
std::map<RsGxsId, RsTlvSecurityKey>::const_iterator it;
s += GetTlvStringSize(groupId);
if(!keys.empty())
{
for(it = keys.begin(); it != keys.end() ; ++it)
s += (it->second).TlvSize();
}
for(std::map<RsGxsId, RsTlvPublicRSAKey>::const_iterator it = public_keys.begin(); it != public_keys.end() ; ++it)
s += (it->second).TlvSize();
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::const_iterator it = private_keys.begin(); it != private_keys.end() ; ++it)
s += (it->second).TlvSize();
return s;
}
@ -279,17 +278,13 @@ bool RsTlvSecurityKeySet::SetTlv(void *data, uint32_t size, uint32_t *offset) c
/* groupId */
ok &= SetTlvString(data, tlvend, offset, TLV_TYPE_STR_GROUPID, groupId);
if(!keys.empty())
{
std::map<RsGxsId, RsTlvSecurityKey>::const_iterator it;
for(it = keys.begin(); it != keys.end() ; ++it)
for(std::map<RsGxsId, RsTlvPublicRSAKey>::const_iterator it = public_keys.begin(); it != public_keys.end() ; ++it)
ok &= (it->second).SetTlv(data, size, offset);
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::const_iterator it = private_keys.begin(); it != private_keys.end() ; ++it)
ok &= (it->second).SetTlv(data, size, offset);
}
return ok;
return ok;
}
@ -319,37 +314,48 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset)
/* groupId */
ok &= GetTlvString(data, tlvend, offset, TLV_TYPE_STR_GROUPID, groupId);
/* while there is TLV */
while((*offset) + 2 < tlvend)
{
/* get the next type */
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
/* while there is TLV */
while((*offset) + 2 < tlvend)
{
/* get the next type */
uint16_t tlvsubtype = GetTlvType( &(((uint8_t *) data)[*offset]) );
switch(tlvsubtype)
{
case TLV_TYPE_SECURITYKEY:
// Security key set can be composed of public or private keys. We sort them into the correct bins after deserialisation
switch(tlvsubtype)
{
case TLV_TYPE_SECURITY_KEY:
{
uint32_t offset_save = *offset ;
RsTlvPublicRSAKey public_key;
if(public_key.GetTlv(data, tlvend, offset))
public_keys[public_key.keyId] = public_key;
else
{
RsTlvSecurityKey key;
ok &= key.GetTlv(data, size, offset);
if (ok)
{
keys[key.keyId] = key;
key.TlvClear(); /* so that the Map can get control - should be ref counted*/
}
*offset = offset_save ;
RsTlvPrivateRSAKey private_key;
if(private_key.GetTlv(data, tlvend, offset))
private_keys[private_key.keyId] = private_key;
}
break;
default:
ok &= SkipUnknownTlv(data, tlvend, offset);
break;
}
break ;
}
default:
ok &= SkipUnknownTlv(data, tlvend, offset);
break;
if (!ok)
}
if (!ok)
break;
}
/***************************************************************************
* NB: extra components could be added (for future expansion of the type).
* or be present (if this code is reading an extended version).
@ -368,6 +374,7 @@ bool RsTlvSecurityKeySet::GetTlv(void *data, uint32_t size, uint32_t *offset)
return ok;
}
// prints out contents of RsTlvSecurityKeySet
std::ostream &RsTlvSecurityKeySet::print(std::ostream &out, uint16_t indent) const
{
@ -378,8 +385,9 @@ std::ostream &RsTlvSecurityKeySet::print(std::ostream &out, uint16_t indent) con
out << "GroupId: " << groupId;
out << std::endl;
std::map<RsGxsId, RsTlvSecurityKey>::const_iterator it;
for(it = keys.begin(); it != keys.end() ; ++it)
for( std::map<RsGxsId, RsTlvPublicRSAKey>::const_iterator it = public_keys.begin(); it != public_keys.end() ; ++it)
(it->second).print(out, int_Indent);
for( std::map<RsGxsId, RsTlvPrivateRSAKey>::const_iterator it = private_keys.begin(); it != private_keys.end() ; ++it)
(it->second).print(out, int_Indent);
printEnd(out, "RsTlvSecurityKeySet", indent);
@ -709,3 +717,23 @@ uint32_t RsTlvKeySignatureSet::TlvSize() const
return s;
}

View File

@ -31,6 +31,7 @@
#include "serialiser/rstlvitem.h"
#include "serialiser/rstlvbinary.h"
#include "serialiser/rstlvbase.h"
#include "retroshare/rsgxsifacetypes.h"
#include <map>
@ -46,41 +47,66 @@ const uint32_t RSTLV_KEY_DISTRIB_ADMIN = 0x0040;
const uint32_t RSTLV_KEY_DISTRIB_IDENTITY = 0x0080;
const uint32_t RSTLV_KEY_DISTRIB_MASK = 0x00f0;
class RsTlvSecurityKey: public RsTlvItem
// Old class for RsTlvSecurityKey. Is kept for backward compatibility, but should not be serialised anymore
class RsTlvRSAKey: public RsTlvItem
{
public:
RsTlvRSAKey();
virtual bool checkKey() const = 0 ; // this pure virtual forces people to explicitly declare if they use a public or a private key.
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream& print(std::ostream &out, uint16_t indent) const;
/* clears KeyData - but doesn't delete - to transfer ownership */
void ShallowClear();
RsGxsId keyId; // Mandatory :
uint32_t keyFlags; // Mandatory ;
uint32_t startTS; // Mandatory :
uint32_t endTS; // Mandatory :
RsTlvBinaryData keyData; // Mandatory :
};
// The two classes below are by design incompatible, making it impossible to pass a private key as a public key
class RsTlvPrivateRSAKey: public RsTlvRSAKey
{
public:
virtual ~RsTlvPrivateRSAKey() {}
virtual bool checkKey() const ;
};
class RsTlvPublicRSAKey: public RsTlvRSAKey
{
public:
RsTlvSecurityKey();
virtual ~RsTlvSecurityKey() {}
virtual ~RsTlvPublicRSAKey() {}
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
/* clears KeyData - but doesn't delete - to transfer ownership */
void ShallowClear();
RsGxsId keyId; // Mandatory :
uint32_t keyFlags; // Mandatory ;
uint32_t startTS; // Mandatory :
uint32_t endTS; // Mandatory :
RsTlvBinaryData keyData; // Mandatory :
virtual bool checkKey() const ;
};
class RsTlvSecurityKeySet: public RsTlvItem
{
public:
RsTlvSecurityKeySet() { return; }
virtual ~RsTlvSecurityKeySet() { return; }
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
public:
RsTlvSecurityKeySet() { return; }
virtual ~RsTlvSecurityKeySet() { return; }
// creates the public keys that are possible missing although the private keys are present.
void createPublicFromPrivateKeys();
virtual uint32_t TlvSize() const;
virtual void TlvClear();
virtual bool SetTlv(void *data, uint32_t size, uint32_t *offset) const;
virtual bool GetTlv(void *data, uint32_t size, uint32_t *offset);
virtual std::ostream &print(std::ostream &out, uint16_t indent) const;
std::string groupId; // Mandatory :
std::map<RsGxsId, RsTlvSecurityKey> keys; // Mandatory :
std::string groupId; // Mandatory :
std::map<RsGxsId, RsTlvPublicRSAKey> public_keys; // Mandatory :
std::map<RsGxsId, RsTlvPrivateRSAKey> private_keys; // Mandatory :
};

View File

@ -1062,6 +1062,7 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
/* check cache */
if(!(pit->second.subscription_flags & GXS_EXTERNAL_CIRCLE_FLAGS_KEY_AVAILABLE))
{
if(mIdentities->haveKey(pit->first))
{
pit->second.subscription_flags |= GXS_EXTERNAL_CIRCLE_FLAGS_KEY_AVAILABLE;
@ -1070,26 +1071,27 @@ bool p3GxsCircles::locked_processLoadingCacheEntry(RsGxsCircleCache& cache)
#endif
}
else
{
std::list<PeerId> peers;
{
std::list<PeerId> peers;
if(!cache.mOriginator.isNull())
{
peers.push_back(cache.mOriginator) ;
if(!cache.mOriginator.isNull())
{
peers.push_back(cache.mOriginator) ;
#ifdef DEBUG_CIRCLES
std::cerr << " Requesting unknown/unloaded identity: " << pit->first << " to originator " << cache.mOriginator << std::endl;
std::cerr << " Requesting unknown/unloaded identity: " << pit->first << " to originator " << cache.mOriginator << std::endl;
#endif
}
else
{
std::cerr << " (WW) cache entry for circle " << cache.mCircleId << " has empty originator. Asking info for GXS id " << pit->first << " to all connected friends." << std::endl;
}
else
{
std::cerr << " (WW) cache entry for circle " << cache.mCircleId << " has empty originator. Asking info for GXS id " << pit->first << " to all connected friends." << std::endl;
rsPeers->getOnlineList(peers) ;
}
rsPeers->getOnlineList(peers) ;
}
mIdentities->requestKey(pit->first, peers);
//isUnprocessedPeers = true;
}
mIdentities->requestKey(pit->first, peers);
//isUnprocessedPeers = true;
}
}
#ifdef DEBUG_CIRCLES
else
std::cerr << " Key is available. Nothing to process." << std::endl;

View File

@ -152,8 +152,7 @@ RsIdentity *rsIdentity = NULL;
p3IdService::p3IdService(RsGeneralDataService *gds, RsNetworkExchangeService *nes, PgpAuxUtils *pgpUtils)
: RsGxsIdExchange(gds, nes, new RsGxsIdSerialiser(), RS_SERVICE_GXS_TYPE_GXSID, idAuthenPolicy()),
RsIdentity(this), GxsTokenQueue(this), RsTickEvent(),
mPublicKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdPublicKeyCache"),
mPrivateKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdPrivateKeyCache"),
mKeyCache(GXSID_MAX_CACHE_SIZE, "GxsIdKeyCache"),
mIdMtx("p3IdService"), mNes(nes),
mPgpUtils(pgpUtils)
{
@ -401,11 +400,11 @@ void p3IdService::cleanUnusedKeys()
int n=0 ;
IdCacheEntryCleaner idcec(mKeysTS) ;
mPublicKeyCache.applyToAllCachedEntries(idcec,&IdCacheEntryCleaner::processEntry);
mKeyCache.applyToAllCachedEntries(idcec,&IdCacheEntryCleaner::processEntry);
ids_to_delete = idcec.ids_to_delete ;
}
std::cerr << "Collected " << ids_to_delete.size() << " keys to delete among " << mPublicKeyCache.size() << std::endl;
std::cerr << "Collected " << ids_to_delete.size() << " keys to delete among " << mKeyCache.size() << std::endl;
for(std::list<RsGxsId>::const_iterator it(ids_to_delete.begin());it!=ids_to_delete.end();++it)
{
@ -520,37 +519,28 @@ bool p3IdService:: getIdDetails(const RsGxsId &id, RsIdentityDetails &details)
std::cerr << std::endl;
#endif
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
if (mPublicKeyCache.fetch(id, data))
{
details = data.details;
details.mLastUsageTS = locked_getLastUsageTS(id) ;
// one utf8 symbol can be at most 4 bytes long - would be better to measure real unicode length !!!
if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4)
details.mNickname = "[too long a name]" ;
rsReputations->getReputationInfo(id,details.mReputation) ;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
return true;
}
RsGxsIdCache data;
/* try private cache too */
if (mPrivateKeyCache.fetch(id, data))
{
details = data.details;
details.mLastUsageTS = locked_getLastUsageTS(id) ;
rsReputations->getReputationInfo(id,details.mReputation) ;
return true;
}
}
if (mKeyCache.fetch(id, data))
{
details = data.details;
details.mLastUsageTS = locked_getLastUsageTS(id) ;
// one utf8 symbol can be at most 4 bytes long - would be better to measure real unicode length !!!
if(details.mNickname.length() > RSID_MAXIMUM_NICKNAME_SIZE*4)
details.mNickname = "[too long a name]" ;
rsReputations->getReputationInfo(id,details.mReputation) ;
return true;
}
}
/* it isn't there - add to public requests */
cache_request_load(id);
cache_request_load(id);
return false;
}
@ -661,35 +651,24 @@ bool p3IdService::getRecognTagRequest(const RsGxsId &id, const std::string &comm
std::cerr << "p3IdService::getRecognTagRequest()";
std::cerr << std::endl;
#endif
if (!havePrivateKey(id))
if(!isOwnId(id))
{
#ifdef DEBUG_RECOGN
std::cerr << "p3IdService::getRecognTagRequest() Dont have private key";
std::cerr << std::endl;
#endif
// attempt to load it.
cache_request_load(id);
return false;
std::cerr << "(EE) cannot retrieve own key to create tag request. KeyId=" << id << std::endl;
return false ;
}
RsTlvSecurityKey key;
RsTlvPrivateRSAKey key;
std::string nickname;
RsGxsIdCache data ;
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
if (!mPrivateKeyCache.fetch(id, data))
{
#ifdef DEBUG_RECOGN
std::cerr << "p3IdService::getRecognTagRequest() Cache failure";
std::cerr << std::endl;
#endif
return false;
}
key = data.pubkey;
nickname = data.details.mNickname;
if(!mKeyCache.fetch(id, data))
return false ;
nickname = data.details.mNickname ;
key = data.priv_key ;
}
return RsRecogn::createTagRequest(key, id, nickname, tag_class, tag_type, comment, tag);
@ -704,13 +683,16 @@ bool p3IdService::getRecognTagRequest(const RsGxsId &id, const std::string &comm
bool p3IdService::haveKey(const RsGxsId &id)
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
return mPublicKeyCache.is_cached(id);
return mKeyCache.is_cached(id);
}
bool p3IdService::havePrivateKey(const RsGxsId &id)
{
if(! isOwnId(id))
return false ;
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
return mPrivateKeyCache.is_cached(id);
return mKeyCache.is_cached(id) ;
}
bool p3IdService::requestKey(const RsGxsId &id, const std::list<PeerId> &peers)
@ -738,22 +720,23 @@ bool p3IdService::isPendingNetworkRequest(const RsGxsId& gxsId)
return false;
}
bool p3IdService::getKey(const RsGxsId &id, RsTlvSecurityKey &key)
bool p3IdService::getKey(const RsGxsId &id, RsTlvPublicRSAKey &key)
{
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
if (mPublicKeyCache.fetch(id, data))
{
key = data.pubkey;
return true;
}
}
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
cache_request_load(id);
if (mKeyCache.fetch(id, data))
{
key = data.pub_key;
return true;
}
}
key.keyId.clear() ;
return false;
cache_request_load(id);
key.keyId.clear() ;
return false;
}
bool p3IdService::requestPrivateKey(const RsGxsId &id)
@ -764,31 +747,29 @@ bool p3IdService::requestPrivateKey(const RsGxsId &id)
return cache_request_load(id);
}
bool p3IdService::getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key)
bool p3IdService::getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key)
{
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
if (mPrivateKeyCache.fetch(id, data))
{
key = data.pubkey;
return true;
}
}
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
key.keyId.clear() ;
cache_request_load(id);
if (mKeyCache.fetch(id, data))
{
key = data.priv_key;
return true;
}
}
return false ;
key.keyId.clear() ;
cache_request_load(id);
return false ;
}
bool p3IdService::signData(const uint8_t *data,uint32_t data_size,const RsGxsId& own_gxs_id,RsTlvKeySignature& signature,uint32_t& error_status)
{
//RsIdentityDetails details ;
RsTlvSecurityKey signature_key ;
//getIdDetails(own_gxs_id,details);
RsTlvPrivateRSAKey signature_key ;
int i ;
for(i=0;i<6;++i)
@ -827,7 +808,7 @@ bool p3IdService::validateData(const uint8_t *data,uint32_t data_size,const RsTl
{
// RsIdentityDetails details ;
// getIdDetails(signature.keyId,details);
RsTlvSecurityKey signature_key ;
RsTlvPublicRSAKey signature_key ;
for(int i=0;i< (force_load?6:1);++i)
if(!getKey(signature.keyId,signature_key) || signature_key.keyData.bin_data == NULL)
@ -862,7 +843,7 @@ bool p3IdService::validateData(const uint8_t *data,uint32_t data_size,const RsTl
}
bool p3IdService::encryptData(const uint8_t *decrypted_data,uint32_t decrypted_data_size,uint8_t *& encrypted_data,uint32_t& encrypted_data_size,const RsGxsId& encryption_key_id,bool force_load,uint32_t& error_status)
{
RsTlvSecurityKey encryption_key ;
RsTlvPublicRSAKey encryption_key ;
// get the key, and let the cache find it.
for(int i=0;i<(force_load?6:1);++i)
@ -892,7 +873,7 @@ bool p3IdService::encryptData(const uint8_t *decrypted_data,uint32_t decrypted_d
bool p3IdService::decryptData(const uint8_t *encrypted_data,uint32_t encrypted_data_size,uint8_t *& decrypted_data,uint32_t& decrypted_size,const RsGxsId& key_id,uint32_t& error_status)
{
RsTlvSecurityKey encryption_key ;
RsTlvPrivateRSAKey encryption_key ;
// Get the key, and let the cache find it. It's our own key, so we should be able to find it, even if it takes
// some seconds.
@ -952,7 +933,8 @@ bool p3IdService::getReputation(const RsGxsId &id, GixsReputation &rep)
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache data;
if (mPublicKeyCache.fetch(id, data))
if (mKeyCache.fetch(id, data))
{
rep.id = id;
rep.score = 0;//data.details.mReputation.mOverallScore;
@ -1217,24 +1199,24 @@ bool p3IdService::createGroup(uint32_t& token, RsGxsIdGroup &group)
return true;
}
bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
{
RsGxsId id(group.mMeta.mGroupId);
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
RsGxsId id(group.mMeta.mGroupId);
RsGxsIdGroupItem* item = new RsGxsIdGroupItem();
item->fromGxsIdGroup(group,false) ;
item->fromGxsIdGroup(group,false) ;
#ifdef DEBUG_IDS
std::cerr << "p3IdService::updateGroup() Updating RsGxsId: " << id;
std::cerr << std::endl;
#endif
RsGenExchange::updateGroup(token, item);
RsGenExchange::updateGroup(token, item);
// if its in the cache - clear it.
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
if (mPublicKeyCache.erase(id))
if (mKeyCache.erase(id))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::updateGroup() Removed from PublicKeyCache";
@ -1246,21 +1228,6 @@ bool p3IdService::updateGroup(uint32_t& token, RsGxsIdGroup &group)
#ifdef DEBUG_IDS
std::cerr << "p3IdService::updateGroup() Not in PublicKeyCache";
std::cerr << std::endl;
#endif
}
if (mPrivateKeyCache.erase(id))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::updateGroup() Removed from PrivateKeyCache";
std::cerr << std::endl;
#endif
}
else
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::updateGroup() Not in PrivateKeyCache";
std::cerr << std::endl;
#endif
}
}
@ -1285,7 +1252,7 @@ bool p3IdService::deleteGroup(uint32_t& token, RsGxsIdGroup &group)
// if its in the cache - clear it.
{
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
if (mPublicKeyCache.erase(id))
if (mKeyCache.erase(id))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::deleteGroup() Removed from PublicKeyCache";
@ -1300,21 +1267,6 @@ bool p3IdService::deleteGroup(uint32_t& token, RsGxsIdGroup &group)
#endif
}
if (mPrivateKeyCache.erase(id))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::deleteGroup() Removed from PrivateKeyCache";
std::cerr << std::endl;
#endif
}
else
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::deleteGroup() Not in PrivateKeyCache";
std::cerr << std::endl;
#endif
}
std::list<RsGxsId>::iterator lit = std::find( mOwnIds.begin(), mOwnIds.end(), id);
if (lit != mOwnIds.end())
{
@ -1704,40 +1656,61 @@ std::string SSGxsIdGroup::save() const
*
*/
RsGxsIdCache::RsGxsIdCache()
{
return;
RsGxsIdCache::RsGxsIdCache() {}
RsGxsIdCache::RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pkey, const std::list<RsRecognTag> &tagList)
{
init(item,in_pkey,RsTlvPrivateRSAKey(),tagList) ;
}
RsGxsIdCache::RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvSecurityKey &in_pkey, const std::list<RsRecognTag> &tagList)
RsGxsIdCache::RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pkey, const RsTlvPrivateRSAKey& privkey, const std::list<RsRecognTag> &tagList)
{
// Save Keys.
pubkey = in_pkey;
init(item,in_pkey,privkey,tagList) ;
}
// Save Time for ServiceString comparisions.
mPublishTs = item->meta.mPublishTs;
void RsGxsIdCache::init(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pub_key, const RsTlvPrivateRSAKey& in_priv_key,const std::list<RsRecognTag> &tagList)
{
// Save Keys.
pub_key = in_pub_key;
priv_key = in_priv_key;
// Save Time for ServiceString comparisions.
mPublishTs = item->meta.mPublishTs;
// Save RecognTags.
mRecognTags = tagList;
// Save RecognTags.
mRecognTags = tagList;
details.mAvatar.copy((uint8_t *) item->mImage.binData.bin_data, item->mImage.binData.bin_len);
details.mAvatar.copy((uint8_t *) item->mImage.binData.bin_data, item->mImage.binData.bin_len);
// Fill in Details.
details.mNickname = item->meta.mGroupName;
details.mId = RsGxsId(item->meta.mGroupId);
// Fill in Details.
details.mNickname = item->meta.mGroupName;
details.mId = RsGxsId(item->meta.mGroupId);
#ifdef DEBUG_IDS
std::cerr << "RsGxsIdCache::RsGxsIdCache() for: " << details.mId;
std::cerr << std::endl;
std::cerr << "RsGxsIdCache::RsGxsIdCache() for: " << details.mId;
std::cerr << std::endl;
#endif // DEBUG_IDS
details.mFlags = 0 ;
if(item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) details.mFlags |= RS_IDENTITY_FLAGS_IS_OWN_ID;
if(item->meta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) details.mFlags |= RS_IDENTITY_FLAGS_PGP_LINKED;
details.mFlags = 0 ;
/* rest must be retrived from ServiceString */
updateServiceString(item->meta.mServiceString);
if(item->meta.mSubscribeFlags & GXS_SERV::GROUP_SUBSCRIBE_ADMIN) details.mFlags |= RS_IDENTITY_FLAGS_IS_OWN_ID;
if(item->meta.mGroupFlags & RSGXSID_GROUPFLAG_REALID) details.mFlags |= RS_IDENTITY_FLAGS_PGP_LINKED;
// do some tests
if(details.mFlags & RS_IDENTITY_FLAGS_IS_OWN_ID)
{
if(!priv_key.checkKey())
std::cerr << "(EE) Private key missing for own identity " << pub_key.keyId << std::endl;
}
if(!pub_key.checkKey())
std::cerr << "(EE) Public key missing for identity " << pub_key.keyId << std::endl;
if(!GxsSecurity::checkFingerprint(pub_key))
details.mFlags |= RS_IDENTITY_FLAGS_IS_DEPRECATED;
/* rest must be retrived from ServiceString */
updateServiceString(item->meta.mServiceString);
}
void RsGxsIdCache::updateServiceString(std::string serviceString)
@ -1951,6 +1924,7 @@ bool p3IdService::cache_process_recogntaginfo(const RsGxsIdGroupItem *item, std:
return true;
}
// Loads in the cache the group data from the given group item, retrieved from sqlite storage.
bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
{
@ -1963,56 +1937,42 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
/* extract key from keys */
RsTlvSecurityKeySet keySet;
RsTlvSecurityKey pubkey;
RsTlvSecurityKey fullkey;
RsTlvPublicRSAKey pubkey;
RsTlvPrivateRSAKey fullkey;
bool pub_key_ok = false;
bool full_key_ok = false;
RsGxsId id (item->meta.mGroupId.toStdString());
if (!getGroupKeys(RsGxsGroupId(id.toStdString()), keySet))
{
std::cerr << "p3IdService::cache_store() ERROR getting GroupKeys for: ";
std::cerr << item->meta.mGroupId;
std::cerr << std::endl;
std::cerr << "p3IdService::cache_store() ERROR getting GroupKeys for: "<< item->meta.mGroupId << std::endl;
return false;
}
std::map<RsGxsId, RsTlvSecurityKey>::iterator kit;
//std::cerr << "p3IdService::cache_store() KeySet is:";
//keySet.print(std::cerr, 10);
for (kit = keySet.keys.begin(); kit != keySet.keys.end(); ++kit)
{
for (std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator kit = keySet.private_keys.begin(); kit != keySet.private_keys.end(); ++kit)
if (kit->second.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_store() Found Admin Key";
std::cerr << std::endl;
#endif // DEBUG_IDS
/* save full key - if we have it */
if (kit->second.keyFlags & RSTLV_KEY_TYPE_FULL)
{
fullkey = kit->second;
full_key_ok = true;
if(GxsSecurity::extractPublicKey(fullkey,pubkey))
pub_key_ok = true ;
}
else
{
pubkey = kit->second;
pub_key_ok = true ;
}
/* cache public key always
* we don't need to check the keyFlags,
* as both FULL and PUBLIC_ONLY keys contain the PUBLIC key
*/
std::cerr << "p3IdService::cache_store() Found Admin Key" << std::endl;
#endif
fullkey = kit->second;
full_key_ok = true;
}
}
for (std::map<RsGxsId, RsTlvPublicRSAKey>::iterator kit = keySet.public_keys.begin(); kit != keySet.public_keys.end(); ++kit)
if (kit->second.keyFlags & RSTLV_KEY_DISTRIB_ADMIN)
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_store() Found Admin public Key" << std::endl;
#endif
pubkey = kit->second;
pub_key_ok = true ;
}
assert(!( pubkey.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
assert(!full_key_ok || (fullkey.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
if (!pub_key_ok)
{
@ -2027,27 +1987,14 @@ bool p3IdService::cache_store(const RsGxsIdGroupItem *item)
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
assert(!(pubkey.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
// Create Cache Data.
RsGxsIdCache pubcache(item, pubkey, tagList);
RsGxsIdCache keycache(item, pubkey, fullkey,tagList);
if(mContacts.find(id) != mContacts.end())
pubcache.details.mFlags |= RS_IDENTITY_FLAGS_IS_A_CONTACT;
mPublicKeyCache.store(id, pubcache);
mPublicKeyCache.resize();
keycache.details.mFlags |= RS_IDENTITY_FLAGS_IS_A_CONTACT;
if (full_key_ok)
{
RsGxsIdCache fullcache(item, fullkey, tagList);
if(mContacts.find(id) != mContacts.end())
pubcache.details.mFlags |= RS_IDENTITY_FLAGS_IS_A_CONTACT;
mPrivateKeyCache.store(id, fullcache);
mPrivateKeyCache.resize();
}
mKeyCache.store(id, keycache);
mKeyCache.resize();
return true;
}
@ -2251,31 +2198,18 @@ bool p3IdService::cache_update_if_cached(const RsGxsId &id, std::string serviceS
/* retrieve - update, save */
RsStackMutex stack(mIdMtx); /********** STACK LOCKED MTX ******/
RsGxsIdCache pub_data;
if (mPublicKeyCache.fetch(id, pub_data))
RsGxsIdCache updated_data;
if(mKeyCache.fetch(id, updated_data))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_update_if_cached() Updating Public Cache";
std::cerr << std::endl;
#endif // DEBUG_IDS
assert(!(pub_data.pubkey.keyFlags & RSTLV_KEY_TYPE_FULL)) ;
pub_data.updateServiceString(serviceString);
mPublicKeyCache.store(id, pub_data);
}
RsGxsIdCache priv_data;
if (mPrivateKeyCache.fetch(id, priv_data))
{
#ifdef DEBUG_IDS
std::cerr << "p3IdService::cache_update_if_cached() Updating Private Cache";
std::cerr << std::endl;
#endif // DEBUG_IDS
priv_data.updateServiceString(serviceString);
mPrivateKeyCache.store(id, priv_data);
updated_data.updateServiceString(serviceString);
mKeyCache.store(id, updated_data);
}
return true;
@ -2444,7 +2378,7 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
}
else
{
RsTlvSecurityKey seckey;
RsTlvPublicRSAKey seckey;
if (getKey(*vit, seckey))
{
#ifdef DEBUG_IDS
@ -2476,7 +2410,7 @@ bool p3IdService::cachetest_handlerequest(uint32_t token)
}
else
{
RsTlvSecurityKey seckey;
RsTlvPrivateRSAKey seckey;
if (getPrivateKey(*vit, seckey))
{
// success!
@ -2615,22 +2549,19 @@ RsGenExchange::ServiceCreate_Return p3IdService::service_CreateGroup(RsGxsGrpIte
item->print(std::cerr);
std::cerr << std::endl;
#endif // DEBUG_IDS
item->meta.mGroupId.clear();
/********************* TEMP HACK UNTIL GXS FILLS IN GROUP_ID *****************/
// find private admin key
std::map<RsGxsId, RsTlvSecurityKey>::iterator mit = keySet.keys.begin();
for(; mit != keySet.keys.end(); ++mit)
{
RsTlvSecurityKey& pk = mit->second;
if(pk.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
for(std::map<RsGxsId, RsTlvPrivateRSAKey>::iterator mit = keySet.private_keys.begin();mit != keySet.private_keys.end(); ++mit)
if(mit->second.keyFlags == (RSTLV_KEY_DISTRIB_ADMIN | RSTLV_KEY_TYPE_FULL))
{
item->meta.mGroupId = RsGxsGroupId(pk.keyId);
item->meta.mGroupId = RsGxsGroupId(mit->second.keyId);
break;
}
}
if(mit == keySet.keys.end())
if(item->meta.mGroupId.isNull())
{
std::cerr << "p3IdService::service_CreateGroup() ERROR no admin key";
std::cerr << std::endl;

View File

@ -32,6 +32,7 @@
#include "gxs/rsgixs.h" // Internal Interfaces.
#include "gxs/gxstokenqueue.h"
#include "serialiser/rsgxsiditems.h"
#include <map>
#include <string>
@ -191,18 +192,24 @@ class RsGxsIdGroupItem;
class RsGxsIdCache
{
public:
RsGxsIdCache();
RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvSecurityKey &in_pkey,
const std::list<RsRecognTag> &tagList);
public:
RsGxsIdCache();
void updateServiceString(std::string serviceString);
RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pkey, const RsTlvPrivateRSAKey& privkey, const std::list<RsRecognTag> &tagList);
RsGxsIdCache(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pkey, const std::list<RsRecognTag> &tagList);
void updateServiceString(std::string serviceString);
time_t mPublishTs;
std::list<RsRecognTag> mRecognTags; // Only partially validated.
time_t mPublishTs;
std::list<RsRecognTag> mRecognTags; // Only partially validated.
RsIdentityDetails details;
RsTlvSecurityKey pubkey;
RsIdentityDetails details;
RsTlvPublicRSAKey pub_key;
RsTlvPrivateRSAKey priv_key;
private:
void init(const RsGxsIdGroupItem *item, const RsTlvPublicRSAKey& in_pub_key, const RsTlvPrivateRSAKey& in_priv_key,const std::list<RsRecognTag> &tagList);
};
@ -286,8 +293,8 @@ virtual bool setAsRegularContact(const RsGxsId& id,bool is_a_contact) ;
virtual bool haveKey(const RsGxsId &id);
virtual bool havePrivateKey(const RsGxsId &id);
virtual bool getKey(const RsGxsId &id, RsTlvSecurityKey &key);
virtual bool getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key);
virtual bool getKey(const RsGxsId &id, RsTlvPublicRSAKey &key);
virtual bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey &key);
virtual bool requestKey(const RsGxsId &id, const std::list<PeerId> &peers);
virtual bool requestPrivateKey(const RsGxsId &id);
@ -350,8 +357,7 @@ virtual void handle_event(uint32_t event_type, const std::string &elabel);
std::map<RsGxsId, std::list<RsPeerId> > mCacheLoad_ToCache, mPendingCache;
// Switching to RsMemCache for Key Caching.
RsMemCache<RsGxsId, RsGxsIdCache> mPublicKeyCache;
RsMemCache<RsGxsId, RsGxsIdCache> mPrivateKeyCache;
RsMemCache<RsGxsId, RsGxsIdCache> mKeyCache;
/************************************************************************
* Refreshing own Ids.

View File

@ -144,7 +144,7 @@ template<class Key, class Value> template<class ClientClass> bool RsMemCache<Key
return res ;
}
template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &key, Value &data)
template<class Key, class Value> bool RsMemCache<Key, Value>::fetch(const Key &key, Value& data)
{
#ifdef DEBUG_RSMEMCACHE
std::cerr << "RsMemCache::fetch()";

View File

@ -327,6 +327,7 @@ bool rsa_sanity_check(RSA *rsa)
}
#warning this code should be using GxsSecurity signature code. Not some own made signature call.
bool RsRecogn::signTag(EVP_PKEY *signKey, RsGxsRecognTagItem *item)
{
@ -374,6 +375,8 @@ bool RsRecogn::signTag(EVP_PKEY *signKey, RsGxsRecognTagItem *item)
return true;
}
#warning this code should be using GxsSecurity signature code. Not some own made signature call.
bool RsRecogn::signSigner(EVP_PKEY *signKey, RsGxsRecognSignerItem *item)
{
std::cerr << "RsRecogn::signSigner()";
@ -429,6 +432,7 @@ bool RsRecogn::signSigner(EVP_PKEY *signKey, RsGxsRecognSignerItem *item)
return true;
}
#warning this code should be using GxsSecurity signature code. Not some own made signature call.
bool RsRecogn::signTagRequest(EVP_PKEY *signKey, RsGxsRecognReqItem *item)
{
@ -560,7 +564,7 @@ RsGxsRecognTagItem *RsRecogn::extractTag(const std::string &encoded)
}
bool RsRecogn::createTagRequest(const RsTlvSecurityKey &key, const RsGxsId &id, const std::string &nickname, uint16_t tag_class, uint16_t tag_type, const std::string &comment, std::string &tag)
bool RsRecogn::createTagRequest(const RsTlvPrivateRSAKey &key, const RsGxsId &id, const std::string &nickname, uint16_t tag_class, uint16_t tag_type, const std::string &comment, std::string &tag)
{
EVP_PKEY *signKey = EVP_PKEY_new();
RSA *rsakey = d2i_RSAPrivateKey(NULL, (const unsigned char **)&key.keyData.bin_data, key.keyData.bin_len);

View File

@ -52,7 +52,7 @@ std::string getRsaKeyId(RSA *pubkey);
RsGxsRecognTagItem *extractTag(const std::string &encoded);
bool createTagRequest(const RsTlvSecurityKey &key,
bool createTagRequest(const RsTlvPrivateRSAKey &key,
const RsGxsId &id, const std::string &nickname,
uint16_t tag_class, uint16_t tag_type,
const std::string &comment, std::string &tag);

View File

@ -1007,7 +1007,7 @@ std::string p3FeedReaderThread::getProxyForFeed(const RsFeedReaderFeed &feed)
RsFeedReaderErrorState p3FeedReaderThread::processMsg(const RsFeedReaderFeed &feed, RsFeedReaderMsg *msg, std::string &errorString)
{
long todo_fill_errorString;
//long todo_fill_errorString;
if (!msg) {
return RS_FEED_ERRORSTATE_PROCESS_INTERNAL_ERROR;
@ -1073,7 +1073,7 @@ RsFeedReaderErrorState p3FeedReaderThread::processMsg(const RsFeedReaderFeed &fe
if (isRunning()) {
/* process description */
long todo; // encoding
//long todo; // encoding
HTMLWrapper html;
if (html.readHTML(msg->description.c_str(), url.c_str())) {
xmlNodePtr root = html.getRootElement();
@ -1527,7 +1527,7 @@ RsFeedReaderErrorState p3FeedReaderThread::processXslt(const std::string &xslt,
RsFeedReaderErrorState result = RS_FEED_ERRORSTATE_OK;
/* process description */
long todo; // encoding
//long todo; // encoding
HTMLWrapper html;
if (html.readHTML(description.c_str(), "")) {
xmlNodePtr root = html.getRootElement();

View File

@ -227,7 +227,7 @@ void xProgressBar::paint()
linearGrad.setColorAt(1.00, gradColor1);
painter->setPen(gradBorderColor);
int width = static_cast<int>(rect.width()-1-2*hSpan) ;
uint32_t width = static_cast<uint32_t>(rect.width()-1-2*hSpan) ;
painter->setBrush(linearGrad);

View File

@ -577,7 +577,7 @@ void IdDialog::loadCircleGroupMeta(const uint32_t &token)
#endif
// remove any identity that has an item, but no subscription flag entry
std::vector<QTreeWidgetItem*> to_delete ;
for(uint32_t k=0;k<item->childCount();++k)
if(details.mSubscriptionFlags.find(RsGxsId(item->child(k)->data(CIRCLEGROUP_CIRCLE_COL_GROUPID,Qt::UserRole).toString().toStdString())) == details.mSubscriptionFlags.end())
to_delete.push_back(item->child(k));
@ -1374,19 +1374,33 @@ bool IdDialog::fillIdListItem(const RsGxsIdGroup& data, QTreeWidgetItem *&item,
item->setTextAlignment(RSID_COL_VOTES, Qt::AlignRight);
item->setData(RSID_COL_VOTES,Qt::DisplayRole, QString::number(info.mOverallReputationScore - 1.0f,'f',3));
if(isOwnId)
{
QFont font = item->font(RSID_COL_NICKNAME) ;
font.setBold(true) ;
item->setFont(RSID_COL_NICKNAME,font) ;
item->setFont(RSID_COL_IDTYPE,font) ;
item->setFont(RSID_COL_KEYID,font) ;
if(isOwnId)
{
RsIdentityDetails idd ;
rsIdentity->getIdDetails(RsGxsId(data.mMeta.mGroupId),idd) ;
QString tooltip = tr("This identity is owned by you");
item->setToolTip(RSID_COL_NICKNAME, tooltip) ;
item->setToolTip(RSID_COL_KEYID, tooltip) ;
item->setToolTip(RSID_COL_IDTYPE, tooltip) ;
}
QFont font = item->font(RSID_COL_NICKNAME) ;
font.setBold(true) ;
item->setFont(RSID_COL_NICKNAME,font) ;
item->setFont(RSID_COL_IDTYPE,font) ;
item->setFont(RSID_COL_KEYID,font) ;
QString tooltip = tr("This identity is owned by you");
if(idd.mFlags & RS_IDENTITY_FLAGS_IS_DEPRECATED)
{
item->setForeground(RSID_COL_NICKNAME,QBrush(Qt::red));
item->setForeground(RSID_COL_KEYID,QBrush(Qt::red));
item->setForeground(RSID_COL_IDTYPE,QBrush(Qt::red));
tooltip += tr("\nThis identity has a unsecure fingerprint (It's probably quite old).\nYou should get rid of it now and use a new one.\nThese identities will soon be not supported anymore.") ;
}
item->setToolTip(RSID_COL_NICKNAME, tooltip) ;
item->setToolTip(RSID_COL_KEYID, tooltip) ;
item->setToolTip(RSID_COL_IDTYPE, tooltip) ;
}
QPixmap pixmap ;

View File

@ -624,8 +624,9 @@ void NewsFeed::loadChannelPublishKey(const uint32_t &token)
std::cerr << std::endl;
return;
}
#ifdef UNUSED_CODE
MessageComposer::sendChannelPublishKey(groups[0]);
#endif
}
void NewsFeed::loadForumGroup(const uint32_t &token)
@ -717,8 +718,9 @@ void NewsFeed::loadForumPublishKey(const uint32_t &token)
std::cerr << std::endl;
return;
}
#ifdef UNUSED_CODE
MessageComposer::sendForumPublishKey(groups[0]);
#endif
}
void NewsFeed::loadPostedGroup(const uint32_t &token)

View File

@ -295,9 +295,10 @@ void PostedItem::fill()
ui->voteDownButton->setEnabled(false);
}
uint32_t up, down, nComments;
#if 0
uint32_t up, down, nComments;
bool ok = rsPosted->retrieveScores(mPost.mMeta.mServiceString, up, down, nComments);
if(ok)

View File

@ -464,7 +464,7 @@ void PostedListWidget::clearPosts()
mPosts.clear();
}
bool PostedListWidget::navigatePostItem(const RsGxsMessageId &msgId)
bool PostedListWidget::navigatePostItem(const RsGxsMessageId & /*msgId*/)
{
//TODO
return false;

View File

@ -65,7 +65,7 @@ void AvatarDefs::getAvatarFromSslId(const RsPeerId& sslId, QPixmap &avatar, cons
}
void AvatarDefs::getAvatarFromGxsId(const RsGxsId& gxsId, QPixmap &avatar, const QString& defaultImage)
{
int size = 0;
//int size = 0;
/* get avatar */
RsIdentityDetails details ;

View File

@ -334,112 +334,114 @@ QString GroupTreeWidget::itemIdAt(QPoint &point)
void GroupTreeWidget::fillGroupItems(QTreeWidgetItem *categoryItem, const QList<GroupItemInfo> &itemList)
{
if (categoryItem == NULL) {
return;
}
QString filterText = ui->filterLineEdit->text();
/* Iterate all items */
QList<GroupItemInfo>::const_iterator it;
for (it = itemList.begin(); it != itemList.end(); ++it) {
const GroupItemInfo &itemInfo = *it;
QTreeWidgetItem *item = NULL;
/* Search exisiting item */
int childCount = categoryItem->childCount();
for (int child = 0; child < childCount; ++child) {
QTreeWidgetItem *childItem = categoryItem->child(child);
if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) {
/* Found child */
item = childItem;
break;
}
}
if (item == NULL) {
item = new RSTreeWidgetItem(compareRole);
item->setData(COLUMN_DATA, ROLE_ID, itemInfo.id);
categoryItem->addChild(item);
}
item->setText(COLUMN_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
/* Set last post */
qlonglong lastPost = itemInfo.lastpost.toTime_t();
item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting
/* Set visible posts */
item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting
/* Set icon */
if (ui->treeWidget->itemWidget(item, COLUMN_NAME)) {
/* Item is waiting, save icon in role */
item->setData(COLUMN_DATA, ROLE_SAVED_ICON, itemInfo.icon);
} else {
item->setIcon(COLUMN_NAME, itemInfo.icon);
}
/* Set popularity */
QString tooltip = PopularityDefs::tooltip(itemInfo.popularity);
item->setIcon(COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity));
item->setData(COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting
/* Set tooltip */
if (itemInfo.privatekey) {
tooltip += "\n" + tr("You have admin rights");
}
if(!IS_GROUP_SUBSCRIBED(itemInfo.subscribeFlags))
{
tooltip += "\n" + QString::number(itemInfo.max_visible_posts) + " messages available" ;
tooltip += "\n" + tr("Subscribe to download and read messages") ;
if (categoryItem == NULL) {
return;
}
item->setToolTip(COLUMN_NAME, tooltip);
item->setToolTip(COLUMN_POPULARITY, tooltip);
QString filterText = ui->filterLineEdit->text();
item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags);
/* Iterate all items */
QList<GroupItemInfo>::const_iterator it;
for (it = itemList.begin(); it != itemList.end(); ++it) {
const GroupItemInfo &itemInfo = *it;
/* Set color */
QBrush brush;
if (itemInfo.privatekey) {
brush = QBrush(textColorPrivateKey());
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY);
} else {
brush = ui->treeWidget->palette().color(QPalette::Text);
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD);
}
item->setForeground(COLUMN_NAME, brush);
QTreeWidgetItem *item = NULL;
/* Calculate score */
calculateScore(item, filterText);
}
/* Search exisiting item */
int childCount = categoryItem->childCount();
for (int child = 0; child < childCount; ++child) {
QTreeWidgetItem *childItem = categoryItem->child(child);
if (childItem->data(COLUMN_DATA, ROLE_ID).toString() == itemInfo.id) {
/* Found child */
item = childItem;
break;
}
}
/* Remove all items not in list */
int child = 0;
int childCount = categoryItem->childCount();
while (child < childCount) {
QString id = categoryItem->child(child)->data(COLUMN_DATA, ROLE_ID).toString();
if (item == NULL) {
item = new RSTreeWidgetItem(compareRole);
item->setData(COLUMN_DATA, ROLE_ID, itemInfo.id);
categoryItem->addChild(item);
}
for (it = itemList.begin(); it != itemList.end(); ++it) {
if (it->id == id) {
break;
}
}
item->setText(COLUMN_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_NAME, itemInfo.name);
item->setData(COLUMN_DATA, ROLE_DESCRIPTION, itemInfo.description);
if (it == itemList.end()) {
delete(categoryItem->takeChild(child));
childCount = categoryItem->childCount();
} else {
++child;
}
}
/* Set last post */
qlonglong lastPost = itemInfo.lastpost.toTime_t();
item->setData(COLUMN_DATA, ROLE_LASTPOST, -lastPost); // negative for correct sorting
resort(categoryItem);
/* Set visible posts */
item->setData(COLUMN_DATA, ROLE_POSTS, -itemInfo.max_visible_posts);// negative for correct sorting
/* Set icon */
if (ui->treeWidget->itemWidget(item, COLUMN_NAME)) {
/* Item is waiting, save icon in role */
item->setData(COLUMN_DATA, ROLE_SAVED_ICON, itemInfo.icon);
} else {
item->setIcon(COLUMN_NAME, itemInfo.icon);
}
/* Set popularity */
QString tooltip = PopularityDefs::tooltip(itemInfo.popularity);
item->setIcon(COLUMN_POPULARITY, PopularityDefs::icon(itemInfo.popularity));
item->setData(COLUMN_DATA, ROLE_POPULARITY, -itemInfo.popularity); // negative for correct sorting
/* Set tooltip */
if (itemInfo.adminKey)
tooltip += "\n" + tr("You are admin (modify names and description using Edit menu)");
else if (itemInfo.publishKey)
tooltip += "\n" + tr("You have been granted as publisher (you can post here!)");
if(!IS_GROUP_SUBSCRIBED(itemInfo.subscribeFlags))
{
tooltip += "\n" + QString::number(itemInfo.max_visible_posts) + " messages available" ;
tooltip += "\n" + tr("Subscribe to download and read messages") ;
}
item->setToolTip(COLUMN_NAME, tooltip);
item->setToolTip(COLUMN_POPULARITY, tooltip);
item->setData(COLUMN_DATA, ROLE_SUBSCRIBE_FLAGS, itemInfo.subscribeFlags);
/* Set color */
QBrush brush;
if (itemInfo.publishKey) {
brush = QBrush(textColorPrivateKey());
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_PRIVATEKEY);
} else {
brush = ui->treeWidget->palette().color(QPalette::Text);
item->setData(COLUMN_DATA, ROLE_COLOR, GROUPTREEWIDGET_COLOR_STANDARD);
}
item->setForeground(COLUMN_NAME, brush);
/* Calculate score */
calculateScore(item, filterText);
}
/* Remove all items not in list */
int child = 0;
int childCount = categoryItem->childCount();
while (child < childCount) {
QString id = categoryItem->child(child)->data(COLUMN_DATA, ROLE_ID).toString();
for (it = itemList.begin(); it != itemList.end(); ++it) {
if (it->id == id) {
break;
}
}
if (it == itemList.end()) {
delete(categoryItem->takeChild(child));
childCount = categoryItem->childCount();
} else {
++child;
}
}
resort(categoryItem);
}
void GroupTreeWidget::setUnreadCount(QTreeWidgetItem *item, int unreadCount)

View File

@ -47,7 +47,7 @@ public:
GroupItemInfo()
{
popularity = 0;
privatekey = false;
publishKey = false;
subscribeFlags = 0;
max_visible_posts =0;
}
@ -59,7 +59,8 @@ public:
int popularity;
QDateTime lastpost;
QIcon icon;
bool privatekey;
bool publishKey;
bool adminKey;
quint32 subscribeFlags;
quint32 max_visible_posts ;
};

View File

@ -293,7 +293,7 @@ PictureFlowState::PictureFlowState():
PictureFlowState::~PictureFlowState()
{
for(uint i=0;i<slideImages.size();++i)
for(int i=0;i<slideImages.size();++i)
delete slideImages[i] ;
slideImages.clear() ;
}
@ -1104,7 +1104,7 @@ void PictureFlow::setCenterIndex(int index)
void PictureFlow::clear()
{
for(uint i=0;i<d->state->slideImages.size();++i)
for(int i=0;i<d->state->slideImages.size();++i)
delete d->state->slideImages[i] ;
d->state->slideImages.clear() ;

View File

@ -332,10 +332,10 @@ void RSGraphWidget::paintEvent(QPaintEvent *)
_painter->end();
}
QSizeF RSGraphWidget::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const
QSizeF RSGraphWidget::sizeHint(Qt::SizeHint which, const QSizeF& /* constraint */) const
{
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
//float fact = FS/14.0 ;
switch(which)
{
@ -408,7 +408,7 @@ void RSGraphWidget::pointsFromData(const std::vector<QPointF>& values,QVector<QP
int x = _rec.width();
int y = _rec.height();
float time_step = 1.0f ; // number of seconds per pixel
//float time_step = 1.0f ; // number of seconds per pixel
/* Translate all data points to points on the graph frame */
@ -522,9 +522,9 @@ void RSGraphWidget::paintLine(const QVector<QPointF>& points, QColor color, Qt::
void RSGraphWidget::paintTotals()
{
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
//float fact = FS/14.0 ;
int x = SCALE_WIDTH*fact + FS, y = 0;
//int x = SCALE_WIDTH*fact + FS, y = 0;
int rowHeight = FS;
#if !defined(Q_OS_MAC)
@ -593,12 +593,12 @@ void RSGraphWidget::paintScale2()
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
int bottom = _rec.height();
//int bottom = _rec.height();
static const int npix = 100*fact ;
for(int i=_rec.width();i>SCALE_WIDTH*fact;i-=npix)
{
qreal pos = bottom - FS;
//qreal pos = bottom - FS;
int seconds = (_rec.width()-i)/_time_scale ; // pixels / (pixels per second) => seconds
QString text = QString::number(seconds)+ " secs";
@ -626,7 +626,7 @@ void RSGraphWidget::wheelEvent(QWheelEvent *e)
void RSGraphWidget::paintLegend()
{
int bottom = _rec.height();
//int bottom = _rec.height();
std::vector<QPointF> vals ;
_source->getCurrentValues(vals) ;

View File

@ -318,7 +318,7 @@ void PGPKeyDialog::applyDialog()
}
//check the GPG trustlvl
if(ui.trustlevel_CB->currentIndex() != detail.trustLvl)
if(ui.trustlevel_CB->currentIndex() != (int)detail.trustLvl)
rsPeers->trustGPGCertificate(pgpId, ui.trustlevel_CB->currentIndex());
uint32_t max_upload_speed = ui.maxUploadSpeed_SB->value() ;

View File

@ -286,7 +286,7 @@ void GxsGroupFrameDialog::groupTreeCustomPopupMenu(QPoint point)
action->setEnabled (!mGroupId.isNull() && isAdmin);
if (shareKeyType()) {
action = contextMnu.addAction(QIcon(IMAGE_SHARE), tr("Share admin permissions"), this, SLOT(shareKey()));
action = contextMnu.addAction(QIcon(IMAGE_SHARE), tr("Share publish permissions"), this, SLOT(sharePublishKey()));
action->setEnabled(!mGroupId.isNull() && isPublisher);
}
@ -429,7 +429,7 @@ void GxsGroupFrameDialog::markMsgAsUnread()
}
}
void GxsGroupFrameDialog::shareKey()
void GxsGroupFrameDialog::sharePublishKey()
{
if (mGroupId.isNull()) {
return;
@ -673,7 +673,8 @@ void GxsGroupFrameDialog::groupInfoToGroupItemInfo(const RsGroupMetaData &groupI
groupItemInfo.popularity = groupInfo.mPop;
groupItemInfo.lastpost = QDateTime::fromTime_t(groupInfo.mLastPost);
groupItemInfo.subscribeFlags = groupInfo.mSubscribeFlags;
groupItemInfo.privatekey = IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags) ;
groupItemInfo.publishKey = IS_GROUP_PUBLISHER(groupInfo.mSubscribeFlags) ;
groupItemInfo.adminKey = IS_GROUP_ADMIN(groupInfo.mSubscribeFlags) ;
groupItemInfo.max_visible_posts = groupInfo.mVisibleMsgCount ;
#if TOGXS

View File

@ -122,7 +122,7 @@ private slots:
void markMsgAsRead();
void markMsgAsUnread();
void shareKey();
void sharePublishKey();
void loadComment(const RsGxsGroupId &grpId, const RsGxsMessageId &msgId, const QString &title);

View File

@ -78,8 +78,8 @@ void GroupShareKey::setTyp()
return;
ui->headerFrame->setHeaderImage(QPixmap(":/images/channels.png"));
ui->headerFrame->setHeaderText(tr("Share channel admin permissions"));
ui->sharekeyinfo_label->setText(tr("You can allow your friends to publish in your channel and to modify the description. Or you can send the admin permissions to another Retroshare instance. Select the friends which you want to be allowed to publish in this channel. Note: it is not possible to revoke channel admin permissions."));
ui->headerFrame->setHeaderText(tr("Share channel publish permissions"));
ui->sharekeyinfo_label->setText(tr("You can allow your friends to publish in your channel, or send the publish permissions to another Retroshare instance of yours. Select the friends which you want to be allowed to publish in this channel. Note: it is currently not possible to revoke channel publish permissions."));
}
else if(mGrpType == FORUM_KEY_SHARE)
{

View File

@ -45,6 +45,7 @@ static void fillLabelCallback(GxsIdDetailsType type, const RsIdentityDetails &de
case GXS_ID_DETAILS_TYPE_EMPTY:
case GXS_ID_DETAILS_TYPE_LOADING:
case GXS_ID_DETAILS_TYPE_FAILED:
case GXS_ID_DETAILS_TYPE_BANNED:
break;
case GXS_ID_DETAILS_TYPE_DONE:

View File

@ -627,6 +627,7 @@ void MessageComposer::sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId
rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_USER_REQUEST);
}
#ifdef UNUSED_CODE
void MessageComposer::sendChannelPublishKey(RsGxsChannelGroup &group)
{
// QString channelName = QString::fromUtf8(group.mMeta.mGroupName.c_str());
@ -658,6 +659,7 @@ void MessageComposer::sendForumPublishKey(RsGxsForumGroup &group)
// QString msgText = tr("... %1 ...<br>%2").arg(forumName, link.toHtml());
// rsMail->SystemMessage(title.toUtf8().constData(), msgText.toUtf8().constData(), RS_MSG_PUBLISH_KEY);
}
#endif
void MessageComposer::closeEvent (QCloseEvent * event)
{
@ -1532,7 +1534,7 @@ QString MessageComposer::getRecipientEmailAddress(const RsGxsId& id,const RsIden
return (QString("%2 <")+tr("Distant identity:")+" %2@%1>").arg(QString::fromStdString(id.toStdString())).arg(QString::fromUtf8(detail.mNickname.c_str())) ;
}
QString MessageComposer::getRecipientEmailAddress(const RsPeerId& id,const RsPeerDetails& detail)
QString MessageComposer::getRecipientEmailAddress(const RsPeerId& /* id */,const RsPeerDetails& detail)
{
QString location_name = detail.location.empty()?tr("[Missing]"):QString::fromUtf8(detail.location.c_str()) ;

View File

@ -64,8 +64,10 @@ public:
static QString recommendMessage();
static void recommendFriend(const std::set <RsPeerId> &sslIds, const RsPeerId &to = RsPeerId(), const QString &msg = "", bool autoSend = false);
static void sendConnectAttemptMsg(const RsPgpId &gpgId, const RsPeerId &sslId, const QString &sslName);
#ifdef UNUSED_CODE
static void sendChannelPublishKey(RsGxsChannelGroup &group);
static void sendForumPublishKey(RsGxsForumGroup &group);
#endif
static MessageComposer *newMsg(const std::string &msgId = "");
static MessageComposer *replyMsg(const std::string &msgId, bool all);

View File

@ -304,7 +304,7 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
_painter->setPen(pen) ;
int i=0;
int x=5/14.0*S ;
//int x=5/14.0*S ;
int y=S*fMATRIX_START_Y ;
for(std::list<RsPeerId>::const_iterator it(ssllist.begin());it!=ssllist.end();++it,++i)
@ -383,7 +383,7 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
static const std::string global_switch[2] = { ":/icons/global_switch_off_128.png",
":/icons/global_switch_on_128.png" } ;
for(int i=0;i<service_ids.size();++i)
for(uint32_t i=0;i<service_ids.size();++i)
{
RsServicePermissions serv_perm ;
rsServiceControl->getServicePermissions(service_ids[i],serv_perm) ;
@ -450,7 +450,7 @@ void RSPermissionMatrixWidget::paintEvent(QPaintEvent *)
// now display some info about current node.
if(n_row_selected < peer_ids.size() && n_col_selected < service_ids.size())
if(n_row_selected < (int)peer_ids.size() && n_col_selected < (int)service_ids.size())
{
QRect position = computeNodePosition(n_row_selected,n_col_selected,false) ;
@ -592,36 +592,14 @@ bool RSPermissionMatrixWidget::computeServiceGlobalSwitch(int x,int y,uint32_t&
return true ;
}
void RSPermissionMatrixWidget::defaultPermissionSwitched(uint32_t ServiceId,bool b)
void RSPermissionMatrixWidget::defaultPermissionSwitched(uint32_t /* ServiceId */,bool /* b */)
{
NOT_IMPLEMENTED ;
}
void RSPermissionMatrixWidget::userPermissionSwitched(uint32_t ServiceId,const RsPeerId& friend_id,bool b)
void RSPermissionMatrixWidget::userPermissionSwitched(uint32_t /* ServiceId */,const RsPeerId& /* friend_id */,bool /* b */)
{
NOT_IMPLEMENTED ;
}
// void RSGraphWidget::paintLegend()
// {
// int bottom = _rec.height();
//
// std::vector<float> vals ;
// _source->getCurrentValues(vals) ;
//
// for(uint i=0;i<vals.size();++i)
// {
// qreal paintStep = 4+FONT_SIZE;
// qreal pos = 20+i*paintStep;
// QString text = _source->legend(i,vals[i]) ;
//
// QPen oldPen = _painter->pen();
// _painter->setPen(QPen(getColor(i), Qt::SolidLine));
// _painter->drawLine(QPointF(SCALE_WIDTH+10.0, pos), QPointF(SCALE_WIDTH+30.0, pos));
// _painter->setPen(oldPen);
//
// _painter->setPen(SCALE_COLOR);
// _painter->drawText(QPointF(SCALE_WIDTH + 40,pos + 0.5*FONT_SIZE), text) ;
// }
// }

View File

@ -496,7 +496,7 @@ void ServerPage::ipFilterContextMenu(const QPoint& point)
if(item == NULL)
return ;
bool status = item->data(Qt::UserRole).toBool();
//bool status = item->data(Qt::UserRole).toBool();
uint32_t reason = ui.filteredIpsTable->item(row,COLUMN_REASON)->data(Qt::UserRole).toUInt();
@ -594,7 +594,7 @@ void ServerPage::moveToWhiteList2()
rsBanList->addIpRange(addr,2,RSBANLIST_TYPE_WHITELIST, tr("Added by you").toStdString());
}
void ServerPage::ipWhiteListContextMenu(const QPoint& point)
void ServerPage::ipWhiteListContextMenu(const QPoint& /* point */)
{
QMenu contextMenu(this) ;
int row = ui.whiteListIpsTable->currentRow();

View File

@ -411,7 +411,7 @@ void BWGraphSource::setSelector(int selector_type,int graph_type,const std::stri
{
if(graph_type == GRAPH_TYPE_SINGLE)
{
bool ok = false ;
//bool ok = false ;
int tmp = QString::fromStdString(selector_client_string).toInt() ;
if(tmp > 0 && tmp < 0x10000)

View File

@ -62,7 +62,7 @@ void BandwidthStatsWidget::updateComboBoxes()
// Setup button/combobox info
uint32_t indx = 2 ;
int indx = 2 ;
//RsPeerDetails details ;
RsPeerId current_friend_id(ui.friend_CB->itemData(ui.friend_CB->currentIndex()).toString().toStdString()) ;

View File

@ -171,7 +171,7 @@ void BWListDelegate::paint(QPainter * painter, const QStyleOptionViewItem & opti
QSize BWListDelegate::sizeHint(const QStyleOptionViewItem & option/*option*/, const QModelIndex & index) const
{
float FS = QFontMetricsF(option.font).height();
float fact = FS/14.0 ;
//float fact = FS/14.0 ;
float w = QFontMetricsF(option.font).width(index.data(Qt::DisplayRole).toString());
@ -187,8 +187,8 @@ BwCtrlWindow::BwCtrlWindow(QWidget *parent)
BWDelegate = new BWListDelegate();
bwTreeWidget->setItemDelegate(BWDelegate);
float FS = QFontMetricsF(font()).height();
float fact = FS/14.0 ;
//float FS = QFontMetricsF(font()).height();
//float fact = FS/14.0 ;
/* Set header resize modes and initial section sizes Peer TreeView*/
QHeaderView * _header = bwTreeWidget->header () ;

View File

@ -279,7 +279,7 @@ void DhtWindow::updateNetStatus()
void DhtWindow::updateNetPeers()
{
QTreeWidget *peerTreeWidget = ui.peerTreeWidget;
//QTreeWidget *peerTreeWidget = ui.peerTreeWidget;
std::list<RsPeerId> peerIds;
std::list<RsPeerId>::iterator it;
@ -654,7 +654,7 @@ void DhtWindow::updateDhtPeers()
}
}
QTreeWidget *dhtTreeWidget = ui.dhtTreeWidget;
//QTreeWidget *dhtTreeWidget = ui.dhtTreeWidget;
ui.dhtTreeWidget->clear();

View File

@ -167,7 +167,7 @@ void GlobalRouterStatistics::updateContent()
groupBox->setTitle(tr("Pending packets")+": " + QString::number(cache_infos.size()) );
for(int i=0;i<cache_infos.size();++i)
for(uint32_t i=0;i<cache_infos.size();++i)
{
QTreeWidgetItem *item = new QTreeWidgetItem();
treeWidget->addTopLevelItem(item);
@ -324,7 +324,7 @@ void GlobalRouterStatisticsWidget::updateContent()
// oy += celly ;
// oy += celly ;
static const int MaxKeySize = 20*fact ;
//static const int MaxKeySize = 20*fact ;
painter.setFont(monospace_f) ;
int n=0;

View File

@ -34,7 +34,7 @@
#include "gui/settings/rsharesettings.h"
RttStatistics::RttStatistics(QWidget *parent)
RttStatistics::RttStatistics(QWidget * /*parent*/)
{
setupUi(this) ;

View File

@ -227,8 +227,8 @@ GxsTunnelsDialog::GxsTunnelsDialog(QWidget *parent)
m_bProcessSettings = false;
float fontHeight = QFontMetricsF(font()).height();
float fact = fontHeight/14.0;
//float fontHeight = QFontMetricsF(font()).height();
//float fact = fontHeight/14.0;
maxWidth = 200 ;
maxHeight = 200 ;

View File

@ -74,7 +74,7 @@ char *getpass (const char *prompt)
}
#endif
void NotifyTxt::notifyErrorMsg(int list, int type, std::string msg)
void NotifyTxt::notifyErrorMsg(int /* list */, int /* type */, std::string /* msg */)
{
return;
}
@ -101,7 +101,7 @@ bool NotifyTxt::askForPluginConfirmation(const std::string& plugin_file_name, co
return a == 'y' ;
}
bool NotifyTxt::askForPassword(const std::string& question, bool prev_is_bad, std::string& password,bool& cancel)
bool NotifyTxt::askForPassword(const std::string& question, bool /* prev_is_bad */, std::string& password,bool& cancel)
{
std::string question1="Please enter your PGP password for key:\n " + question + " :";
char *passwd = getpass(question1.c_str()) ;
@ -112,7 +112,7 @@ bool NotifyTxt::askForPassword(const std::string& question, bool prev_is_bad, st
}
void NotifyTxt::notifyListChange(int list, int type)
void NotifyTxt::notifyListChange(int list, int /* type */)
{
//std::cerr << "NotifyTxt::notifyListChange()" << std::endl;
switch(list)

View File

@ -155,8 +155,8 @@ public:
* @return a pointer to a valid profile if successful, otherwise NULL
*
*/
bool getKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; }
bool getPrivateKey(const RsGxsId &id, RsTlvSecurityKey &key){ return false; } // For signing outgoing messages.
bool getKey(const RsGxsId &id, RsTlvPrublicRSAKey& key){ return false; }
bool getPrivateKey(const RsGxsId &id, RsTlvPrivateRSAKey& key){ return false; } // For signing outgoing messages.
private:

View File

@ -35,8 +35,8 @@
TEST(libretroshare_gxs, GxsSecurity)
{
RsTlvSecurityKey pub_key ;
RsTlvSecurityKey priv_key ;
RsTlvSecurityKey_deprecated pub_key ;
RsTlvSecurityKey_deprecated priv_key ;
EXPECT_TRUE(GxsSecurity::generateKeyPair(pub_key,priv_key)) ;
@ -45,7 +45,7 @@ TEST(libretroshare_gxs, GxsSecurity)
EXPECT_TRUE( pub_key.keyId == priv_key.keyId );
EXPECT_TRUE( pub_key.startTS == priv_key.startTS );
RsTlvSecurityKey pub_key2 ;
RsTlvSecurityKey_deprecated pub_key2 ;
EXPECT_TRUE(GxsSecurity::extractPublicKey(priv_key,pub_key2)) ;
EXPECT_TRUE( pub_key.keyId == pub_key2.keyId );

View File

@ -70,7 +70,7 @@ void init_item(RsTlvSecurityKeySet& ks)
RsGxsId a_str;
a_str = RsGxsId::random();
RsTlvSecurityKey& a_key = ks.keys[a_str];
RsTlvSecurityKey_deprecated& a_key = ks.keys[a_str];
init_item(a_key);
a_key.keyId = a_str;
}
@ -81,7 +81,7 @@ bool operator==(const RsTlvSecurityKeySet& l, const RsTlvSecurityKeySet& r)
if(l.groupId != r.groupId) return false;
std::map<RsGxsId, RsTlvSecurityKey>::const_iterator l_cit = l.keys.begin(),
std::map<RsGxsId, RsTlvSecurityKey_deprecated>::const_iterator l_cit = l.keys.begin(),
r_cit = r.keys.begin();
for(; l_cit != l.keys.end(); l_cit++, r_cit++){
@ -94,7 +94,7 @@ bool operator==(const RsTlvSecurityKeySet& l, const RsTlvSecurityKeySet& r)
bool operator==(const RsTlvSecurityKey& sk1, const RsTlvSecurityKey& sk2)
bool operator==(const RsTlvSecurityKey_deprecated& sk1, const RsTlvSecurityKey_deprecated& sk2)
{
if(sk1.startTS != sk2.startTS) return false;
@ -183,7 +183,7 @@ bool operator==(const RsTlvBinaryData& bd1, const RsTlvBinaryData& bd2)
}
void init_item(RsTlvSecurityKey& sk)
void init_item(RsTlvSecurityKey_deprecated& sk)
{
int randnum = rand()%313131;

View File

@ -58,7 +58,7 @@ void randString(const uint32_t, std::wstring&);
/* for testing compound tlv items */
void init_item(RsTlvSecurityKey&);
void init_item(RsTlvSecurityKey_deprecated&);
void init_item(RsTlvSecurityKeySet&);
void init_item(RsTlvKeySignature&);
void init_item(RsTlvKeySignatureSet&);
@ -70,7 +70,7 @@ void init_item(RsTlvPeerIdSet&);
void init_item(RsTlvImage&);
void init_item(RsTlvPeerIdSet&);
bool operator==(const RsTlvSecurityKey&, const RsTlvSecurityKey& );
bool operator==(const RsTlvSecurityKey_deprecated&, const RsTlvSecurityKey_deprecated& );
bool operator==(const RsTlvSecurityKeySet&, const RsTlvSecurityKeySet& );
bool operator==(const RsTlvKeySignature&, const RsTlvKeySignature& );
bool operator==(const RsTlvBinaryData&, const RsTlvBinaryData&);

View File

@ -68,7 +68,7 @@ int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
uint32_t tmpoffset = 0;
/* List of all the TLV types it could be! */
RsTlvSecurityKey skey;
RsTlvSecurityKey_deprecated skey;
RsTlvSecurityKeySet skeyset;
RsTlvKeySignature keysign;
@ -114,7 +114,7 @@ int test_TlvRandom(void *data, uint32_t len, uint32_t offset)
EXPECT_TRUE(test_SetTlvItem(&kv, TLV_TYPE_KEYVALUE, data, len, offset));
EXPECT_TRUE(test_SetTlvItem(&kvset, TLV_TYPE_KEYVALUESET, data, len, offset));
std::cerr << "test_TlvRandom:: Testing Keys (TYPESET)" << std::endl;
EXPECT_TRUE(test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY, data, len, offset));
EXPECT_TRUE(test_SetTlvItem(&skey, TLV_TYPE_SECURITYKEY_deprecated, data, len, offset));
EXPECT_TRUE(test_SetTlvItem(&skeyset, TLV_TYPE_SECURITYKEYSET, data, len, offset));
EXPECT_TRUE(test_SetTlvItem(&keysign, TLV_TYPE_KEYSIGNATURE, data, len, offset));