summaryrefslogtreecommitdiffstats
path: root/kgpg/kgpginterface.h
blob: 4fb21b263d56bbfa72d2d6cefa4585ebbb3f12e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
/***************************************************************************
                          kgpginterface.h  -  description
                             -------------------
    begin                : Sat Jun 29 2002
    copyright          : (C) 2002 by Jean-Baptiste Mardelle
    email                : bj@altern.org
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KGPGINTERFACE_H
#define KGPGINTERFACE_H


#include <qobject.h>
#include <kdialogbase.h>
#include <kurl.h>
#include <qdatetime.h>

class QLabel;
class KProcIO;
class KProcess;
class KLed;

/**
 * Encrypt a file using gpg.
 */

class KgpgInterface : public QObject
{

        Q_OBJECT

public:
        /**
         * Initialize the class
         */
        KgpgInterface();

	        /*
         * Destructor for the class.
         */
        ~KgpgInterface();

public slots:

        /**Encrypt file function
         * @param userIDs the recipients key id's.
         * @param srcUrl Kurl of the file to encrypt.
         * @param destUrl Kurl for the encrypted file.
         * @param Options String with the wanted gpg options. ex: "--armor"
         * @param symetrical bool whether the encryption should be symmetrical.
         */
        void KgpgEncryptFile(QStringList encryptKeys,KURL srcUrl,KURL destUrl,QStringList Options=QString::null,bool symetrical=false);

        /**Encrypt file function
         * @param userIDs the key user identification.
         * @param srcUrl Kurl of the file to decrypt.
         * @param destUrl Kurl for the decrypted file.
         * @param chances int number of trials left for decryption (used only as an info displayed in the password dialog)
         */
        void KgpgDecryptFile(KURL srcUrl,KURL destUrl,QStringList Options=QStringList());

        /**Sign file function
         * @param keyID QString the signing key ID.
         * @param srcUrl Kurl of the file to sign.
         * @param Options String with the wanted gpg options. ex: "--armor"
         */
        void KgpgSignFile(QString keyID,KURL srcUrl,QStringList Options=QStringList());

        /**Verify file function
         * @param sigUrl Kurl of the signature file.
         * @param srcUrl Kurl of the file to be verified. If empty, gpg will try to find it using the signature file name (by removing the .sig extensio)
         */
        void KgpgVerifyFile(KURL sigUrl,KURL srcUrl=KURL()) ;

	void KgpgVerifyText(QString text);
	void slotverifyread(KProcIO *p);
	void slotverifyresult(KProcess*);
	
	
        /**Import key function
         * @param url Kurl the url of the key file. Allows public & secret key import.
         */
        void importKeyURL(KURL url);
        /**Import key function
         * @param keystr QString containing th key. Allows public & secret key import.
        */
        void importKey(QString keystr);

        /**Key signature function
         * @param keyID QString the ID of the key to be signed
         * @param signKeyID QString the ID of the signing key
         * @param signKeyMail QString the name of the signing key (only used to prompt user for passphrase)
         * @param local bool should the signature be local
         */
        void KgpgSignKey(QString keyID,QString signKeyID,QString signKeyMail=QString::null,bool local=false,int checking=0);

        /**Key signature deletion function
         * @param keyID QString the ID of the key
         * @param signKeyID QString the ID of the signature key
         */
        void KgpgDelSignature(QString keyID,QString signKeyID);

        /**Encrypt text function
         * @param text QString text to be encrypted.
         * @param userIDs the recipients key id's.
         * @param Options String with the wanted gpg options. ex: "--armor"
         * returns the encrypted text or empty string if encyption failed
         */
        void KgpgEncryptText(QString text,QStringList userIDs, QStringList Options=QString::null);

        /**Decrypt text function
        * @param text QString text to be decrypted.
        * @param userID QString the name of the decryption key (only used to prompt user for passphrase)
        */
	//static QString KgpgDecryptText(QString text,QString userID);
	void KgpgDecryptText(QString text,QStringList Options=QString::null);
	void txtdecryptfin(KProcess *);

