summaryrefslogtreecommitdiffstats
path: root/kgpg/kgpginterface.h
blob: 2433c725459ec09c3c6b0f82c52c5c31fd85fc0d (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
405
406
/***************************************************************************
                          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 <tqobject.h>
#include <kdialogbase.h>
#include <kurl.h>
#include <tqdatetime.h>

class TQLabel;
class KProcIO;
class TDEProcess;
class KLed;

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

class KgpgInterface : public TQObject
{

        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(TQStringList encryptKeys,KURL srcUrl,KURL destUrl,TQStringList Options=TQString(),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,TQStringList Options=TQStringList());

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

        /**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(TQString text);
	void slotverifyread(KProcIO *p);
	void slotverifyresult(TDEProcess*);
	
	
        /**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 TQString containing th key. Allows public & secret key import.
        */
        void importKey(TQString keystr);

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

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

        /**Encrypt text function
         * @param text TQString 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(TQString text,TQStringList userIDs, TQStringList Options=TQString());

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

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

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

	TQString getKey(TQStringList IDs, bool attributes);

        void KgpgKeyExpire(TQString keyID,TQDate date,bool unlimited);
        void KgpgTrustExpire(TQString keyID,int keyTrust);
	void KgpgChangePass(TQString keyID);

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

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

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



private slots:

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

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

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

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

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

        /**
                * Reads output of the delete signature process
                */
        void delsigprocess(KProcIO *p);
        /**
                * Checks output of the delete signature process
                */
        void delsignover(TDEProcess *p);
        /**
                * Checks output of the import process
                */
        void importURLover(TDEProcess *p);
        void importover(TDEProcess *);
        /**
                 * 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(TDEProcess *p);

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

        void txtreadencprocess(KProcIO *p);

        void txtencryptfin(TDEProcess *);

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

        //void txtdecryptfin(TDEProcess *);


signals:

	void missingSignature(TQString);
	void verifyOver(TQString,TQString);

	/**
               *  emitted when a txt decryption failed. returns log output
               */
	void txtdecryptionfailed(TQString);
	/**
               *  emitted when a txt encryption starts.
               */
	void txtencryptionstarted();
	
	/**
               *  emitted when a txt decryption finished. returns decrypted text
               */
	void txtdecryptionfinished(TQString);
        /**
               *  emitted when a txt encryption finished. returns encrypted text
               */
        void txtencryptionfinished(TQString);
        /**
               *  emitted when an error occurred
               */
        void errormessage(TQString);
        /**
                *  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(TQString);
        /**
                *  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(TQStringList);
        /**
                *  true if verify successful, false on error.
                */
        void verifyfinished();
        /**
                *  emmitted if signature key is missing & user want to import it from keyserver
                */
        void verifyquerykey(TQString ID);
        /**
                *  true if signature successful, false on error.
                */
        void signfinished();
	void delPhotoFinished();
	void delPhotoError(TQString);
	
	void addPhotoFinished();
	void addPhotoError(TQString);
	void refreshOrphaned();
	
	void addUidFinished();
	void addUidError(TQString);
	
        void trustfinished();
	void revokecertificate(TQString);
	void revokeurl(TQString);
        void expirationFinished(int);
	void signalPhotoList(TQStringList);
	void passwordChanged();
	
	void txtSignOver(TQString);


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

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

};

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

#endif // KGPGINTERFACE_HKGPGINTERFACE_H