You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
241 lines
8.0 KiB
241 lines
8.0 KiB
15 years ago
|
/***************************************************************************
|
||
|
knewstuffsecure.cpp - description
|
||
|
-------------------
|
||
|
begin : Tue Jun 22 12:19:55 2004
|
||
|
copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
|
||
|
***************************************************************************/
|
||
|
|
||
|
/***************************************************************************
|
||
|
* *
|
||
|
* This program is free software; you can redistribute it and/or modify *
|
||
|
* it under the terms of the GNU Library General Public License as *
|
||
|
* published by the Free Software Foundation; version 2 of the License. *
|
||
|
* *
|
||
|
***************************************************************************/
|
||
|
//qt includes
|
||
15 years ago
|
#include <tqfileinfo.h>
|
||
15 years ago
|
|
||
|
//kde includes
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
12 years ago
|
#include <tdeio/netaccess.h>
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
#include <ktar.h>
|
||
|
#include <ktempdir.h>
|
||
|
|
||
|
//app includes
|
||
|
#include "engine.h"
|
||
|
#include "knewstuffsecure.h"
|
||
|
#include "security.h"
|
||
|
|
||
|
using namespace KNS;
|
||
|
|
||
10 years ago
|
TDENewStuffSecure::TDENewStuffSecure(const TQString &type, TQWidget *parentWidget)
|
||
|
: TDENewStuff(type, parentWidget)
|
||
15 years ago
|
{
|
||
|
m_tempDir = 0L;
|
||
15 years ago
|
connect(engine(), TQT_SIGNAL(uploadFinished(bool)), TQT_SLOT(slotUploadFinished(bool)));
|
||
15 years ago
|
}
|
||
|
|
||
|
|
||
10 years ago
|
TDENewStuffSecure::~TDENewStuffSecure()
|
||
15 years ago
|
{
|
||
|
removeTempDirectory();
|
||
|
}
|
||
|
|
||
10 years ago
|
bool TDENewStuffSecure::install(const TQString &fileName)
|
||
15 years ago
|
{
|
||
|
bool ok = true;
|
||
|
|
||
|
removeTempDirectory();
|
||
|
m_tempDir = new KTempDir();
|
||
|
m_tempDir->setAutoDelete(true);
|
||
|
KTar tar(fileName, "application/x-gzip");
|
||
|
if (tar.open(IO_ReadOnly))
|
||
|
{
|
||
|
const KArchiveDirectory *directory = tar.directory();
|
||
|
directory->copyTo(m_tempDir->name(), true);
|
||
|
m_tarName = "";
|
||
15 years ago
|
TQStringList entries = directory->entries();
|
||
|
for (TQStringList::Iterator it = entries.begin(); it != entries.end(); ++it)
|
||
15 years ago
|
{
|
||
|
if (*it != "signature" && *it != "md5sum")
|
||
|
{
|
||
|
m_tarName = *it;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
tar.close();
|
||
|
if (m_tarName.isEmpty())
|
||
|
ok = false;
|
||
|
else
|
||
|
{
|
||
|
m_tarName.prepend(m_tempDir->name());
|
||
15 years ago
|
connect(Security::ref(), TQT_SIGNAL(validityResult(int)), this, TQT_SLOT(slotValidated(int)));
|
||
15 years ago
|
Security::ref()->checkValidity(m_tarName);
|
||
|
}
|
||
|
} else
|
||
|
ok = false;
|
||
|
if (!ok)
|
||
14 years ago
|
KMessageBox::error(parentWidget(), i18n("There was an error with the downloaded resource tarball file. Possible causes are damaged archive or invalid directory structure in the archive."), i18n("Resource Installation Error"));
|
||
15 years ago
|
return ok;
|
||
|
}
|
||
|
|
||
10 years ago
|
void TDENewStuffSecure::slotValidated(int result)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString errorString;
|
||
|
TQString signatureStr;
|
||
15 years ago
|
bool valid = true;
|
||
|
if (result == -1)
|
||
|
{
|
||
|
errorString ="<br>- " + i18n("No keys were found.");
|
||
|
valid = false;
|
||
|
} else
|
||
|
if (result == 0)
|
||
|
{
|
||
|
errorString ="<br>- " + i18n("The validation failed for unknown reason.");
|
||
|
valid = false;
|
||
|
} else
|
||
|
{
|
||
|
KeyStruct key = Security::ref()->signatureKey();
|
||
|
if (!(result & Security::MD5_OK ))
|
||
|
{
|
||
|
errorString = "<br>- " + i18n("The MD5SUM check failed, the archive might be broken.");
|
||
|
valid = false;
|
||
|
}
|
||
|
if (result & Security::SIGNED_BAD)
|
||
|
{
|
||
|
errorString += "<br>- " + i18n("The signature is bad, the archive might be broken or altered.");
|
||
|
valid = false;
|
||
|
}
|
||
|
if (result & Security::SIGNED_OK)
|
||
|
{
|
||
|
if (result & Security::TRUSTED)
|
||
|
{
|
||
|
kdDebug() << "Signed and trusted " << endl;
|
||
|
} else
|
||
|
{
|
||
|
errorString += "<br>- " + i18n("The signature is valid, but untrusted.");
|
||
|
valid = false;
|
||
|
}
|
||
|
}
|
||
|
if (result & Security::UNKNOWN)
|
||
|
{
|
||
|
errorString += "<br>- " + i18n("The signature is unknown.");
|
||
|
valid = false;
|
||
|
} else
|
||
|
{
|
||
|
signatureStr = i18n("The resource was signed with key <i>0x%1</i>, belonging to <i>%2 <%3></i>.").arg(key.id.right(8)).arg(key.name).arg(key.mail);
|
||
|
}
|
||
|
}
|
||
|
if (!valid)
|
||
|
{
|
||
|
signatureStr.prepend( "<br>");
|
||
14 years ago
|
if (KMessageBox::warningContinueCancel(parentWidget(), i18n("<qt>There is a problem with the resource file you have downloaded. The errors are :<b>%1</b><br>%2<br><br>Installation of the resource is <b>not recommended</b>.<br><br>Do you want to proceed with the installation?</qt>").arg(errorString).arg(signatureStr), i18n("Problematic Resource File")) == KMessageBox::Continue)
|
||
15 years ago
|
valid = true;
|
||
|
} else
|
||
14 years ago
|
KMessageBox::information(parentWidget(), i18n("<qt>%1<br><br>Press OK to install it.</qt>").arg(signatureStr), i18n("Valid Resource"), "Show Valid Signature Information");
|
||
15 years ago
|
if (valid)
|
||
|
{
|
||
|
installResource();
|
||
|
emit installFinished();
|
||
|
} else
|
||
|
{
|
||
12 years ago
|
TDEConfig *cfg = TDEGlobal::config();
|
||
10 years ago
|
cfg->deleteGroup("TDENewStuffStatus");
|
||
|
cfg->setGroup("TDENewStuffStatus");
|
||
15 years ago
|
for (TQMap<TQString, TQString>::ConstIterator it = m_installedResources.constBegin(); it != m_installedResources.constEnd(); ++it)
|
||
15 years ago
|
{
|
||
|
cfg->writeEntry(it.key(), it.data());
|
||
|
}
|
||
|
cfg->sync();
|
||
|
}
|
||
|
removeTempDirectory();
|
||
15 years ago
|
disconnect(Security::ref(), TQT_SIGNAL(validityResult(int)), this, TQT_SLOT(slotValidated(int)));
|
||
15 years ago
|
}
|
||
|
|
||
10 years ago
|
void TDENewStuffSecure::downloadResource()
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEConfig *cfg = TDEGlobal::config();
|
||
10 years ago
|
m_installedResources = cfg->entryMap("TDENewStuffStatus");
|
||
15 years ago
|
engine()->ignoreInstallResult(true);
|
||
10 years ago
|
TDENewStuff::download();
|
||
15 years ago
|
}
|
||
|
|
||
10 years ago
|
bool TDENewStuffSecure::createUploadFile(const TQString &fileName)
|
||
15 years ago
|
{
|
||
|
Q_UNUSED(fileName);
|
||
|
return true;
|
||
|
}
|
||
|
|
||
10 years ago
|
void TDENewStuffSecure::uploadResource(const TQString& fileName)
|
||
15 years ago
|
{
|
||
15 years ago
|
connect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
|
||
15 years ago
|
removeTempDirectory();
|
||
|
m_tempDir = new KTempDir();
|
||
|
m_tempDir->setAutoDelete(true);
|
||
15 years ago
|
TQFileInfo f(fileName);
|
||
15 years ago
|
m_signedFileName = m_tempDir->name() + "/" + f.fileName();
|
||
12 years ago
|
TDEIO::NetAccess::file_copy(KURL::fromPathOrURL(fileName), KURL::fromPathOrURL(m_signedFileName), -1, true);
|
||
15 years ago
|
Security::ref()->signFile(m_signedFileName);
|
||
|
}
|
||
|
|
||
10 years ago
|
void TDENewStuffSecure::slotFileSigned(int result)
|
||
15 years ago
|
{
|
||
|
if (result == 0)
|
||
|
{
|
||
14 years ago
|
KMessageBox::error(parentWidget(), i18n("The signing failed for unknown reason."));
|
||
15 years ago
|
} else
|
||
|
{
|
||
|
if (result & Security::BAD_PASSPHRASE)
|
||
|
{
|
||
14 years ago
|
if (KMessageBox::warningContinueCancel(parentWidget(), i18n("There are no keys usable for signing or you did not entered the correct passphrase.\nProceed without signing the resource?")) == KMessageBox::Cancel)
|
||
15 years ago
|
{
|
||
15 years ago
|
disconnect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
|
||
15 years ago
|
removeTempDirectory();
|
||
|
return;
|
||
|
}
|
||
|
}
|
||
|
KTar tar(m_signedFileName + ".signed", "application/x-gzip");
|
||
|
tar.open(IO_WriteOnly);
|
||
15 years ago
|
TQStringList files;
|
||
15 years ago
|
files << m_signedFileName;
|
||
|
files << m_tempDir->name() + "/md5sum";
|
||
|
files << m_tempDir->name() + "/signature";
|
||
|
|
||
15 years ago
|
for (TQStringList::Iterator it_f = files.begin(); it_f != files.end(); ++it_f)
|
||
15 years ago
|
{
|
||
15 years ago
|
TQFile file(*it_f);
|
||
15 years ago
|
file.open(IO_ReadOnly);
|
||
15 years ago
|
TQByteArray bArray = file.readAll();
|
||
|
tar.writeFile(TQFileInfo(file).fileName(), "user", "group", bArray.size(), bArray.data());
|
||
15 years ago
|
file.close();
|
||
|
}
|
||
|
tar.close();
|
||
12 years ago
|
TDEIO::NetAccess::file_move(KURL::fromPathOrURL(m_signedFileName + ".signed"), KURL::fromPathOrURL(m_signedFileName), -1, true);
|
||
10 years ago
|
TDENewStuff::upload(m_signedFileName, TQString::null);
|
||
15 years ago
|
disconnect(Security::ref(), TQT_SIGNAL(fileSigned(int)), this, TQT_SLOT(slotFileSigned(int)));
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
10 years ago
|
void TDENewStuffSecure::slotUploadFinished(bool result)
|
||
15 years ago
|
{
|
||
|
Q_UNUSED(result);
|
||
|
removeTempDirectory();
|
||
|
}
|
||
|
|
||
10 years ago
|
void TDENewStuffSecure::removeTempDirectory()
|
||
15 years ago
|
{
|
||
|
if (m_tempDir)
|
||
|
{
|
||
12 years ago
|
TDEIO::NetAccess::del(KURL().fromPathOrURL(m_tempDir->name()), parentWidget());
|
||
15 years ago
|
delete m_tempDir;
|
||
|
m_tempDir = 0L;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#include "knewstuffsecure.moc"
|