	/**Extract list of photographic user id's
        * @param keyID the recipients key id's.
        */
	void KgpgGetPhotoList(QString keyID);

	void getOutput(KProcess *, char *data, int );
	void getCmdOutput(KProcess *p, char *data, int );

	QString getKey(QStringList IDs, bool attributes);

        void KgpgKeyExpire(QString keyID,QDate date,bool unlimited);
        void KgpgTrustExpire(QString keyID,int keyTrust);
	void KgpgChangePass(QString keyID);

	void KgpgRevokeKey(QString keyID,QString revokeUrl,int reason,QString description);
	void revokeover(KProcess *);
	void revokeprocess(KProcIO *p);
	void KgpgDeletePhoto(QString keyID,QString uid);
	void KgpgAddPhoto(QString keyID,QString imagePath);

	void KgpgAddUid(QString keyID,QString name,QString email,QString comment);
	
        void KgpgDecryptFileToText(KURL srcUrl,QStringList Options);
	void KgpgSignText(QString text,QString userIDs, QStringList Options);

        static QString getGpgSetting(QString name,QString configFile);
	static QString getGpgMultiSetting(QString name,QString configFile);
        static void setGpgSetting(QString name,QString ID,QString url);
	static void setGpgMultiSetting(QString name,QStringList values,QString url);
        static bool getGpgBoolSetting(QString name,QString configFile);
	static void setGpgBoolSetting(QString name,bool enable,QString url);
        static QStringList getGpgGroupNames(QString configFile);
	static QStringList getGpgGroupSetting(QString name,QString configFile);
	static void setGpgGroupSetting(QString name,QStringList values, QString configFile);
	static void delGpgGroup(QString name, QString configFile);
	static QString checkForUtf8(QString txt);
	static QString checkForUtf8bis(QString txt);
	static int getGpgVersion();



private slots:

        void openSignConsole();
        /**
              * Checks output of the signature process
              */
        void signover(KProcess *);
        /**
                * Read output of the signature process
                */
        void sigprocess(KProcIO *p);

        /**
         * Checks if the encrypted file was saved.
         */
        void encryptfin(KProcess *);

        /**
                * Checks if the decrypted file was saved.
                */
        void decryptfin(KProcess *);

        /**
                * Checks if the signing was successful.
                */
        void signfin(KProcess *p);

        /**
                * Checks the number of uid's for a key-> if greater than one, key signature will switch to konsole mode
                */
        int checkuid(QString KeyID);

        /**
                * Reads output of the delete signature process
                */
        void delsigprocess(KProcIO *p);
        /**
                * Checks output of the delete signature process
                */
        void delsignover(KProcess *p);
        /**
                * Checks output of the import process
                */
        void importURLover(KProcess *p);
        void importover(KProcess *);
        /**
                 * Read output of the import process
                 */
        void importprocess(KProcIO *p);
        /**
                 * Reads output of the current process + allow overwriting of a file
                 */
        void readprocess(KProcIO *p);
        /**
                * Reads output of the current encryption process + allow overwriting of a file
                */
        void readencprocess(KProcIO *p);
        /**
                * Reads output of the current signing process + allow overwriting of a file
                */
        void readsignprocess(KProcIO *p);
        /**
                * Reads output of the current decryption process + allow overwriting of a file
                */
        void readdecprocess(KProcIO *p);
        /**
                 * Checks output of the verify process
                 */
        void verifyfin(KProcess *p);

        void expprocess(KProcIO *p);
        void expover(KProcess*);
        void trustprocess(KProcIO *p);
	void passprocess(KProcIO *p);
        void trustover(KProcess *);
	void passover(KProcess *);

        void txtreadencprocess(KProcIO *p);

        void txtencryptfin(KProcess *);

