added code to generate 3072 and 4096 bit PGP keys at startup (Patch from Serhaf)

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@7841 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2015-01-12 22:02:43 +00:00
parent 7bc98f1cd5
commit 8cb3ae6d2e
9 changed files with 75 additions and 37 deletions

View File

@ -360,7 +360,7 @@ bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids
return true ;
}
bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passphrase, RsPgpId& pgpId, std::string& errString)
bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passphrase, RsPgpId& pgpId, const int keynumbits, std::string& errString)
{
// Some basic checks
@ -384,13 +384,16 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
errString = std::string("(EE) passphrase in certificate exceeds the maximum allowed passphrase size") ;
return false ;
}
if(keynumbits % 1024 != 0)
{
errString = std::string("(EE) RSA key length is not a multiple of 1024") ;
return false ;
}
// Now the real thing
RsStackMutex mtx(pgphandlerMtx) ; // lock access to PGP memory structures.
RsStackFileLock flck(_pgp_lock_filename) ; // lock access to PGP directory.
static const int KEY_NUMBITS = 2048 ;
// 1 - generate keypair - RSA-2048
//
ops_user_id_t uid ;
@ -398,7 +401,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
uid.user_id = (unsigned char *)s ;
unsigned long int e = 65537 ; // some prime number
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(KEY_NUMBITS,e,&uid) ;
ops_keydata_t *key = ops_rsa_create_selfsigned_keypair(keynumbits, e, &uid) ;
free(s) ;
@ -409,7 +412,7 @@ bool PGPHandler::GeneratePGPCertificate(const std::string& name, const std::stri
ops_create_info_t *cinfo = NULL ;
ops_memory_t *buf = NULL ;
ops_setup_memory_write(&cinfo, &buf, 0);
ops_setup_memory_write(&cinfo, &buf, 0);
if(!ops_write_transferable_secret_key(key,(unsigned char *)passphrase.c_str(),passphrase.length(),ops_false,cinfo))
{

View File

@ -77,7 +77,7 @@ class PGPHandler
bool exportGPGKeyPair(const std::string& filename,const RsPgpId& exported_id) const ;
bool availableGPGCertificatesWithPrivateKeys(std::list<RsPgpId>& ids);
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, std::string& errString) ;
bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString) ;
bool LoadCertificateFromString(const std::string& pem, RsPgpId& gpg_id, std::string& error_string);

View File

@ -329,11 +329,11 @@ bool AuthGPG::active()
return gpgKeySelected;
}
bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, std::string& errString)
bool AuthGPG::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId& pgpId, const int keynumbits, std::string& errString)
{
RsStackMutex stack(gpgMtxEngine); /******* LOCKED ******/
return PGPHandler::GeneratePGPCertificate(name, email, passwd, pgpId, errString) ;
return PGPHandler::GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString) ;
}
/**** These Two are common */

View File

@ -135,7 +135,7 @@ class AuthGPG: public p3Config, public RsThread, public PGPHandler
/* Init by generating new Own PGP Cert, or selecting existing PGP Cert */
virtual int GPGInit(const RsPgpId &ownId);
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
virtual bool GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
/*********************************************************************************/
/************************* STAGE 3 ***********************************************/

View File

@ -139,7 +139,7 @@ namespace RsAccounts
// PGP Accounts.
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
// PGP Support Functions.
bool ExportIdentity(const std::string& fname,const RsPgpId& pgp_id) ;

View File

@ -840,9 +840,9 @@ bool RsAccountsDetail::SelectPGPAccount(const RsPgpId& pgpId)
}
bool RsAccountsDetail::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString)
bool RsAccountsDetail::GeneratePGPCertificate(const std::string& name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
{
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
return AuthGPG::getAuthGPG()->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
}
// PGP Support Functions.
@ -1222,9 +1222,9 @@ int RsAccounts::GetPGPLoginDetails(const RsPgpId& id, std::string &name, std
return rsAccounts->GetPGPLoginDetails(id, name, email);
}
bool RsAccounts::GeneratePGPCertificate(const std::string &name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString)
bool RsAccounts::GeneratePGPCertificate(const std::string &name, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString)
{
return rsAccounts->GeneratePGPCertificate(name, email, passwd, pgpId, errString);
return rsAccounts->GeneratePGPCertificate(name, email, passwd, pgpId, keynumbits, errString);
}
// PGP Support Functions.

View File

@ -89,7 +89,7 @@ class RsAccountsDetail
int GetPGPLogins(std::list<RsPgpId> &pgpIds);
int GetPGPLoginDetails(const RsPgpId& id, std::string &name, std::string &email);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, std::string &errString);
bool GeneratePGPCertificate(const std::string&, const std::string& email, const std::string& passwd, RsPgpId &pgpId, const int keynumbits, std::string &errString);
bool SelectPGPAccount(const RsPgpId& pgpId);

View File

@ -147,6 +147,11 @@ GenCertDialog::GenCertDialog(bool onlyGenerateIdentity, QWidget *parent)
ui.entropy_bar->setValue(0) ;
// make sure that QVariant always takes an 'int' otherwise the program will crash!
ui.keylength_comboBox->addItem("2048 bits", QVariant(2048));
ui.keylength_comboBox->addItem("3072 bits", QVariant(3072));
ui.keylength_comboBox->addItem("4096 bits", QVariant(4096));
#if QT_VERSION >= 0x040700
ui.email_input->setPlaceholderText(tr("[Optional] Visible to your friends, and friends of friends.")) ;
ui.node_input->setPlaceholderText(tr("[Required] Examples: Home, Laptop,...")) ;
@ -259,6 +264,8 @@ void GenCertDialog::newGPGKeyGenUiSetup() {
ui.genButton->setVisible(true);
ui.genprofileinfo_label->hide();
ui.header_label->show();
ui.keylength_label->show();
ui.keylength_comboBox->show();
} else {
genNewGPGKey = false;
ui.name_label->hide();
@ -280,10 +287,11 @@ void GenCertDialog::newGPGKeyGenUiSetup() {
ui.headerFrame->setHeaderText(tr("Create a new node"));
ui.genprofileinfo_label->show();
ui.header_label->hide();
ui.keylength_label->hide();
ui.keylength_comboBox->hide();
}
}
void GenCertDialog::hiddenUiSetup()
{
@ -432,6 +440,8 @@ void GenCertDialog::genPerson()
ui.importIdentity_PB->hide();
ui.genprofileinfo_label->hide();
ui.hidden_checkbox->hide();
ui.keylength_label->hide();
ui.keylength_comboBox->hide();
setCursor(Qt::WaitCursor) ;
@ -439,7 +449,13 @@ void GenCertDialog::genPerson()
while(QAbstractEventDispatcher::instance()->processEvents(QEventLoop::AllEvents)) ;
std::string email_str = "" ;
RsAccounts::GeneratePGPCertificate(ui.name_input->text().toUtf8().constData(), email_str.c_str(), ui.password_input->text().toUtf8().constData(), PGPId, err_string);
RsAccounts::GeneratePGPCertificate(
ui.name_input->text().toUtf8().constData(),
email_str.c_str(),
ui.password_input->text().toUtf8().constData(),
PGPId,
ui.keylength_comboBox->itemData(ui.keylength_comboBox->currentIndex()).toInt(),
err_string);
setCursor(Qt::ArrowCursor) ;
}

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>784</width>
<width>805</width>
<height>509</height>
</rect>
</property>
@ -18,7 +18,16 @@
<normaloff>:/images/logo/logo_16.png</normaloff>:/images/logo/logo_16.png</iconset>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<property name="margin">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<property name="spacing">
@ -247,6 +256,13 @@
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="keylength_label">
<property name="text">
<string>RSA key length</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
@ -353,10 +369,30 @@ anonymous, you can use a fake email.</string>
</item>
</layout>
</item>
<item>
<widget class="QComboBox" name="keylength_comboBox"/>
</item>
</layout>
</item>
</layout>
</item>
<item row="5" column="0">
<widget class="QProgressBar" name="entropy_bar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="4" column="0">
<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 row="3" column="0">
<widget class="QLabel" name="label_hiddenaddr2">
<property name="minimumSize">
@ -379,23 +415,6 @@ anonymous, you can use a fake email.</string>
</property>
</widget>
</item>
<item row="4" column="0">
<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 row="5" column="0">
<widget class="QProgressBar" name="entropy_bar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QPushButton" name="genButton">
<property name="maximumSize">