added entropy collection system based on mouse movement to location/identity creation, to make keys less predictable

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6753 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2013-09-23 20:55:34 +00:00
parent 6b1613d8bb
commit cda8557b73
5 changed files with 316 additions and 140 deletions

View file

@ -25,10 +25,89 @@
#include "GenCertDialog.h"
#include <QAbstractEventDispatcher>
#include <QFileDialog>
#include <QGraphicsOpacityEffect>
#include <QTimer>
#include <QMessageBox>
#include <QMouseEvent>
#include <QTextBrowser>
#include <QProgressBar>
#include <time.h>
#include <math.h>
#include <iostream>
class EntropyCollectorWidget: public QTextBrowser
{
public:
EntropyCollectorWidget(QProgressBar *pr,QWidget *p = NULL)
: QTextBrowser(p)
{
progress = pr ;
setMouseTracking(true) ;
entropy_values_collected = 0 ;
}
virtual void mouseMoveEvent(QMouseEvent *e)
{
std::cerr << "Mouse moved: " << e->x() << ", " << e->y() << std::endl;
++entropy_values_collected ;
progress->setValue(entropy_values_collected*100 / 4096) ;
}
int entropy_values_collected ;
QProgressBar *progress ;
};
class MyFilter: public QObject
{
public:
virtual bool eventFilter(QObject *obj, QEvent *event)
{
if(event->type() == QEvent::MouseMove)
std::cerr << "Mouse moved !"<< std::endl;
return QObject::eventFilter(obj,event) ;
}
};
void GenCertDialog::grabMouse()
{
static int last_x = 0 ;
static int last_y = 0 ;
static uint32_t count = 0 ;
uint32_t x = QCursor::pos().x() ;
uint32_t y = QCursor::pos().y() ;
if(last_x == x && last_y == y)
return ;
last_x = x ;
last_y = y ;
// Let's do some shuffle with mouse coordinates. Does not need to be cryptographically random,
// since the random number generator will shuffle this appropriately in openssl.
//
uint32_t E = ((count*x*86243 + y*y*15641) & 0xffff) ^ 0xb374;
uint32_t F = ((x*44497*y*count + x*x) & 0xffff) ^ 0x395b ;
++count ;
// std::cerr << "Mouse grabed at " << x << " " << y << ". Adding entropy E=" << std::hex << E << ", F=" << F << ", digit =" << E + (F << 16) << std::dec << std::endl;
ui.entropy_bar->setValue(count*100/2048) ;
if(ui.entropy_bar->value() < 20)
ui.genButton->setEnabled(false) ;
else
ui.genButton->setEnabled(true) ;
RsInit::collectEntropy(E+(F << 16)) ;
}
static bool MyEventFilter(void *message, long *result)
{
std::cerr << "Event called " << message << std::endl;
return false ;
}
/** Default constructor */
GenCertDialog::GenCertDialog(bool onlyGenerateIdentity, QWidget *parent)
: QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::WindowCloseButtonHint), mOnlyGenerateIdentity(onlyGenerateIdentity)
@ -47,13 +126,36 @@ GenCertDialog::GenCertDialog(bool onlyGenerateIdentity, QWidget *parent)
//ui.genName->setFocus(Qt::OtherFocusReason);
// QObject *obj = QCoreApplication::eventFilter() ;
// std::cerr << "Event filter : " << obj << std::endl;
// QCoreApplication::instance()->setEventFilter(MyEventFilter) ;
entropy_timer = new QTimer ;
entropy_timer->start(20) ;
QObject::connect(entropy_timer,SIGNAL(timeout()),this,SLOT(grabMouse())) ;
// EntropyCollectorWidget *ecw = new EntropyCollectorWidget(ui.entropy_bar,this) ;
// ecw->resize(size()) ;
// ecw->move(0,0) ;
//
// QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect ;
// effect->setOpacity(0.2) ;
// ecw->setGraphicsEffect(effect) ;
//ecw->setBackgroundColor(QColor::fromRGB(1,1,1)) ;
// ecw->show() ;
ui.entropy_bar->setValue(0) ;
#if QT_VERSION >= 0x040700
ui.email_input->setPlaceholderText(tr("[Optional] Visible to your friends, and friends of friends.")) ;
ui.location_input->setPlaceholderText(tr("[Required] Examples: Home, Laptop,...")) ;
ui.name_input->setPlaceholderText(tr("[Required] Visible to your friends, and friends of friends."));
ui.password_input->setPlaceholderText(tr("[Required] This password protects your PGP key."));
ui.password_input_2->setPlaceholderText(tr("[Required] Type the same password again here."));
#endif
ui.location_input->setToolTip(tr("Put a meaningful location. ex : home, laptop, etc. \nThis field will be used to differentiate different installations with\nthe same identity (PGP key).")) ;
ui.email_input->hide() ;
ui.email_label->hide() ;
@ -64,6 +166,11 @@ GenCertDialog::GenCertDialog(bool onlyGenerateIdentity, QWidget *parent)
init();
}
GenCertDialog::~GenCertDialog()
{
entropy_timer->stop() ;
}
void GenCertDialog::init()
{
std::cerr << "Finding PGPUsers" << std::endl;
@ -120,6 +227,13 @@ void GenCertDialog::init()
newGPGKeyGenUiSetup();
}
void GenCertDialog::mouseMoveEvent(QMouseEvent *e)
{
std::cerr << "Mouse : " << e->x() << ", " << e->y() << std::endl;
QDialog::mouseMoveEvent(e) ;
}
void GenCertDialog::newGPGKeyGenUiSetup() {
if (ui.new_gpg_key_checkbox->isChecked()) {
@ -129,7 +243,9 @@ void GenCertDialog::newGPGKeyGenUiSetup() {
// ui.email_label->show();
// ui.email_input->show();
ui.password_label->show();
ui.password_label_2->show();
ui.password_input->show();
ui.password_input_2->show();
ui.genPGPuserlabel->hide();
ui.genPGPuser->hide();
ui.importIdentity_PB->hide() ;
@ -144,7 +260,9 @@ void GenCertDialog::newGPGKeyGenUiSetup() {
// ui.email_label->hide();
// ui.email_input->hide();
ui.password_label->hide();
ui.password_label_2->hide();
ui.password_input->hide();
ui.password_input_2->hide();
ui.genPGPuserlabel->show();
ui.genPGPuser->show();
ui.importIdentity_PB->setVisible(!mOnlyGenerateIdentity);
@ -236,6 +354,15 @@ void GenCertDialog::genPerson()
QMessageBox::Ok);
return;
}
if(ui.password_input->text() != ui.password_input_2->text())
{
QMessageBox::warning(this,
tr("Generate PGP key Failure"),
tr("Passwords to not match"),
QMessageBox::Ok);
return;
}
//generate a new gpg key
std::string err_string;
ui.no_gpg_key_label->setText(tr("Generating new PGP key, please be patient: this process needs generating large prime numbers, and can take some minutes on slow computers. \n\nFill in your PGP password when asked, to sign your new key."));
@ -245,6 +372,8 @@ void GenCertDialog::genPerson()
ui.name_input->hide();
// ui.email_label->hide();
// ui.email_input->hide();
ui.password_label_2->hide();
ui.password_input_2->hide();
ui.password_label->hide();
ui.password_input->hide();
ui.genPGPuserlabel->hide();
@ -252,7 +381,6 @@ void GenCertDialog::genPerson()
ui.location_label->hide();
ui.location_input->hide();
ui.genButton->hide();
ui.label_location2->hide();
ui.importIdentity_PB->hide();
ui.genprofileinfo_label->hide();