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

@ -41,6 +41,7 @@
#define RS_USE_PGPSSL 1
#include <stdint.h>
#include <list>
#include <map>
#include <vector>
@ -88,6 +89,7 @@ class RsInit
/*!
* Generating GPGme Account
*/
static bool collectEntropy(uint32_t bytes) ;
static int GetPGPLogins(std::list<std::string> &pgpIds);
static int GetPGPLoginDetails(const std::string& id, std::string &name, std::string &email);
static bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString);

View File

@ -51,6 +51,7 @@
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <openssl/rand.h>
#include <fcntl.h>
#if (defined(__unix__) || defined(unix)) && !defined(USG)
@ -1217,6 +1218,12 @@ bool RsInit::SelectGPGAccount(const std::string& gpgId)
return retVal;
}
bool RsInit::collectEntropy(uint32_t n)
{
RAND_seed(&n,4) ;
return true ;
}
bool RsInit::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, std::string &pgpId, std::string &errString)
{

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();

View File

@ -24,6 +24,8 @@
#include "ui_GenCertDialog.h"
class QMouseEvent ;
class GenCertDialog : public QDialog
{
Q_OBJECT
@ -32,11 +34,14 @@ public:
/** Default constructor */
GenCertDialog(bool onlyGenerateIdentity, QWidget *parent = 0);
virtual ~GenCertDialog() ;
virtual void mouseMoveEvent(QMouseEvent *e) ;
private slots:
void genPerson();
void importIdentity();
void exportIdentity();
void newGPGKeyGenUiSetup();
void grabMouse();
private:
void init();
@ -46,6 +51,8 @@ private:
bool genNewGPGKey;
bool mOnlyGenerateIdentity;
QTimer *entropy_timer ;
};
#endif

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>691</width>
<height>392</height>
<height>584</height>
</rect>
</property>
<property name="windowTitle">
@ -38,8 +38,8 @@
</property>
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="no_gpg_key_label">
<property name="text">
<string>It looks like you don't own any profile (PGP keys). Please fill in the form below to create one, or import an existing profile.</string>
@ -49,117 +49,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="genPGPuser">
<property name="toolTip">
<string>Your profile is associated with a PGP key. RetroShare currently ignores DSA keys.</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="name_label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="name_input">
<property name="toolTip">
<string>Enter your nickname here</string>
</property>
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="password_label">
<property name="toolTip">
<string>This Password is for PGP</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QLineEdit" name="password_input">
<property name="toolTip">
<string>Put a strong password here. This password protects your PGP key.</string>
</property>
<property name="inputMask">
<string/>
</property>
<property name="maxLength">
<number>1024</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="location_label">
<property name="text">
<string>Location</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLineEdit" name="location_input">
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item row="7" column="1">
<widget class="QLabel" name="label_location2">
<property name="minimumSize">
<size>
<width>0</width>
<height>30</height>
</size>
</property>
<property name="lineWidth">
<number>1</number>
</property>
<property name="text">
<string>Put a meaningful location. ex : home, laptop, etc. This field will be used to differentiate different installations with the same identity (PGP key).</string>
</property>
<property name="scaledContents">
<bool>false</bool>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QPushButton" name="genButton">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<property name="text">
<string>Create new identity</string>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/contact_new.png</normaloff>:/images/contact_new.png</iconset>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="genPGPuserlabel">
<property name="text">
<string>Use identity</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2" stretch="0,0,0,0">
<property name="spacing">
<number>6</number>
@ -228,14 +118,80 @@
</item>
</layout>
</item>
<item row="4" column="0">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="genPGPuserlabel">
<property name="text">
<string>Use identity</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="name_label">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="email_label">
<property name="text">
<string>Email</string>
</property>
</widget>
</item>
<item row="4" column="1">
<item>
<widget class="QLabel" name="password_label">
<property name="toolTip">
<string>This Password is for PGP</string>
</property>
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="password_label_2">
<property name="toolTip">
<string>This Password is for PGP</string>
</property>
<property name="text">
<string>Password (check)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="location_label">
<property name="text">
<string>Location</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QComboBox" name="genPGPuser">
<property name="toolTip">
<string>Your profile is associated with a PGP key. RetroShare currently ignores DSA keys.</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="name_input">
<property name="toolTip">
<string>Enter your nickname here</string>
</property>
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="email_input">
<property name="toolTip">
<string>Be careful: this email will be visible to your friends and friends
@ -247,6 +203,83 @@ anonymous, you can use a fake email.</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="password_input">
<property name="toolTip">
<string>Put a strong password here. This password protects your PGP key.</string>
</property>
<property name="inputMask">
<string/>
</property>
<property name="maxLength">
<number>1024</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="password_input_2">
<property name="toolTip">
<string>Put a strong password here. This password protects your PGP key.</string>
</property>
<property name="inputMask">
<string/>
</property>
<property name="maxLength">
<number>1024</number>
</property>
<property name="echoMode">
<enum>QLineEdit::Password</enum>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="location_input">
<property name="maxLength">
<number>64</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QLabel" name="entropy_label">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p align=&quot;justify&quot;&gt;Before proceeding, move your mouse around to help Retroshare collect as much randomness as possible. Filling the progressbar to 20% is needed, 100% is advised.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QProgressBar" name="entropy_bar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="genButton">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>26</height>
</size>
</property>
<property name="text">
<string>Create new identity</string>
</property>
<property name="icon">
<iconset resource="images.qrc">
<normaloff>:/images/contact_new.png</normaloff>:/images/contact_new.png</iconset>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@ -266,19 +299,6 @@ anonymous, you can use a fake email.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="0">
<widget class="QLabel" name="genprofileinfo_label">
<property name="font">
@ -295,6 +315,19 @@ anonymous, you can use a fake email.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>1</width>
<height>1</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
@ -325,7 +358,6 @@ anonymous, you can use a fake email.</string>
<tabstop>genPGPuser</tabstop>
<tabstop>name_input</tabstop>
<tabstop>email_input</tabstop>
<tabstop>password_input</tabstop>
<tabstop>location_input</tabstop>
</tabstops>
<resources>