- fixed a few bugs in cert creation window:

* private key was not correctly added to private keyring
   * self signature validation was reported unsuccessful when unknown signatures where found
- enabled key import when no key is present


git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5389 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2012-08-07 19:16:17 +00:00
parent 4581067b78
commit 702263686e
4 changed files with 55 additions and 13 deletions

View File

@ -25,6 +25,7 @@ extern "C" {
#include "pgp/pgpkeyutil.h"
//#define DEBUG_PGPHANDLER 1
//#define PGPHANDLER_DSA_SUPPORT
PassphraseCallback PGPHandler::_passphrase_callback = NULL ;
@ -327,7 +328,11 @@ bool PGPHandler::availableGPGCertificatesWithPrivateKeys(std::list<PGPIdType>& i
while( (keydata = ops_keyring_get_key_by_index(_secring,i++)) != NULL )
if(ops_keyring_find_key_by_id(_pubring,keydata->key_id) != NULL) // check that the key is in the pubring as well
{
#ifdef PGPHANDLER_DSA_SUPPORT
if(keydata->key.pkey.algorithm == OPS_PKA_RSA || keydata->key.pkey.algorithm == OPS_PKA_DSA)
#else
if(keydata->key.pkey.algorithm == OPS_PKA_RSA)
#endif
ids.push_back(PGPIdType(keydata->key_id)) ;
#ifdef DEBUG_PGPHANDLER
else
@ -620,7 +625,9 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
dummy_keyring.nkeys_allocated=1 ;
dummy_keyring.keys=const_cast<ops_keydata_t*>(pubkey) ;
if( (!ops_validate_key_signatures(result, const_cast<ops_keydata_t*>(pubkey), &dummy_keyring, cb_get_passphrase)) || result->valid_count != 1 || result->invalid_count > 0)
ops_validate_key_signatures(result, const_cast<ops_keydata_t*>(pubkey), &dummy_keyring, cb_get_passphrase) ;
if(result->valid_count != 1 || memcmp((unsigned char*)result->valid_sigs[0].signer_id,pubkey->key_id,KEY_ID_SIZE))
{
import_error = "Cannot validate self signature for the imported key. Sorry." ;
return false ;
@ -646,6 +653,9 @@ bool PGPHandler::importGPGKeyPair(const std::string& filename,PGPIdType& importe
return false ;
}
ops_teardown_file_write(cinfo,fd) ;
addNewKeyToOPSKeyring(_secring,*seckey) ;
initCertificateInfo(_secret_keyring_map[ imported_key_id.toStdString() ],seckey,_secring->nkeys-1) ;
}
else
import_error = "Private key already exists! Not importing it again." ;
@ -820,6 +830,7 @@ bool PGPHandler::decryptTextFromFile(const PGPIdType&,std::string& text,const st
if (f == NULL)
{
std::cerr << "Cannot open file " << inputfile << " for read." << std::endl;
return false;
}

View File

@ -52,9 +52,6 @@ GenCertDialog::GenCertDialog(QWidget *parent, Qt::WFlags flags)
//ui.genName->setFocus(Qt::OtherFocusReason);
QString titleString("<span style=\"font-size:17pt; font-weight:500;"
"color:white;\">%1</span>");
#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,...")) ;
@ -64,8 +61,18 @@ GenCertDialog::GenCertDialog(QWidget *parent, Qt::WFlags flags)
/* get all available pgp private certificates....
* mark last one as default.
*/
init() ;
}
void GenCertDialog::init()
{
std::cerr << "Finding PGPUsers" << std::endl;
ui.genPGPuser->clear() ;
QString titleString("<span style=\"font-size:17pt; font-weight:500;" "color:white;\">%1</span>");
std::list<std::string> pgpIds;
std::list<std::string>::iterator it;
bool foundGPGKeys = false;
@ -93,7 +100,7 @@ GenCertDialog::GenCertDialog(QWidget *parent, Qt::WFlags flags)
} else {
ui.no_gpg_key_label->show();
ui.new_gpg_key_checkbox->setChecked(true);
ui.new_gpg_key_checkbox->hide();
ui.new_gpg_key_checkbox->setEnabled(false);
ui.progressBar->hide();
setWindowTitle(tr("Create new Identity"));
ui.genButton->setText(tr("Generate new Identity"));
@ -118,8 +125,11 @@ void GenCertDialog::newGPGKeyGenUiSetup() {
ui.password_input->show();
ui.genPGPuserlabel->hide();
ui.genPGPuser->hide();
ui.exportIdentity_PB->hide() ;
ui.importIdentity_PB->hide() ;
if(ui.genPGPuser->count() == 0)
ui.exportIdentity_PB->hide() ;
// ui.importIdentity_PB->hide() ;
setWindowTitle(tr("Create new Identity"));
ui.genButton->setText(tr("Generate new Identity"));
ui.label_3->setText( titleStr.arg( tr("Create a new Identity") ) ) ;
@ -171,15 +181,21 @@ void GenCertDialog::importIdentity()
QMessageBox::information(this,tr("Identity not loaded"),tr("Your identity was not loaded properly:")+" \n "+QString::fromStdString(err_string)) ;
return ;
}
else
{
std::string name,email ;
std::string name,email ;
RsInit::GetPGPLoginDetails(gpg_id, name, email);
std::cerr << "Adding PGPUser: " << name << " id: " << gpg_id << std::endl;
RsInit::GetPGPLoginDetails(gpg_id, name, email);
std::cerr << "Adding PGPUser: " << name << " id: " << gpg_id << std::endl;
QVariant userData(QString::fromStdString(gpg_id));
QString gid = QString::fromStdString(gpg_id).right(8) ;
ui.genPGPuser->addItem(QString::fromUtf8(name.c_str()) + " <" + QString::fromUtf8(email.c_str()) + "> (" + gid + ")", userData);
QMessageBox::information(this,tr("New identity imported"),tr("Your identity was imported successfuly:")+" \n"+"\nName :"+QString::fromStdString(name)+"\nemail: " + QString::fromStdString(email)+"\nKey ID: "+QString::fromStdString(gpg_id)+"\n\n"+tr("You can use it now to create a new location.")) ;
}
init() ;
// QVariant userData(QString::fromStdString(gpg_id));
// QString gid = QString::fromStdString(gpg_id).right(8) ;
// ui.genPGPuser->addItem(QString::fromUtf8(name.c_str()) + " <" + QString::fromUtf8(email.c_str()) + "> (" + gid + ")", userData);
}
void GenCertDialog::genPerson()

View File

@ -49,6 +49,8 @@ private slots:
private:
void init() ;
/** Loads the saved connectidialog settings */
// void loadSettings();
void loadCertificates();

View File

@ -662,6 +662,19 @@ border: 1px solid #CCCCCC;}</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="3" column="0">