diff options
Diffstat (limited to 'kgpg/keyservers.cpp')
-rw-r--r-- | kgpg/keyservers.cpp | 601 |
1 files changed, 448 insertions, 153 deletions
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 : [email protected] + + updated to handle gpg21 : Sun Jul 30 10:18:29 CEST 2017 + copyright : (C) 2017 by Emanoil Kotsev + email : [email protected] ***************************************************************************/ /*************************************************************************** @@ -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<TQString,TQString> hashImportList; + + TQMap<TQString,TQStringList>::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: " <<line<< endl; + if (line.startsWith("pub")) { + const TQString trust=line.section(':',1,1); switch( trust[0] ) { case 'i': dead=true; @@ -142,20 +173,44 @@ void keyServer::slotprocread(KProcIO *p) dead=false; break; } - tst=tst.section(':',9,9); - if (tst.length()>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<TQString,TQString>::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"<<keyserv<<"--command-fd=0"<<"--status-fd=2"<<"--search-keys"<<page->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"<<keyserv<<"--command-fd=0"<<"--with-colon"; + *searchproc<<"--status-fd=2"<<"--search-keys"<<page->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<TQString,TQStringList>::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<<ite.key(); + } + } + + for (TQMap<TQString,TQStringList>::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: " <<page->kLEimportid->text() <<endl; + + readmessage=TQString(); + count=0; + hashMap.clear(); + invalidKeys.clear(); + keysToImport.clear(); + TQString keyserv=page->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"<<keyserv<<"--recv-keys"; TQString keyNames=page->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<<TQString(TQFile::encodeName(fkeyNames)); - } - TQObject::connect(importproc, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(slotimportresult(TDEProcess *))); - TQObject::connect(importproc, TQT_SIGNAL(readReady(KProcIO *)),this, TQT_SLOT(slotimportread(KProcIO *))); + if ( keyNames.startsWith("0x") ) { + searchproc=new KProcIO(TQTextCodec::codecForLocale()); + *searchproc << "gpg"<<"--utf8-strings"<<"--no-secmem-warning"; + 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" << 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"<<keyserv<<"--recv-keys"; + + for (TQStringList::Iterator it = keysToImport.begin(); it != keysToImport.end(); it++ ) { + *importproc<< (*it) ; + } + + TQObject::connect(importproc, TQT_SIGNAL(processExited(TDEProcess *)),TQT_TQOBJECT(this), TQT_SLOT(slotimportresult(TDEProcess *))); + TQObject::connect(importproc, TQT_SIGNAL(readReady(KProcIO *)),TQT_TQOBJECT(this), TQT_SLOT(slotimportread(KProcIO *))); + importproc->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<TQString,TQStringList>::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<<ite.key(); + readmessage += "<qt>"+i18n("Public Key")+": <i>0x"; + if (rev) { + readmessage += ite.key() + " (" + i18n("Revoked"); + } + if (exp) { + readmessage += ", "+i18n("Expired"); + } + readmessage += ")</i><br></qt>\n"; + } + } + + for (TQMap<TQString,TQStringList>::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("<qt>One secret key not imported.<br></qt>","<qt>%n secret keys not imported.<br></qt>",notImportesNbSec.toULong()); if (importedNbSucess!="0") resultMessage+=i18n("<qt><b>One key imported:</b><br></qt>","<qt><b>%n keys imported:</b><br></qt>",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"<<lastID<<endl; - emit importFinished(lastID); + TQString lastID=TQString( importedKeys.last().section(" ",0,0).right(8)); + if ( !lastID.isEmpty() ) { + //kdDebug(2100)<<"++++++++++imported key"<<lastID<<endl; + emit importFinished(lastID); } if (importpop) @@ -546,6 +840,7 @@ void keyServer::slotimportread(KProcIO *p) void keyServer::syncCombobox() { +// kdDebug(2100) << k_funcinfo << endl; config->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 |