From e2bee02e9917c7407de600d7d577cd536e281b4a Mon Sep 17 00:00:00 2001 From: Emanoil Kotsev Date: Sat, 9 Dec 2017 15:54:36 +0100 Subject: [PATCH] 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/keyinfowidget.cpp | 292 +++++++----- kgpg/keyservers.cpp | 601 ++++++++++++++++++------ kgpg/keyservers.h | 7 +- kgpg/kgpg.cpp | 129 +++-- kgpg/kgpginterface.cpp | 343 +++++++++++--- kgpg/kgpgoptions.cpp | 259 ++++++---- kgpg/kgpgoptions.h | 2 +- kgpg/listkeys.cpp | 1015 ++++++++++++++++++++++++++++------------ kgpg/main.cpp | 4 +- kgpg/popuppublic.cpp | 184 +++++--- kgpg/popuppublic.h | 3 +- 11 files changed, 1988 insertions(+), 851 deletions(-) diff --git a/kgpg/keyinfowidget.cpp b/kgpg/keyinfowidget.cpp index 1de61af..1b833ac 100644 --- a/kgpg/keyinfowidget.cpp +++ b/kgpg/keyinfowidget.cpp @@ -4,6 +4,10 @@ begin : Mon Nov 18 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 ***************************************************************************/ /*************************************************************************** @@ -90,36 +94,56 @@ KgpgKeyInfo::KgpgKeyInfo(TQWidget *parent, const char *name,TQString sigkey):KDi void KgpgKeyInfo::slotDisableKey(bool isOn) { -TDEProcess kp; - - kp<<"gpg" - <<"--no-tty" - <<"--edit-key" - < hashMap; + + TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprint --list-key "+KShellProcess::quote(Keyid); + + pass=popen(TQFile::encodeName(gpgcmd),"r"); + while ( fgets( line, sizeof(line), pass) ) { + TQString tst=TQString::fromUtf8(line); + 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(pass); + + TQMap::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQStringList::Iterator it; + TQString fullname,gpgOutput; + TQColor trustColor; + TQString fingervalue=TQString(); + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString gpgOutput = (*it); + + if (gpgOutput.startsWith("uat")) { + hasPhoto=true; + } + if ( gpgOutput.startsWith("pub") ) { TQString algo=gpgOutput.section(':',3,3); switch( algo.toInt() ) { case 1: @@ -198,21 +222,39 @@ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprin prop->kLTrust->setText(tr); prop->pixmapTrust->setPaletteBackgroundColor(trustColor); - fullID=gpgOutput.section(':',4,4); - displayedKeyID=fullID.right(8); - prop->tLID->setText(fullID); + TQString fullID=gpgOutput.section(':',4,4); + displayedKeyID=fullID.right(8); + prop->tLID->setText(fullID); - TQString fullname=gpgOutput.section(':',9,9); + fullname=gpgOutput.section(':',9,9); - TQDate date = TQDate::fromString(gpgOutput.section(':',5,5), Qt::ISODate); - prop->tLCreation->setText(TDEGlobal::locale()->formatDate(date)); + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t(gpgOutput.section(':',5,5).toInt()); + date = timestamp.date(); + } + else { + date = TQDate::fromString(gpgOutput.section(':',5,5), Qt::ISODate); + } + Q_ASSERT ( date.isValid())/* tqWarning("create date is not valid")*/; - if (gpgOutput.section(':',6,6).isEmpty()) expirationDate=i18n("Unlimited"); - else - { - date = TQDate::fromString(gpgOutput.section(':',6,6), Qt::ISODate); - expirationDate=TDEGlobal::locale()->formatDate(date); - } + prop->tLCreation->setText(TDEGlobal::locale()->formatDate(date)); + if (gpgOutput.section(':',6,6).isEmpty()) { + expirationDate=i18n("Unlimited"); + } + else { + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t(gpgOutput.section(':',6,6).toInt()); + date = timestamp.date(); + } + else { + date = TQDate::fromString(gpgOutput.section(':',6,6), Qt::ISODate); + } + Q_ASSERT (date.isValid()) /* tqWarning("Expirationdate date is not valid")*/; + expirationDate=TDEGlobal::locale()->formatDate(date); + } prop->tLExpiration->setText(expirationDate); prop->tLLength->setText(gpgOutput.section(':',2,2)); @@ -240,7 +282,25 @@ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprin break; } prop->kCOwnerTrust->setCurrentItem(ownerTrust); + } + + if ( gpgOutput.startsWith("uid") && fullname.isEmpty() ) { + fullname = gpgOutput.section(':',9,9); + } + if (gpgOutput.startsWith("fpr") && (fingervalue.isNull())) { + fingervalue=gpgOutput.section(':',9,9); + // format fingervalue in 4-digit groups + uint len = fingervalue.length(); + if ((len > 0) && (len % 4 == 0)) { + for (uint n = 0; 4*(n+1) < len; n++) { + fingervalue.insert(5*n+4, ' '); + } + } + prop->lEFinger->setText(fingervalue); + } + } + if (!fullname.isEmpty()) { if (fullname.find("<")!=-1) { TQString kmail=fullname; if (fullname.find(")")!=-1) @@ -266,29 +326,20 @@ TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --with-fingerprin prop->tLComment->setText(i18n("none")); prop->tLName->setText(""+KgpgInterface::checkForUtf8(kname).replace(TQRegExp("<"),"<")+""); - - } - if (gpgOutput.startsWith("fpr") && (fingervalue.isNull())) { - fingervalue=gpgOutput.section(':',9,9); - // format fingervalue in 4-digit groups - uint len = fingervalue.length(); - if ((len > 0) && (len % 4 == 0)) - for (uint n = 0; 4*(n+1) < len; n++) - fingervalue.insert(5*n+4, ' '); - prop->lEFinger->setText(fingervalue); } } - pclose(pass); } void KgpgKeyInfo::slotSetMainPhoto(TQStringList list) { +// kdDebug(2100) << k_funcinfo << endl; prop->comboId->insertStringList(list); reloadMainPhoto(prop->comboId->currentText()); } void KgpgKeyInfo::reloadMainPhoto(const TQString &uid) { +// kdDebug(2100) << k_funcinfo << endl; kgpginfotmp=new KTempFile(); kgpginfotmp->setAutoDelete(true); @@ -305,6 +356,7 @@ void KgpgKeyInfo::reloadMainPhoto(const TQString &uid) void KgpgKeyInfo::slotMainImageRead(TDEProcess *p) { +// kdDebug(2100) << k_funcinfo << endl; p->deleteLater(); TQPixmap pixmap; pixmap.load(kgpginfotmp->name()); @@ -319,10 +371,11 @@ KgpgKeyInfo::~KgpgKeyInfo() void KgpgKeyInfo::slotSetPhoto(const TQPixmap &pix) { -TQImage dup=pix.convertToImage(); -TQPixmap dup2; -dup2.convertFromImage(dup.scale(prop->pLPhoto->width(),prop->pLPhoto->height(),TQ_ScaleMin)); -prop->pLPhoto->setPixmap(dup2); +// kdDebug(2100) << k_funcinfo << endl; + TQImage dup=pix.convertToImage(); + TQPixmap dup2; + dup2.convertFromImage(dup.scale(prop->pLPhoto->width(),prop->pLPhoto->height(),TQ_ScaleMin)); + prop->pLPhoto->setPixmap(dup2); } @@ -330,6 +383,7 @@ prop->pLPhoto->setPixmap(dup2); void KgpgKeyInfo::finishphotoreadprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) if (required.find("keyedit.prompt")!=-1) { @@ -342,6 +396,7 @@ void KgpgKeyInfo::finishphotoreadprocess(KProcIO *p) void KgpgKeyInfo::openPhoto() { +// 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()); @@ -352,61 +407,69 @@ void KgpgKeyInfo::openPhoto() void KgpgKeyInfo::slotChangeExp() { -chdate=new KDialogBase( this, "choose_date", true,i18n("Choose New Expiration"),KDialogBase::Ok | KDialogBase::Cancel); -TQWidget *page = new TQWidget(chdate); -kb= new TQCheckBox(i18n("Unlimited"),page ); - -if (prop->tLExpiration->text()==i18n("Unlimited")) -{ -kdt= new KDatePicker( page ); -kb->setChecked(true); -kdt->setEnabled(false); -} -else -kdt= new KDatePicker(page,TDEGlobal::locale()->readDate(prop->tLExpiration->text())); -TQVBoxLayout *vbox=new TQVBoxLayout(page,3); -vbox->addWidget(kdt); -vbox->addWidget(kb); -connect(kb,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableDate(bool))); -connect(chdate,TQT_SIGNAL(okClicked()),this,TQT_SLOT(slotChangeDate())); -connect(kdt,TQT_SIGNAL(dateChanged(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate))); -connect(kdt,TQT_SIGNAL(dateEntered(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate))); - -chdate->setMainWidget(page); -chdate->show(); +// kdDebug(2100) << k_funcinfo << endl; + chdate=new KDialogBase( this, "choose_date", true,i18n("Choose New Expiration"),KDialogBase::Ok | KDialogBase::Cancel); + TQWidget *page = new TQWidget(chdate); + kb= new TQCheckBox(i18n("Unlimited"),page ); + + if (prop->tLExpiration->text()==i18n("Unlimited")) { + kdt= new KDatePicker( page ); + kb->setChecked(true); + kdt->setEnabled(false); + } + else { + kdt= new KDatePicker(page,TDEGlobal::locale()->readDate(prop->tLExpiration->text())); + } + TQVBoxLayout *vbox=new TQVBoxLayout(page,3); + vbox->addWidget(kdt); + vbox->addWidget(kb); + connect(kb,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableDate(bool))); + connect(chdate,TQT_SIGNAL(okClicked()),this,TQT_SLOT(slotChangeDate())); + connect(kdt,TQT_SIGNAL(dateChanged(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate))); + connect(kdt,TQT_SIGNAL(dateEntered(TQDate)),this,TQT_SLOT(slotCheckDate(TQDate))); + + chdate->setMainWidget(page); + chdate->show(); } void KgpgKeyInfo::slotCheckDate(TQDate date) { -chdate->enableButtonOK(date>=TQDate::currentDate ()); +// kdDebug(2100) << k_funcinfo << endl; +// kdDebug(2100) << "slotCheckDate" << date<enableButtonOK(date>=TQDate::currentDate ()); } void KgpgKeyInfo::slotChangeDate() { -KgpgInterface *KeyExpirationProcess=new KgpgInterface(); - if (kb->isChecked()) - KeyExpirationProcess->KgpgKeyExpire(displayedKeyID,TQDate::currentDate(),true); - else +// kdDebug(2100) << k_funcinfo << endl; + KgpgInterface *KeyExpirationProcess=new KgpgInterface(); +// kdDebug(2100) << "slotChangeDate" << kdt->date()<isChecked()) { + KeyExpirationProcess->KgpgKeyExpire(displayedKeyID,TQDate::currentDate(),true); + } + else { KeyExpirationProcess->KgpgKeyExpire(displayedKeyID,kdt->date(),false); - connect(KeyExpirationProcess,TQT_SIGNAL(expirationFinished(int)),this,TQT_SLOT(slotInfoExpirationChanged(int))); + } + connect(KeyExpirationProcess,TQT_SIGNAL(expirationFinished(int)),this,TQT_SLOT(slotInfoExpirationChanged(int))); } void KgpgKeyInfo::slotEnableDate(bool isOn) { -if (isOn) -{ -kdt->setEnabled(false); -chdate->enableButtonOK(true); -} -else -{ -kdt->setEnabled(true); -chdate->enableButtonOK(kdt->date()>=TQDate::currentDate ()); -} +// kdDebug(2100) << k_funcinfo << endl; + if (isOn) { + kdt->setEnabled(false); + chdate->enableButtonOK(true); + } + else { + kdt->setEnabled(true); + //kdDebug(2100) << "slotEnableDate" << kdt->date()<enableButtonOK(kdt->date()>=TQDate::currentDate ()); + } } void KgpgKeyInfo::slotinfoimgread(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; TQPixmap pixmap; pixmap.load(kgpginfotmp->name()); emit signalPhotoId(pixmap); @@ -415,13 +478,15 @@ void KgpgKeyInfo::slotinfoimgread(TDEProcess *) void KgpgKeyInfo::slotChangePass() { - KgpgInterface *ChangeKeyPassProcess=new KgpgInterface(); - ChangeKeyPassProcess->KgpgChangePass(displayedKeyID); +// kdDebug(2100) << k_funcinfo << endl; + KgpgInterface *ChangeKeyPassProcess=new KgpgInterface(); + ChangeKeyPassProcess->KgpgChangePass(displayedKeyID); connect(ChangeKeyPassProcess,TQT_SIGNAL(passwordChanged()),this,TQT_SLOT(slotInfoPasswordChanged())); } void KgpgKeyInfo::slotChangeTrust(int newTrust) { +// kdDebug(2100) << k_funcinfo << endl; KgpgInterface *KeyTrustProcess=new KgpgInterface(); KeyTrustProcess->KgpgTrustExpire(displayedKeyID,newTrust); connect(KeyTrustProcess,TQT_SIGNAL(trustfinished()),this,TQT_SLOT(slotInfoTrustChanged())); @@ -430,36 +495,45 @@ void KgpgKeyInfo::slotChangeTrust(int newTrust) void KgpgKeyInfo::slotInfoPasswordChanged() { -KPassivePopup::message(i18n("Passphrase for the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this); +// kdDebug(2100) << k_funcinfo << endl; + KPassivePopup::message(i18n("Passphrase for the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this); } void KgpgKeyInfo::slotInfoTrustChanged() { -keyWasChanged=true; -loadKey(displayedKeyID); -//KPassivePopup::message(i18n("Owner trust of the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this,0,600); + keyWasChanged=true; + loadKey(displayedKeyID); + //KPassivePopup::message(i18n("Owner trust of the key was changed"),TQString(),TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this,0,600); } void KgpgKeyInfo::slotInfoExpirationChanged(int res) { -TQString infoMessage,infoText; -if (res==3) -{ -keyWasChanged=true; -if (kb->isChecked()) prop->tLExpiration->setText(i18n("Unlimited")); -else prop->tLExpiration->setText(TDEGlobal::locale()->formatDate(kdt->date())); -} -if (res==2) { -infoMessage=i18n("Could not change expiration");infoText=i18n("Bad passphrase"); -KPassivePopup::message(infoMessage,infoText,TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this); -} +// kdDebug(2100) << k_funcinfo << endl; + TQString infoMessage,infoText; + if (res==3) { + keyWasChanged=true; + if (kb->isChecked()) { + prop->tLExpiration->setText(i18n("Unlimited")); + } + else { + prop->tLExpiration->setText(TDEGlobal::locale()->formatDate(kdt->date())); + } + } + if (res==2) { + infoMessage=i18n("Could not change expiration"); + infoText=i18n("Bad passphrase"); + KPassivePopup::message(infoMessage,infoText,TDEGlobal::iconLoader()->loadIcon("kgpg",TDEIcon::Desktop),this); + } } void KgpgKeyInfo::slotPreOk() { -if (keyWasChanged) emit keyNeedsRefresh(); -accept(); +// kdDebug(2100) << k_funcinfo << endl; + if (keyWasChanged) { + emit keyNeedsRefresh(); + } + accept(); } #include "keyinfowidget.moc" diff --git a/kgpg/keyservers.cpp b/kgpg/keyservers.cpp index 364de3a..9442653 100644 --- a/kgpg/keyservers.cpp +++ b/kgpg/keyservers.cpp @@ -4,6 +4,10 @@ begin : Tue Nov 26 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 ***************************************************************************/ /*************************************************************************** @@ -61,34 +65,40 @@ keyServer::keyServer(TQWidget *parent, const char *name,bool modal,bool autoClos syncCombobox(); page->kLEimportid->setFocus(); + currentKey = TQString(); + hashMap.clear(); connect(page->Buttonimport,TQT_SIGNAL(clicked()),this,TQT_SLOT(slotImport())); connect(page->Buttonsearch,TQT_SIGNAL(clicked()),this,TQT_SLOT(slotSearch())); connect(page->Buttonexport,TQT_SIGNAL(clicked()),this,TQT_SLOT(slotPreExport())); connect(this,TQT_SIGNAL(okClicked()),this,TQT_SLOT(slotOk())); - connect(page->cBproxyI,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableProxyI(bool))); - connect(page->cBproxyE,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableProxyE(bool))); - - connect(page->kLEimportid, TQT_SIGNAL( textChanged ( const TQString & )), this, TQT_SLOT( slotTextChanged( const TQString &))); - page->cBproxyI->setChecked(KGpgSettings::useProxy()); - page->cBproxyE->setChecked(KGpgSettings::useProxy()); - const char *httpproxy = getenv("http_proxy"); - if (httpproxy) { - page->cBproxyI->setEnabled(true); - page->cBproxyE->setEnabled(true); - page->kLEproxyI->setText(httpproxy); - page->kLEproxyE->setText(httpproxy); - } + if (KgpgInterface::getGpgVersion() < 210 ) { // was removed in 2.1 + connect(page->cBproxyI,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableProxyI(bool))); + connect(page->cBproxyE,TQT_SIGNAL(toggled(bool)),this,TQT_SLOT(slotEnableProxyE(bool))); + } + connect(page->kLEimportid, TQT_SIGNAL( textChanged ( const TQString & )), this, TQT_SLOT( slotTextChanged( const TQString &))); + if (KgpgInterface::getGpgVersion() < 210 ) { // was removed in 2.1 + page->cBproxyI->setChecked(KGpgSettings::useProxy()); + page->cBproxyE->setChecked(KGpgSettings::useProxy()); + const char *httpproxy = getenv("http_proxy"); + if (httpproxy) { + page->cBproxyI->setEnabled(true); + page->cBproxyE->setEnabled(true); + page->kLEproxyI->setText(httpproxy); + page->kLEproxyE->setText(httpproxy); + } + } KProcIO *encid=new KProcIO(TQTextCodec::codecForLocale()); *encid << "gpg"<<"--no-secmem-warning"<<"--no-tty"<<"--with-colon"<<"--list-keys"; + TQObject::connect(encid, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotprocresult(TDEProcess *))); TQObject::connect(encid, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotprocread(KProcIO *))); encid->start(TDEProcess::NotifyOnExit,true); page->Buttonimport->setEnabled( !page->kLEimportid->text().isEmpty()); page->Buttonsearch->setEnabled( !page->kLEimportid->text().isEmpty()); -setMinimumSize(sizeHint()); + setMinimumSize(sizeHint()); } @@ -98,6 +108,7 @@ keyServer::~keyServer() void keyServer::slotTextChanged( const TQString &text) { +// kdDebug(2100) << k_funcinfo << endl; page->Buttonimport->setEnabled( !text.isEmpty()); page->Buttonsearch->setEnabled( !text.isEmpty()); @@ -112,19 +123,39 @@ void keyServer::slotEnableProxyE(bool on) page->kLEproxyE->setEnabled(on); } - - void keyServer::slotprocread(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; ///////////////////////////////////////////////////////////////// extract encryption keys - bool dead; TQString tst; //TQPixmap pixkeySingle(TDEGlobal::iconLoader()->loadIcon("kgpg_key1",TDEIcon::Small,20)); while (p->readln(tst)!=-1) { - //tst=tst.stripWhiteSpace(); - if (tst.startsWith("pub")) { - const TQString trust=tst.section(':',1,1); - TQString id=TQString("0x"+tst.section(':',4,4).right(8)); +// kdDebug(2100) << k_funcinfo << "Read one public key line: " << tst << endl; + if ( tst.startsWith("pub") ) { + currentKey = tst.section(':',4,4).right(8); + TQStringList lst; lst << tst; + hashMap.insert(currentKey,tst); + } + else { + hashMap.find(currentKey).data().append(tst); + } + } +} + +void keyServer::slotprocresult(TDEProcess *) { + + TQMap hashImportList; + + TQMap::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQString fullname,id; + bool dead; + + for (TQStringList::Iterator it = ite.data().begin(); it != ite.data().end(); it++) { + TQString line = (*it); +// kdDebug(2100) << k_funcinfo << "Export line: " <35) { - tst.remove(35,tst.length()); - tst+="..."; - } - if ((!dead) && (!tst.isEmpty())) -// page->kCBexportkey->insertItem(pixkeySingle,id+": "+tst); - page->kCBexportkey->insertItem(id+": "+tst); - } - } + fullname = line.section(':',9,9); + id = "0x"+line.section(':',4,4).right(8); + } + if ( line.startsWith("uid") && fullname.isEmpty() ) { + fullname = line.section(':',9,9); + } + } +// if (fullname.length()>35) { +// fullname.remove(35,fullname.length()); +// fullname+="..."; +// } + + TQString tst; + if (fullname.find("<",0)!=-1) { + tst=fullname.section('<',0,0); + } + + if (!tst.isEmpty()) { + fullname = tst; + } + + if ((!dead) && (!fullname.isEmpty())) { + if ( hashImportList.find(id) == hashImportList.end() ) { + hashImportList.insert(fullname,id); + } + } + } + + for (TQMap::Iterator ite = hashImportList.begin(); ite != hashImportList.end() ; ite++) { + // page->kCBexportkey->insertItem(pixkeySingle,id+": "+tst); + page->kCBexportkey->insertItem(ite.data()+": "+ite.key()); + } + } void keyServer::slotSearch() { +// kdDebug(2100) << k_funcinfo << endl; if (page->kCBimportks->currentText().isEmpty()) return; @@ -164,7 +219,13 @@ void keyServer::slotSearch() return; } - //listpop = new KeyServer( this,"result",WType_Dialog | WShowModal); + currentKey = TQString(); + //listpop = new KeyServer( this,"result",WType_Dialog | WShowModal); + hashMap.clear(); + invalidKeys.clear(); + keyNumbers=0; + count=0; + readmessage=TQString(); dialogServer=new KDialogBase(KDialogBase::Swallow, i18n("Import Key From Keyserver"), KDialogBase::Ok | KDialogBase::Close,KDialogBase::Ok,this,0,true); @@ -182,24 +243,30 @@ void keyServer::slotSearch() connect(dialogServer,TQT_SIGNAL(closeClicked()),this,TQT_SLOT(handleQuit())); connect( listpop , TQT_SIGNAL( destroyed() ) , this, TQT_SLOT( abortSearch())); - count=0; - cycle=false; - readmessage=TQString(); + searchproc=new KProcIO(TQTextCodec::codecForLocale()); TQString keyserv=page->kCBimportks->currentText(); - *searchproc<<"gpg"<<"--utf8-strings"; - if (page->cBproxyI->isChecked()) { - searchproc->setEnvironment("http_proxy",page->kLEproxyI->text()); - *searchproc<< "--keyserver-options"<<"honor-http-proxy"; - } else - *searchproc<< "--keyserver-options"<<"no-honor-http-proxy"; - *searchproc<<"--keyserver"<kLEimportid->text().stripWhiteSpace(); + + *searchproc<<"gpg"<<"--utf8-strings"/*<<"--no-tty"*/; + if (KgpgInterface::getGpgVersion() < 210 ) { // was removed in 2.1 + if (page->cBproxyI->isChecked()) { + searchproc->setEnvironment("http_proxy",page->kLEproxyI->text()); + *searchproc<< "--keyserver-options"<<"honor-http-proxy"; + } + else { + *searchproc<< "--keyserver-options"<<"no-honor-http-proxy"; + } + } + *searchproc<<"--keyserver"<kLEimportid->text().stripWhiteSpace(); keyNumbers=0; + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); TQObject::connect(searchproc, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotsearchresult(TDEProcess *))); TQObject::connect(searchproc, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotsearchread(KProcIO *))); + searchproc->setUsePty(TDEProcess::Stdout,false); // EKO: very important line - it took me a day to find out why I should use it searchproc->start(TDEProcess::NotifyOnExit,true); - TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); + dialogServer->setMainWidget(listpop); listpop->setMinimumSize(listpop->sizeHint()); listpop->setMinimumWidth(550); @@ -208,9 +275,11 @@ void keyServer::slotSearch() void keyServer::handleQuit() { +// kdDebug(2100) << k_funcinfo << endl; if (searchproc->isRunning()) { TQApplication::restoreOverrideCursor(); + searchproc->closePty(); disconnect(searchproc,0,0,0); searchproc->kill(); } @@ -220,6 +289,7 @@ void keyServer::handleQuit() void keyServer::abortSearch() { +// kdDebug(2100) << k_funcinfo << endl; if (dialogServer) { delete dialogServer; dialogServer=0L; @@ -228,6 +298,7 @@ void keyServer::abortSearch() void keyServer::preimport() { +// kdDebug(2100) << k_funcinfo << endl; transferKeyID(); if (listpop->kLEID->text().isEmpty()) { KMessageBox::sorry(this,i18n("You must choose a key.")); @@ -240,6 +311,7 @@ void keyServer::preimport() void keyServer::transferKeyID() { +// kdDebug(2100) << k_funcinfo << endl; if (!listpop->kLVsearch->firstChild()) return; TQString kid,keysToSearch; @@ -255,9 +327,167 @@ void keyServer::transferKeyID() listpop->kLEID->setText(keysToSearch.stripWhiteSpace()); } +void keyServer::slotsearchread(KProcIO *p) +{ +// kdDebug(2100) << k_funcinfo << endl; + TQString required = TQString(); + + while (p->readln(required,true)!=-1) { + // kdDebug(2100) << "\tRead one search key line: " << required << endl; + if (required.find("keysearch.prompt")!=-1) { + p->setComm(TDEProcess::Stdin); + if (KgpgInterface::getGpgVersion() < 210) { + if (count != 1) { + p->writeStdin(TQString("N")); + } + else { + p->writeStdin(TQString("Q")); + p->closeWhenDone(); + } + } + else { + p->writeStdin(TQString("N")); // in 2.1 pressing N ends the session if output is empty +// if (count == 1) +// p->closeWhenDone(); + } + p->setComm(TDEProcess::Stdout); + required = TQString(); + continue; + } + if ( required.isEmpty() ) { + continue; + } + if ( required.find("GOT_IT")!=-1 ) { + required = TQString(); + continue; + } + + if ( required.startsWith("info") ) { + count = required.section(':',2,2).toInt(); + required = TQString(); + continue; + } + if ( required.startsWith("pub") ) { + currentKey = required.section(':',1,1).right(8); + if ( hashMap.find(currentKey) == hashMap.end() ) { + TQStringList lst; lst.append(required.simplifyWhiteSpace()); + hashMap.insert(currentKey,lst); + count--; + } + else { + hashMap.find(currentKey).data().append(required.simplifyWhiteSpace()); + } + required = TQString(); + } + else { + hashMap.find(currentKey).data().append(required.simplifyWhiteSpace()); + required = TQString(); + } + } +} + void keyServer::slotsearchresult(TDEProcess *) { - TQString nb; +// kdDebug(2100) << k_funcinfo << endl; + TQString nb; + + // check if key is valid + for (TQMap::Iterator ite = hashMap.begin(); ite != hashMap.end() ; ite++) { + TQStringList::Iterator it; + bool skip=false; + // this is to prevent offering to import expired or revoked keys + // first find out if key is revoked or expired + for (it = ite.data().begin(); it != ite.data().end(); it++ ) { + TQStringList keyString=TQStringList::split(":",(*it),true); + // kdDebug(2100) << k_funcinfo << "Key line: " << (*it) << endl; + if (keyString[0] == "pub") { + if (! keyString[6].isEmpty() ) { + if (keyString[6] == "r") { + skip = true; + } + } + if (! keyString[5].isEmpty() ) { // expiration date + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t( keyString[5].toInt() ); + date = timestamp.date(); + } + else { + date = TQDate::fromString(keyString[5], Qt::ISODate); + } + Q_ASSERT (date.isValid()) /*tqWarning("create date is not valid")*/; + if (date < TQDate::currentDate() ) { + skip = true; + } + } + } + } + if (skip) { + invalidKeys<::Iterator ite = hashMap.begin(); ite != hashMap.end() ; ite++) { + if (invalidKeys.find(ite.key()) != invalidKeys.end() ) { + continue; + } + // very good our keys is neither revoken nor expired - we can offer it for download + for (TQStringList::Iterator it = ite.data().begin(); it != ite.data().end(); it++ ) { + TQStringList keyString=TQStringList::split(":",(*it),true); + // kdDebug(2100) << k_funcinfo << "Processing key line: " << (*it) << endl; + TQString created; + if (keyString[0] == "pub") { + if (! keyString[4].isEmpty() ) { + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t( keyString[4].toInt() ); + date = timestamp.date(); + } + else { + date = TQDate::fromString(keyString[4], Qt::ISODate); + } + created=TDEGlobal::locale()->formatDate(date, true); + } + kitem=new TDEListViewItem(listpop->kLVsearch,TQString(),TQString(), created, keyString[1]); + keyNumbers++; + } + if (keyString[0] == "uid") { + TQString keymail,keyname; + if (! keyString[2].isEmpty() ) { + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t( keyString[2].toInt() ); + date = timestamp.date(); + } + else { + date = TQDate::fromString(keyString[2], Qt::ISODate); + } + created=TDEGlobal::locale()->formatDate(date, true); + } + if (keyString[1].find("<")!=-1) { + keymail=keyString[1].section('<',-1,-1); + if (keymail.endsWith(">")) { + keymail.truncate(keymail.length()-1); + } + keyname=keyString[1].section('<',0,0); + } + else { + keymail=TQString(); + keyname=keyString[1]; + } + if (kitem != 0 ) { + kitem->setText(0,keyname); + //if ( kitem->getText(1).isEmpty() ) kitem->setText(1,keymail); + TDEListViewItem *subk = new TDEListViewItem(kitem,keyname,keymail,created,TQString()); + subk->setSelectable(false); + } + } + } + } + dialogServer->enableButtonOK(true); TQApplication::restoreOverrideCursor(); nb=nb.setNum(keyNumbers); @@ -271,98 +501,36 @@ void keyServer::slotsearchresult(TDEProcess *) } } -void keyServer::slotsearchread(KProcIO *p) -{ - TQString required; - TQString keymail,keyname; - while (p->readln(required,true)!=-1) { - //required=TQString::fromUtf8(required); - - if (required.find("keysearch.prompt")!=-1) { - if (count<4) - p->writeStdin(TQString("N")); - else { - p->writeStdin(TQString("Q")); - p->closeWhenDone(); - } - required=TQString(); - } - - if (required.find("GOT_IT")!=-1) { - count++; - required=TQString(); - } - - if (required.find("(")==0) { - cycle=true; - TQString fullname=required.remove(0,required.find(")")+1).stripWhiteSpace(); - if (fullname.find("<")!=-1) { - keymail=fullname.section('<',-1,-1); - if (keymail.endsWith(">")) keymail.truncate(keymail.length()-1); - keyname=fullname.section('<',0,0); - } else { - keymail=TQString(); - keyname=fullname; - } - kitem=new TDEListViewItem(listpop->kLVsearch,keyname,keymail,TQString(),TQString()); - keyNumbers++; - count=0; - required=TQString(); - } - - if ((cycle) && (!required.isEmpty())) { - TQString subkey=required.stripWhiteSpace(); - if (subkey.find(" key ")!=-1 && subkey.at(0).isDigit ()) - { - TQString kid=subkey.section(",",0,0).stripWhiteSpace(); - kid=kid.right(8); - kitem->setText(3,kid); - TQString creation=subkey.section("created",1,1); - if (creation.startsWith(":")) creation=creation.right(creation.length()-1); - kitem->setText(2,creation); - cycle=false; - } - else - { - if (subkey.find("<")!=-1) { - keymail=subkey.section('<',-1,-1); - if (keymail.endsWith(">")) keymail.truncate(keymail.length()-1); - keyname=subkey.section('<',0,0); - } else { - keymail=TQString(); - keyname=subkey; - } - TDEListViewItem *subk = new TDEListViewItem(kitem,keyname,keymail,TQString(),TQString()); - subk->setSelectable(false); - } - required=TQString(); - } - } -} - void keyServer::slotPreExport() { +// kdDebug(2100) << k_funcinfo << endl; slotExport(TQStringList(page->kCBexportkey->currentText().section(':', 0, 0))); } void keyServer::slotExport(TQStringList keyIds) { +// kdDebug(2100) << k_funcinfo << endl; if (page->kCBexportks->currentText().isEmpty()) return; readmessage=TQString(); + hashMap.clear(); exportproc=new KProcIO(TQTextCodec::codecForLocale()); TQString keyserv=page->kCBexportks->currentText(); - *exportproc<<"gpg"<<"--utf8-strings"; - if (!page->exportAttributes->isChecked()) - *exportproc<<"--export-options"<<"no-include-attributes"; - - if (page->cBproxyE->isChecked()) { - exportproc->setEnvironment("http_proxy",page->kLEproxyE->text()); - *exportproc<< "--keyserver-options"<<"honor-http-proxy"; - } else - *exportproc<< "--keyserver-options"<<"no-honor-http-proxy"; - *exportproc << "--status-fd=2" << "--keyserver" << keyserv << "--send-keys" << keyIds; + *exportproc<<"gpg"<<"--utf8-strings"; + if (!page->exportAttributes->isChecked()) { + *exportproc<<"--export-options"<<"no-include-attributes"; + } + if (KgpgInterface::getGpgVersion() < 210 ) { // was removed in 2.1 + if (page->cBproxyE->isChecked()) { + exportproc->setEnvironment("http_proxy",page->kLEproxyE->text()); + *exportproc<< "--keyserver-options"<<"honor-http-proxy"; + } + else { + *exportproc<< "--keyserver-options"<<"no-honor-http-proxy"; + } + } + *exportproc << "--status-fd=2" << "--keyserver" << keyserv << "--send-keys" << keyIds; TQObject::connect(exportproc, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotexportresult(TDEProcess *))); TQObject::connect(exportproc, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotimportread(KProcIO *))); @@ -384,6 +552,7 @@ void keyServer::slotExport(TQStringList keyIds) void keyServer::abortExport() { +// kdDebug(2100) << k_funcinfo << endl; TQApplication::restoreOverrideCursor(); if (exportproc->isRunning()) { @@ -394,48 +563,112 @@ void keyServer::abortExport() void keyServer::slotexportresult(TDEProcess*) { +// kdDebug(2100) << k_funcinfo << endl; TQApplication::restoreOverrideCursor(); KMessageBox::information(0,readmessage); if (importpop) delete importpop; } - void keyServer::slotImport() { +// kdDebug(2100) << k_funcinfo << endl; if (page->kCBimportks->currentText().isEmpty()) return; if (page->kLEimportid->text().isEmpty()) { - KMessageBox::sorry(this,i18n("You must enter a search string.")); + KMessageBox::sorry(this,i18n("You must select a valid key for import")); return; } - readmessage=TQString(); - importproc=new KProcIO(TQTextCodec::codecForLocale()); - TQString keyserv=page->kCBimportks->currentText(); - *importproc<<"gpg"<<"--utf8-strings"; - if (page->cBproxyI->isChecked()) { - importproc->setEnvironment("http_proxy",page->kLEproxyI->text()); - *importproc<< "--keyserver-options"<<"honor-http-proxy"; - } else - *importproc<< "--keyserver-options"<<"no-honor-http-proxy"; +// kdDebug(2100) << k_funcinfo << "Asked for import: " <kLEimportid->text() <kCBimportks->currentText(); +/* + * + * This function is called from search and from signature import + * so we need to make sure we have a valid keys for import + * When import is triggered from the search key dialog, we alread have the full ids + * When import is triggered from the signature import popup, we have names, but only + * if single signature is select we can import from the server + * + * search the keys first and pass the full pub key ids to the importproc + * to prevent importing pub keys for revocation and normal pub keys together + * we check to see if key is marked as revoc and look for another key that would + * be associated with the revoking one, so we skip both key and everything that + * belongs to this public key + * + * we also check the expiration date and refuse to import expired keys + * + */ - *importproc<<"--status-fd=2"<<"--keyserver"<kLEimportid->text(); keyNames=keyNames.stripWhiteSpace(); keyNames=keyNames.simplifyWhiteSpace(); - while (!keyNames.isEmpty()) { - TQString fkeyNames=keyNames.section(' ',0,0); - keyNames.remove(0,fkeyNames.length()); - keyNames=keyNames.stripWhiteSpace(); - *importproc<cBproxyI->isChecked()) { + searchproc->setEnvironment("http_proxy",page->kLEproxyI->text()); + *searchproc << "--keyserver-options"<<"honor-http-proxy"; + } + else { + *searchproc << "--keyserver-options"<<"no-honor-http-proxy"; + } + } + *searchproc << "--keyserver" << keyserv << "--status-fd=2" /*<<"--debug-level"<<"guru"*/; + *searchproc << "--command-fd=0" << "--with-colon" << "--search-keys"; + + while (!keyNames.isEmpty()) { + TQString fkeyNames=keyNames.section(' ',0,0); + keyNames.remove(0,fkeyNames.length()); + keyNames=keyNames.stripWhiteSpace(); + *searchproc<< TQString(TQFile::encodeName(fkeyNames)); + } + TQObject::connect(searchproc, TQT_SIGNAL(processExited(TDEProcess *)),TQT_TQOBJECT(this), TQT_SLOT(slotksearchprocresult(TDEProcess *))); + TQObject::connect(searchproc, TQT_SIGNAL(readReady(KProcIO *)),TQT_TQOBJECT(this), TQT_SLOT(slotsearchread(KProcIO *))); + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); + searchproc->setUsePty(TDEProcess::Stdout,false); // EKO: very important line - it took me a day to find out why I should use it + searchproc->start(TDEProcess::Block,true); + if (searchproc->isRunning()) { + searchproc->closePty(); + disconnect(searchproc,0,0,0); + searchproc->kill(); + } + } + else { + keysToImport = TQStringList::split(" ",keyNames,true); + } + + importproc=new KProcIO(TQTextCodec::codecForLocale()); + *importproc<<"gpg"<<"--utf8-strings"; + if (KgpgInterface::getGpgVersion() < 210 ) { // was removed in 2.1 + if (page->cBproxyI->isChecked()) { + importproc->setEnvironment("http_proxy",page->kLEproxyI->text()); + *importproc<< "--keyserver-options"<<"honor-http-proxy"; + } + else { + *importproc<< "--keyserver-options"<<"no-honor-http-proxy"; + } + } + *importproc<<"--status-fd=2"<<"--keyserver"<start(TDEProcess::NotifyOnExit,true); importproc->closeWhenDone(); - TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); + importpop = new TQDialog( this,0,true,TQt::WDestructiveClose); TQVBoxLayout *vbox=new TQVBoxLayout(importpop,3); TQLabel *tex=new TQLabel(importpop); @@ -452,6 +685,7 @@ void keyServer::slotImport() void keyServer::abortImport() { +// kdDebug(2100) << k_funcinfo << endl; TQApplication::restoreOverrideCursor(); if (importproc->isRunning()) { @@ -462,8 +696,66 @@ void keyServer::abortImport() if (autoCloseWindow) close(); } +void keyServer::slotksearchprocresult(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << k_funcinfo << endl; + // leave only valid keys in the list + for (TQMap::Iterator ite = hashMap.begin(); ite != hashMap.end() ; ite++) { + bool exp=false; + bool rev=false; + for (TQStringList::Iterator it = ite.data().begin(); it != ite.data().end(); it++ ) { + TQStringList keyString=TQStringList::split(":",(*it),true); + // kdDebug(2100) << k_funcinfo << "Read one key line: " << (*it) << endl; + if (keyString[0] == "pub") { + if (! keyString[6].isEmpty() ) { + if (keyString[6] == "r") { + rev = true; + } + } + if (! keyString[5].isEmpty() ) { // expiration date + TQDate date; + if (KgpgInterface::getGpgVersion() >= 210 ) { + TQDateTime timestamp; + timestamp.setTime_t( keyString[5].toInt() ); + date = timestamp.date(); + } + else { + date = TQDate::fromString(keyString[5], Qt::ISODate); + } + Q_ASSERT (date.isValid()) /*tqWarning("create date is not valid")*/; + if (date < TQDate::currentDate() ) { + exp = true; + } + } + } + } + if (exp || rev) { + invalidKeys<0x"; + if (rev) { + readmessage += ite.key() + " (" + i18n("Revoked"); + } + if (exp) { + readmessage += ", "+i18n("Expired"); + } + readmessage += ")
\n"; + } + } + + for (TQMap::Iterator ite = hashMap.begin(); ite != hashMap.end() ; ite++) { + if (invalidKeys.find(ite.key()) == invalidKeys.end() ) { + // keys are neither revoked nor expired + for (TQStringList::Iterator it = ite.data().begin(); it != ite.data().end(); it++ ) { + if ( (*it).startsWith("pub") ) { + keysToImport << (*it).section(":",1,1); + } + } + } + } +} + void keyServer::slotimportresult(TDEProcess*) { +// kdDebug(2100) << k_funcinfo << endl; TQApplication::restoreOverrideCursor(); TQString importedNb,importedNbSucess,importedNbProcess,resultMessage, parsedOutput,importedNbUnchanged,importedNbSig; TQString notImportesNbSec,importedNbMissing,importedNbRSA,importedNbUid,importedNbSub,importedNbRev,readNbSec; @@ -471,6 +763,7 @@ void keyServer::slotimportresult(TDEProcess*) parsedOutput=readmessage; TQStringList importedKeys; + TQApplication::restoreOverrideCursor(); while (parsedOutput.find("IMPORTED")!=-1) { parsedOutput.remove(0,parsedOutput.find("IMPORTED")+8); @@ -518,14 +811,15 @@ void keyServer::slotimportresult(TDEProcess*) resultMessage+=i18n("One secret key not imported.
","%n secret keys not imported.
",notImportesNbSec.toULong()); if (importedNbSucess!="0") resultMessage+=i18n("One key imported:
","%n keys imported:
",importedNbSucess.toULong()); - } else - resultMessage=i18n("No key imported... \nCheck detailed log for more infos"); + } + else { + resultMessage=i18n("No key imported... \nCheck detailed log for more infos"); + } - TQString lastID=TQString("0x"+importedKeys.last().section(" ",0,0).right(8)); - if (!lastID.isEmpty()) - { - //kdDebug(2100)<<"++++++++++imported key"<setGroup("Servers"); TQString serverList=config->readEntry("Server_List"); @@ -555,8 +850,8 @@ void keyServer::syncCombobox() page->kCBimportks->clear(); if (!optionsServer.isEmpty()) { - page->kCBexportks->insertItem(optionsServer); - page->kCBimportks->insertItem(optionsServer); + page->kCBexportks->insertItem(optionsServer + " " + i18n("(Default)")); + page->kCBimportks->insertItem(optionsServer + " " + i18n("(Default)")); } else if ( serverList.isEmpty() ) serverList = "hkp://wwwkeys.eu.pgp.net,hkp://search.keyserver.net,hkp://wwwkeys.pgp.net,hkp://pgp.dtype.org,hkp://wwwkeys.us.pgp.net"; // same as ini kgpgoptions.cpp diff --git a/kgpg/keyservers.h b/kgpg/keyservers.h index 4a089f8..51e98a8 100644 --- a/kgpg/keyservers.h +++ b/kgpg/keyservers.h @@ -51,6 +51,7 @@ public slots: void slotexportresult(TDEProcess*); void slotimportread(KProcIO *p); void slotprocread(KProcIO *p); + void slotprocresult(TDEProcess *); void slotPreExport(); void slotExport(TQStringList keyIds); void preimport(); @@ -59,13 +60,17 @@ public slots: void slotEnableProxyE(bool on); void handleQuit(); void slotTextChanged( const TQString &text); +// void slotksearchprocread(KProcIO *p); + void slotksearchprocresult(TDEProcess *); private: TQDialog *importpop; KSimpleConfig *config; uint keyNumbers; - TQString readmessage; + TQString readmessage, currentKey;; + TQStringList keysToImport, invalidKeys; + TQMap hashMap; KProcIO *importproc,*exportproc; KProcIO *searchproc; searchRes *listpop; diff --git a/kgpg/kgpg.cpp b/kgpg/kgpg.cpp index c711e3a..0d7acd2 100644 --- a/kgpg/kgpg.cpp +++ b/kgpg/kgpg.cpp @@ -4,6 +4,10 @@ begin : Mon Nov 18 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 ***************************************************************************/ /*************************************************************************** @@ -174,7 +178,7 @@ compressionScheme=cp; void MyView::startFolderEncode(TQStringList selec,TQStringList encryptOptions,bool ,bool symetric) { -TQString extension; +TQString extension=""; if (compressionScheme==0) extension=".zip"; @@ -646,33 +650,65 @@ void MyView::startWizard() wiz->kURLRequester2->setMode(2);*/ FILE *fp,*fp2; - TQString tst,tst2,name,trustedvals="idre-"; + TQString trustedvals="idre-"; TQString firstKey=TQString(); char line[300]; bool counter=false; + TQString currentKey; + TQMap hashMap; fp = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-secret-keys", "r"); while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - if (tst.startsWith("sec")) { - name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); - if (!name.isEmpty()) { - fp2 = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-keys "+TQFile::encodeName(tst.section(':',4,4)), "r"); - while ( fgets( line, sizeof(line), fp2)) { - tst2=TQString::fromUtf8(line); - if (tst2.startsWith("pub") && (trustedvals.find(tst2.section(':',1,1))==-1)) { - counter=true; - wiz->CBdefault->insertItem(tst.section(':',4,4).right(8)+": "+name); - if (firstKey.isEmpty()) - firstKey=tst.section(':',4,4).right(8)+": "+name; - break; - } - } - pclose(fp2); - } - } - } - pclose(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); + + TQMap::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TDEListViewItem *item; + TQStringList::Iterator it; + + TQString name,id; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + if (tst.startsWith("sec") ) { + if ( KgpgInterface::getGpgVersion() < 210) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + id = tst.section(':',4,4); + } + if ( tst.startsWith("uid") && KgpgInterface::getGpgVersion() >= 210 ) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + } + + if (!name.isEmpty()) { + fp2 = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-keys "+TQFile::encodeName(id), "r"); + while ( fgets( line, sizeof(line), fp2)) { + TQString tst2=TQString::fromUtf8(line); + if (tst2.startsWith("pub") && (trustedvals.find(tst2.section(':',1,1))==-1)) { + counter=true; + wiz->CBdefault->insertItem(id.right(8)+": "+name); + if (firstKey.isEmpty()) { + firstKey=id.right(8)+": "+name; + } + break; + } + } + pclose(fp2); + } + } + wiz->CBdefault->setCurrentItem(firstKey); //connect(wiz->pushButton4,TQT_SIGNAL(clicked()),TQT_TQOBJECT(this),TQT_SLOT(slotGenKey())); if (!counter) @@ -692,23 +728,48 @@ void MyView::startWizard() void MyView::slotWizardChange() { - TQString tst,name; - char line[300]; - FILE *fp; if (wiz->indexOf(wiz->currentPage())==2) { TQString defaultID=KgpgInterface::getGpgSetting("default-key",wiz->kURLRequester1->url()); if (defaultID.isEmpty()) return; - fp = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-secret-keys "+TQFile::encodeName(defaultID), "r"); - while ( fgets( line, sizeof(line), fp)) { - tst=TQString::fromUtf8(line); - if (tst.startsWith("sec")) { - name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); - wiz->CBdefault->setCurrentItem(tst.section(':',4,4).right(8)+": "+name); - } - } - pclose(fp); + + char line[300]; + FILE *fp; + TQString id, name, currentKey; + TQMap hashMap; + fp = popen("gpg --display-charset=utf-8 --no-tty --with-colon --list-secret-keys "+TQFile::encodeName(defaultID), "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); + + TQMap::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + for (TQStringList::Iterator it = ite.data().begin(); it != ite.data().end(); it++) { + TQString tst = (*it); + tst=TQString::fromUtf8(line); + if ( tst.startsWith("sec") ) { + if (KgpgInterface::getGpgVersion() < 210) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + id=tst.section(':',4,4).right(8); + } + if ( (tst.startsWith("uid") && KgpgInterface::getGpgVersion() >= 210) ) { + name=KgpgInterface::checkForUtf8(tst.section(':',9,9)); + } + } + } + wiz->CBdefault->setCurrentItem(id+": "+name); } } diff --git a/kgpg/kgpginterface.cpp b/kgpg/kgpginterface.cpp index 637198b..0d15df2 100644 --- a/kgpg/kgpginterface.cpp +++ b/kgpg/kgpginterface.cpp @@ -4,6 +4,10 @@ begin : Mon Jul 8 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 ***************************************************************************/ /*************************************************************************** @@ -44,6 +48,7 @@ #include #include #include +#include #include "kgpginterface.h" #include "listkeys.h" @@ -76,6 +81,7 @@ FILE *fp; void KgpgInterface::updateIDs(TQString txtString) { +// kdDebug(2100) << k_funcinfo << endl; int cut=txtString.find(' ',22,false); txtString.remove(0,cut); if (txtString.find("(",0,false)!=-1) @@ -91,6 +97,7 @@ void KgpgInterface::updateIDs(TQString txtString) void KgpgInterface::KgpgEncryptFile(TQStringList encryptKeys,KURL srcUrl,KURL destUrl, TQStringList Options, bool symetrical) { +// kdDebug(2100) << k_funcinfo << endl; sourceFile=srcUrl; message=TQString(); @@ -123,6 +130,7 @@ KgpgInterface::~KgpgInterface() void KgpgInterface::encryptfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (message.find("END_ENCRYPTION")!=-1) emit encryptionfinished(sourceFile); else { @@ -132,6 +140,7 @@ void KgpgInterface::encryptfin(TDEProcess *) void KgpgInterface::readencprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required; while (p->readln(required,true)!=-1) { if (required.find("BEGIN_ENCRYPTION",0,false)!=-1) @@ -162,6 +171,7 @@ void KgpgInterface::readencprocess(KProcIO *p) void KgpgInterface::KgpgDecryptFile(KURL srcUrl,KURL destUrl,TQStringList Options) { +// kdDebug(2100) << k_funcinfo << endl; message=TQString(); step=3; decryptUrl=srcUrl.path(); @@ -187,6 +197,7 @@ void KgpgInterface::KgpgDecryptFile(KURL srcUrl,KURL destUrl,TQStringList Option void KgpgInterface::decryptfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if ((message.find("DECRYPTION_OKAY")!=-1) && (message.find("END_DECRYPTION")!=-1)) //&& (message.find("GOODMDC")!=-1) emit decryptionfinished(); else @@ -196,6 +207,7 @@ void KgpgInterface::decryptfin(TDEProcess *) void KgpgInterface::readdecprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required; while (p->readln(required,true)!=-1) { if (required.find("BEGIN_DECRYPTION",0,false)!=-1) @@ -247,6 +259,7 @@ void KgpgInterface::readdecprocess(KProcIO *p) void KgpgInterface::KgpgEncryptText(TQString text,TQStringList userIDs, TQStringList Options) { +// kdDebug(2100) << k_funcinfo << endl; message=TQString(); //TQTextCodec *codec = TDEGlobal::charsets()->codecForName(TDEGlobal::locale()->encoding()); TQTextCodec *codec =TQTextCodec::codecForLocale (); @@ -279,6 +292,7 @@ void KgpgInterface::KgpgEncryptText(TQString text,TQStringList userIDs, TQString void KgpgInterface::txtencryptfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (!message.isEmpty()) emit txtencryptionfinished(message); else @@ -287,6 +301,7 @@ void KgpgInterface::txtencryptfin(TDEProcess *) void KgpgInterface::txtreadencprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required; while (p->readln(required,true)!=-1) { if (required.find("BEGIN_ENCRYPTION",0,false)!=-1) @@ -318,6 +333,7 @@ void KgpgInterface::txtreadencprocess(KProcIO *p) void KgpgInterface::KgpgDecryptText(TQString text,TQStringList Options) { +// kdDebug(2100) << k_funcinfo << endl; gpgOutput=TQString(); log=TQString(); @@ -345,6 +361,7 @@ void KgpgInterface::KgpgDecryptText(TQString text,TQStringList Options) void KgpgInterface::txtdecryptfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if ((decok) && (!badmdc)) emit txtdecryptionfinished(message); @@ -360,12 +377,14 @@ emit txtdecryptionfailed(log); void KgpgInterface::getOutput(TDEProcess *, char *data, int ) { +// kdDebug(2100) << k_funcinfo << endl; message.append(TQString::fromUtf8(data)); } void KgpgInterface::getCmdOutput(TDEProcess *p, char *data, int ) { +// kdDebug(2100) << k_funcinfo << endl; gpgOutput.append(TQString::fromUtf8(data)); log.append(data); @@ -434,6 +453,7 @@ void KgpgInterface::getCmdOutput(TDEProcess *p, char *data, int ) void KgpgInterface::KgpgSignText(TQString text,TQString userIDs, TQStringList Options) { +// kdDebug(2100) << k_funcinfo << endl; message=TQString(); step=4; TQString txtprocess; @@ -458,7 +478,7 @@ void KgpgInterface::KgpgSignText(TQString text,TQString userIDs, TQStringList Op proc->start(TDEProcess::NotifyOnExit,false); /*if (useAgent) { - kdDebug(2100)<<"Using Agent+++++++++++++"<writeStdin(txtprocess,true); proc->closeWhenDone(); @@ -470,6 +490,7 @@ void KgpgInterface::KgpgSignText(TQString text,TQString userIDs, TQStringList Op void KgpgInterface::txtsignfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << "MSG: " << message<readln(required,true)!=-1) { // kdDebug(2100)<<"SIGNING: "<closeWhenDone(); } + if (required.find("BEGIN_SIGNING")!=-1) { + p->writeStdin(message,true); + message=TQString(); + p->closeWhenDone(); + } + if ((required.find("passphrase.enter")!=-1)) { if (step>1) step--; @@ -513,6 +542,7 @@ void KgpgInterface::txtsignprocess(KProcIO *p) } else if (!required.startsWith("[GNUPG:]")) message+=required+"\n"; +// kdDebug(2100)<<"SIGNING: "<canEncode(text)) text=text.utf8(); @@ -569,6 +601,7 @@ void KgpgInterface::KgpgVerifyText(TQString text) void KgpgInterface::slotverifyresult(TDEProcess*) { +// kdDebug(2100) << k_funcinfo << endl; if (signmiss) emit missingSignature(signID); else { if (signID.isEmpty()) signID=i18n("No signature found."); @@ -579,6 +612,7 @@ if (signmiss) emit missingSignature(signID); void KgpgInterface::slotverifyread(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required; while (p->readln(required,true)!=-1) { @@ -613,6 +647,7 @@ TQString required; Md5Widget::Md5Widget(TQWidget *parent, const char *name,KURL url):KDialogBase( parent, name, true,i18n("MD5 Checksum"),Apply | Close) { +// kdDebug(2100) << k_funcinfo << endl; setButtonApply(i18n("Compare MD5 with Clipboard")); mdSum=TQString(); TQFile f(url.path()); @@ -664,6 +699,7 @@ Md5Widget::~Md5Widget() void Md5Widget::slotApply() { +// kdDebug(2100) << k_funcinfo << endl; TQClipboard *cb = TQApplication::clipboard(); TQString text; // Copy text from the clipboard (paste) @@ -692,6 +728,7 @@ void Md5Widget::slotApply() void KgpgInterface::KgpgSignFile(TQString keyID,KURL srcUrl,TQStringList Options) { +// kdDebug(2100) << k_funcinfo << endl; ////////////////////////////////////// create a detached signature for a chosen file message=TQString(); step=3; @@ -714,6 +751,7 @@ void KgpgInterface::KgpgSignFile(TQString keyID,KURL srcUrl,TQStringList Options void KgpgInterface::signfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (message.find("SIG_CREATED")!=-1) KMessageBox::information(0,i18n("The signature file %1 was successfully created.").arg(file.fileName())); else if (message.find("BAD_PASSPHRASE")!=-1) @@ -726,6 +764,7 @@ void KgpgInterface::signfin(TDEProcess *) void KgpgInterface::readsignprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required; while (p->readln(required,true)!=-1) { if (required.find("USERID_HINT",0,false)!=-1) @@ -766,6 +805,7 @@ void KgpgInterface::readsignprocess(KProcIO *p) void KgpgInterface::KgpgVerifyFile(KURL sigUrl,KURL srcUrl) { +// kdDebug(2100) << k_funcinfo << endl; ////////////////////////////////////// verify signature for a chosen file message=TQString(); signID=TQString(); @@ -786,7 +826,8 @@ void KgpgInterface::KgpgVerifyFile(KURL sigUrl,KURL srcUrl) void KgpgInterface::readprocess(KProcIO *p) { -TQString required; +// kdDebug(2100) << k_funcinfo << endl; + TQString required; while (p->readln(required,true)!=-1) { message+=required+"\n"; @@ -821,6 +862,7 @@ TQString required; void KgpgInterface::verifyfin(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (!signmiss) { if (signID.isEmpty()) signID=i18n("No signature found."); (void) new KDetailedInfo(0,"verify_result",signID,message); @@ -839,6 +881,7 @@ void KgpgInterface::verifyfin(TDEProcess *) void KgpgInterface::KgpgSignKey(TQString keyID,TQString signKeyID,TQString signKeyMail,bool local,int checking) { +// kdDebug(2100) << k_funcinfo << endl; signKeyMail.replace(TQRegExp("<"),"<"); konsChecked=checking; konsLocal=local; @@ -861,88 +904,186 @@ void KgpgInterface::KgpgSignKey(TQString keyID,TQString signKeyID,TQString signK else *conprocess<<"sign"; TQObject::connect(conprocess,TQT_SIGNAL(readReady(KProcIO *)),this,TQT_SLOT(sigprocess(KProcIO *))); TQObject::connect(conprocess, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(signover(TDEProcess *))); + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); conprocess->start(TDEProcess::NotifyOnExit,true); } void KgpgInterface::sigprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); - while (p->readln(required,true)!=-1) - { + while (p->readln(required,true)!=-1) { + output+=required+"\n"; - output+=required+"\n"; - if (required.find("USERID_HINT",0,false)!=-1) - updateIDs(required); + if ( KgpgInterface::getGpgVersion() >= 210 ) { + // kdDebug(2100) << k_funcinfo << " line " << required << endl; + if (required.find("USERID_HINT",0,false)!=-1) { + updateIDs(required); + } - if (signSuccess==4) { - if (required.find("GET_")!=-1) - p->writeStdin(TQString("quit")); - p->closeWhenDone(); - return; - } + if (signSuccess==4 && required.find("GET_")!=-1) { + // kdDebug(2100) << k_funcinfo << " success quit" << endl; + p->writeStdin(TQString("quit")); + p->closeWhenDone(); + return; + } - if ((required.find("GOOD_PASSPHRASE")!=-1)) { - signSuccess=3; - step=2; - } + if ((required.find("GOOD_PASSPHRASE")!=-1)) { + // kdDebug(2100) << k_funcinfo << " GOOD_PASSPHRASE" << endl; + signSuccess=3; + step=2; + } - if (required.find("sign_uid.expire")!=-1) { - p->writeStdin(TQString("Never")); - required=TQString(); - } - if (required.find("sign_uid.class")!=-1) { - p->writeStdin(TQString::number(konsChecked)); - required=TQString(); - } - if (required.find("sign_uid.okay")!=-1) { - p->writeStdin(TQString("Y")); - required=TQString(); - } + if (required.find("sign_uid.expire")!=-1) { + // kdDebug(2100) << k_funcinfo << " sign_uid.expire" << endl; + p->writeStdin(TQString("Never")); + required=TQString(); + } + if (required.find("sign_uid.class")!=-1) { + // kdDebug(2100) << k_funcinfo << " sign_uid.class" << endl; + p->writeStdin(TQString::number(konsChecked)); + required=TQString(); + } + if (required.find("sign_all.okay")!=-1 || required.find("sign_uid.okay")!=-1 ) { + // kdDebug(2100) << k_funcinfo << " sign_uid.okay" << endl; + step=2; + p->writeStdin(TQString("Y")); + required=TQString(); + } + if (required.find("PINENTRY_LAUNCHED")!=-1) { + // kdDebug(2100) << k_funcinfo << "PINENTRY_LAUNCHED" << endl; + // p->writeStdin(TQString::number(konsChecked)); + required=TQString(); + } - if (required.find("sign_all.okay")!=-1) { - p->writeStdin(TQString("Y")); - required=TQString(); - } + if (required.find("passphrase.enter")!=-1) { + TQCString signpass; + // kdDebug(2100) << k_funcinfo << "passphrase.enter" << endl; + TQApplication::restoreOverrideCursor(); + int code=KPasswordDialog::getPassword(signpass,i18n("%1 Enter passphrase for %2:") + .arg(errMessage).arg(userIDs)); + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); + if (code!=TQDialog::Accepted) { + signSuccess=4; ///// aborted by user mode + required=TQString(); + p->writeStdin(TQString("quit")); + p->closeWhenDone(); + return; + } + p->writeStdin(signpass,true); + required=TQString(); + // step=2; + } + if ((step==2) && (required.find("keyedit.prompt")!=-1) ) { + // kdDebug(2100) << k_funcinfo << "key sign" << endl; + p->writeStdin(TQString("save")); + p->closeWhenDone(); + signSuccess=4; + required=TQString(); + } + if (required.find("BAD_PASSPHRASE")!=-1) { + // kdDebug(2100) << k_funcinfo << "BAD_PASSPHRASE" << endl; + errMessage=i18n("Bad passphrase. Try again.
"); + required=TQString(); + signSuccess=2; ///// bad passphrase + } +// if (required.find("GET_")!=-1) { /////// gpg asks for something unusal, turn to konsole mode +// // kdDebug(2100) << k_funcinfo << "GET_ " << required << endl; +// if (signSuccess!=2) { +// signSuccess=1; ///// switching to console mode +// } +// } + } - if (required.find("passphrase.enter")!=-1) { - TQCString signpass; - int code=KPasswordDialog::getPassword(signpass,i18n("%1 Enter passphrase for %2:") - .arg(errMessage).arg(userIDs)); - if (code!=TQDialog::Accepted) { - signSuccess=4; ///// aborted by user mode - required=TQString(); - p->writeStdin(TQString("quit")); - p->closeWhenDone(); - return; - } - p->writeStdin(signpass,true); - required=TQString(); - // step=2; - } - if ((step==2) && (required.find("keyedit.prompt")!=-1)) { - p->writeStdin(TQString("save")); - required=TQString(); - } - if (required.find("BAD_PASSPHRASE")!=-1) { - errMessage=i18n("Bad passphrase. Try again.
"); - required=TQString(); - signSuccess=2; ///// bad passphrase - } - if (required.find("GET_")!=-1) /////// gpg asks for something unusal, turn to konsole mode - { - if (signSuccess!=2) - signSuccess=1; ///// switching to console mode - p->writeStdin(TQString("quit")); - p->closeWhenDone(); + else { // (KgpgInterface::getGpgVersion() < 210) + // kdDebug(2100) << k_funcinfo << " line " << required << endl; + if (required.find("USERID_HINT",0,false)!=-1) { + updateIDs(required); + } - } - } + if (signSuccess==4) { + // kdDebug(2100) << k_funcinfo << " success quit" << endl; + if (required.find("GET_")!=-1) { + p->writeStdin(TQString("quit")); + } + p->closeWhenDone(); + return; + } + + if ((required.find("GOOD_PASSPHRASE")!=-1)) { + // kdDebug(2100) << k_funcinfo << " GOOD_PASSPHRASE" << endl; + signSuccess=3; + step=2; + } + + if (required.find("sign_uid.expire")!=-1) { + // kdDebug(2100) << k_funcinfo << " sign_uid.expire" << endl; + p->writeStdin(TQString("Never")); + required=TQString(); + } + if (required.find("sign_uid.class")!=-1) { + // kdDebug(2100) << k_funcinfo << " sign_uid.class" << endl; + p->writeStdin(TQString::number(konsChecked)); + required=TQString(); + } + if (required.find("sign_all.okay")!=-1 || required.find("sign_uid.okay")!=-1 ) { + // kdDebug(2100) << k_funcinfo << " sign_uid.okay" << endl; + p->writeStdin(TQString("Y")); + required=TQString(); + } + if (required.find("PINENTRY_LAUNCHED")!=-1) { + // kdDebug(2100) << k_funcinfo << "PINENTRY_LAUNCHED" << endl; + // p->writeStdin(TQString::number(konsChecked)); + required=TQString(); + } + + if (required.find("passphrase.enter")!=-1) { + TQApplication::restoreOverrideCursor(); + TQCString signpass; + // kdDebug(2100) << k_funcinfo << "passphrase.enter" << endl; + int code=KPasswordDialog::getPassword(signpass,i18n("%1 Enter passphrase for %2:") + .arg(errMessage).arg(userIDs)); + TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor)); + if (code!=TQDialog::Accepted) { + signSuccess=4; ///// aborted by user mode + required=TQString(); + p->writeStdin(TQString("quit")); + p->closeWhenDone(); + return; + } + p->writeStdin(signpass,true); + required=TQString(); + // step=2; + } + if ((step==2) && (required.find("keyedit.prompt")!=-1) ) { + // kdDebug(2100) << k_funcinfo << "key save" << endl; + p->writeStdin(TQString("save")); + required=TQString(); + } + if (required.find("BAD_PASSPHRASE")!=-1) { + // kdDebug(2100) << k_funcinfo << "BAD_PASSPHRASE" << endl; + errMessage=i18n("Bad passphrase. Try again.
"); + required=TQString(); + signSuccess=2; ///// bad passphrase + } + if (required.find("GET_")!=-1) { /////// gpg asks for something unusal, turn to konsole mode + // kdDebug(2100) << k_funcinfo << "GET_ " << required << endl; + if (signSuccess!=2) { + signSuccess=1; ///// switching to console mode + } + p->writeStdin(TQString("quit")); + p->closeWhenDone(); + } + } + } } void KgpgInterface::signover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; + TQApplication::restoreOverrideCursor(); if (signSuccess>1) emit signatureFinished(signSuccess); //// signature successful or bad passphrase else { @@ -957,6 +1098,7 @@ void KgpgInterface::signover(TDEProcess *) void KgpgInterface::openSignConsole() { +// kdDebug(2100) << k_funcinfo << endl; TDEProcess conprocess; TDEConfig *config = TDEGlobal::config(); config->setGroup("General"); @@ -977,6 +1119,7 @@ void KgpgInterface::openSignConsole() void KgpgInterface::KgpgDelSignature(TQString keyID,TQString signKeyID) { +// kdDebug(2100) << k_funcinfo << endl; if (checkuid(keyID)>0) { KMessageBox::sorry(0,i18n("This key has more than one user ID.\nEdit the key manually to delete signature.")); return; @@ -1009,12 +1152,14 @@ void KgpgInterface::KgpgDelSignature(TQString keyID,TQString signKeyID) *conprocess<<"--edit-key"<start(TDEProcess::NotifyOnExit,true); } void KgpgInterface::delsigprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) @@ -1044,6 +1189,8 @@ void KgpgInterface::delsigprocess(KProcIO *p) void KgpgInterface::delsignover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; + TQApplication::restoreOverrideCursor(); emit delsigfinished(deleteSuccess); } @@ -1051,10 +1198,14 @@ void KgpgInterface::delsignover(TDEProcess *) int KgpgInterface::checkuid(TQString KeyID) { +// kdDebug(2100) << k_funcinfo << "KeyID: " << KeyID<< endl; FILE *fp; TQString encResult; char buffer[200]; int uidcnt=0; + if (KgpgInterface::getGpgVersion() > 210 ) { + uidcnt=-1; // there is always one uid in the new version + } TQString gpgcmd="gpg --no-tty --no-secmem-warning --with-colon --list-sigs "+KeyID; ////////// encode with untrusted keys or armor if checked by user @@ -1064,6 +1215,7 @@ int KgpgInterface::checkuid(TQString KeyID) if (encResult.startsWith("uid")) uidcnt++; } +// kdDebug(2100) << k_funcinfo << "uid count: " << uidcnt<< endl; pclose(fp); return uidcnt; } @@ -1074,12 +1226,17 @@ int KgpgInterface::checkuid(TQString KeyID) void KgpgInterface::KgpgKeyExpire(TQString keyID,TQDate date,bool unlimited) { +// kdDebug(2100) << k_funcinfo << endl; + +// kdDebug(2100) << "KgpgKeyExpire date: " << date; + expSuccess=0; step=0; if (unlimited) expirationDelay=0; else expirationDelay=TQDate::currentDate().daysTo(date); +// kdDebug(2100) << "KgpgKeyExpire date: " << TQDate::currentDate().daysTo(date) <readln(required,true)!=-1) { @@ -1152,6 +1310,7 @@ void KgpgInterface::expprocess(KProcIO *p) void KgpgInterface::expover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if ((expSuccess==3) || (expSuccess==2)) emit expirationFinished(expSuccess); //// signature successful or bad passphrase else { @@ -1171,6 +1330,7 @@ void KgpgInterface::expover(TDEProcess *) void KgpgInterface::KgpgTrustExpire(TQString keyID,int keyTrust) { +// kdDebug(2100) << k_funcinfo << endl; trustValue=keyTrust+1; /* Don't know=1; Do NOT trust=2; Marginally=3; Fully=4; Ultimately=5; */ @@ -1186,6 +1346,7 @@ void KgpgInterface::KgpgTrustExpire(TQString keyID,int keyTrust) void KgpgInterface::trustprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { output+=required+"\n"; @@ -1219,6 +1380,7 @@ void KgpgInterface::trustprocess(KProcIO *p) void KgpgInterface::trustover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; emit trustfinished(); } @@ -1228,6 +1390,7 @@ void KgpgInterface::trustover(TDEProcess *) void KgpgInterface::KgpgChangePass(TQString keyID) { +// kdDebug(2100) << k_funcinfo << endl; step=1; output=TQString(); message=TQString(); @@ -1242,6 +1405,7 @@ void KgpgInterface::KgpgChangePass(TQString keyID) void KgpgInterface::passprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { @@ -1320,6 +1484,7 @@ void KgpgInterface::passprocess(KProcIO *p) void KgpgInterface::passover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; //emit trustfinished(); } @@ -1329,6 +1494,7 @@ void KgpgInterface::passover(TDEProcess *) TQString KgpgInterface::getKey(TQStringList IDs, bool attributes) { +// kdDebug(2100) << k_funcinfo << endl; keyString=TQString(); KProcIO *proc=new KProcIO(TQTextCodec::codecForLocale()); *proc<< "gpg"<<"--no-tty"<<"--no-secmem-warning"<<"--utf8-strings"; @@ -1346,6 +1512,7 @@ TQString KgpgInterface::getKey(TQStringList IDs, bool attributes) void KgpgInterface::slotReadKey(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString outp; while (p->readln(outp)!=-1) if (!outp.startsWith("gpg:")) keyString+=outp+"\n"; @@ -1358,6 +1525,7 @@ void KgpgInterface::importKeyURL(KURL url) { ///////////// import a key +// kdDebug(2100) << k_funcinfo << endl; if( TDEIO::NetAccess::download( url, tempKeyFile,0) ) { message=TQString(); KProcIO *conprocess=new KProcIO(TQTextCodec::codecForLocale()); @@ -1386,6 +1554,7 @@ void KgpgInterface::importKey(TQString keystr) void KgpgInterface::importover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; TQStringList importedKeysIds; TQStringList messageList; TQString resultMessage; @@ -1450,6 +1619,7 @@ kdDebug(2100)<<"Importing is over"<readln(outp)!=-1) { if (outp.find("http-proxy")==-1) @@ -1471,6 +1642,7 @@ void KgpgInterface::importprocess(KProcIO *p) void KgpgInterface::KgpgAddUid(TQString keyID,TQString name,TQString email,TQString comment) { +// kdDebug(2100) << k_funcinfo << endl; uidName=name; uidComment=comment; uidEmail=email; @@ -1487,12 +1659,14 @@ addSuccess=true; void KgpgInterface::adduidover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (addSuccess) emit addUidFinished(); else emit addUidError(output); } void KgpgInterface::adduidprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { output+=required+"\n"; @@ -1556,6 +1730,7 @@ void KgpgInterface::adduidprocess(KProcIO *p) void KgpgInterface::KgpgGetPhotoList(TQString keyID) { +// kdDebug(2100) << k_funcinfo << endl; photoList.clear(); output=TQString(); photoCount=1; @@ -1571,6 +1746,7 @@ userIDs=keyID; void KgpgInterface::photoreadprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { output+=required+"\n"; @@ -1581,6 +1757,7 @@ void KgpgInterface::photoreadprocess(KProcIO *p) void KgpgInterface::photoreadover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; for (int i=1;isetAutoDelete(true); TQString pgpgOutput="cp %i "+kgpginfotmp->name(); @@ -1608,6 +1786,7 @@ KProcIO *conprocess=new KProcIO(TQTextCodec::codecForLocale()); void KgpgInterface::KgpgDeletePhoto(TQString keyID,TQString uid) { +// kdDebug(2100) << k_funcinfo << endl; delSuccess=true; output=TQString(); KProcIO *conprocess=new KProcIO(TQTextCodec::codecForLocale()); @@ -1620,12 +1799,14 @@ void KgpgInterface::KgpgDeletePhoto(TQString keyID,TQString uid) void KgpgInterface::delphotoover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (delSuccess) emit delPhotoFinished(); else emit delPhotoError(output); } void KgpgInterface::delphotoprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { output+=required+"\n"; @@ -1670,6 +1851,7 @@ void KgpgInterface::delphotoprocess(KProcIO *p) void KgpgInterface::KgpgAddPhoto(TQString keyID,TQString imagePath) { +// kdDebug(2100) << k_funcinfo << endl; photoUrl=imagePath; output=TQString(); addSuccess=true; @@ -1683,12 +1865,14 @@ addSuccess=true; void KgpgInterface::addphotoover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (addSuccess) emit addPhotoFinished(); else emit addPhotoError(output); } void KgpgInterface::addphotoprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { output+=required+"\n"; @@ -1747,6 +1931,7 @@ void KgpgInterface::addphotoprocess(KProcIO *p) void KgpgInterface::KgpgRevokeKey(TQString keyID,TQString revokeUrl,int reason,TQString description) { +// kdDebug(2100) << k_funcinfo << endl; revokeReason=reason; revokeSuccess=false; revokeDescription=description; @@ -1764,6 +1949,7 @@ void KgpgInterface::KgpgRevokeKey(TQString keyID,TQString revokeUrl,int reason,T void KgpgInterface::revokeover(TDEProcess *) { +// kdDebug(2100) << k_funcinfo << endl; if (!revokeSuccess) KMessageBox::detailedSorry(0,i18n("Creation of the revocation certificate failed..."),output); else { @@ -1778,27 +1964,33 @@ void KgpgInterface::revokeover(TDEProcess *) void KgpgInterface::revokeprocess(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; TQString required=TQString(); while (p->readln(required,true)!=-1) { output+=required+"\n"; + // kdDebug(2100) << k_funcinfo << " line " << required << endl; if (required.find("USERID_HINT",0,false)!=-1) updateIDs(required); if ((required.find("GOOD_PASSPHRASE")!=-1)) + // kdDebug(2100) << k_funcinfo << " GOOD_PASSPHRASE " << endl; revokeSuccess=true; if ((required.find("gen_revoke.okay")!=-1) || (required.find("ask_revocation_reason.okay")!=-1) || (required.find("openfile.overwrite.okay")!=-1)) { + // kdDebug(2100) << k_funcinfo << " gen_revoke.okay " << endl; p->writeStdin(TQString("YES")); required=TQString(); } if (required.find("ask_revocation_reason.code")!=-1) { + // kdDebug(2100) << k_funcinfo << " ask_revocation_reason.code " << endl; p->writeStdin(TQString::number(revokeReason)); required=TQString(); } if (required.find("passphrase.enter")!=-1) { + // kdDebug(2100) << k_funcinfo << " passphrase.enter " << endl; TQCString signpass; int code=KPasswordDialog::getPassword(signpass,i18n("Enter passphrase for %1:").arg(userIDs)); if (code!=TQDialog::Accepted) { @@ -1812,6 +2004,7 @@ void KgpgInterface::revokeprocess(KProcIO *p) } if (required.find("ask_revocation_reason.text")!=-1) { + // kdDebug(2100) << k_funcinfo << " ask_revocation_reason.text " << endl; // kdDebug(2100)<<"description"<writeStdin(revokeDescription); revokeDescription=TQString(); @@ -1833,6 +2026,7 @@ void KgpgInterface::revokeprocess(KProcIO *p) TQString KgpgInterface::getGpgSetting(TQString name,TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; name=name.stripWhiteSpace()+" "; TQFile qfile(TQFile::encodeName(configFile)); if (qfile.open(IO_ReadOnly) && (qfile.exists())) { @@ -1855,6 +2049,7 @@ TQString KgpgInterface::getGpgSetting(TQString name,TQString configFile) TQString KgpgInterface::getGpgMultiSetting(TQString name,TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; // get GnuPG setting for item that can have multiple entries (eg. encrypt-to) TQString parsedResult=TQString(); @@ -1884,6 +2079,7 @@ TQString parsedResult=TQString(); void KgpgInterface::delGpgGroup(TQString name, TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; TQString textToWrite; TQFile qfile(TQFile::encodeName(configFile)); if (qfile.open(IO_ReadOnly) && (qfile.exists())) { @@ -1912,6 +2108,7 @@ void KgpgInterface::delGpgGroup(TQString name, TQString configFile) void KgpgInterface::setGpgGroupSetting(TQString name,TQStringList values, TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; TQString textToWrite; bool found=false; TQFile qfile(TQFile::encodeName(configFile)); @@ -1951,6 +2148,7 @@ void KgpgInterface::setGpgGroupSetting(TQString name,TQStringList values, TQStri TQStringList KgpgInterface::getGpgGroupSetting(TQString name,TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; TQFile qfile(TQFile::encodeName(configFile)); if (qfile.open(IO_ReadOnly) && (qfile.exists())) { @@ -1978,6 +2176,7 @@ TQStringList KgpgInterface::getGpgGroupSetting(TQString name,TQString configFile TQStringList KgpgInterface::getGpgGroupNames(TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; TQStringList groups; TQFile qfile(TQFile::encodeName(configFile)); if (qfile.open(IO_ReadOnly) && (qfile.exists())) { @@ -2000,6 +2199,7 @@ TQStringList KgpgInterface::getGpgGroupNames(TQString configFile) bool KgpgInterface::getGpgBoolSetting(TQString name,TQString configFile) { +// kdDebug(2100) << k_funcinfo << endl; name=name; TQFile qfile(TQFile::encodeName(configFile)); if (qfile.open(IO_ReadOnly) && (qfile.exists())) { @@ -2019,6 +2219,7 @@ bool KgpgInterface::getGpgBoolSetting(TQString name,TQString configFile) void KgpgInterface::setGpgSetting(TQString name,TQString value,TQString url) { +// kdDebug(2100) << k_funcinfo << endl; name=name+" "; TQString textToWrite; bool found=false; @@ -2045,7 +2246,7 @@ void KgpgInterface::setGpgSetting(TQString name,TQString value,TQString url) if (qfile.open(IO_WriteOnly)) { TQTextStream t( &qfile); - t << textToWrite; + t << textToWrite; // FIXME: this shouldn't write at the end of the gpg.conf file qfile.close(); } } @@ -2054,6 +2255,7 @@ void KgpgInterface::setGpgSetting(TQString name,TQString value,TQString url) void KgpgInterface::setGpgMultiSetting(TQString name,TQStringList values,TQString url) { +// kdDebug(2100) << k_funcinfo << endl; name=name+" "; TQString textToWrite; bool found=false; @@ -2086,6 +2288,7 @@ void KgpgInterface::setGpgMultiSetting(TQString name,TQStringList values,TQStrin void KgpgInterface::setGpgBoolSetting(TQString name,bool enable,TQString url) { +// kdDebug(2100) << k_funcinfo << endl; TQString textToWrite; bool found=false; TQFile qfile(TQFile::encodeName(url)); @@ -2119,6 +2322,7 @@ void KgpgInterface::setGpgBoolSetting(TQString name,bool enable,TQString url) TQString KgpgInterface::checkForUtf8bis(TQString txt) { +// kdDebug(2100) << k_funcinfo << endl; if (strchr (txt.ascii(), 0xc3) || (txt.find("\\x")!=-1)) txt=checkForUtf8(txt); else { @@ -2131,6 +2335,7 @@ TQString KgpgInterface::checkForUtf8bis(TQString txt) TQString KgpgInterface::checkForUtf8(TQString txt) { +// kdDebug(2100) << k_funcinfo << endl; // code borrowed from gpa const char *s; 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" diff --git a/kgpg/kgpgoptions.h b/kgpg/kgpgoptions.h index 5b981de..272384e 100644 --- a/kgpg/kgpgoptions.h +++ b/kgpg/kgpgoptions.h @@ -60,7 +60,7 @@ private: TQPixmap pixkeySingle,pixkeyDouble; TQString fileEncryptionKey; TQString gpgConfigPath; - TQString keyServer,defaultServerList; + TQString defaultServerList; TQString defaultKeyServer; TQFont startFont; bool useAgent; 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 #include #include +#include #include #include @@ -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 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::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("

Do you want to import file %1 into your key ring?

").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() <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"<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 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"<desktopEntryName()+" %i"))<<"--edit-key"<currentItem()->parent()->text(6)<<"uid"<currentItem()->text(6)<<"showphoto"<<"quit"; + *p<<"gpg"<<"--no-tty" + <<"--photo-viewer"<desktopEntryName()+" %i")) + <<"--edit-key"<currentItem()->parent()->text(6) + <<"uid"<currentItem()->text(6) + <<"showphoto"<<"quit"; p->start(TDEProcess::DontCare,true); } void listKeys::listsigns() { +// kdDebug(2100) << k_funcinfo << endl; //kdDebug(2100)<<"Edit -------------------------------"<currentItem()==NULL) return; @@ -1646,6 +1706,7 @@ void listKeys::listsigns() void listKeys::groupAdd() { +// kdDebug(2100) << k_funcinfo << endl; TQPtrList 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 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"<availableKeys->firstChild(); foundId=false; while (item) { - kdDebug(2100)<<"Searching in key: "<text(0)<text(0)<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" - <text(6); + kp<<"-e" <<"gpg" <<"--no-secmem-warning" + <<"-u" <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 (keyCountrefreshcurrentkey(signList.at(keyCount)); - - else if (success==2) - KMessageBox::sorry(this,i18n("Bad passphrase, key %1 not signed.").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("Bad passphrase, key %1 not signed.").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" - <currentItem()->text(6) + kp<<"-e" <<"gpg" <<"--no-secmem-warning" <<"--utf8-strings" + <<"--edit-key" <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"<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)<setGroup("General"); *conprocess<< config->readPathEntry("TerminalApplication","konsole"); - *conprocess<<"-e"<<"gpg" - <<"--no-secmem-warning" + *conprocess<<"-e"<<"gpg" <<"--no-secmem-warning" <<"--delete-secret-key"<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 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)<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"<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 hashMap; +// kdDebug(2100)<<"Expanding Key: "<text(6)<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::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: "<text(6)<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] <setAutoDelete(true); TQString pgpgOutput="cp %i "+kgpgphototmp->name(); KProcIO *p=new KProcIO(TQTextCodec::codecForLocale()); - *p<<"gpg"<<"--no-tty"<<"--photo-viewer"<text(6)<<"uid"<text(6) + <<"uid"<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 "<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"< 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<::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"<setPixmap(0,pixkeyGroup); item->setExpandable(false); } - kdDebug(2100)<<"Finished Groups"< 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::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 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::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"<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:--------"<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 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 <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::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<= 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]; diff --git a/kgpg/main.cpp b/kgpg/main.cpp index 44f4b7e..73b99bf 100644 --- a/kgpg/main.cpp +++ b/kgpg/main.cpp @@ -4,6 +4,8 @@ begin : Mon Jul 8 2002 copyright : (C) 2002 by Jean-Baptiste Mardelle email : bj@altern.org + + updated main version : Sun Jul 30 10:18:29 CEST 2017 ***************************************************************************/ /*************************************************************************** @@ -29,7 +31,7 @@ static const char description[] = I18N_NOOP("Kgpg - simple gui for gpg\n\nKgpg was designed to make gpg very easy to use.\nI tried to make it as secure as possible.\nHope you enjoy it."); -static const char version[] = "1.2.2"; +static const char version[] = "1.3.0"; static TDECmdLineOptions options[] = { diff --git a/kgpg/popuppublic.cpp b/kgpg/popuppublic.cpp index 7ae2eb3..07eb33e 100644 --- a/kgpg/popuppublic.cpp +++ b/kgpg/popuppublic.cpp @@ -4,6 +4,10 @@ begin : Sat Jun 29 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 ***************************************************************************/ /*************************************************************************** @@ -322,6 +326,8 @@ void popupPublic::refresh(bool state) void popupPublic::refreshkeys() { keysList->clear(); + currentKey = TQString(); + hashMap.clear(); TQStringList groups= TQStringList::split(",", KGpgSettings::groups()); if (!groups.isEmpty()) { @@ -366,80 +372,115 @@ void popupPublic::slotSetVisible() void popupPublic::slotprocread(KProcIO *p) { +// kdDebug(2100) << k_funcinfo << endl; ///////////////////////////////////////////////////////////////// extract encryption keys - bool dead; - TQString tst,keyname,keymail; + TQString tst; TQString defaultKey = KGpgSettings::defaultKey().right(8); - while (p->readln(tst)!=-1) { - if (tst.startsWith("pub")) { - TQStringList keyString=TQStringList::split(":",tst,true); - dead=false; - const TQString trust=keyString[1]; - TQString val=keyString[6]; - TQString id=TQString("0x"+keyString[4].right(8)); - if (val.isEmpty()) - val=i18n("Unlimited"); - TQString tr; - switch( trust[0] ) { - case 'o': - untrustedList<setSelectable(false); - if (seclist.find(tst,0,FALSE)!=-1) - item->setPixmap(0,keyPair); - else - item->setPixmap(0,keySingle); - } - } - } + while (p->readln(tst)!=-1) { +// 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,tst); + } + else { + hashMap.find(currentKey).data().append(tst); + } + } + + TQMap::Iterator ite; + for (ite = hashMap.begin(); ite != hashMap.end(); ite++) { + TQStringList::Iterator it; + TQString fullname,keyname,keymail,val,id; + bool dead; + + for (it = ite.data().begin(); it != ite.data().end(); it++) { + TQString line = (*it); + + if (line.startsWith("pub")) { + TQStringList keyString=TQStringList::split(":",line,true); + dead=false; + const TQString trust=keyString[1]; + val=keyString[6]; + id=TQString("0x"+keyString[4].right(8)); + if (val.isEmpty()) { + val=i18n("Unlimited"); + } + TQString tr; + switch( trust[0] ) { + case 'o': + untrustedList<setSelectable(false); + if (seclist.find(fullname,0,FALSE)!=-1) { + item->setPixmap(0,keyPair); + } + else { + item->setPixmap(0,keySingle); + } + } + } } @@ -459,8 +500,9 @@ kdDebug(2100)<<"Ok pressed"<isChecked()) return; if (CBsymmetric->isChecked()) selectedKeys=NULL; -kdDebug(2100)<<"Selected Key:"<isChecked()) returnOptions<<"--always-trust"; if (CBarmor->isChecked()) diff --git a/kgpg/popuppublic.h b/kgpg/popuppublic.h index 8f9e418..7f860f6 100644 --- a/kgpg/popuppublic.h +++ b/kgpg/popuppublic.h @@ -41,8 +41,9 @@ public: TQCheckBox *CBarmor,*CBuntrusted,*CBshred,*CBsymmetric,*CBhideid; bool fmode,trusted; TQPixmap keyPair,keySingle,keyGroup; - TQString seclist; + TQString seclist, currentKey; TQStringList untrustedList; + TQMap hashMap; private: TDEConfig *config;