From e2bee02e9917c7407de600d7d577cd536e281b4a Mon Sep 17 00:00:00 2001 From: Emanoil Kotsev Date: Sat, 9 Dec 2017 15:54:36 +0100 Subject: Add support for GnuPG 2.1 This resolves Bug 2791 Sort keys by name on export Fix the twice display of the default key server Signed-off-by: Emanoil Kotsev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Additional formatting adjustments Signed-off-by: Slávek Banko (cherry picked from commit 9125ead96055376ab2b48f8b5780524c0ee244ac) --- kgpg/kgpgoptions.cpp | 259 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 160 insertions(+), 99 deletions(-) (limited to 'kgpg/kgpgoptions.cpp') diff --git a/kgpg/kgpgoptions.cpp b/kgpg/kgpgoptions.cpp index 9a07a83..d564167 100644 --- a/kgpg/kgpgoptions.cpp +++ b/kgpg/kgpgoptions.cpp @@ -65,15 +65,23 @@ class TQTabWidget; kgpgOptions::kgpgOptions(TQWidget *parent, const char *name) : TDEConfigDialog( parent, name, KGpgSettings::self()) { - defaultServerList="hkp://wwwkeys.eu.pgp.net "; - defaultServerList+=i18n("(Default)"); + defaultKeyServer="hkp://wwwkeys.eu.pgp.net"; + defaultServerList=defaultKeyServer; +// defaultServerList+=i18n("(Default)"); defaultServerList+=",hkp://search.keyserver.net,hkp://wwwkeys.pgp.net,hkp://pgp.dtype.org,hkp://wwwkeys.us.pgp.net"; config = new TDEConfig ("kgpgrc"); config->setGroup("Servers"); + defaultKeyServer=config->readEntry("Default_Server",defaultKeyServer); + TQString keyServer = KgpgInterface::getGpgSetting("keyserver", KGpgSettings::gpgConfigPath()); + + if (!keyServer.isEmpty() ) { + defaultKeyServer=keyServer; + } + serverList=TQStringList::split (",",config->readEntry("Server_List",defaultServerList)); - keyServer = KgpgInterface::getGpgSetting("keyserver", KGpgSettings::gpgConfigPath()); - if (!keyServer.isEmpty()) serverList.prepend(keyServer+" "+i18n("(Default)")); + +// kdDebug(2100)<<"Servers: "<< serverList.join(", ")<gpg_home_path->text(),this,i18n("New GnuPG Home Location")); -if (gpgHome.isEmpty()) return; -if (!gpgHome.endsWith("/")) gpgHome.append("/"); + TQString gpgHome=KFileDialog::getExistingDirectory(page4->gpg_home_path->text(),this,i18n("New GnuPG Home Location")); + if (gpgHome.isEmpty()) { + return; + } + if (!gpgHome.endsWith("/")) { + gpgHome.append("/"); + } TQString confPath="options"; - if (!TQFile(gpgHome+confPath).exists()) { - confPath="gpg.conf"; - if (!TQFile(gpgHome+confPath).exists()) - { - if (KMessageBox::questionYesNo(this,i18n("No configuration file was found in the selected location.\nDo you want to create it now ?\n\nWithout configuration file, neither KGpg nor Gnupg will work properly."),i18n("No Configuration File Found"),i18n("Create"),i18n("Ignore"))==KMessageBox::Yes) ////////// Try to create config File by running gpg once - { - KProcIO *p=new KProcIO(); - *p<<"gpg"<<"--homedir"<start(TDEProcess::Block); //// start gnupg so that it will create a config file + if (!TQFile(gpgHome+confPath).exists()) { confPath="gpg.conf"; - TQFile confFile(gpgHome+confPath); - if (!confFile.open(IO_WriteOnly)) - {KMessageBox::sorry(this,i18n("Cannot create configuration file. Please check if destination media is mounted and if you have write access")); - return; - } - else - { - TQTextStream stream( &confFile ); - stream<<"# Config file created by KGpg\n\n"; - confFile.close(); - } - } - else confPath=TQString(); - } + if (!TQFile(gpgHome+confPath).exists()) { + if (KMessageBox::questionYesNo(this,i18n("No configuration file was found in the selected location.\nDo you want to create it now ?\n\nWithout configuration file, neither KGpg nor Gnupg will work properly."),i18n("No Configuration File Found"),i18n("Create"),i18n("Ignore")) + ==KMessageBox::Yes) {////////// Try to create config File by running gpg once + KProcIO *p=new KProcIO(); + *p<<"gpg"<<"--homedir"<start(TDEProcess::Block); //// start gnupg so that it will create a config file + confPath="gpg.conf"; + TQFile confFile(gpgHome+confPath); + if (!confFile.open(IO_WriteOnly)) { + KMessageBox::sorry(this,i18n("Cannot create configuration file. Please check if destination media is mounted and if you have write access")); + return; + } + else { + TQTextStream stream( &confFile ); + stream<<"# Config file created by KGpg\n\n"; + confFile.close(); + } + } + else { + confPath=TQString(); + } } - page4->gpg_conf_path->setText(confPath); - page4->gpg_home_path->setText(gpgHome); + } + page4->gpg_conf_path->setText(confPath); + page4->gpg_home_path->setText(gpgHome); } void kgpgOptions::updateWidgets() { -TQString pubKeyring,privKeyring; + TQString pubKeyring,privKeyring; gpgConfigPath = KGpgSettings::gpgConfigPath(); page4->gpg_conf_path->setText(KURL(gpgConfigPath).fileName()); @@ -254,17 +266,23 @@ TQString pubKeyring,privKeyring; page4->use_agent->setChecked( useAgent ); - keyServer = KgpgInterface::getGpgSetting("keyserver", gpgConfigPath); - defaultKeyServer = "hkp://wwwkeys.pgp.net"; + TQString keyServer = KgpgInterface::getGpgSetting("keyserver", gpgConfigPath); +// defaultKeyServer = "hkp://wwwkeys.pgp.net"; + + if (!keyServer.isEmpty()) { + defaultKeyServer = keyServer; + } + else { + defaultKeyServer = "hkp://wwwkeys.pgp.net"; + } - if (keyServer.isEmpty()) - keyServer = defaultKeyServer; + serverList.prepend(defaultKeyServer+" "+i18n("(Default)")); page6->ServerBox->clear(); page6->ServerBox->insertStringList(serverList); - kdDebug(2100)<<"Finishing options"<ServerBox->clear(); page6->ServerBox->insertStringList(TQStringList::split(",",defaultServerList)); - kdDebug(2100)<<"Finishing default options"<ServerBox->count();i++) - { - TQString currItem=page6->ServerBox->text(i); - if (currItem.find(" ")!=-1) // it is the default keyserver - keyServer=currItem.section(" ",0,0); - else - { - serverList.append(currItem); - } + for (uint i=0;iServerBox->count();i++) { // 0 is always the default + TQString currItem=page6->ServerBox->text(i); + if (currItem.find(" ")!=-1) {// it is the default keyserver + defaultKeyServer = currItem.section(" ",0,0); + } + else { + serverList.append(currItem); + } } - KgpgInterface::setGpgSetting("keyserver",keyServer, KGpgSettings::gpgConfigPath()); - serverList.prepend(keyServer+" "+i18n("(Default)")); + KgpgInterface::setGpgSetting("keyserver",defaultKeyServer, KGpgSettings::gpgConfigPath()); + //serverList.prepend(keyServer+" "+i18n("(Default)")); currList=serverList.join(","); if (keyGood!=page3->kcfg_ColorGood->color()) @@ -437,6 +454,7 @@ void kgpgOptions::updateSettings() // KGpgSettings::writeConfig(); config->setGroup("Servers"); + config->writeEntry("Default_Server",defaultKeyServer); config->writeEntry("Server_List",currList); emit settingsUpdated(); if (emitReload) emit reloadKeyList(); @@ -483,13 +501,18 @@ void kgpgOptions::slotRemoveMenu(TQString menu) TQString path=locateLocal("data","konqueror/servicemenus/"+menu); TQFile qfile(path); - if (qfile.exists()) - qfile.remove(); - { - //if (!qfile.remove()) KMessageBox::sorry(this,i18n("Cannot remove service menu. Check permissions")); - //else KMessageBox::information(this,i18n("Service menu 'Decrypt File' has been removed.")); - } - //else KMessageBox::sorry(this,i18n("No service menu found")); + if (qfile.exists()) { + qfile.remove(); + //if (!qfile.remove()) { + // KMessageBox::sorry(this,i18n("Cannot remove service menu. Check permissions")); + //} + //else { + // KMessageBox::information(this,i18n("Service menu 'Decrypt File' has been removed.")); + //} + } + //else { + // KMessageBox::sorry(this,i18n("No service menu found")); + //} } @@ -518,9 +541,11 @@ void kgpgOptions::listkey() //////// update display of keys in main management window FILE *fp; - TQString tst,name,trustedvals="idre-",issec; + TQString name,trustedvals="idre-",issec; int counter=0; char line[300]; + TQString currentKey; + TQMap hashMap; FILE *fp2; @@ -533,33 +558,64 @@ void kgpgOptions::listkey() pclose(fp2); - fp = popen("gpg --no-tty --with-colon --list-keys", "r"); - while ( fgets( line, sizeof(line), fp)) { - tst=line; - if (tst.startsWith("pub")) { - name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); - if ((!name.isEmpty()) && (trustedvals.find(tst.section(':',1,1))==-1)) { - counter++; - //name=name.section('<',-1,-1); - // name=name.section('>',0,0); - names+=name; - ids+=tst.section(':',4,4); - if (tst.section(':',4,4).right(8)==alwaysKeyID) - alwaysKeyName=tst.section(':',4,4).right(8)+":"+name; - if (issec.find(tst.section(':',4,4).right(8),0,FALSE)!=-1) - { + fp = popen("gpg --no-tty --with-colon --list-keys", "r"); + while ( fgets( line, sizeof(line), fp)) { + TQString tst=TQString::fromUtf8(line); + kdDebug(2100) << k_funcinfo << "Read one secret key line: " << tst << endl; + if ( tst.startsWith("pub") ) { + currentKey = tst.section(':',4,4); + TQStringList lst; lst << tst; + hashMap.insert(currentKey,lst); + } + else { + hashMap.find(currentKey).data().append(tst); + } + } + pclose(fp); + +// process the list + + TQMap::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TDEListViewItem *item; + TQStringList::Iterator it; + bool dead = true; + TQString name,id,val; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + if ( tst.startsWith("pub") ) { + if ( KgpgInterface::getGpgVersion() < 210 ) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + val = tst.section(':',1,1); + id = tst.section(':',4,4); + } + if ( tst.startsWith("uid") && KgpgInterface::getGpgVersion() >= 210 ) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + } + + if ((!name.isEmpty()) && (trustedvals.find(val)==-1)) { + counter++; + //name=name.section('<',-1,-1); + // name=name.section('>',0,0); + names+=name; + ids+=id; + if (id.right(8)==alwaysKeyID) { + alwaysKeyName=id.right(8)+":"+name; + } + if (issec.find(id.right(8),0,FALSE)!=-1) { //*** page1->file_key->insertItem(pixkeyDouble,tst.section(':',4,4).right(8)+":"+name); //*** page1->always_key->insertItem(pixkeyDouble,tst.section(':',4,4).right(8)+":"+name); - } - else - { + } + else { //*** page1->file_key->insertItem(pixkeySingle,tst.section(':',4,4).right(8)+":"+name); //*** page1->always_key->insertItem(pixkeySingle,tst.section(':',4,4).right(8)+":"+name); - } - } - } - } - pclose(fp); + } + } + } + if (counter==0) { ids+="0"; //*** page1->file_key->insertItem(i18n("none")); @@ -569,32 +625,37 @@ void kgpgOptions::listkey() void kgpgOptions::slotAddKeyServer() { -TQString newServer=KInputDialog::getText(i18n("Add New Key Server"),i18n("Server URL:")); -if (!newServer.isEmpty()) -page6->ServerBox->insertItem(newServer.stripWhiteSpace()); -page6->ServerBox->setSelected(page6->ServerBox->findItem(newServer.stripWhiteSpace()),true); + TQString newServer=KInputDialog::getText(i18n("Add New Key Server"),i18n("Server URL:")); + if (!newServer.isEmpty()) { + page6->ServerBox->insertItem(newServer.stripWhiteSpace()); + } + page6->ServerBox->setSelected(page6->ServerBox->findItem(newServer.stripWhiteSpace()),true); } void kgpgOptions::slotDelKeyServer() { -bool defaultDeleted=false; -if (page6->ServerBox->currentText().find(" ")!=-1) defaultDeleted=true; -page6->ServerBox->removeItem(page6->ServerBox->currentItem()); -page6->ServerBox->setSelected(0,true); -if (defaultDeleted) page6->ServerBox->changeItem(page6->ServerBox->currentText().section(" ",0,0)+" "+i18n("(Default)"),0); + bool defaultDeleted=false; + if (page6->ServerBox->currentText().find(" ")!=-1) { + defaultDeleted=true; + } + page6->ServerBox->removeItem(page6->ServerBox->currentItem()); + page6->ServerBox->setSelected(0,true); + if (defaultDeleted) { + page6->ServerBox->changeItem(page6->ServerBox->currentText().section(" ",0,0)+" "+i18n("(Default)"),0); + } } void kgpgOptions::slotDefaultKeyServer() { -uint curr=page6->ServerBox->currentItem(); -page6->ServerBox->changeItem(page6->ServerBox->currentText ().section(" ",0,0)+" "+i18n("(Default)"),curr); + uint curr=page6->ServerBox->currentItem(); + page6->ServerBox->changeItem(page6->ServerBox->currentText ().section(" ",0,0)+" "+i18n("(Default)"),curr); -for (uint i=0;iServerBox->count();i++) -{ -if (i!=curr) -page6->ServerBox->changeItem(page6->ServerBox->text(i).section(" ",0,0),i); -} -page6->ServerBox->setSelected(curr,true); + for (uint i=0;iServerBox->count();i++) { + if (i!=curr) { + page6->ServerBox->changeItem(page6->ServerBox->text(i).section(" ",0,0),i); + } + } + page6->ServerBox->setSelected(curr,true); } #include "kgpgoptions.moc" -- cgit v1.2.1