mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-06-28 16:17:28 -04:00
added systematic consistency checking of public/private RSA keys at deserialisation time
This commit is contained in:
parent
b9ba51f2ba
commit
25c0c9d4ce
4 changed files with 34 additions and 14 deletions
|
@ -28,6 +28,7 @@
|
|||
#include "rstlvbase.h"
|
||||
#include "rsbaseserial.h"
|
||||
#include "util/stacktrace.h"
|
||||
#include "gxs/gxssecurity.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -96,7 +97,7 @@ bool RsTlvRSAKey::SetTlv(void *data, uint32_t size, uint32_t *offset) const
|
|||
return false; /* not enough space */
|
||||
}
|
||||
|
||||
bool ok = checkFlags(keyFlags); // check before serialise, just in case
|
||||
bool ok = checkKey(); // check before serialise, just in case
|
||||
|
||||
/* start at data[offset] */
|
||||
/* add mandatory parts first */
|
||||
|
@ -184,7 +185,7 @@ bool RsTlvRSAKey::GetTlv(void *data, uint32_t size, uint32_t *offset)
|
|||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
return ok && checkFlags(keyFlags) ;
|
||||
return ok && checkKey() ;
|
||||
}
|
||||
|
||||
std::ostream& RsTlvRSAKey::print(std::ostream &out, uint16_t indent) const
|
||||
|
@ -217,7 +218,15 @@ std::ostream& RsTlvRSAKey::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 ************************************/
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ class RsTlvRSAKey: public RsTlvItem
|
|||
{
|
||||
public:
|
||||
RsTlvRSAKey();
|
||||
virtual bool checkFlags(uint32_t flags) const = 0 ; // this pure virtual forces people to explicitly declare if they use a public or a private key.
|
||||
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();
|
||||
|
@ -64,8 +64,6 @@ public:
|
|||
/* clears KeyData - but doesn't delete - to transfer ownership */
|
||||
void ShallowClear();
|
||||
|
||||
bool check() const { return checkFlags(keyFlags) && (!keyId.isNull()) ; }
|
||||
|
||||
RsGxsId keyId; // Mandatory :
|
||||
uint32_t keyFlags; // Mandatory ;
|
||||
uint32_t startTS; // Mandatory :
|
||||
|
@ -80,14 +78,14 @@ class RsTlvPrivateRSAKey: public RsTlvRSAKey
|
|||
public:
|
||||
virtual ~RsTlvPrivateRSAKey() {}
|
||||
|
||||
virtual bool checkFlags(uint32_t flags) const { return bool(flags & RSTLV_KEY_TYPE_FULL) && !bool(flags & RSTLV_KEY_TYPE_PUBLIC_ONLY) ; }
|
||||
virtual bool checkKey() const ;
|
||||
};
|
||||
class RsTlvPublicRSAKey: public RsTlvRSAKey
|
||||
{
|
||||
public:
|
||||
virtual ~RsTlvPublicRSAKey() {}
|
||||
|
||||
virtual bool checkFlags(uint32_t flags) const { return bool(flags & RSTLV_KEY_TYPE_PUBLIC_ONLY) && !bool(flags & RSTLV_KEY_TYPE_FULL) ; }
|
||||
virtual bool checkKey() const ;
|
||||
};
|
||||
|
||||
class RsTlvSecurityKeySet: public RsTlvItem
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue