diff options
author | Emanoil Kotsev <deloptes@gmail.com> | 2017-12-09 15:54:36 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2017-12-09 15:54:36 +0100 |
commit | 9125ead96055376ab2b48f8b5780524c0ee244ac (patch) | |
tree | ae094b5757d75c020f26f57cd0f27b06bce79bf1 /kgpg/listkeys.cpp | |
parent | 96765e0aa27a58e8747b8f867713fd1cc45c19b4 (diff) | |
download | tdeutils-9125ead96055376ab2b48f8b5780524c0ee244ac.tar.gz tdeutils-9125ead96055376ab2b48f8b5780524c0ee244ac.zip |
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 <deloptes@gmail.com>
Additional formatting adjustments
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'kgpg/listkeys.cpp')
-rw-r--r-- | kgpg/listkeys.cpp | 1015 |
1 files changed, 703 insertions, 312 deletions
diff --git a/kgpg/listkeys.cpp b/kgpg/listkeys.cpp index 4b1f2ee..2c75853 100644 --- a/kgpg/listkeys.cpp +++ b/kgpg/listkeys.cpp @@ -4,6 +4,10 @@ begin : Thu Jul 4 2002 copyright : (C) 2002 by Jean-Baptiste Mardelle email : bj@altern.org + + updated to handle gpg21 : Sun Jul 30 10:18:29 CEST 2017 + copyright : (C) 2017 by Emanoil Kotsev + email : deloptes@yahoo.com ***************************************************************************/ /*************************************************************************** @@ -47,6 +51,7 @@ #include <tqtoolbutton.h> #include <tqradiobutton.h> #include <tqpopupmenu.h> +#include <tqcursor.h> #include <kurlrequester.h> #include <tdeio/netaccess.h> @@ -216,7 +221,6 @@ TQString UpdateViewItem::key( int column, bool ) const KgpgSelKey::KgpgSelKey(TQWidget *parent, const char *name,bool allowMultipleSelection, TQString preselected): KDialogBase( parent, name, true,i18n("Private Key List"),Ok | Cancel) { - TQString keyname; page = new TQWidget(this); TQLabel *labeltxt; TDEIconLoader *loader = TDEGlobal::iconLoader(); @@ -239,49 +243,82 @@ KDialogBase( parent, name, true,i18n("Private Key List"),Ok | Cancel) if (preselected==TQString()) preselected = KGpgSettings::defaultKey(); FILE *fp,*fp2; - TQString fullname,tst,tst2; char line[300]; bool selectedok=false; bool warn=false; - TDEListViewItem *item; + TQString currentKey; + TQMap<TQString,TQStringList> hashMap; + + fp = popen("gpg --no-tty --with-colons --list-secret-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("sec") ) { + 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<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TDEListViewItem *item; + TQStringList::Iterator it; + bool dead = true; + TQString fullname,val,id; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + TQStringList keyString=TQStringList::split(":",tst,true); + if (tst.startsWith("sec")) { + val=keyString[6]; + id=TQString("0x"+keyString[4].right(8)); + if (val.isEmpty()) { + val=i18n("Unlimited"); + } + fullname=keyString[9]; + + fp2 = popen(TQFile::encodeName(TQString("gpg --no-tty --with-colons --list-key %1").arg(KShellProcess::quote(id))), "r"); + dead=true; + while ( fgets( line, sizeof(line), fp2)) { + TQString tst2=TQString::fromUtf8(line); + if (tst2.startsWith("pub")) { + const TQString trust2=tst2.section(':',1,1); + switch( trust2[0] ) { + case 'f': + dead=false; + break; + case 'u': + dead=false; + break; + case '-': + if (tst2.section(':',11,11).find('D')==-1) { + warn=true; + } + break; + default: + break; + } + if (tst2.section(':',11,11).find('D')!=-1) { + dead=true; + } + break; + } + } + pclose(fp2); + } + if ( tst.startsWith("uid") && fullname.isEmpty() ) { + fullname = tst.section(':',9,9); + } + } - fp = popen("gpg --no-tty --with-colons --list-secret-keys", "r"); - while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - if (tst.startsWith("sec")) { - TQStringList keyString=TQStringList::split(":",tst,true); - TQString val=keyString[6]; - TQString id=TQString("0x"+keyString[4].right(8)); - if (val.isEmpty()) - val=i18n("Unlimited"); - fullname=keyString[9]; - - fp2 = popen(TQFile::encodeName(TQString("gpg --no-tty --with-colons --list-key %1").arg(KShellProcess::quote(id))), "r"); - bool dead=true; - while ( fgets( line, sizeof(line), fp2)) { - tst2=TQString::fromUtf8(line); - if (tst2.startsWith("pub")) { - const TQString trust2=tst2.section(':',1,1); - switch( trust2[0] ) { - case 'f': - dead=false; - break; - case 'u': - dead=false; - break; - case '-': - if (tst2.section(':',11,11).find('D')==-1) warn=true; - break; - default: - break; - } - if (tst2.section(':',11,11).find('D')!=-1) - dead=true; - break; - } - } - pclose(fp2); if (!fullname.isEmpty() && (!dead)) { TQString keyMail,keyName; if (fullname.find("<")!=-1) { @@ -308,8 +345,6 @@ KDialogBase( parent, name, true,i18n("Private Key List"),Ok | Cancel) } } } - } - pclose(fp); if (warn) { @@ -395,6 +430,7 @@ TQString KgpgSelKey::getkeyMail() KeyView::KeyView( TQWidget *parent, const char *name ) : TDEListView( parent, name ) { +// kdDebug(2100) << k_funcinfo << endl; TDEIconLoader *loader = TDEGlobal::iconLoader(); pixkeyOrphan=loader->loadIcon("kgpg_key4",TDEIcon::Small,20); @@ -434,6 +470,7 @@ KeyView::KeyView( TQWidget *parent, const char *name ) void KeyView::droppedfile (KURL url) { +// kdDebug(2100) << k_funcinfo << endl; if (KMessageBox::questionYesNo(this,i18n("<p>Do you want to import file <b>%1</b> into your key ring?</p>").arg(url.path()), TQString(), i18n("Import"), i18n("Do Not Import"))!=KMessageBox::Yes) return; @@ -479,8 +516,8 @@ void KeyView::startDrag() mySearchLine::mySearchLine(TQWidget *parent, KeyView *listView, const char *name) :TDEListViewSearchLine(parent,listView,name) { -searchListView=listView; -setKeepParentsVisible(false); + searchListView=listView; + setKeepParentsVisible(false); } mySearchLine::~ mySearchLine() @@ -497,6 +534,7 @@ else return TDEListViewSearchLine::itemMatches(item,s); void mySearchLine::updateSearch(const TQString& s) { +// kdDebug(2100) << k_funcinfo << endl; TDEListViewSearchLine::updateSearch(s); if (searchListView->displayOnlySecret || !searchListView->displayDisabled) { @@ -521,8 +559,10 @@ void mySearchLine::updateSearch(const TQString& s) listKeys::listKeys(TQWidget *parent, const char *name) : DCOPObject( "KeyInterface" ), TDEMainWindow(parent, name,0) { +// kdDebug(2100) << k_funcinfo << endl; //KWin::setType(TQt::WDestructiveClose); + keysList2 = new KeyView(this); keysList2->photoKeysList=TQString(); keysList2->groupNb=0; @@ -725,6 +765,8 @@ listKeys::listKeys(TQWidget *parent, const char *name) : DCOPObject( "KeyInterfa connect(s_kgpgEditor,TQT_SIGNAL(refreshImported(TQStringList)),keysList2,TQT_SLOT(slotReloadKeys(TQStringList))); connect(this,TQT_SIGNAL(fontChanged(TQFont)),s_kgpgEditor,TQT_SLOT(slotSetFont(TQFont))); connect(s_kgpgEditor->view->editor,TQT_SIGNAL(refreshImported(TQStringList)),keysList2,TQT_SLOT(slotReloadKeys(TQStringList))); + +// kdDebug(2100) << k_funcinfo << "getGpgversion" << KgpgInterface::getGpgVersion() <<endl; } @@ -849,6 +891,7 @@ void listKeys::slotGotoDefaultKey() void listKeys::refreshKeyFromServer() { +// kdDebug(2100) << k_funcinfo << endl; if (keysList2->currentItem()==NULL) return; TQString keyIDS; @@ -874,6 +917,7 @@ void listKeys::refreshKeyFromServer() void listKeys::refreshFinished() { +// kdDebug(2100) << k_funcinfo << endl; if (kServer) kServer=0L; @@ -902,6 +946,7 @@ void listKeys::slotDelUid() void listKeys::slotregenerate() { +// kdDebug(2100) << k_funcinfo << endl; FILE *fp; TQString tst; char line[300]; @@ -1029,6 +1074,7 @@ void listKeys::slotSetPhotoSize(int size) void listKeys::findKey() { +// kdDebug(2100) << k_funcinfo << endl; KFindDialog fd(this,"find_dialog",0,""); if ( fd.exec() != TQDialog::Accepted ) return; @@ -1039,6 +1085,7 @@ void listKeys::findKey() void listKeys::findFirstKey() { +// kdDebug(2100) << k_funcinfo << endl; if (searchString.isEmpty()) return; bool foundItem=true; @@ -1075,6 +1122,7 @@ void listKeys::findFirstKey() void listKeys::findNextKey() { +// kdDebug(2100) << k_funcinfo << endl; //kdDebug(2100)<<"find next"<<endl; if (searchString.isEmpty()) { findKey(); @@ -1119,6 +1167,7 @@ void listKeys::findNextKey() void listKeys::addToKAB() { +// kdDebug(2100) << k_funcinfo << endl; TDEABC::Key key; if (!keysList2->currentItem()) return; //TQString email=extractKeyMail(keysList2->currentItem()).stripWhiteSpace(); @@ -1200,6 +1249,7 @@ void listKeys::closeEvent ( TQCloseEvent * e ) void listKeys::showKeyServer() { +// kdDebug(2100) << k_funcinfo << endl; keyServer *ks=new keyServer(this); connect(ks,TQT_SIGNAL( importFinished(TQString) ) , keysList2, TQT_SLOT(refreshcurrentkey(TQString))); ks->exec(); @@ -1211,6 +1261,7 @@ void listKeys::showKeyServer() void listKeys::checkList() { +// kdDebug(2100) << k_funcinfo << endl; TQPtrList<TQListViewItem> exportList=keysList2->selectedItems(); if (exportList.count()>1) { @@ -1266,6 +1317,7 @@ void listKeys::quitApp() void listKeys::readOptions() { +// kdDebug(2100) << k_funcinfo << endl; clipboardMode=TQClipboard::Clipboard; if (KGpgSettings::useMouseSelection() && (kapp->clipboard()->supportsSelection())) clipboardMode=TQClipboard::Selection; @@ -1488,6 +1540,7 @@ void listKeys::slotexportsec() void listKeys::slotexport() { +// kdDebug(2100) << k_funcinfo << endl; ///////////////////// export key if (keysList2->currentItem()==NULL) return; @@ -1599,6 +1652,7 @@ void listKeys::slotProcessExportClip(TQString keys) void listKeys::showKeyInfo(TQString keyID) { +// kdDebug(2100) << k_funcinfo << endl; KgpgKeyInfo *opts=new KgpgKeyInfo(this,"key_props",keyID); opts->show(); } @@ -1606,16 +1660,22 @@ void listKeys::showKeyInfo(TQString keyID) void listKeys::slotShowPhoto() { +// kdDebug(2100) << k_funcinfo << endl; TDETrader::OfferList offers = TDETrader::self()->query("image/jpeg", "Type == 'Application'"); KService::Ptr ptr = offers.first(); //KMessageBox::sorry(0,ptr->desktopEntryName()); KProcIO *p=new KProcIO(TQTextCodec::codecForLocale()); - *p<<"gpg"<<"--no-tty"<<"--photo-viewer"<<TQString(TQFile::encodeName(ptr->desktopEntryName()+" %i"))<<"--edit-key"<<keysList2->currentItem()->parent()->text(6)<<"uid"<<keysList2->currentItem()->text(6)<<"showphoto"<<"quit"; + *p<<"gpg"<<"--no-tty" + <<"--photo-viewer"<<TQString(TQFile::encodeName(ptr->desktopEntryName()+" %i")) + <<"--edit-key"<<keysList2->currentItem()->parent()->text(6) + <<"uid"<<keysList2->currentItem()->text(6) + <<"showphoto"<<"quit"; p->start(TDEProcess::DontCare,true); } void listKeys::listsigns() { +// kdDebug(2100) << k_funcinfo << endl; //kdDebug(2100)<<"Edit -------------------------------"<<endl; if (keysList2->currentItem()==NULL) return; @@ -1646,6 +1706,7 @@ void listKeys::listsigns() void listKeys::groupAdd() { +// kdDebug(2100) << k_funcinfo << endl; TQPtrList<TQListViewItem> addList=gEdit->availableKeys->selectedItems(); for ( uint i = 0; i < addList.count(); ++i ) if ( addList.at(i) ) { @@ -1655,6 +1716,7 @@ void listKeys::groupAdd() void listKeys::groupRemove() { +// kdDebug(2100) << k_funcinfo << endl; TQPtrList<TQListViewItem> remList=gEdit->groupKeys->selectedItems(); for ( uint i = 0; i < remList.count(); ++i ) if ( remList.at(i) ) { @@ -1664,6 +1726,7 @@ void listKeys::groupRemove() void listKeys::deleteGroup() { +// kdDebug(2100) << k_funcinfo << endl; if (!keysList2->currentItem() || !keysList2->currentItem()->text(6).isEmpty()) return; @@ -1686,6 +1749,7 @@ void listKeys::deleteGroup() void listKeys::groupChange() { +// kdDebug(2100) << k_funcinfo << endl; TQStringList selected; TQListViewItem *item=gEdit->groupKeys->firstChild(); while (item) { @@ -1697,6 +1761,7 @@ void listKeys::groupChange() void listKeys::createNewGroup() { +// kdDebug(2100) << k_funcinfo << endl; TQStringList badkeys,keysGroup; if (keysList2->selectedItems().count()>0) { @@ -1745,7 +1810,8 @@ void listKeys::createNewGroup() void listKeys::groupInit(TQStringList keysGroup) { - kdDebug(2100)<<"preparing group"<<endl; +// kdDebug(2100) << k_funcinfo << endl; +// kdDebug(2100)<<"preparing group"<<endl; TQStringList lostKeys; bool foundId; @@ -1754,7 +1820,7 @@ void listKeys::groupInit(TQStringList keysGroup) TQListViewItem *item=gEdit->availableKeys->firstChild(); foundId=false; while (item) { - kdDebug(2100)<<"Searching in key: "<<item->text(0)<<endl; + // kdDebug(2100)<<"Searching in key: "<<item->text(0)<<endl; if (TQString(*it).right(8).lower()==item->text(2).right(8).lower()) { gEdit->groupKeys->insertItem(item); foundId=true; @@ -1771,6 +1837,7 @@ void listKeys::groupInit(TQStringList keysGroup) void listKeys::editGroup() { +// kdDebug(2100) << k_funcinfo << endl; if (!keysList2->currentItem() || !keysList2->currentItem()->text(6).isEmpty()) return; TQStringList keysGroup; @@ -1826,6 +1893,7 @@ void listKeys::editGroup() void listKeys::signkey() { +// kdDebug(2100) << k_funcinfo << endl; /////////////// sign a key if (keysList2->currentItem()==NULL) return; @@ -1833,11 +1901,16 @@ void listKeys::signkey() return; signList=keysList2->selectedItems(); - bool keyDepth=true; - for ( uint i = 0; i < signList.count(); ++i ) - if ( signList.at(i) ) - if (signList.at(i)->depth()!=0) - keyDepth=false; + + bool keyDepth=true; + for ( uint i = 0; i < signList.count(); ++i ) { + if ( signList.at(i) ) { + if (signList.at(i)->depth()!=0) { + keyDepth=false; + } + } + // kdDebug(2100) << k_funcinfo << "List at: " << signList.at(i)->text(6) << endl; + } if (!keyDepth) { KMessageBox::sorry(this,i18n("You can only sign primary keys. Please check your selection.")); return; @@ -1859,6 +1932,7 @@ void listKeys::signkey() if ((len > 0) && (len % 4 == 0)) for (uint n = 0; 4*(n+1) < len; n++) fingervalue.insert(5*n+4, ' '); + break; } } pclose(pass); @@ -1916,6 +1990,11 @@ void listKeys::signkey() keyCount=0; delete opts; globalCount=signList.count(); + +// kdDebug(2100) << k_funcinfo << "Terminal sign checked: " << terminalSign->isChecked() << endl; +// kdDebug(2100) << k_funcinfo << "globalCount : " << globalCount << endl; +// kdDebug(2100) << k_funcinfo << "signList Count : " << globalCount << endl; + if (!terminalSign->isChecked()) signLoop(); else { @@ -1924,26 +2003,25 @@ void listKeys::signkey() TDEConfig *config = TDEGlobal::config(); config->setGroup("General"); kp<< config->readPathEntry("TerminalApplication","konsole"); - kp<<"-e" - <<"gpg" - <<"--no-secmem-warning" - <<"-u" - <<globalkeyID - <<"--edit-key" - <<signList.at(0)->text(6); + kp<<"-e" <<"gpg" <<"--no-secmem-warning" + <<"-u" <<globalkeyID <<"--edit-key" <<signList.at(0)->text(6); if (globalisLocal) kp<<"lsign"; else kp<<"sign"; + + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); kp.start(TDEProcess::Block); keysList2->refreshcurrentkey(keysList2->currentItem()); + TQApplication::restoreOverrideCursor(); } } void listKeys::signLoop() { +// kdDebug(2100) << k_funcinfo << endl; if (keyCount<globalCount) { - kdDebug(2100)<<"Sign process for key: "<<keyCount<<" on a total of "<<signList.count()<<endl; + // kdDebug(2100)<<"Sign process for key: "<<keyCount<<" on a total of "<<signList.count()<<endl; if ( signList.at(keyCount) ) { KgpgInterface *signKeyProcess=new KgpgInterface(); TQObject::connect(signKeyProcess,TQT_SIGNAL(signatureFinished(int)),TQT_TQOBJECT(this),TQT_SLOT(signatureResult(int))); @@ -1954,12 +2032,16 @@ void listKeys::signLoop() void listKeys::signatureResult(int success) { - if (success==3) - keysList2->refreshcurrentkey(signList.at(keyCount)); - - else if (success==2) - KMessageBox::sorry(this,i18n("<qt>Bad passphrase, key <b>%1</b> not signed.</qt>").arg(signList.at(keyCount)->text(0)+i18n(" (")+signList.at(keyCount)->text(1)+i18n(")"))); - +// kdDebug(2100) << k_funcinfo << endl; +// kdDebug(2100) << k_funcinfo << "success" << success << endl; + if ( success>=3 ) { + keysList2->refreshcurrentkey(signList.at(keyCount)); + } + else { + if (success==2) { + KMessageBox::sorry(this,i18n("<qt>Bad passphrase, key <b>%1</b> not signed.</qt>").arg(signList.at(keyCount)->text(0)+i18n(" (")+signList.at(keyCount)->text(1)+i18n(")"))); + } + } keyCount++; signLoop(); } @@ -1967,6 +2049,7 @@ void listKeys::signatureResult(int success) void listKeys::importallsignkey() { +//// kdDebug(2100) << k_funcinfo << endl; if (keysList2->currentItem()==NULL) return; if (! keysList2->currentItem()->firstChild()) { @@ -1989,6 +2072,7 @@ void listKeys::importallsignkey() void listKeys::preimportsignkey() { +// kdDebug(2100) << k_funcinfo << endl; if (keysList2->currentItem()==NULL) return; else @@ -1997,7 +2081,7 @@ void listKeys::preimportsignkey() bool listKeys::importRemoteKey(TQString keyID) { - +// kdDebug(2100) << k_funcinfo << endl; kServer=new keyServer(0,"server_dialog",false,true); kServer->page->kLEimportid->setText(keyID); kServer->page->Buttonimport->setDefault(true); @@ -2013,6 +2097,7 @@ bool listKeys::importRemoteKey(TQString keyID) void listKeys::dcopImportFinished() { +// kdDebug(2100) << k_funcinfo << endl; if (kServer) kServer=0L; TQByteArray params; @@ -2024,11 +2109,13 @@ void listKeys::dcopImportFinished() void listKeys::importsignkey(TQString importKeyId) { +// kdDebug(2100) << k_funcinfo << endl; /////////////// sign a key kServer=new keyServer(0,"server_dialog",false); kServer->page->kLEimportid->setText(importKeyId); //kServer->Buttonimport->setDefault(true); kServer->slotImport(); +// kServer->slotSearch(); //kServer->show(); connect( kServer, TQT_SIGNAL( importFinished(TQString) ) , this, TQT_SLOT( importfinished())); } @@ -2036,6 +2123,7 @@ void listKeys::importsignkey(TQString importKeyId) void listKeys::importfinished() { +// kdDebug(2100) << k_funcinfo << endl; if (kServer) kServer=0L; refreshkey(); @@ -2044,10 +2132,12 @@ void listKeys::importfinished() void listKeys::delsignkey() { +// kdDebug(2100) << k_funcinfo << endl; /////////////// sign a key if (keysList2->currentItem()==NULL) return; - if (keysList2->currentItem()->depth()>1) { + if ( (keysList2->currentItem()->depth()>1 && KgpgInterface::getGpgVersion() < 210 ) + || (keysList2->currentItem()->depth()>2 && KgpgInterface::getGpgVersion() >= 210 ) ) { KMessageBox::sorry(this,i18n("Edit key manually to delete this signature.")); return; } @@ -2055,9 +2145,13 @@ void listKeys::delsignkey() TQString signID,parentKey,signMail,parentMail; ////////////////// open a key selection dialog (KgpgSelKey, see begining of this file) - parentKey=keysList2->currentItem()->parent()->text(6); + parentKey=(( KgpgInterface::getGpgVersion() < 210 ) + ? keysList2->currentItem()->parent()->text(6) + : keysList2->currentItem()->parent()->parent()->text(6)); signID=keysList2->currentItem()->text(6); - parentMail=keysList2->currentItem()->parent()->text(0)+" ("+keysList2->currentItem()->parent()->text(1)+")"; + parentMail=(( KgpgInterface::getGpgVersion() < 210 ) + ? keysList2->currentItem()->parent()->text(0)+" ("+keysList2->currentItem()->parent()->text(1)+")" + : keysList2->currentItem()->parent()->parent()->text(0)+" ("+keysList2->currentItem()->parent()->parent()->text(1)+")"); signMail=keysList2->currentItem()->text(0)+" ("+keysList2->currentItem()->text(1)+")"; if (parentKey==signID) { @@ -2075,6 +2169,7 @@ void listKeys::delsignkey() void listKeys::delsignatureResult(bool success) { +// kdDebug(2100) << k_funcinfo << endl; if (success) { TQListViewItem *top=keysList2->currentItem(); while (top->depth()!=0) @@ -2088,6 +2183,7 @@ void listKeys::delsignatureResult(bool success) void listKeys::slotedit() { +// kdDebug(2100) << k_funcinfo << endl; if (!keysList2->currentItem()) return; if (keysList2->currentItem()->depth()!=0) @@ -2100,12 +2196,8 @@ void listKeys::slotedit() TDEConfig *config = TDEGlobal::config(); config->setGroup("General"); kp<< config->readPathEntry("TerminalApplication","konsole"); - kp<<"-e" - <<"gpg" - <<"--no-secmem-warning" - <<"--utf8-strings" - <<"--edit-key" - <<keysList2->currentItem()->text(6) + kp<<"-e" <<"gpg" <<"--no-secmem-warning" <<"--utf8-strings" + <<"--edit-key" <<keysList2->currentItem()->text(6) <<"help"; kp.start(TDEProcess::Block); keysList2->refreshcurrentkey(keysList2->currentItem()); @@ -2114,6 +2206,7 @@ void listKeys::slotedit() void listKeys::slotgenkey() { +// kdDebug(2100) << k_funcinfo << endl; ////////// generate key keyGenerate *genkey=new keyGenerate(this,0); if (genkey->exec()==TQDialog::Accepted) { @@ -2230,6 +2323,7 @@ void listKeys::slotgenkey() void listKeys::readgenprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required; while (p->readln(required,true)!=-1) { if (required.find("KEY_CREATED")!=-1) @@ -2242,11 +2336,16 @@ void listKeys::readgenprocess(KProcIO *p) void listKeys::genover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; newkeyID=TQString(); continueSearch=true; KProcIO *conprocess=new KProcIO(TQTextCodec::codecForLocale()); + TQString fpropt = (KgpgInterface::getGpgVersion() < 210 ) ? "--fingerprint" : "--with-fingerprint"; *conprocess<< "gpg"; - *conprocess<<"--no-secmem-warning"<<"--with-colons"<<"--fingerprint"<<"--list-keys"<<newKeyName; + *conprocess<<"--no-secmem-warning" + <<"--with-colons" + << fpropt + <<"--list-keys"<<newKeyName; TQObject::connect(conprocess,TQT_SIGNAL(readReady(KProcIO *)),TQT_TQOBJECT(this),TQT_SLOT(slotReadFingerProcess(KProcIO *))); TQObject::connect(conprocess, TQT_SIGNAL(processExited(TDEProcess *)),TQT_TQOBJECT(this), TQT_SLOT(newKeyDone(TDEProcess *))); conprocess->start(TDEProcess::NotifyOnExit,true); @@ -2255,16 +2354,17 @@ void listKeys::genover(TDEProcess *) void listKeys::slotReadFingerProcess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString outp; while (p->readln(outp)!=-1) { - if (outp.startsWith("pub") && (continueSearch)) { + if ( outp.startsWith("pub") && (continueSearch)) { newkeyID=outp.section(':',4,4).right(8).prepend("0x"); } if (outp.startsWith("fpr")) { if (newkeyFinger.lower()==outp.section(':',9,9).lower()) continueSearch=false; - // kdDebug(2100)<<newkeyFinger<<" test:"<<outp.section(':',9,9)<<endl; + // kdDebug(2100)<<newkeyFinger<<" test:"<<outp.section(':',9,9)<<endl; } } } @@ -2272,6 +2372,7 @@ void listKeys::slotReadFingerProcess(KProcIO *p) void listKeys::newKeyDone(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; changeMessage(i18n("Ready"),0); // refreshkey(); if (newkeyID.isEmpty()) { @@ -2321,6 +2422,7 @@ void listKeys::newKeyDone(TDEProcess *) void listKeys::doFilePrint(TQString url) { +// kdDebug(2100) << k_funcinfo << endl; TQFile qfile(url); if (qfile.open(IO_ReadOnly)) { TQTextStream t( &qfile ); @@ -2331,6 +2433,7 @@ void listKeys::doFilePrint(TQString url) void listKeys::doPrint(TQString txt) { +// kdDebug(2100) << k_funcinfo << endl; KPrinter prt; //kdDebug(2100)<<"Printing..."<<endl; if (prt.setup(this)) { @@ -2355,8 +2458,7 @@ void listKeys::deleteseckey() TDEConfig *config = TDEGlobal::config(); config->setGroup("General"); *conprocess<< config->readPathEntry("TerminalApplication","konsole"); - *conprocess<<"-e"<<"gpg" - <<"--no-secmem-warning" + *conprocess<<"-e"<<"gpg" <<"--no-secmem-warning" <<"--delete-secret-key"<<keysList2->currentItem()->text(6); TQObject::connect(conprocess, TQT_SIGNAL(processExited(TDEProcess *)),TQT_TQOBJECT(this), TQT_SLOT(reloadSecretKeys())); conprocess->start(TDEProcess::NotifyOnExit,TDEProcess::AllOutput); @@ -2364,6 +2466,7 @@ void listKeys::deleteseckey() void listKeys::reloadSecretKeys() { +// kdDebug(2100) << k_funcinfo << endl; FILE *fp; char line[300]; keysList2->secretList=TQString(); @@ -2379,6 +2482,7 @@ void listKeys::reloadSecretKeys() void listKeys::confirmdeletekey() { +// kdDebug(2100) << k_funcinfo << endl; if (keysList2->currentItem()->depth()!=0) { if ((keysList2->currentItem()->depth()==1) && (keysList2->currentItem()->text(4)=="-") && (keysList2->currentItem()->text(6).startsWith("0x"))) delsignkey(); @@ -2422,24 +2526,25 @@ void listKeys::confirmdeletekey() void listKeys::deletekey() { +// kdDebug(2100) << k_funcinfo << endl; TQPtrList<TQListViewItem> exportList=keysList2->selectedItems(); +// kdDebug(2100) << k_funcinfo << "Delete list count: " << exportList.count() << endl; if (exportList.count()==0) return; TDEProcess gp; - gp << "gpg" - << "--no-tty" - << "--no-secmem-warning" - << "--batch" - << "--yes" - << "--delete-key"; + gp << "gpg" << "--no-tty" << "--no-secmem-warning" << "--batch" << "--yes" << "--delete-key"; for ( uint i = 0; i < exportList.count(); ++i ) if ( exportList.at(i) ) gp<<(exportList.at(i)->text(6)).stripWhiteSpace(); gp.start(TDEProcess::Block); - for ( uint i = 0; i < exportList.count(); ++i ) - if ( exportList.at(i) ) - keysList2->refreshcurrentkey(exportList.at(i)); +// FIXME: this produces an error when key was successfully removed +// for ( uint i = 0; i < exportList.count(); ++i ) { +// if ( exportList.at(i) ) { +// keysList2->refreshcurrentkey(exportList.at(i)); +// } +// } + if (keysList2->currentItem()) { TQListViewItem * myChild = keysList2->currentItem(); while(!myChild->isVisible()) { @@ -2460,13 +2565,18 @@ void listKeys::deletekey() keysList2->setCurrentItem(myChild); } } - else stateChanged("empty_list"); + else { + stateChanged("empty_list"); + } + + keysList2->refreshkeylist(); // update the list to remove signitures from the deleted key changeMessage(i18n("%1 Keys, %2 Groups").arg(keysList2->childCount()-keysList2->groupNb).arg(keysList2->groupNb),1); } void listKeys::slotPreImportKey() { +// kdDebug(2100) << k_funcinfo << endl; KDialogBase *dial=new KDialogBase( KDialogBase::Swallow, i18n("Key Import"), KDialogBase::Ok | KDialogBase::Cancel, KDialogBase::Ok, this, "key_import",true); SrcSelect *page=new SrcSelect(); @@ -2504,9 +2614,9 @@ void listKeys::slotPreImportKey() void KeyView::expandGroup(TQListViewItem *item) { - +// kdDebug(2100) << k_funcinfo << endl; TQStringList keysGroup=KgpgInterface::getGpgGroupSetting(item->text(0),KGpgSettings::gpgConfigPath()); - kdDebug(2100)<<keysGroup<<endl; +// kdDebug(2100)<<keysGroup<<endl; for ( TQStringList::Iterator it = keysGroup.begin(); it != keysGroup.end(); ++it ) { UpdateViewItem *item2=new UpdateViewItem(item,TQString(*it),TQString(),TQString(),TQString(),TQString(),TQString(),TQString()); item2->setPixmap(0,pixkeyGroup); @@ -2516,10 +2626,13 @@ void KeyView::expandGroup(TQListViewItem *item) TQPixmap KeyView::slotGetPhoto(TQString photoId,bool mini) { +// kdDebug(2100) << k_funcinfo << endl; KTempFile *phototmp=new KTempFile(); TQString popt="cp %i "+phototmp->name(); KProcIO *p=new KProcIO(TQTextCodec::codecForLocale()); - *p<<"gpg"<<"--show-photos"<<"--photo-viewer"<<TQString(TQFile::encodeName(popt))<<"--list-keys"<<photoId; + *p<<"gpg"<<"--show-photos" + <<"--photo-viewer"<<TQString(TQFile::encodeName(popt)) + <<"--list-keys"<<photoId; p->start(TDEProcess::Block); TQPixmap pixmap; @@ -2538,48 +2651,71 @@ TQPixmap KeyView::slotGetPhoto(TQString photoId,bool mini) void KeyView::expandKey(TQListViewItem *item) { - +// kdDebug(2100) << k_funcinfo << endl; if (item->childCount()!=0) return; // key has already been expanded FILE *fp; - TQString cycle; - TQStringList tst; - char tmpline[300]; + + + char line[300]; + TQString currentKey; + TQMap<TQString,TQStringList> hashMap; +// kdDebug(2100)<<"Expanding Key: "<<item->text(6)<<endl; + + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); + fp = popen(TQFile::encodeName(TQString("gpg --no-secmem-warning --no-tty --with-colons --list-sigs "+item->text(6))), "r"); + + while ( fgets( line, sizeof(line), fp)) { + TQString tst=TQString::fromUtf8(line); +// kdDebug(2100) << k_funcinfo << "Read one public sig line: " << tst; + if ( tst.startsWith("pub") ) { + currentKey = tst.section(':',4,4).right(8); + TQStringList lst; lst << tst; + hashMap.insert(currentKey,lst); + } + else { + hashMap.find(currentKey).data().append(tst); + } + } + pclose(fp); + + TQMap<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQStringList::Iterator it; + TQString cycle="pub"; + bool noID = (KgpgInterface::getGpgVersion() < 210 ) ? false : true; + UpdateViewItem *itemsub=NULL; UpdateViewItem *itemuid=NULL; UpdateViewItem *itemsig=NULL; UpdateViewItem *itemrev=NULL; TQPixmap keyPhotoId; int uidNumber=2; - bool dropFirstUid=false; - - kdDebug(2100)<<"Expanding Key: "<<item->text(6)<<endl; - - cycle="pub"; - bool noID=false; - fp = popen(TQFile::encodeName(TQString("gpg --no-secmem-warning --no-tty --with-colons --list-sigs "+item->text(6))), "r"); - - while ( fgets( tmpline, sizeof(tmpline), fp)) { - TQString line = TQString::fromUtf8( tmpline ); - tst=TQStringList::split(":",line,true); - if ((tst[0]=="pub") && (tst[9].isEmpty())) /// Primary User Id is separated from public key - uidNumber=1; - if (tst[0]=="uid" || tst[0]=="uat") { - if (dropFirstUid) { - dropFirstUid=false; - } else { + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString line = (*it); + TQStringList tst=TQStringList::split(":",line,true); +// // kdDebug(2100)<<"Loop: "<< tst[0] << " : " << tst[9] <<endl; + if ((tst[0]=="pub") && (tst[9].isEmpty())) {/// Primary User Id is separated from public key + noID=true; + continue; + } + if (tst[0]=="uid" || tst[0]=="uat") { gpgKey uidKey=extractKey(line); if (tst[0]=="uat") { - kdDebug(2100)<<"Found photo at uid "<<uidNumber<<endl; + // kdDebug(2100)<<"Found photo at uid "<<uidNumber<<endl; itemuid= new UpdateViewItem(item,i18n("Photo id"),TQString(),TQString(),"-","-","-",TQString::number(uidNumber)); if (displayPhoto) { kgpgphototmp=new KTempFile(); kgpgphototmp->setAutoDelete(true); TQString pgpgOutput="cp %i "+kgpgphototmp->name(); KProcIO *p=new KProcIO(TQTextCodec::codecForLocale()); - *p<<"gpg"<<"--no-tty"<<"--photo-viewer"<<TQString(TQFile::encodeName(pgpgOutput)); - *p<<"--edit-key"<<item->text(6)<<"uid"<<TQString::number(uidNumber)<<"showphoto"<<"quit"; + *p<<"gpg"<<"--no-tty" + <<"--photo-viewer"<<TQString(TQFile::encodeName(pgpgOutput)) + <<"--edit-key"<<item->text(6) + <<"uid"<<TQString::number(uidNumber) + <<"showphoto"<<"quit"; p->start(TDEProcess::Block); TQPixmap pixmap; pixmap.load(kgpgphototmp->name()); @@ -2592,82 +2728,122 @@ void KeyView::expandKey(TQListViewItem *item) } else itemuid->setPixmap(0,pixuserphoto); itemuid->setPixmap(2,uidKey.trustpic); - cycle="uid"; } else { - kdDebug(2100)<<"Found uid at "<<uidNumber<<endl; - itemuid= new UpdateViewItem(item,uidKey.gpgkeyname,uidKey.gpgkeymail,TQString(),"-","-","-","-"); + // kdDebug(2100)<<"Found uid at "<<uidNumber<<endl; + itemuid= new UpdateViewItem(item,uidKey.gpgkeyname,uidKey.gpgkeymail,TQString(),"-","-",uidKey.gpgkeycreation,uidKey.gpgkeyid); itemuid->setPixmap(2,uidKey.trustpic); + // FIXME not sure if first item is oldest item - the one set when key was generated + // but in my opinion the identity of the oldest item should be assigned to the pub/main entry if (noID) { item->setText(0,uidKey.gpgkeyname); item->setText(1,uidKey.gpgkeymail); noID=false; } itemuid->setPixmap(0,pixuserid); - cycle="uid"; - } - } - uidNumber++; - } else + } + cycle="uid"; + uidNumber++; + } if (tst[0]=="rev") { gpgKey revKey=extractKey(line); - if (cycle=="uid" || cycle=="uat") + if (cycle=="uid") { itemrev= new UpdateViewItem(itemuid,revKey.gpgkeyname,revKey.gpgkeymail+i18n(" [Revocation signature]"),"-","-","-",revKey.gpgkeycreation,revKey.gpgkeyid); - else if (cycle=="pub") { //////////////public key revoked + } + if (cycle=="pub") { //////////////public key revoked itemrev= new UpdateViewItem(item,revKey.gpgkeyname,revKey.gpgkeymail+i18n(" [Revocation signature]"),"-","-","-",revKey.gpgkeycreation,revKey.gpgkeyid); - dropFirstUid=true; - } else if (cycle=="sub") + //dropFirstUid=true; + } + if (cycle=="sub") { itemrev= new UpdateViewItem(itemsub,revKey.gpgkeyname,revKey.gpgkeymail+i18n(" [Revocation signature]"),"-","-","-",revKey.gpgkeycreation,revKey.gpgkeyid); + } itemrev->setPixmap(0,pixRevoke); - } else - - - if (tst[0]=="sig") { - gpgKey sigKey=extractKey(line); - - if (tst[10].endsWith("l")) - sigKey.gpgkeymail+=i18n(" [local]"); - - if (cycle=="pub") - itemsig= new UpdateViewItem(item,sigKey.gpgkeyname,sigKey.gpgkeymail,"-",sigKey.gpgkeyexpiration,"-",sigKey.gpgkeycreation,sigKey.gpgkeyid); - if (cycle=="sub") - itemsig= new UpdateViewItem(itemsub,sigKey.gpgkeyname,sigKey.gpgkeymail,"-",sigKey.gpgkeyexpiration,"-",sigKey.gpgkeycreation,sigKey.gpgkeyid); - if (cycle=="uid") - itemsig= new UpdateViewItem(itemuid,sigKey.gpgkeyname,sigKey.gpgkeymail,"-",sigKey.gpgkeyexpiration,"-",sigKey.gpgkeycreation,sigKey.gpgkeyid); - - itemsig->setPixmap(0,pixsignature); - } else - if (tst[0]=="sub") { - gpgKey subKey=extractKey(line); - itemsub= new UpdateViewItem(item,i18n("%1 subkey").arg(subKey.gpgkeyalgo),TQString(),TQString(),subKey.gpgkeyexpiration,subKey.gpgkeysize,subKey.gpgkeycreation,subKey.gpgkeyid); - itemsub->setPixmap(0,pixkeySingle); - itemsub->setPixmap(2,subKey.trustpic); - cycle="sub"; - - } - } - pclose(fp); + } + if (tst[0]=="sig") { + gpgKey sigKey=extractKey(line); + + if (tst[10].endsWith("l")) { + sigKey.gpgkeymail+=i18n(" [local]"); + } + + if (cycle=="pub") { + itemsig= new UpdateViewItem( + item, + sigKey.gpgkeyname, + sigKey.gpgkeymail, + "-", + sigKey.gpgkeyexpiration, + "-", + sigKey.gpgkeycreation, + sigKey.gpgkeyid); + } + if (cycle=="sub") { + itemsig= new UpdateViewItem( + itemsub, + sigKey.gpgkeyname, + sigKey.gpgkeymail, + "-", + sigKey.gpgkeyexpiration, + "-", + sigKey.gpgkeycreation, + sigKey.gpgkeyid); + } + if (cycle=="uid") { + itemsig= new UpdateViewItem( + itemuid, + sigKey.gpgkeyname, + sigKey.gpgkeymail, + "-", + sigKey.gpgkeyexpiration, + "-", + sigKey.gpgkeycreation, + sigKey.gpgkeyid); + } + itemsig->setPixmap(0,pixsignature); + } + if (tst[0]=="sub") { + gpgKey subKey=extractKey(line); + itemsub= new UpdateViewItem( + item, + i18n("%1 subkey").arg(subKey.gpgkeyalgo), + TQString(), + TQString(), + subKey.gpgkeyexpiration, + subKey.gpgkeysize, + subKey.gpgkeycreation, + subKey.gpgkeyid + ); + itemsub->setPixmap(0,pixkeySingle); + itemsub->setPixmap(2,subKey.trustpic); + cycle="sub"; + } + } + } + TQApplication::restoreOverrideCursor(); } void listKeys::refreshkey() { +// kdDebug(2100) << k_funcinfo << endl; keysList2->refreshkeylist(); listViewSearch->updateSearch(listViewSearch->text()); } void KeyView::refreshkeylist() { +// kdDebug(2100) << k_funcinfo << endl; emit statusMessage(i18n("Loading Keys..."),0,true); kapp->processEvents(); //////// update display of keys in main management window - kdDebug(2100)<<"Refreshing key list"<<endl; - TQString tst; +// kdDebug(2100)<<"Refreshing key list"<<endl; + char line[300]; UpdateViewItem *item=NULL; - bool noID=false; - bool emptyList=true; TQString openKeys; + bool emptyList=true; + TQMap<TQString,TQStringList> hashMap; + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); // get current position. TQListViewItem *current = currentItem(); if(current != NULL) { @@ -2686,32 +2862,67 @@ void KeyView::refreshkeylist() fp2 = popen("gpg --no-secmem-warning --no-tty --with-colons --list-secret-keys", "r"); while ( fgets( line, sizeof(line), fp2)) { TQString lineRead=TQString::fromUtf8(line); - kdDebug(2100) << k_funcinfo << "Read one secret key line: " << lineRead << endl; +// kdDebug(2100) << k_funcinfo << "Read one secret key line: " << lineRead << endl; if (lineRead.startsWith("sec")) issec<<lineRead.section(':',4,4).right(8); } pclose(fp2); TQString defaultKey = KGpgSettings::defaultKey(); - fp = popen("gpg --no-secmem-warning --no-tty --with-colons --list-keys", "r"); - while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - kdDebug(2100) << k_funcinfo << "Read one public key line: " << tst << endl; - if (tst.startsWith("pub")) { - emptyList=false; - noID=false; - gpgKey pubKey=extractKey(tst); + TQString currentKey; + + fp = popen("gpg --no-secmem-warning --no-tty --with-colons --list-keys", "r"); + while ( fgets( line, sizeof(line), fp)) { + TQString tst=TQString::fromUtf8(line); +// kdDebug(2100) << k_funcinfo << "Read one public 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<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQStringList::Iterator it; + gpgKey pubKey; bool isbold=false; bool isexpired=false; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + if ( tst.startsWith("pub") ){ + emptyList=false; + pubKey=extractKey(tst); if (pubKey.gpgkeyid==defaultKey) isbold=true; if (pubKey.gpgkeytrust==i18n("Expired")) isexpired=true; - if (pubKey.gpgkeyname.isEmpty()) - noID=true; + } + if ( tst.startsWith("uid") && pubKey.gpgkeyname.isEmpty() ){ + gpgKey tmpKey=extractKey(tst); + pubKey.gpgkeyname = tmpKey.gpgkeyname; + pubKey.gpgkeymail = tmpKey.gpgkeymail; + } + } - item=new UpdateViewItem(this,pubKey.gpgkeyname,pubKey.gpgkeymail,TQString(),pubKey.gpgkeyexpiration,pubKey.gpgkeysize,pubKey.gpgkeycreation,pubKey.gpgkeyid,isbold,isexpired); + item=new UpdateViewItem( + this, + pubKey.gpgkeyname, + pubKey.gpgkeymail, + TQString(), + pubKey.gpgkeyexpiration, + pubKey.gpgkeysize, + pubKey.gpgkeycreation, + pubKey.gpgkeyid, + isbold, + isexpired); item->setPixmap(2,pubKey.trustpic); item->setExpandable(true); @@ -2727,27 +2938,36 @@ void KeyView::refreshkeylist() if (openKeys.find(pubKey.gpgkeyid)!=-1) item->setOpen(true); - } + } - } - pclose(fp); if (!issec.isEmpty()) insertOrphanedKeys(issec); if (emptyList) { - kdDebug(2100)<<"No key found"<<endl; + // kdDebug(2100)<<"No key found"<<endl; emit statusMessage(i18n("Ready"),0); return; } - kdDebug(2100)<<"Checking Groups"<<endl; +// kdDebug(2100)<<"Checking Groups"<<endl; TQStringList groups=KgpgInterface::getGpgGroupNames(KGpgSettings::gpgConfigPath()); groupNb=groups.count(); - for ( TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) + for ( TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { if (!TQString(*it).isEmpty()) { - item=new UpdateViewItem(this,TQString(*it),TQString(),TQString(),TQString(),TQString(),TQString(),TQString(),false,false); + item=new UpdateViewItem( + this, + TQString(*it), + TQString(), + TQString(), + TQString(), + TQString(), + TQString(), + TQString(), + false, + false); item->setPixmap(0,pixkeyGroup); item->setExpandable(false); } - kdDebug(2100)<<"Finished Groups"<<endl; + } +// kdDebug(2100)<<"Finished Groups"<<endl; TQListViewItem *newPos=0L; if(current != NULL) { @@ -2770,35 +2990,77 @@ void KeyView::refreshkeylist() emit statusMessage(i18n("%1 Keys, %2 Groups").arg(childCount()-groupNb).arg(groupNb),1); emit statusMessage(i18n("Ready"),0); - kdDebug(2100)<<"Refresh Finished"<<endl; + TQApplication::restoreOverrideCursor(); +// kdDebug(2100)<<"Refresh Finished"<<endl; } void KeyView::insertOrphan(TQString currentID) { +// kdDebug(2100) << k_funcinfo << endl; FILE *fp; char line[300]; UpdateViewItem *item=NULL; bool keyFound=false; + TQString currentKey; + TQMap<TQString,TQStringList> hashMap; + fp = popen("gpg --no-secmem-warning --no-tty --with-colons --list-secret-keys", "r"); while ( fgets( line, sizeof(line), fp)) { - TQString lineRead=TQString::fromUtf8(line); - if ((lineRead.startsWith("sec")) && (lineRead.section(':',4,4).right(8))==currentID.right(8)) { - gpgKey orphanedKey=extractKey(lineRead); - keyFound=true; - bool isbold=false; - bool isexpired=false; + TQString tst=TQString::fromUtf8(line); +// kdDebug(2100) << k_funcinfo << "Read one public key line: " << tst << endl; + if ( tst.startsWith("sec") ) { + 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<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQStringList::Iterator it; + gpgKey orphanedKey; + keyFound=false; + bool isbold=false; + bool isexpired=false; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tmp = (*it); + if ((tmp.startsWith("sec")) && (tmp.section(':',4,4).right(8))==currentID.right(8)) { + orphanedKey=extractKey(tmp); + keyFound=true; // if (orphanedKey.gpgkeyid==defaultKey) // isbold=true; - if (orphanedKey.gpgkeytrust==i18n("Expired")) - isexpired=true; + if (orphanedKey.gpgkeytrust==i18n("Expired")) { + isexpired=true; + } // if (orphanedKey.gpgkeyname.isEmpty()) // noID=true; + } + if ( tmp.startsWith("uid") && orphanedKey.gpgkeyname.isEmpty() ){ + gpgKey tmpKey=extractKey(tmp); + orphanedKey.gpgkeyname = tmpKey.gpgkeyname; + orphanedKey.gpgkeymail = tmpKey.gpgkeymail; + } + } + item=new UpdateViewItem( + this, + orphanedKey.gpgkeyname, + orphanedKey.gpgkeymail, + TQString(), + orphanedKey.gpgkeyexpiration, + orphanedKey.gpgkeysize, + orphanedKey.gpgkeycreation, + orphanedKey.gpgkeyid, + isbold, + isexpired); + item->setPixmap(0,pixkeyOrphan); + } - item=new UpdateViewItem(this,orphanedKey.gpgkeyname,orphanedKey.gpgkeymail,TQString(),orphanedKey.gpgkeyexpiration,orphanedKey.gpgkeysize,orphanedKey.gpgkeycreation,orphanedKey.gpgkeyid,isbold,isexpired); - item->setPixmap(0,pixkeyOrphan); - } - } - pclose(fp); if (!keyFound) { orphanList.remove(currentID); setSelected(currentItem(),true); @@ -2811,32 +3073,70 @@ void KeyView::insertOrphan(TQString currentID) void KeyView::insertOrphanedKeys(TQStringList orphans) { - FILE *fp; - char line[300]; - fp = popen("gpg --no-secmem-warning --no-tty --with-colons --list-secret-keys", "r"); - while ( fgets( line, sizeof(line), fp)) { - TQString lineRead=TQString::fromUtf8(line); - if ((lineRead.startsWith("sec")) && (orphans.find(lineRead.section(':',4,4).right(8))!=orphans.end())) { - gpgKey orphanedKey=extractKey(lineRead); - - bool isbold=false; - bool isexpired=false; - // if (orphanedKey.gpgkeyid==defaultKey) - // isbold=true; - if (orphanedKey.gpgkeytrust==i18n("Expired")) - isexpired=true; - // if (orphanedKey.gpgkeyname.isEmpty()) - // noID=true; - orphanList+=orphanedKey.gpgkeyid+","; - UpdateViewItem *item=new UpdateViewItem(this,orphanedKey.gpgkeyname,orphanedKey.gpgkeymail,TQString(),orphanedKey.gpgkeyexpiration,orphanedKey.gpgkeysize,orphanedKey.gpgkeycreation,orphanedKey.gpgkeyid,isbold,isexpired); - item->setPixmap(0,pixkeyOrphan); - } - } - pclose(fp); +// kdDebug(2100) << k_funcinfo << endl; + FILE *fp; + char line[300]; + TQString currentKey; + TQMap<TQString,TQStringList> hashMap; + + fp = popen("gpg --no-secmem-warning --no-tty --with-colons --list-secret-keys", "r"); + while ( fgets( line, sizeof(line), fp)) { + TQString tst=TQString::fromUtf8(line); +// kdDebug(2100) << k_funcinfo << "Read one public key line: " << tst << endl; + if ( tst.startsWith("sec") ) { + 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<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQStringList::Iterator it; + gpgKey orphanedKey; + bool isbold=false; + bool isexpired=false; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tmp = (*it); + if ((tmp.startsWith("sec")) && (orphans.find(tmp.section(':',4,4).right(8))!=orphans.end())) { + orphanedKey=extractKey(tmp); +// if (orphanedKey.gpgkeyid==defaultKey) +// isbold=true; + if (orphanedKey.gpgkeytrust==i18n("Expired")) { + isexpired=true; + } + orphanList+=orphanedKey.gpgkeyid+","; + } + if ( tmp.startsWith("uid") && orphanedKey.gpgkeyname.isEmpty() ){ + gpgKey tmpKey=extractKey(tmp); + orphanedKey.gpgkeyname = tmpKey.gpgkeyname; + orphanedKey.gpgkeymail = tmpKey.gpgkeymail; + } + } + UpdateViewItem *item=new UpdateViewItem( + this, + orphanedKey.gpgkeyname, + orphanedKey.gpgkeymail, + TQString(), + orphanedKey.gpgkeyexpiration, + orphanedKey.gpgkeysize, + orphanedKey.gpgkeycreation, + orphanedKey.gpgkeyid, + isbold, + isexpired); + item->setPixmap(0,pixkeyOrphan); + } } void KeyView::refreshgroups() { +// kdDebug(2100) << k_funcinfo << endl; TQListViewItem *item=firstChild(); while (item) { if (item->text(6).isEmpty()) { @@ -2849,19 +3149,31 @@ void KeyView::refreshgroups() TQStringList groups=KgpgInterface::getGpgGroupNames(KGpgSettings::gpgConfigPath()); groupNb=groups.count(); - for ( TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) - if (!TQString(*it).isEmpty()) { - item=new UpdateViewItem(this,TQString(*it),TQString(),TQString(),TQString(),TQString(),TQString(),TQString(),false,false); - item->setPixmap(0,pixkeyGroup); - item->setExpandable(false); - } + for ( TQStringList::Iterator it = groups.begin(); it != groups.end(); ++it ) { + if (!TQString(*it).isEmpty()) { + item=new UpdateViewItem( + this, + TQString(*it), + TQString(), + TQString(), + TQString(), + TQString(), + TQString(), + TQString(), + false, + false); + item->setPixmap(0,pixkeyGroup); + item->setExpandable(false); + } + } emit statusMessage(i18n("%1 Keys, %2 Groups").arg(childCount()-groupNb).arg(groupNb),1); emit statusMessage(i18n("Ready"),0); } void KeyView::refreshselfkey() { - kdDebug(2100)<<"Refreshing key"<<endl; +// kdDebug(2100) << k_funcinfo << endl; +// kdDebug(2100)<<"Refreshing key"<<endl; if (currentItem()->depth()==0) refreshcurrentkey(currentItem()); else @@ -2870,6 +3182,7 @@ void KeyView::refreshselfkey() void KeyView::slotReloadKeys(TQStringList keyIDs) { +// kdDebug(2100) << k_funcinfo << endl; if (keyIDs.isEmpty()) return; if (keyIDs.first()=="ALL") @@ -2880,7 +3193,7 @@ void KeyView::slotReloadKeys(TQStringList keyIDs) for ( TQStringList::Iterator it = keyIDs.begin(); it != keyIDs.end(); ++it ) { refreshcurrentkey(*it); } - kdDebug(2100)<<"Refreshing key:--------"<<TQString((keyIDs.last()).right(8).prepend("0x"))<<endl; +// kdDebug(2100)<<"Refreshing key:--------"<<TQString((keyIDs.last()).right(8).prepend("0x"))<<endl; ensureItemVisible(this->findItem((keyIDs.last()).right(8).prepend("0x"),6)); emit statusMessage(i18n("%1 Keys, %2 Groups").arg(childCount()-groupNb).arg(groupNb),1); emit statusMessage(i18n("Ready"),0); @@ -2888,6 +3201,7 @@ void KeyView::slotReloadKeys(TQStringList keyIDs) void KeyView::slotReloadOrphaned() { +// kdDebug(2100) << k_funcinfo << endl; TQStringList issec; FILE *fp,*fp2; char line[300]; @@ -2923,12 +3237,17 @@ void KeyView::slotReloadOrphaned() void KeyView::refreshcurrentkey(TQString currentID) { +// kdDebug(2100) << k_funcinfo << endl; if (currentID.isNull()) return; - UpdateViewItem *item=NULL; - TQString issec=TQString(); FILE *fp,*fp2; char line[300]; + TQString issec=TQString(); + TQString defaultKey = KGpgSettings::defaultKey(); + TQString currentKey; + TQMap<TQString,TQStringList> hashMap; + + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); fp2 = popen("gpg --no-secmem-warning --no-tty --with-colons --list-secret-keys", "r"); while ( fgets( line, sizeof(line), fp2)) { TQString lineRead=TQString::fromUtf8(line); @@ -2937,53 +3256,99 @@ void KeyView::refreshcurrentkey(TQString currentID) } pclose(fp2); - TQString defaultKey = KGpgSettings::defaultKey(); - - TQString tst; - bool keyFound=false; +// kdDebug(2100) << "currentID: " << currentID <<endl; TQString cmd="gpg --no-secmem-warning --no-tty --with-colons --list-keys "+currentID; fp = popen(TQFile::encodeName(cmd), "r"); while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - if (tst.startsWith("pub")) { - gpgKey pubKey=extractKey(tst); - keyFound=true; - bool isbold=false; - bool isexpired=false; - if (pubKey.gpgkeyid==defaultKey) - isbold=true; - if (pubKey.gpgkeytrust==i18n("Expired")) - isexpired=true; - item=new UpdateViewItem(this,pubKey.gpgkeyname,pubKey.gpgkeymail,TQString(),pubKey.gpgkeyexpiration,pubKey.gpgkeysize,pubKey.gpgkeycreation,pubKey.gpgkeyid,isbold,isexpired); - item->setPixmap(2,pubKey.trustpic); - item->setVisible(true); - item->setExpandable(true); - if (issec.find(pubKey.gpgkeyid.right(8),0,FALSE)!=-1) { - item->setPixmap(0,pixkeyPair); - secretList+=pubKey.gpgkeyid; - } else { - item->setPixmap(0,pixkeySingle); - } - } - } - pclose(fp); + TQString tst=TQString::fromUtf8(line); +// kdDebug(2100) << k_funcinfo << "Read one public 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); + if (hashMap.isEmpty()) { + return; // deleted keys do not exist + } - if (!keyFound) { - if (orphanList.find(currentID)==-1) - orphanList+=currentID+","; - insertOrphan(currentID); - return; - } - if (orphanList.find(currentID)!=-1) - orphanList.remove(currentID); +// process the list + + TQMap<TQString,TQStringList>::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + UpdateViewItem *item=NULL; + TQStringList::Iterator it; + gpgKey pubKey; + bool keyFound=false; + bool isbold=false; + bool isexpired=false; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + if ( tst.startsWith("pub") ) { + keyFound=true; + pubKey=extractKey(tst); + if (pubKey.gpgkeyid==defaultKey) { + isbold=true; + } + if (pubKey.gpgkeytrust==i18n("Expired")) { + isexpired=true; + } + } + if ( tst.startsWith("uid") && pubKey.gpgkeyname.isEmpty() ) { + gpgKey tmpKey=extractKey(tst); + pubKey.gpgkeyname = tmpKey.gpgkeyname; + pubKey.gpgkeymail = tmpKey.gpgkeymail; + } + } - clearSelection(); - setCurrentItem(item); + item=new UpdateViewItem( + this, + pubKey.gpgkeyname, + pubKey.gpgkeymail, + TQString(), + pubKey.gpgkeyexpiration, + pubKey.gpgkeysize, + pubKey.gpgkeycreation, + pubKey.gpgkeyid, + isbold, + isexpired); + item->setPixmap(2,pubKey.trustpic); + item->setVisible(true); + item->setExpandable(true); + if (issec.find(pubKey.gpgkeyid.right(8),0,FALSE)!=-1) { + item->setPixmap(0,pixkeyPair); + secretList+=pubKey.gpgkeyid; + } + else { + item->setPixmap(0,pixkeySingle); + } + + if (!keyFound) { + if (orphanList.find(currentID)==-1) { + orphanList+=currentID+","; + } + insertOrphan(currentID); + return; + } + if (orphanList.find(currentID)!=-1) { + orphanList.remove(currentID); + } + + clearSelection(); + setCurrentItem(item); + } + TQApplication::restoreOverrideCursor(); } void KeyView::refreshcurrentkey(TQListViewItem *current) { +// kdDebug(2100) << k_funcinfo << endl; if (!current) return; bool keyIsOpen=false; @@ -3002,74 +3367,100 @@ void KeyView::refreshcurrentkey(TQListViewItem *current) void KeyView::refreshTrust(int color,TQColor newColor) { -if (!newColor.isValid()) return; -TQPixmap blankFrame,newtrust; -int trustFinger=0; -blankFrame.load(locate("appdata", "pics/kgpg_blank.png")); -newtrust.load(locate("appdata", "pics/kgpg_fill.png")); -newtrust.fill(newColor); -bitBlt(&newtrust,0,0,&blankFrame,0,0,50,15); -switch (color) -{ -case GoodColor: -trustFinger=trustgood.serialNumber(); -trustgood=newtrust; -break; -case BadColor: -trustFinger=trustbad.serialNumber(); -trustbad=newtrust; -break; -case UnknownColor: -trustFinger=trustunknown.serialNumber(); -trustunknown=newtrust; -break; -case RevColor: -trustFinger=trustrevoked.serialNumber(); -trustrevoked=newtrust; -break; -} -TQListViewItem *item=firstChild(); - while (item) { - if (item->pixmap(2)) - { - if (item->pixmap(2)->serialNumber()==trustFinger) item->setPixmap(2,newtrust); +// kdDebug(2100) << k_funcinfo << endl; + if (!newColor.isValid()) return; + TQPixmap blankFrame,newtrust; + int trustFinger=0; + blankFrame.load(locate("appdata", "pics/kgpg_blank.png")); + newtrust.load(locate("appdata", "pics/kgpg_fill.png")); + newtrust.fill(newColor); + bitBlt(&newtrust,0,0,&blankFrame,0,0,50,15); + switch (color) { + case GoodColor: + trustFinger=trustgood.serialNumber(); + trustgood=newtrust; + break; + case BadColor: + trustFinger=trustbad.serialNumber(); + trustbad=newtrust; + break; + case UnknownColor: + trustFinger=trustunknown.serialNumber(); + trustunknown=newtrust; + break; + case RevColor: + trustFinger=trustrevoked.serialNumber(); + trustrevoked=newtrust; + break; + } + TQListViewItem *item=firstChild(); + while (item) { + if (item->pixmap(2)) { + if (item->pixmap(2)->serialNumber()==trustFinger) { + item->setPixmap(2,newtrust); } - item=item->nextSibling(); - } + } + item=item->nextSibling(); + } } gpgKey KeyView::extractKey(TQString keyColon) { +// kdDebug(2100) << k_funcinfo << "keyColon: " << keyColon<<endl; TQStringList keyString=TQStringList::split(":",keyColon,true); - gpgKey ret; + gpgKey ret; ret.gpgkeysize=keyString[2]; ret.gpgkeycreation=keyString[5]; if(!ret.gpgkeycreation.isEmpty()) { - TQDate date = TQDate::fromString(ret.gpgkeycreation, Qt::ISODate); + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t( ret.gpgkeycreation.toInt()); + date = timestamp.date(); + } + else { + date = TQDate::fromString(ret.gpgkeycreation, Qt::ISODate); + } + Q_ASSERT (date.isValid()) /*tqWarning("create date is not valid")*/; ret.gpgkeycreation=TDEGlobal::locale()->formatDate(date, true); } - TQString tid=keyString[4]; + TQString tid= (keyColon.startsWith("uid")) ? keyString[7] : keyString[4]; ret.gpgkeyid=TQString("0x"+tid.right(8)); +// ret.gpgkeyid=(keyColon.startsWith("uid")) ? keyString[7] : keyString[4]; ret.gpgkeyexpiration=keyString[6]; if (ret.gpgkeyexpiration.isEmpty()) ret.gpgkeyexpiration=i18n("Unlimited"); else { - TQDate date = TQDate::fromString(ret.gpgkeyexpiration, Qt::ISODate); + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t(ret.gpgkeyexpiration.toInt()); + date = timestamp.date(); + } + else { + date = TQDate::fromString(ret.gpgkeyexpiration, Qt::ISODate); + } + Q_ASSERT (date.isValid()) /*tqWarning("expire date is not valid")*/; ret.gpgkeyexpiration=TDEGlobal::locale()->formatDate(date, true); } - TQString fullname=keyString[9]; - if (fullname.find("<")!=-1) { - ret.gpgkeymail=fullname.section('<',-1,-1); - ret.gpgkeymail.truncate(ret.gpgkeymail.length()-1); - ret.gpgkeyname=fullname.section('<',0,0); - //ret.gpgkeyname=ret.gpgkeyname.section('(',0,0); - } else { - ret.gpgkeymail=TQString(); - ret.gpgkeyname=fullname; - //ret.gpgkeyname=fullname.section('(',0,0); - } + // search for Fullname + if ( ! keyString[9].isEmpty() ) { + TQString fullname=keyString[9]; + + if (fullname.find("<")!=-1) { + ret.gpgkeymail=fullname.section('<',-1,-1); + ret.gpgkeymail.truncate(ret.gpgkeymail.length()-1); + ret.gpgkeyname=fullname.section('<',0,0); + //ret.gpgkeyname=ret.gpgkeyname.section('(',0,0); + } + else { + ret.gpgkeymail=TQString(); + ret.gpgkeyname=fullname; + //ret.gpgkeyname=fullname.section('(',0,0); + } + } //ret.gpgkeyname=KgpgInterface::checkForUtf8(ret.gpgkeyname); // FIXME lukas TQString algo=keyString[3]; |