Add support for GnuPG 2.1

This resolves Bug 2791
Sort keys by name on export
Fix the twice display of the default key server
Signed-off-by: Emanoil Kotsev <deloptes@gmail.com>

Additional formatting adjustments
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>

(cherry picked from commit 9125ead960)
pull/30/head
Emanoil Kotsev 7 years ago committed by Slávek Banko
parent e2a62bdbfb
commit e2bee02e99

@ -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"
<<displayedKeyID;
if (isOn) kp<<"disable";
else kp<<"enable";
// kdDebug(2100) << k_funcinfo << endl;
TDEProcess kp;
kp<<"gpg" <<"--no-tty" <<"--edit-key" <<displayedKeyID;
if (isOn) kp<<"disable";
else kp<<"enable";
kp<<"save";
kp.start(TDEProcess::Block);
loadKey(displayedKeyID);
keyWasChanged=true;
kp.start(TDEProcess::Block);
loadKey(displayedKeyID);
keyWasChanged=true;
}
void KgpgKeyInfo::loadKey(TQString Keyid)
{
TQColor trustColor;
TQString fingervalue=TQString();
FILE *pass;
char line[200]="";
TQString gpgOutput,fullID;
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)) {
gpgOutput=TQString::fromUtf8(line);
if (gpgOutput.startsWith("uat"))
hasPhoto=true;
if (gpgOutput.startsWith("pub")) {
// kdDebug(2100) << k_funcinfo << endl;
FILE *pass;
char line[200]="";
TQString currentKey;
TQMap<TQString,TQStringList> 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<TQString,TQStringList>::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("<qt><b>"+KgpgInterface::checkForUtf8(kname).replace(TQRegExp("<"),"&lt;")+"</b></qt>");
}
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<<endl;
chdate->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()<<endl;
if (kb->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()<<endl;
chdate->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"

@ -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<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

@ -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<TQString,TQStringList> hashMap;
KProcIO *importproc,*exportproc;
KProcIO *searchproc;
searchRes *listpop;

@ -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<TQString,TQStringList> 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<TQString,TQStringList>::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<TQString,TQStringList> 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<TQString,TQStringList>::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);
}
}

