Cache and protect MasterKey - speeds up saving a lot
Added option to save database after every change Improved license information git-svn-id: https://svn.code.sf.net/p/keepassx/code/trunk@226 b624d157-de02-0410-bad0-e51aec6abb33
This commit is contained in:
@@ -98,3 +98,46 @@ void SecString::generateSessionKey(){
|
||||
randomize(sessionkey, 32);
|
||||
RC4.setKey(sessionkey, 32);
|
||||
}
|
||||
|
||||
|
||||
SecData::SecData(int len) : locked(true){
|
||||
length = len;
|
||||
data = new quint8[len];
|
||||
}
|
||||
|
||||
SecData::~SecData(){
|
||||
if (!locked){
|
||||
for (int i=0; i<length; i++)
|
||||
data[i] = 0;
|
||||
}
|
||||
delete data;
|
||||
}
|
||||
|
||||
void SecData::lock(){
|
||||
Q_ASSERT(!locked);
|
||||
SecString::RC4.encrypt(data, data, length);
|
||||
locked = true;
|
||||
}
|
||||
|
||||
void SecData::unlock(){
|
||||
Q_ASSERT(locked);
|
||||
SecString::RC4.decrypt(data, data, length);
|
||||
locked = false;
|
||||
}
|
||||
|
||||
void SecData::copyData(quint8* src){
|
||||
unlock();
|
||||
memcpy(data, src, length);
|
||||
lock();
|
||||
}
|
||||
|
||||
void SecData::copyData(SecData& secData){
|
||||
secData.unlock();
|
||||
copyData(*secData);
|
||||
secData.lock();
|
||||
}
|
||||
|
||||
quint8* SecData::operator*(){
|
||||
Q_ASSERT(!locked);
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -22,11 +22,16 @@
|
||||
|
||||
#include "crypto/arcfour.h"
|
||||
|
||||
class SecData;
|
||||
|
||||
//! QString based class with in-memory encryption of its content.
|
||||
/*!
|
||||
This class can hold a QString object in an encrypted buffer. To get access to the string it is neccassary to unlock the SecString object.
|
||||
*/
|
||||
class SecString{
|
||||
|
||||
friend class SecData;
|
||||
|
||||
public:
|
||||
SecString();
|
||||
~SecString();
|
||||
@@ -56,5 +61,21 @@ private:
|
||||
|
||||
};
|
||||
|
||||
class SecData{
|
||||
public:
|
||||
SecData(int len);
|
||||
~SecData();
|
||||
void lock();
|
||||
void unlock();
|
||||
void copyData(quint8* src);
|
||||
void copyData(SecData& secData);
|
||||
quint8* operator*();
|
||||
|
||||
private:
|
||||
quint8* data;
|
||||
int length;
|
||||
bool locked;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -224,3 +224,13 @@ bool lockPage(void* addr, int len){
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool unlockPage(void* addr, int len){
|
||||
#if defined(Q_WS_X11) || defined(Q_WS_MAC)
|
||||
return (munlock(addr, len)==0);
|
||||
#elif defined(Q_WS_WIN)
|
||||
return VirtualUnlock(addr, len);
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -34,5 +34,6 @@ QString makePathRelative(const QString& Abs,const QString& Cur);
|
||||
QString getImageFile(const QString& name);
|
||||
bool createKeyFile(const QString& filename,QString* err, int length=32, bool Hex=true);
|
||||
bool lockPage(void* addr, int len);
|
||||
bool unlockPage(void* addr, int len);
|
||||
|
||||
#endif //TOOLS_H
|
||||
|
||||
Reference in New Issue
Block a user