• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdenewstuff
 

tdenewstuff

  • tdenewstuff
knewstuffsecure.cpp
1/***************************************************************************
2 knewstuffsecure.cpp - description
3 -------------------
4 begin : Tue Jun 22 12:19:55 2004
5 copyright : (C) 2004, 2005 by Andras Mantia <amantia@kde.org>
6 ***************************************************************************/
7
8/***************************************************************************
9 * *
10 * This program is free software; you can redistribute it and/or modify *
11 * it under the terms of the GNU Library General Public License as *
12 * published by the Free Software Foundation; version 2 of the License. *
13 * *
14 ***************************************************************************/
15//qt includes
16#include <tqfileinfo.h>
17
18//kde includes
19#include <tdeconfig.h>
20#include <kdebug.h>
21#include <tdeglobal.h>
22#include <tdeio/netaccess.h>
23#include <tdelocale.h>
24#include <tdemessagebox.h>
25#include <tdestandarddirs.h>
26#include <ktar.h>
27#include <ktempdir.h>
28
29//app includes
30#include "engine.h"
31#include "knewstuffsecure.h"
32#include "security.h"
33
34using namespace KNS;
35
36TDENewStuffSecure::TDENewStuffSecure(const TQString &type, TQWidget *parentWidget)
37 : TDENewStuff(type, parentWidget)
38{
39 m_tempDir = 0L;
40 connect(engine(), TQ_SIGNAL(uploadFinished(bool)), TQ_SLOT(slotUploadFinished(bool)));
41}
42
43
44TDENewStuffSecure::~TDENewStuffSecure()
45{
46 removeTempDirectory();
47}
48
49bool TDENewStuffSecure::install(const TQString &fileName)
50{
51 bool ok = true;
52
53 removeTempDirectory();
54 m_tempDir = new KTempDir();
55 m_tempDir->setAutoDelete(true);
56 KTar tar(fileName, "application/x-gzip");
57 if (tar.open(IO_ReadOnly))
58 {
59 const KArchiveDirectory *directory = tar.directory();
60 directory->copyTo(m_tempDir->name(), true);
61 m_tarName = "";
62 TQStringList entries = directory->entries();
63 for (TQStringList::Iterator it = entries.begin(); it != entries.end(); ++it)
64 {
65 if (*it != "signature" && *it != "md5sum")
66 {
67 m_tarName = *it;
68 break;
69 }
70 }
71 tar.close();
72 if (m_tarName.isEmpty())
73 ok = false;
74 else
75 {
76 m_tarName.prepend(m_tempDir->name());
77 connect(Security::ref(), TQ_SIGNAL(validityResult(int)), this, TQ_SLOT(slotValidated(int)));
78 Security::ref()->checkValidity(m_tarName);
79 }
80 } else
81 ok = false;
82 if (!ok)
83 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"));
84 return ok;
85}
86
87void TDENewStuffSecure::slotValidated(int result)
88{
89 TQString errorString;
90 TQString signatureStr;
91 bool valid = true;
92 if (result == -1)
93 {
94 errorString ="<br>- " + i18n("No keys were found.");
95 valid = false;
96 } else
97 if (result == 0)
98 {
99 errorString ="<br>- " + i18n("The validation failed for unknown reason.");
100 valid = false;
101 } else
102 {
103 KeyStruct key = Security::ref()->signatureKey();
104 if (!(result & Security::MD5_OK ))
105 {
106 errorString = "<br>- " + i18n("The MD5SUM check failed, the archive might be broken.");
107 valid = false;
108 }
109 if (result & Security::SIGNED_BAD)
110 {
111 errorString += "<br>- " + i18n("The signature is bad, the archive might be broken or altered.");
112 valid = false;
113 }
114 if (result & Security::SIGNED_OK)
115 {
116 if (result & Security::TRUSTED)
117 {
118 kdDebug() << "Signed and trusted " << endl;
119 } else
120 {
121 errorString += "<br>- " + i18n("The signature is valid, but untrusted.");
122 valid = false;
123 }
124 }
125 if (result & Security::UNKNOWN)
126 {
127 errorString += "<br>- " + i18n("The signature is unknown.");
128 valid = false;
129 } else
130 {
131 signatureStr = i18n("The resource was signed with key <i>0x%1</i>, belonging to <i>%2 &lt;%3&gt;</i>.").arg(key.id.right(8)).arg(key.name).arg(key.mail);
132 }
133 }
134 if (!valid)
135 {
136 signatureStr.prepend( "<br>");
137 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)
138 valid = true;
139 } else
140 KMessageBox::information(parentWidget(), i18n("<qt>%1<br><br>Press OK to install it.</qt>").arg(signatureStr), i18n("Valid Resource"), "Show Valid Signature Information");
141 if (valid)
142 {
143 installResource();
144 emit installFinished();
145 } else
146 {
147 TDEConfig *cfg = TDEGlobal::config();
148 cfg->deleteGroup("TDENewStuffStatus");
149 cfg->setGroup("TDENewStuffStatus");
150 for (TQMap<TQString, TQString>::ConstIterator it = m_installedResources.constBegin(); it != m_installedResources.constEnd(); ++it)
151 {
152 cfg->writeEntry(it.key(), it.data());
153 }
154 cfg->sync();
155 }
156 removeTempDirectory();
157 disconnect(Security::ref(), TQ_SIGNAL(validityResult(int)), this, TQ_SLOT(slotValidated(int)));
158}
159
160void TDENewStuffSecure::downloadResource()
161{
162 TDEConfig *cfg = TDEGlobal::config();
163 m_installedResources = cfg->entryMap("TDENewStuffStatus");
164 engine()->ignoreInstallResult(true);
165 TDENewStuff::download();
166}
167
168bool TDENewStuffSecure::createUploadFile(const TQString &fileName)
169{
170 Q_UNUSED(fileName);
171 return true;
172}
173
174void TDENewStuffSecure::uploadResource(const TQString& fileName)
175{
176 connect(Security::ref(), TQ_SIGNAL(fileSigned(int)), this, TQ_SLOT(slotFileSigned(int)));
177 removeTempDirectory();
178 m_tempDir = new KTempDir();
179 m_tempDir->setAutoDelete(true);
180 TQFileInfo f(fileName);
181 m_signedFileName = m_tempDir->name() + "/" + f.fileName();
182 TDEIO::NetAccess::file_copy(KURL::fromPathOrURL(fileName), KURL::fromPathOrURL(m_signedFileName), -1, true);
183 Security::ref()->signFile(m_signedFileName);
184}
185
186void TDENewStuffSecure::slotFileSigned(int result)
187{
188 if (result == 0)
189 {
190 KMessageBox::error(parentWidget(), i18n("The signing failed for unknown reason."));
191 } else
192 {
193 if (result & Security::BAD_PASSPHRASE)
194 {
195 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)
196 {
197 disconnect(Security::ref(), TQ_SIGNAL(fileSigned(int)), this, TQ_SLOT(slotFileSigned(int)));
198 removeTempDirectory();
199 return;
200 }
201 }
202 KTar tar(m_signedFileName + ".signed", "application/x-gzip");
203 tar.open(IO_WriteOnly);
204 TQStringList files;
205 files << m_signedFileName;
206 files << m_tempDir->name() + "/md5sum";
207 files << m_tempDir->name() + "/signature";
208
209 for (TQStringList::Iterator it_f = files.begin(); it_f != files.end(); ++it_f)
210 {
211 TQFile file(*it_f);
212 file.open(IO_ReadOnly);
213 TQByteArray bArray = file.readAll();
214 tar.writeFile(TQFileInfo(file).fileName(), "user", "group", bArray.size(), bArray.data());
215 file.close();
216 }
217 tar.close();
218 TDEIO::NetAccess::file_move(KURL::fromPathOrURL(m_signedFileName + ".signed"), KURL::fromPathOrURL(m_signedFileName), -1, true);
219 TDENewStuff::upload(m_signedFileName, TQString::null);
220 disconnect(Security::ref(), TQ_SIGNAL(fileSigned(int)), this, TQ_SLOT(slotFileSigned(int)));
221 }
222}
223
224void TDENewStuffSecure::slotUploadFinished(bool result)
225{
226 Q_UNUSED(result);
227 removeTempDirectory();
228}
229
230void TDENewStuffSecure::removeTempDirectory()
231{
232 if (m_tempDir)
233 {
234 TDEIO::NetAccess::del(KURL().fromPathOrURL(m_tempDir->name()), parentWidget());
235 delete m_tempDir;
236 m_tempDir = 0L;
237 }
238}
239
240#include "knewstuffsecure.moc"
KNS::Engine::ignoreInstallResult
void ignoreInstallResult(bool ignore)
Ignores the return value of the install method.
Definition: engine.cpp:443
TDENewStuffSecure::install
bool install(const TQString &fileName)
Installs the downloaded resource.
Definition: knewstuffsecure.cpp:49
TDENewStuffSecure::TDENewStuffSecure
TDENewStuffSecure(const TQString &type, TQWidget *parentWidget=0)
Constructor.
Definition: knewstuffsecure.cpp:36
TDENewStuffSecure::removeTempDirectory
void removeTempDirectory()
Removes the temporary directory m_tempDir.
Definition: knewstuffsecure.cpp:230
TDENewStuffSecure::createUploadFile
bool createUploadFile(const TQString &fileName)
Reimplemented for internal reasons.
Definition: knewstuffsecure.cpp:168
TDENewStuffSecure::downloadResource
void downloadResource()
Initiates a download.
Definition: knewstuffsecure.cpp:160
TDENewStuffSecure::installResource
virtual void installResource()=0
Installs the resource specified by m_tarName.
TDENewStuffSecure::uploadResource
void uploadResource(const TQString &fileName)
Signs the file and uploads to the central server.
Definition: knewstuffsecure.cpp:174
TDENewStuff
This class provides the functionality to download and upload "new stuff".
Definition: knewstuff.h:70
TDENewStuff::engine
KNS::Engine * engine()
Get the pointer to the engine.
Definition: knewstuff.h:154
TDENewStuff::parentWidget
TQWidget * parentWidget() const
Return parent widget.
Definition: knewstuff.cpp:57
TDENewStuff::upload
void upload()
Start upload process.
Definition: knewstuff.cpp:82
TDENewStuff::download
void download()
Start download process.
Definition: knewstuff.cpp:67
KNS
Handles security releated issues, like signing, verifying.
Definition: downloaddialog.h:37

tdenewstuff

Skip menu "tdenewstuff"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Class Members
  • Related Pages

tdenewstuff

Skip menu "tdenewstuff"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdenewstuff by doxygen 1.9.4
This website is maintained by Timothy Pearson.