@ -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 <kled.h>
#include <kdebug.h>
#include <tdetempfile.h>
#include <tqcursor.h>
#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+++++++++++++"<<endl;
// kdDebug(2100)<<"Using Agent+++++++++++++"<<endl;
//KMessageBox::sorry(0,"using agent");
proc->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<<endl;
if (!message.isEmpty())
emit txtSignOver(message);
else
@ -478,7 +499,9 @@ void KgpgInterface::txtsignfin(TDEProcess *)
void KgpgInterface::txtsignprocess(KProcIO *p)
{
// kdDebug(2100) << k_funcinfo << endl;
TQString required;
while (p->readln(required,true)!=-1) {
// kdDebug(2100)<<"SIGNING: "<<required<<endl;
@ -492,6 +515,12 @@ void KgpgInterface::txtsignprocess(KProcIO *p)
p->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: "<<message<<endl;
}
}
@ -521,14 +551,15 @@ void KgpgInterface::txtsignprocess(KProcIO *p)
void KgpgInterface::KgpgDecryptFileToText(KURL srcUrl,TQStringList Options)
{
// kdDebug(2100) << k_funcinfo << endl;
message=TQString();
userIDs=TQString();
step=3;
anonymous=false;
decfinished=false;
decok=false;
badmdc=false;
decfinished=false;
decok=false;
badmdc=false;
TDEProcess *proc=new TDEProcess();
*proc<<"gpg"<<"--no-tty"<<"--utf8-strings"<<"--no-secmem-warning"<<"--command-fd=0"<<"--status-fd=2"<<"--no-batch"<<"-o"<<"-";
@ -551,6 +582,7 @@ badmdc=false;
void KgpgInterface::KgpgVerifyText(TQString text)
{
// kdDebug(2100) << k_funcinfo << endl;
TQTextCodec *codec =TQTextCodec::codecForLocale ();
if (!codec->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("<"),"&lt;");
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("<qt>%1 Enter passphrase for <b>%2</b>:</qt>")
.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("<b>Bad passphrase</b>. Try again.</br>");
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("<qt>%1 Enter passphrase for <b>%2</b>:</qt>")
.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("<b>Bad passphrase</b>. Try again.</br>");
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("<qt>%1 Enter passphrase for <b>%2</b>:</qt>")
.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("<b>Bad passphrase</b>. Try again.</br>");
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"<<keyID<<"uid 1"<<"delsig";
TQObject::connect(conprocess,TQT_SIGNAL(readReady(KProcIO *)),this,TQT_SLOT(delsigprocess(KProcIO *)));
TQObject::connect(conprocess, TQT_SIGNAL(processExited(TDEProcess *)),this, TQT_SLOT(delsignover(TDEProcess *)));
TQApplication::setOverrideCursor(TQCursor(TQt::BusyCursor));
conprocess->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) <<endl;
output=TQString();
KProcIO *conprocess=new KProcIO(TQTextCodec::codecForLocale());
*conprocess<<"gpg"<<"--no-secmem-warning"<<"--no-tty"<<"--command-fd=0"<<"--status-fd=2"<<"--utf8-strings";
@ -1092,6 +1249,7 @@ void KgpgInterface::KgpgKeyExpire(TQString keyID,TQDate date,bool unlimited)
void KgpgInterface::expprocess(KProcIO *p)
{
// kdDebug(2100) << k_funcinfo << endl;
TQString required=TQString();
while (p->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"<<endl;
void KgpgInterface::importURLover(TDEProcess *p)
{
// kdDebug(2100) << k_funcinfo << endl;
TDEIO::NetAccess::removeTempFile(tempKeyFile);
importover(p);
//KMessageBox::information(0,message);
@ -1458,6 +1628,7 @@ void KgpgInterface::importURLover(TDEProcess *p)
void KgpgInterface::importprocess(KProcIO *p)
{
// kdDebug(2100) << k_funcinfo << endl;
TQString outp;
while (p->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;i<photoCount+1;i++)
if (isPhotoId(i)) photoList+=TQString::number(i);
@ -1589,6 +1766,7 @@ emit signalPhotoList(photoList);
bool KgpgInterface::isPhotoId(int uid)
{
// kdDebug(2100) << k_funcinfo << endl;
KTempFile *kgpginfotmp=new KTempFile();
kgpginfotmp->setAutoDelete(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("<qt>Enter passphrase for <b>%1</b>:</qt>").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"<<endl;
p->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;

@ -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(", ")<<endl;
defaultHomePath=TQDir::homeDirPath()+"/.gnupg/";
if (TQFile(defaultHomePath+"options").exists()) defaultConfigPath="options";
@ -83,7 +91,7 @@ kgpgOptions::kgpgOptions(TQWidget *parent, const char *name)
else defaultConfigPath=TQString();
}
kdDebug(2100)<<"Adding pages"<<endl;
// kdDebug(2100)<<"Adding pages"<<endl;
page1=new Encryption();
page2=new Decryption();
page3=new UIConf();
@ -185,42 +193,46 @@ void kgpgOptions::insertAlwaysKey()
void kgpgOptions::slotChangeHome()
{
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 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"<<gpgHome<<"--no-tty"<<"--list-secret-keys";
p->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"<<gpgHome<<"--no-tty"<<"--list-secret-keys";
p->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"<<endl;
// kdDebug(2100)<<"Finishing options"<<endl;
}
void kgpgOptions::updateWidgetsDefault()
@ -288,7 +306,7 @@ void kgpgOptions::updateWidgetsDefault()
page6->ServerBox->clear();
page6->ServerBox->insertStringList(TQStringList::split(",",defaultServerList));
kdDebug(2100)<<"Finishing default options"<<endl;
// kdDebug(2100)<<"Finishing default options"<<endl;
}
bool kgpgOptions::isDefault()
@ -413,19 +431,18 @@ void kgpgOptions::updateSettings()
TQString currList;
serverList=TQStringList ();
for (uint i=0;i<page6->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;i<page6->ServerBox->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<TQString,TQStringList> 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<TQString,TQStringList>::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;i<page6->ServerBox->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;i<page6->ServerBox->count();i++) {
if (i!=curr) {
page6->ServerBox->changeItem(page6->ServerBox->text(i).section(" ",0,0),i);
}
}
page6->ServerBox->setSelected(curr,true);
}
#include "kgpgoptions.moc"

@ -60,7 +60,7 @@ private:
TQPixmap pixkeySingle,pixkeyDouble;
TQString fileEncryptionKey;
TQString gpgConfigPath;
TQString keyServer,defaultServerList;
TQString defaultServerList;
TQString defaultKeyServer;
TQFont startFont;
bool useAgent;

File diff suppressed because it is too large Load Diff

@ -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[] =
{

@ -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<<id;
break;
case 'i':
dead=true;
break;
case 'd':
dead=true;
break;
case 'r':
dead=true;
break;
case 'e':
dead=true;
break;
case 'q':
untrustedList<<id;
break;
case 'n':
untrustedList<<id;
break;
case 'm':
untrustedList<<id;
break;
case 'f':
break;
case 'u':
break;
default:
untrustedList<<id;
break;
}
if (keyString[11].find('D')!=-1) dead=true;
tst=keyString[9];
if (tst.find("<")!=-1) {
keymail=tst.section('<',-1,-1);
keymail.truncate(keymail.length()-1);
keyname=tst.section('<',0,0);
//if (keyname.find("(")!=-1)
// keyname=keyname.section('(',0,0);
} else {
keymail=TQString();
keyname=tst;//.section('(',0,0);
}
if ((!dead) && (!tst.isEmpty())) {
bool isDefaultKey=false;
if (id.right(8)==defaultKey) isDefaultKey=true;
UpdateViewItem2 *item=new UpdateViewItem2(keysList,keyname,keymail,id,isDefaultKey);
//TDEListViewItem *sub= new TDEListViewItem(item,i18n("ID: %1, trust: %2, validity: %3").arg(id).arg(tr).arg(val));
//sub->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<TQString,TQStringList>::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<<id;
break;
case 'i':
dead=true;
break;
case 'd':
dead=true;
break;
case 'r':
dead=true;
break;
case 'e':
dead=true;
break;
case 'q':
untrustedList<<id;
break;
case 'n':
untrustedList<<id;
break;
case 'm':
untrustedList<<id;
break;
case 'f':
break;
case 'u':
break;
default:
untrustedList<<id;
break;
}
if (keyString[11].find('D')!=-1) {
dead=true;
}
fullname=keyString[9];
}
if ( line.startsWith("uid") && fullname.isEmpty() ) {
fullname = line.section(':',9,9);
}
}
if (fullname.find("<")!=-1) {
keymail=fullname.section('<',-1,-1);
keymail.truncate(keymail.length()-1);
keyname=fullname.section('<',0,0);
//if (keyname.find("(")!=-1) {
// keyname=keyname.section('(',0,0);
//}
}
else {
keymail=TQString();
keyname=fullname;//.section('(',0,0);
}
if ((!dead) && (!fullname.isEmpty())) {
bool isDefaultKey=false;
if (id.right(8)==defaultKey) {
isDefaultKey=true;
}
UpdateViewItem2 *item=new UpdateViewItem2(keysList,keyname,keymail,id,isDefaultKey);
//TDEListViewItem *sub= new TDEListViewItem(item,i18n("ID: %1, trust: %2, validity: %3").arg(id).arg(tr).arg(val));
//sub->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"<<endl;
if (selectedKeys.isEmpty() && !CBsymmetric->isChecked())
return;
if (CBsymmetric->isChecked()) selectedKeys=NULL;
kdDebug(2100)<<"Selected Key:"<<selectedKeys<<endl;
// kdDebug(2100)<<"Selected Key:"<<selectedKeys<<endl;
TQStringList returnOptions;
if (CBuntrusted->isChecked())
returnOptions<<"--always-trust";
if (CBarmor->isChecked())

@ -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<TQString,TQStringList> hashMap;
private:
TDEConfig *config;

Loading…
Cancel
Save