	void delphotoover(KProcess *);
	void delphotoprocess(KProcIO *p);
	void addphotoover(KProcess *);
	void addphotoprocess(KProcIO *p);
	
	void adduidover(KProcess *);
	void adduidprocess(KProcIO *p);
		
	void slotReadKey(KProcIO *p);
	void photoreadover(KProcess *);
	void photoreadprocess(KProcIO *p);
	bool isPhotoId(int uid);
	void updateIDs(QString txtString);
	
	void txtsignprocess(KProcIO *p);
	void txtsignfin(KProcess *);

        //void txtdecryptfin(KProcess *);


signals:

	void missingSignature(QString);
	void verifyOver(QString,QString);

	/**
               *  emitted when a txt decryption failed. returns log output
               */
	void txtdecryptionfailed(QString);
	/**
               *  emitted when a txt encryption starts.
               */
	void txtencryptionstarted();
	
	/**
               *  emitted when a txt decryption finished. returns decrypted text
               */
	void txtdecryptionfinished(QString);
        /**
               *  emitted when a txt encryption finished. returns encrypted text
               */
        void txtencryptionfinished(QString);
        /**
               *  emitted when an error occurred
               */
        void errormessage(QString);
        /**
                *  true if encryption successful, false on error.
                */
        void encryptionfinished(KURL);
        /**
                *  true if key signature deletion successful, false on error.
                */
        void delsigfinished(bool);

        /**
                * Signature process result: 0=successful, 1=error, 2=bad passphrase
                */
        void signatureFinished(int);
        /**
                *  emitted when user cancels process
                */
        void processaborted(bool);
        /**
                *  emitted when the process starts
                */
        void processstarted(QString);
        /**
                *  true if decryption successful, false on error.
                */
        void decryptionfinished();
        /**
                * emitted if bad passphrase was giver
                */
        void badpassphrase(bool);
        /**
                *  true if import successful, false on error.
                */
        void importfinished(QStringList);
        /**
                *  true if verify successful, false on error.
                */
        void verifyfinished();
        /**
                *  emmitted if signature key is missing & user want to import it from keyserver
                */
        void verifyquerykey(QString ID);
        /**
                *  true if signature successful, false on error.
                */
        void signfinished();
	void delPhotoFinished();
	void delPhotoError(QString);
	
	void addPhotoFinished();
	void addPhotoError(QString);
	void refreshOrphaned();
	
	void addUidFinished();
	void addUidError(QString);
	
        void trustfinished();
	void revokecertificate(QString);
	void revokeurl(QString);
        void expirationFinished(int);
	void signalPhotoList(QStringList);
	void passwordChanged();
	
	void txtSignOver(QString);


private:
        /**
        * @internal structure for communication
        */
        QString message,tempKeyFile,userIDs,output,keyString,txtToEncrypt,log;
        QCString passphrase;
        bool deleteSuccess,konsLocal,anonymous,decfinished,decok,badmdc,revokeSuccess,addSuccess,delSuccess;
	bool signmiss;
	QString signID;
        int signSuccess,expSuccess,trustValue,konsChecked;
        int step,signb,sigsearch,expirationDelay;
        QString konsSignKey, konsKeyID,errMessage;
	int revokeReason,photoCount;
	QString revokeDescription,certificateUrl,photoUrl;
	QStringList photoList;
	QString uidName, uidEmail, uidComment;
        KURL sourceFile;
	QString decryptUrl;

	QString gpgOutput;
	
        /**
         * @internal structure for the file information
         */
        KURL file;

};

class  Md5Widget :public KDialogBase
{
        Q_OBJECT
public:
        Md5Widget(QWidget *parent=0, const char *name=0,KURL url=KURL());
        ~Md5Widget();
public slots:
        void slotApply();
private:
        QString mdSum;
        KLed *KLed1;
        QLabel *TextLabel1_2;
};

#endif // KGPGINTERFACE_HKGPGINTERFACE_H