• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

libkpgp

  • sources
  • kde-4.14
  • kdepim
  • libkpgp
kpgpbase6.cpp
Go to the documentation of this file.
1 /*
2  kpgpbase6.cpp
3 
4  Copyright (C) 2001,2002 the KPGP authors
5  See file AUTHORS.kpgp for details
6 
7  This file is part of KPGP, the KDE PGP/GnuPG support library.
8 
9  KPGP is free software; you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation; either version 2 of the License, or
12  (at your option) any later version.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software Foundation,
16  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #include "kpgpbase.h"
20 
21 #include <string.h> /* strncmp */
22 #include <assert.h>
23 
24 #include <QDateTime>
25 
26 #include <klocale.h>
27 #include <kdebug.h>
28 
29 #define PGP6 "pgp"
30 
31 namespace Kpgp {
32 
33 Base6::Base6()
34  : Base2()
35 {
36 }
37 
38 
39 Base6::~Base6()
40 {
41 }
42 
43 
44 int
45 Base6::decrypt( Block& block, const char *passphrase )
46 {
47  int index, index2;
48 
49  clear();
50  input = block.text();
51  int exitStatus = run( PGP6 " +batchmode +language=C -f", passphrase);
52  if( !output.isEmpty() )
53  block.setProcessedText( output );
54  block.setError( error );
55 
56  if(exitStatus == -1) {
57  errMsg = i18n("error running PGP");
58  status = ERROR;
59  block.setStatus( status );
60  return status;
61  }
62 
63  // encrypted message
64  if( error.contains("File is encrypted.") )
65  {
66  //kDebug( 5326 ) <<"kpgpbase: message is encrypted";
67  status |= ENCRYPTED;
68  if((index = error.indexOf("Key for user ID")) != -1 )
69  {
70  // Find out the key for which the phrase is needed
71  index = error.indexOf(':', index) + 2;
72  index2 = error.indexOf('\n', index);
73  block.setRequiredUserId( QLatin1String(error.mid(index, index2 - index)) );
74  //kDebug( 5326 ) <<"Base: key needed is \"" << block.requiredUserId() <<"\"!";
75 
76  // Test output length to find out, if the passphrase is
77  // bad. If someone knows a better way, please fix this.
80  if (!passphrase || !output.length())
81  {
82  errMsg = i18n("Bad passphrase; could not decrypt.");
83  //kDebug( 5326 ) <<"Base: passphrase is bad";
84  status |= BADPHRASE;
85  status |= ERROR;
86  }
87  }
88  else if( error.contains("You do not have the secret key needed to decrypt this file.") )
89  {
90  errMsg = i18n("You do not have the secret key for this message.");
91  //kDebug( 5326 ) <<"Base: no secret key for this message";
92  status |= NO_SEC_KEY;
93  status |= ERROR;
94  }
95  }
96 
97  // signed message
98 
99  // Examples (made with PGP 6.5.8)
100  /* Example no. 1 (signed with unknown key):
101  * File is signed. signature not checked.
102  * Signature made 2001/11/25 11:55 GMT
103  * key does not meet validity threshold.
104  *
105  * WARNING: Because this public key is not certified with a trusted
106  * signature, it is not known with high confidence that this public key
107  * actually belongs to: "(KeyID: 0x475027BD)".
108  */
109  /* Example no. 2 (signed with untrusted key):
110  * File is signed. Good signature from user "Joe User <joe@foo.bar>".
111  * Signature made 2001/12/05 13:09 GMT
112  *
113  * WARNING: Because this public key is not certified with a trusted
114  * signature, it is not known with high confidence that this public key
115  * actually belongs to: "Joe User <joe@foo.bar>".
116  */
117  /* Example no. 3 (signed with trusted key):
118  * File is signed. Good signature from user "Joe User <joe@foo.bar>".
119  * Signature made 2001/12/05 13:09 GMT
120  */
121  if(((index = error.indexOf("File is signed.")) != -1 )
122  || (error.contains("Good signature") ))
123  {
124  //kDebug( 5326 ) <<"Base: message is signed";
125  status |= SIGNED;
126  // determine the signature date
127  if( ( index2 = error.indexOf( "Signature made", index ) ) != -1 )
128  {
129  index2 += 15;
130  int eol = error.indexOf( '\n', index2 );
131  block.setSignatureDate( error.mid( index2, eol-index2 ) );
132  kDebug( 5326 ) <<"Message was signed on '" << block.signatureDate() <<"'";
133  }
134  else
135  block.setSignatureDate( QByteArray() );
136  // determine signature status and signature key
137  if( error.contains("signature not checked") )
138  {
139  index = error.indexOf("KeyID:",index);
140  block.setSignatureKeyId( error.mid(index+9,8) );
141  block.setSignatureUserId( QString() );
142  status |= UNKNOWN_SIG;
143  status |= GOODSIG;
144  }
145  else if((index = error.indexOf("Good signature")) != -1 )
146  {
147  status |= GOODSIG;
148  // get signer
149  index = error.indexOf('"',index)+1;
150  index2 = error.indexOf('"', index);
151  block.setSignatureUserId( QLatin1String(error.mid(index, index2-index)) );
152 
153  // get key ID of signer
154  index = error.indexOf("KeyID:",index2);
155  if (index == -1)
156  block.setSignatureKeyId( QByteArray() );
157  else
158  block.setSignatureKeyId( error.mid(index+9,8) );
159  }
160  else if( error.contains("Can't find the right public key") )
161  {
162  // #### fix this hack
163  // #### This doesn't happen with PGP 6.5.8 because it seems to
164  // #### automatically create an empty pubring if it doesn't exist.
165  status |= UNKNOWN_SIG;
166  status |= GOODSIG; // this is a hack...
167  block.setSignatureUserId( i18n("??? (file ~/.pgp/pubring.pkr not found)") );
168  block.setSignatureKeyId( "???" );
169  }
170  else
171  {
172  status |= ERROR;
173  block.setSignatureUserId( QString() );
174  block.setSignatureKeyId( QByteArray() );
175  }
176  }
177  //kDebug( 5326 ) <<"status =" << status;
178  block.setStatus( status );
179  return status;
180 }
181 
182 
183 Key*
184 Base6::readPublicKey( const KeyID& keyID,
185  const bool readTrust /* = false */,
186  Key* key /* = 0 */ )
187 {
188  status = 0;
189  int exitStatus = run( QByteArray(QByteArray(PGP6 " +batchmode -compatible +verbose=0 +language=C -kvvc "
190  "0x") + keyID), 0, true );
191 
192  if(exitStatus != 0) {
193  status = ERROR;
194  return 0;
195  }
196 
197  key = parseSingleKey( output, key );
198 
199  if( key == 0 )
200  {
201  return 0;
202  }
203 
204  if( readTrust )
205  {
206  exitStatus = run( QByteArray(QByteArray(PGP6 " +batchmode -compatible +verbose=0 +language=C -kc "
207  "0x") + keyID), 0, true );
208 
209  if(exitStatus != 0) {
210  status = ERROR;
211  return 0;
212  }
213 
214  parseTrustDataForKey( key, output );
215  }
216 
217  return key;
218 }
219 
220 
221 KeyList
222 Base6::publicKeys( const QStringList & patterns )
223 {
224  return doGetPublicKeys( PGP6 " +batchmode -compatible +verbose=0 "
225  "+language=C -kvvc", patterns );
226 }
227 
228 
229 /*
230 QStrList
231 Base6::pubKeys()
232 {
233  int index, index2;
234  int exitStatus = 0;
235  int compatibleMode = 1;
236 
237  status = 0;
238  exitStatus = run("pgp +batchmode +language=C -kv -f");
239 
240  if(exitStatus != 0) {
241  status = ERROR;
242  return 0;
243  }
244 
245  //truncate trailing "\n"
246  if (error.length() > 1) error.truncate(error.length()-1);
247 
248  QStrList publicKeys;
249  index = error.indexOf("bits/keyID",1); // skip first to "\n"
250  if (index ==-1)
251  {
252  index = error.indexOf("Type bits",1); // skip first to "\n"
253  if (index == -1)
254  return 0;
255  else
256  compatibleMode = 0;
257  }
258 
259  while( (index = error.indexOf("\n",index)) != -1 )
260  {
261  //parse line
262  QCString line;
263  if( (index2 = error.indexOf("\n",index+1)) != -1 )
264  // skip last line
265  {
266  int index3;
267  if (compatibleMode)
268  {
269  int index_pub = error.indexOf("pub ",index);
270  int index_sec = error.indexOf("sec ",index);
271  if (index_pub < 0)
272  index3 = index_sec;
273  else if (index_sec < 0)
274  index3 = index_pub;
275  else
276  index3 = (index_pub < index_sec ? index_pub : index_sec);
277  }
278  else
279  {
280  int index_rsa = error.indexOf("RSA ",index);
281  int index_dss = error.indexOf("DSS ",index);
282  if (index_rsa < 0)
283  index3 = index_dss;
284  else if (index_dss < 0)
285  index3 = index_rsa;
286  else
287  index3 = (index_rsa < index_dss ? index_rsa : index_dss);
288  }
289 
290  if( (index3 >index2) || (index3 == -1) )
291  {
292  // second address for the same key
293  line = error.mid(index+1,index2-index-1);
294  line = line.trimmed();
295  } else {
296  // line with new key
297  int index4 = error.indexOf(QRegExp("/\\d{2}/\\d{2} "), index);
298  line = error.mid(index4+7,index2-index4-7);
299  }
300  //kDebug( 5326 ) <<"Base: found key for" << (const char *)line;
301 
302  // don't add PGP's comments to the key list
303  if (strncmp(line.data(),"*** KEY EXPIRED ***",19) &&
304  !line.contains(QRegExp("^expires \\d{4}/\\d{2}/\\d{2}")) &&
305  strncmp(line.data(),"*** DEFAULT SIGNING KEY ***",27)) {
306  publicKeys.append(line);
307  }
308  }
309  else
310  break;
311  index = index2;
312  }
313 
314  // Also look for pgp key groups
315  exitStatus = run("pgp +batchmode +language=C -gv -f");
316 
317  if(exitStatus != 0) {
318  status = ERROR;
319  return 0;
320  }
321 
322  index = 0;
323  while ( (index = error.indexOf("\n >", index)) != -1 ) {
324  QCString line;
325  index += 4;
326  index2 = error.indexOf(" \"", index);
327  line = error.mid(index, index2-index+1).trimmed();
328 
329  //kDebug( 5326 ) <<"Base6: found key group for" << line;
330  publicKeys.append(line);
331  }
332 
333  return publicKeys;
334 }
335 */
336 
337 
338 KeyList
339 Base6::secretKeys( const QStringList & patterns )
340 {
341  return publicKeys( patterns );
342 }
343 
344 
345 int
346 Base6::isVersion6()
347 {
348  int exitStatus = run( PGP6, 0, true );
349 
350  if(exitStatus == -1) {
351  errMsg = i18n("error running PGP");
352  status = ERROR;
353  return 0;
354  }
355 
356  if( error.contains("Version 6") )
357  {
358  //kDebug( 5326 ) <<"kpgpbase: pgp version 6.x detected";
359  return 1;
360  }
361 
362  //kDebug( 5326 ) <<"kpgpbase: not pgp version 6.x";
363  return 0;
364 }
365 
366 
367 Key*
368 Base6::parseKeyData( const QByteArray& output, int& offset, Key* key /* = 0 */ )
369 // This function parses the data for a single key which is output by PGP 6
370 // with the following command line arguments:
371 // +batchmode -compatible +verbose=0 +language=C -kvvc
372 // It expects the key data to start at offset and returns the start of
373 // the next key's data in offset.
374 {
375  if( ( strncmp( output.data() + offset, "DSS", 3 ) != 0 ) &&
376  ( strncmp( output.data() + offset, "RSA", 3 ) != 0 ) )
377  {
378  kDebug( 5326 ) <<"Unknown key type or corrupt key data.";
379  return 0;
380  }
381 
382  Subkey *subkey = 0;
383  bool firstLine = true;
384  bool canSign = false;
385  bool canEncr = false;
386  bool fpr = false;
387 
388  while( true )
389  {
390  int eol;
391 
392  // search the end of the current line
393  if( ( eol = output.indexOf( '\n', offset ) ) == -1 )
394  break;
395 
396  //kDebug( 5326 ) <<"Parsing:" << output.mid(offset, eol-offset);
397 
398  if( firstLine && ( !strncmp( output.data() + offset, "DSS", 3 ) ||
399  !strncmp( output.data() + offset, "RSA", 3 ) ) )
400  { // line contains primary key data
401  // Example 1:
402  // RSA 1024 0xE2D074D3 2001/09/09 Test Key <testkey@xyz>
403  // Example 2 (disabled key):
404  // RSA@ 1024 0x8CCB2C1B 2001/11/04 Disabled Test Key <disabled@xyz>
405  // Example 3 (expired key):
406  // RSA 1024 0x7B94827D 2001/09/09 *** KEY EXPIRED ***
407  // Example 4 (revoked key):
408  // RSA 1024 0x956721F9 2001/09/09 *** KEY REVOKED ***
409  // Example 5 (default signing key):
410  // RSA 1024 0x12345678 2001/09/09 *** DEFAULT SIGNING KEY ***
411  // Example 6 (expiring key):
412  // RSA 2048 0xC11DB2E5 2000/02/24 expires 2001/12/31
413  // Example 7 (complex example):
414  // DSS 1024 0x80E104A7 2000/06/05 expires 2002/05/31
415  // DSS 1024 0x80E104A7 2001/06/27 *** KEY REVOKED ***expires 2002/06/27
416  // DH 1024 0x80E104A7 2000/06/05 *** KEY REVOKED ****** KEY EXPIRED ***
417  //kDebug( 5326 )<<"Primary key data:";
418  bool sign = false;
419  bool encr = false;
420 
421  // set default key capabilities
422  if( !strncmp( output.data() + offset, "DSS", 3 ) )
423  sign = true;
424  if( !strncmp( output.data() + offset, "RSA", 3 ) )
425  {
426  sign = true;
427  encr = true;
428  }
429 
430  int pos, pos2;
431 
432  if( key == 0 )
433  key = new Key();
434  else
435  key->clear();
436 
437  subkey = new Subkey( "", false );
438  key->addSubkey( subkey );
439  // expiration date defaults to never
440  subkey->setExpirationDate( -1 );
441 
442  // Key Flags
443  switch( output[offset+3] )
444  {
445  case ' ': // nothing special
446  break;
447  case '@': // disabled key
448  subkey->setDisabled( true );
449  key->setDisabled( true );
450  break;
451  default:
452  kDebug( 5326 ) <<"Unknown key flag.";
453  }
454 
455  // Key Length
456  pos = offset + 4;
457  while( output[pos] == ' ' )
458  pos++;
459  pos2 = output.indexOf( ' ', pos );
460  subkey->setKeyLength( output.mid( pos, pos2-pos ).toUInt() );
461  //kDebug( 5326 ) <<"Key Length:"<<subkey->keyLength();
462 
463  // Key ID
464  pos = pos2 + 1;
465  while( output[pos] == ' ' )
466  pos++;
467  pos += 2; // skip the '0x'
468  pos2 = output.indexOf( ' ', pos );
469  subkey->setKeyID( output.mid( pos, pos2-pos ) );
470  //kDebug( 5326 ) <<"Key ID:"<<subkey->keyID();
471 
472  // Creation Date
473  pos = pos2 + 1;
474  while( output[pos] == ' ' )
475  pos++;
476  pos2 = output.indexOf( ' ', pos );
477  int year = output.mid( pos, 4 ).toInt();
478  int month = output.mid( pos+5, 2 ).toInt();
479  int day = output.mid( pos+8, 2 ).toInt();
480  QDateTime dt( QDate( year, month, day ), QTime( 00, 00 ) );
481  QDateTime epoch( QDate( 1970, 01, 01 ), QTime( 00, 00 ) );
482  // The calculated creation date isn't exactly correct because QDateTime
483  // doesn't know anything about timezones and always assumes local time
484  // although epoch is of course UTC. But as PGP 6 anyway doesn't print
485  // the time this doesn't matter too much.
486  subkey->setCreationDate( epoch.secsTo( dt ) );
487 
488  // User ID or key properties
489  pos = pos2 + 1;
490  while( output[pos] == ' ' )
491  pos++;
492  while( pos < eol )
493  { // loop over User ID resp. key properties
494  if( !strncmp( output.data() + pos, "*** KEY REVOKED ***", 19 ) )
495  {
496  sign = false;
497  encr = false;
498  subkey->setRevoked( true );
499  key->setRevoked( true );
500  pos += 19;
501  //kDebug( 5326 ) <<"Key was revoked.";
502  }
503  else if( !strncmp( output.data() + pos, "*** KEY EXPIRED ***", 19 ) )
504  {
505  sign = false;
506  encr = false;
507  subkey->setExpired( true );
508  key->setExpired( true );
509  pos += 19;
510  //kDebug( 5326 ) <<"Key has expired.";
511  }
512  else if( !strncmp( output.data() + pos, "expires ", 8 ) )
513  {
514  pos += 8;
515  int year = output.mid( pos, 4 ).toInt();
516  int month = output.mid( pos+5, 2 ).toInt();
517  int day = output.mid( pos+8, 2 ).toInt();
518  QDateTime dt( QDate( year, month, day ), QTime( 00, 00 ) );
519  // Here the same comments as for the creation date are valid.
520  subkey->setExpirationDate( epoch.secsTo( dt ) );
521  pos += 10;
522  //kDebug( 5326 ) <<"Key expires...";
523  }
524  else if( !strncmp( output.data() + pos, "*** DEFAULT SIGNING KEY ***", 27 ) )
525  {
526  pos += 27;
527  //kDebug( 5326 ) <<"Key is default signing key.";
528  }
529  else
530  {
531  QByteArray uid = output.mid( pos, eol-pos );
532  key->addUserID( QLatin1String(uid) );
533  pos = eol;
534  //kDebug( 5326 ) <<"User ID:"<<uid;
535  }
536  }
537  // set key capabilities of the primary subkey
538  subkey->setCanEncrypt( encr );
539  subkey->setCanSign( sign );
540  subkey->setCanCertify( sign );
541  // remember the global key capabilities
542  canSign = sign;
543  canEncr = encr;
544  }
545  else if( !strncmp( output.data() + offset, "DSS", 3 ) ||
546  !strncmp( output.data() + offset, " DH", 3 ) ||
547  !strncmp( output.data() + offset, "RSA", 3 ) )
548  { // line contains secondary key data (or data for the next key)
549  if( fpr )
550  break; // here begins the next key's data
551  //kDebug( 5326 )<<"Secondary key data:";
552 
553  if( key == 0 )
554  break;
555 
556  bool sign = false;
557  bool encr = false;
558 
559  // set default key capabilities
560  if( !strncmp( output.data() + offset, "DSS", 3 ) )
561  sign = true;
562  if( !strncmp( output.data() + offset, " DH", 3 ) )
563  encr = true;
564  if( !strncmp( output.data() + offset, "RSA", 3 ) )
565  {
566  sign = true;
567  encr = true;
568  }
569 
570  int pos, pos2;
571 
572  // Key Length of secondary key (ignored)
573  pos = offset + 4;
574  while( output[pos] == ' ' )
575  pos++;
576  pos2 = output.indexOf( ' ', pos );
577 
578  // Key ID (ignored as it is anyway equal to the primary key id)
579  pos = pos2 + 1;
580  while( output[pos] == ' ' )
581  pos++;
582  pos2 = output.indexOf( ' ', pos );
583 
584  // Creation Date of secondary key (ignored)
585  pos = pos2 + 1;
586  while( output[pos] == ' ' )
587  pos++;
588  pos2 = output.indexOf( ' ', pos );
589 
590  // User ID or key properties
591  pos = pos2 + 1;
592  while( output[pos] == ' ' )
593  pos++;
594  while( pos < eol )
595  { // loop over User ID resp. key properties
596  if( !strncmp( output.data() + pos, "*** KEY REVOKED ***", 19 ) )
597  {
598  sign = false;
599  encr = false;
600  pos += 19;
601  //kDebug( 5326 ) <<"Key was revoked.";
602  }
603  else if( !strncmp( output.data() + pos, "*** KEY EXPIRED ***", 19 ) )
604  {
605  sign = false;
606  encr = false;
607  pos += 19;
608  //kDebug( 5326 ) <<"Key has expired.";
609  }
610  else if( !strncmp( output.data() + pos, "expires ", 8 ) )
611  {
612  pos += 18; // skip the expiration date
613  //kDebug( 5326 ) <<"Key expires...";
614  }
615  else if( !strncmp( output.data() + pos, "*** DEFAULT SIGNING KEY ***", 27 ) )
616  {
617  pos += 27;
618  //kDebug( 5326 ) <<"Key is default signing key.";
619  }
620  else
621  {
622  QByteArray uid = output.mid( pos, eol-pos );
623  key->addUserID( QLatin1String(uid) );
624  pos = eol;
625  //kDebug( 5326 ) <<"User ID:"<<uid;
626  }
627  }
628  // store the global key capabilities
629  canSign = canSign || sign;
630  canEncr = canEncr || encr;
631  }
632  else if( !strncmp( output.data() + offset, "Unknown type", 12 ) )
633  { // line contains key data of unknown type (ignored)
634  kDebug( 5326 )<<"Unknown key type.";
635  }
636  else if( output[offset] == ' ' )
637  { // line contains additional key data
638  if( key == 0 )
639  break;
640  //kDebug( 5326 )<<"Additional key data:";
641 
642  int pos = offset + 1;
643  while( output[pos] == ' ' )
644  pos++;
645 
646  if( !strncmp( output.data() + pos, "Key fingerprint = ", 18 ) )
647  { // line contains a fingerprint
648  // Example:
649  // Key fingerprint = D0 6C BB 3A F5 16 82 C4 F3 A0 8A B3 7B 16 99 70
650 
651  fpr = true; // we found a fingerprint
652 
653  pos += 18;
654  QByteArray fingerprint = output.mid( pos, eol-pos );
655  // remove white space from the fingerprint
656  for ( int idx = 0 ; (idx = fingerprint.indexOf(' ', idx)) != -1; )
657  fingerprint.replace( idx, 1, "" );
658 
659  //kDebug( 5326 )<<"Fingerprint:"<<fingerprint;
660  assert( subkey != 0 );
661  subkey->setFingerprint( fingerprint );
662  }
663  else
664  { // line contains an additional user id
665  // Example:
666  // Test key (2nd user ID) <abc@xyz>
667 
668  //kDebug( 5326 )<<"User ID:"<<output.mid( pos, eol-pos );
669  key->addUserID( QLatin1String(output.mid( pos, eol-pos )) );
670  }
671  }
672  else if( !strncmp( output.data() + offset, "sig", 3 ) )
673  { // line contains signature data (ignored)
674  //kDebug( 5326 )<<"Signature.";
675  }
676  else // end of key data
677  break;
678 
679  firstLine = false;
680  offset = eol + 1;
681  }
682 
683  if( key != 0 )
684  {
685  // set the global key capabilities
686  key->setCanEncrypt( canEncr );
687  key->setCanSign( canSign );
688  key->setCanCertify( canSign );
689  //kDebug( 5326 )<<"Key capabilities:"<<(canEncr?"E":"")<<(canSign?"SC":"");
690  }
691 
692  return key;
693 }
694 
695 
696 Key*
697 Base6::parseSingleKey( const QByteArray& output, Key* key /* = 0 */ )
698 {
699  int offset;
700 
701  // search start of header line
702  if( !strncmp( output.data(), "Type bits", 9 ) )
703  offset = 9;
704  else
705  {
706  offset = output.indexOf( "\nType bits" );
707  if( offset == -1 )
708  return 0;
709  else
710  offset += 10;
711  }
712 
713  // key data begins in the next line
714  offset = output.indexOf( '\n', offset ) + 1;
715  if( offset == 0 )
716  return 0;
717 
718  key = parseKeyData( output, offset, key );
719 
720  //kDebug( 5326 ) <<"finished parsing keys";
721 
722  return key;
723 }
724 
725 
726 KeyList
727 Base6::parseKeyList( const QByteArray& output, bool secretKeys )
728 {
729  kDebug( 5326 ) <<"Kpgp::Base6::parseKeyList()";
730  KeyList keys;
731  Key *key = 0;
732  int offset;
733 
734  // search start of header line
735  if( !strncmp( output.data(), "Type bits", 9 ) )
736  offset = 0;
737  else
738  {
739  offset = output.indexOf( "\nType bits" ) + 1;
740  if( offset == 0 )
741  return keys;
742  }
743 
744  // key data begins in the next line
745  offset = output.indexOf( '\n', offset ) + 1;
746  if( offset == -1 )
747  return keys;
748 
749  do
750  {
751  key = parseKeyData( output, offset );
752  if( key != 0 )
753  {
754  key->setSecret( secretKeys );
755  keys.append( key );
756  }
757  }
758  while( key != 0 );
759 
760  //kDebug( 5326 ) <<"finished parsing keys";
761 
762  return keys;
763 }
764 
765 
766 void
767 Base6::parseTrustDataForKey( Key* key, const QByteArray& str )
768 {
769  if( ( key == 0 ) || str.isEmpty() )
770  return;
771 
772  QByteArray keyID = "0x" + key->primaryKeyID();
773  UserIDList userIDs = key->userIDs();
774 
775  // search the start of the trust data
776  int offset = str.indexOf( "\n\n KeyID" );
777  if( offset == -1 )
778  return;
779 
780  offset = str.indexOf( '\n', offset ) + 1;
781  if( offset == 0 )
782  return;
783 
784  bool ultimateTrust = false;
785  if( !strncmp( str.data() + offset+13, "ultimate", 8 ) )
786  ultimateTrust = true;
787 
788  while( true )
789  { // loop over all trust information about this key
790 
791  int eol;
792 
793  // search the end of the current line
794  if( ( eol = str.indexOf( '\n', offset ) ) == -1 )
795  break;
796 
797  if( str[offset+23] != ' ' )
798  { // line contains a validity value for a user ID
799 
800  // determine the validity
801  Validity validity = KPGP_VALIDITY_UNKNOWN;
802  if( !strncmp( str.data() + offset+23, "complete", 8 ) )
803  if( ultimateTrust )
804  validity = KPGP_VALIDITY_ULTIMATE;
805  else
806  validity = KPGP_VALIDITY_FULL;
807  else if( !strncmp( str.data() + offset+23, "marginal", 8 ) )
808  validity = KPGP_VALIDITY_MARGINAL;
809  else if( !strncmp( str.data() + offset+23, "invalid", 7 ) )
810  validity = KPGP_VALIDITY_UNDEFINED;
811 
812  // determine the user ID
813  int pos = offset + 33;
814  QString uid = QLatin1String(str.mid( pos, eol-pos ));
815 
816  // set the validity of the corresponding user ID
817  for( UserIDList::Iterator it = userIDs.begin(); it != userIDs.end(); ++it )
818  if( (*it)->text() == uid )
819  {
820  kDebug( 5326 )<<"Setting the validity of"<<uid<<" to"<<validity;
821  (*it)->setValidity( validity );
822  break;
823  }
824  }
825 
826  offset = eol + 1;
827  }
828 }
829 
830 
831 } // namespace Kpgp
Kpgp::Validity
Validity
These are the possible validity values for a PGP user id and for the owner trust. ...
Definition: kpgpkey.h:32
Kpgp::KeyList
QList< Key * > KeyList
Definition: kpgpkey.h:843
QByteArray::toUInt
uint toUInt(bool *ok, int base) const
Kpgp::Key::setCanCertify
void setCanCertify(const bool canCertify)
Sets the flag if the key can be used to certify keys to canCertify .
Definition: kpgpkey.h:762
Kpgp::Block::setError
void setError(const QByteArray &str)
Definition: kpgpblock.h:222
Kpgp::Key::userIDs
const UserIDList userIDs() const
Returns the list of userIDs.
Definition: kpgpkey.h:807
QByteArray::toInt
int toInt(bool *ok, int base) const
Kpgp::Block::setSignatureDate
void setSignatureDate(const QByteArray &date)
Definition: kpgpblock.h:278
QByteArray
Kpgp::Base::output
QByteArray output
Definition: kpgpbase.h:97
Kpgp::NO_SEC_KEY
Definition: kpgpblock.h:56
Kpgp::KPGP_VALIDITY_ULTIMATE
Definition: kpgpkey.h:39
Kpgp::Key::setCanEncrypt
void setCanEncrypt(const bool canEncrypt)
Sets the flag if the key can be used to encrypt data to canEncrypt .
Definition: kpgpkey.h:752
QByteArray::isEmpty
bool isEmpty() const
Kpgp::KPGP_VALIDITY_FULL
Definition: kpgpkey.h:38
Kpgp::Block
Definition: kpgpblock.h:89
QByteArray::length
int length() const
Kpgp::Base::errMsg
QString errMsg
Definition: kpgpbase.h:99
QTime
Kpgp::BADPHRASE
Definition: kpgpblock.h:54
Kpgp::Block::setRequiredUserId
void setRequiredUserId(const QString &userId)
Definition: kpgpblock.h:302
Kpgp::Key::setSecret
void setSecret(const bool secret)
Sets the flag if the key is a secret key to secret .
Definition: kpgpkey.h:727
Kpgp::Key::setDisabled
void setDisabled(const bool disabled)
Sets the flag if the key has been disabled to disabled .
Definition: kpgpkey.h:742
QByteArray::indexOf
int indexOf(char ch, int from) const
QList::append
void append(const T &value)
Kpgp::Base6::secretKeys
virtual KeyList secretKeys(const QStringList &patterns=QStringList())
Returns the list of secret keys in the users secret keyring.
Definition: kpgpbase6.cpp:339
Kpgp::Base::run
virtual int run(const char *cmd, const char *passphrase=0, bool onlyReadFromPGP=false)
Definition: kpgpbase.cpp:67
Kpgp::Base6::decrypt
virtual int decrypt(Block &block, const char *passphrase=0)
Decrypts the message.
Definition: kpgpbase6.cpp:45
Kpgp::Base6::publicKeys
virtual KeyList publicKeys(const QStringList &patterns=QStringList())
Returns the list of public keys in the users public keyring.
Definition: kpgpbase6.cpp:222
Kpgp::Block::setSignatureUserId
void setSignatureUserId(const QString &userId)
Definition: kpgpblock.h:254
kpgpbase.h
Kpgp::GOODSIG
Definition: kpgpblock.h:51
Kpgp::Key::addUserID
void addUserID(const QString &uid, const Validity validity=KPGP_VALIDITY_UNKNOWN, const bool revoked=false, const bool invalid=false)
Adds a user ID with the given values to the key if uid isn't an empty string.
Definition: kpgpkey.cpp:200
QByteArray::replace
QByteArray & replace(int pos, int len, const char *after)
Kpgp::Base6::Base6
Base6()
Definition: kpgpbase6.cpp:33
QList< UserID * >::Iterator
typedef Iterator
QDate
Kpgp::KPGP_VALIDITY_UNDEFINED
Definition: kpgpkey.h:35
Kpgp::Base2::doGetPublicKeys
KeyList doGetPublicKeys(const QByteArray &cmd, const QStringList &patterns)
Definition: kpgpbase2.cpp:511
QString
QList
Kpgp::Base6::~Base6
virtual ~Base6()
Definition: kpgpbase6.cpp:39
Kpgp::ENCRYPTED
Definition: kpgpblock.h:49
QByteArray::mid
QByteArray mid(int pos, int len) const
Kpgp::Block::signatureDate
QByteArray signatureDate() const
date of the signature WARNING: Will most likely be changed to QDateTime
Definition: kpgpblock.h:272
QStringList
QList::end
iterator end()
Kpgp::KPGP_VALIDITY_MARGINAL
Definition: kpgpkey.h:37
PGP6
#define PGP6
Definition: kpgpbase6.cpp:29
Kpgp::Base6::isVersion6
virtual int isVersion6()
Definition: kpgpbase6.cpp:346
Kpgp::Block::setSignatureKeyId
void setSignatureKeyId(const QByteArray &keyId)
Definition: kpgpblock.h:266
Kpgp::Block::text
QByteArray text() const
Definition: kpgpblock.h:193
QLatin1String
Kpgp::Base6::parseKeyList
virtual KeyList parseKeyList(const QByteArray &, bool)
Definition: kpgpbase6.cpp:727
Kpgp::Key::addSubkey
void addSubkey(const KeyID &keyID, const bool secret=false)
Adds a subkey with the given values to the key if keyID isn't an empty string.
Definition: kpgpkey.cpp:222
Kpgp::Base::input
QByteArray input
Definition: kpgpbase.h:96
Kpgp::Base6::readPublicKey
virtual Key * readPublicKey(const KeyID &keyID, const bool readTrust=false, Key *key=0)
Reads the key data for the given key and returns it.
Definition: kpgpbase6.cpp:184
Kpgp::Key::setExpired
void setExpired(const bool expired)
Sets the flag if the key has expired to expired .
Definition: kpgpkey.h:737
Kpgp::Block::setProcessedText
void setProcessedText(const QByteArray &str)
Definition: kpgpblock.h:209
QByteArray::contains
bool contains(char ch) const
Kpgp::Key::setRevoked
void setRevoked(const bool revoked)
Sets the flag if the key has been revoked to revoked .
Definition: kpgpkey.h:732
QByteArray::data
char * data()
Kpgp::Key
This class is used to store information about a PGP key.
Definition: kpgpkey.h:506
Kpgp::ERROR
Definition: kpgpblock.h:48
Kpgp::KPGP_VALIDITY_UNKNOWN
Definition: kpgpkey.h:34
Kpgp::UNKNOWN_SIG
Definition: kpgpblock.h:53
Kpgp::Base2
Definition: kpgpbase.h:109
Kpgp::Base::clear
virtual void clear()
Definition: kpgpbase.cpp:56
Kpgp::Base::error
QByteArray error
Definition: kpgpbase.h:98
Kpgp::SIGNED
Definition: kpgpblock.h:50
Kpgp::Base::status
int status
Definition: kpgpbase.h:103
Kpgp::Key::setCanSign
void setCanSign(const bool canSign)
Sets the flag if the key can be used to sign data to canSign .
Definition: kpgpkey.h:757
QList::begin
iterator begin()
Kpgp::Key::clear
void clear()
Clears/resets all key data.
Definition: kpgpkey.cpp:117
QDateTime
Kpgp::Block::setStatus
void setStatus(const int status)
Definition: kpgpblock.h:234
Kpgp::Key::primaryKeyID
KeyID primaryKeyID() const
Returns the key ID of the primary key or a null string if there are no subkeys.
Definition: kpgpkey.h:787
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:32:22 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

libkpgp

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

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal