• 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
kpgpbase5.cpp
Go to the documentation of this file.
1 /*
2  kpgpbase5.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 
20 #include "kpgpbase.h"
21 #include "kpgp.h"
22 
23 #include <string.h> /* strncmp */
24 #include <assert.h>
25 
26 #include <QRegExp>
27 #include <QDateTime>
28 
29 #include <klocale.h>
30 #include <kshell.h>
31 #include <kdebug.h>
32 
33 #include <algorithm>
34 
35 
36 namespace Kpgp {
37 
38 Base5::Base5()
39  : Base()
40 {
41 }
42 
43 
44 Base5::~Base5()
45 {
46 }
47 
48 
49 int
50 Base5::encrypt( Block& block, const KeyIDList& recipients )
51 {
52  return encsign( block, recipients, 0 );
53 }
54 
55 
56 int
57 Base5::clearsign( Block& block, const char *passphrase )
58 {
59  return encsign( block, KeyIDList(), passphrase );
60 }
61 
62 
63 int
64 Base5::encsign( Block& block, const KeyIDList& recipients,
65  const char *passphrase )
66 {
67  QByteArray cmd;
68  int exitStatus = 0;
69  int index;
70  // used to work around a bug in pgp5. pgp5 treats files
71  // with non ascii chars (umlauts, etc...) as binary files, but
72  // we want a clear signature
73  bool signonly = false;
74 
75  if(!recipients.isEmpty() && passphrase != 0)
76  cmd = "pgpe +batchmode -afts ";
77  else if(!recipients.isEmpty())
78  cmd = "pgpe +batchmode -aft ";
79  else if(passphrase != 0)
80  {
81  cmd = "pgps +batchmode -abft ";
82  signonly = true;
83  }
84  else
85  {
86  errMsg = i18n("Neither recipients nor passphrase specified.");
87  return OK;
88  }
89 
90  if(passphrase != 0)
91  cmd += addUserId();
92 
93  if(!recipients.isEmpty())
94  {
95  if(Module::getKpgp()->encryptToSelf())
96  {
97  cmd += " -r 0x";
98  cmd += Module::getKpgp()->user();
99  }
100  KeyIDList::ConstIterator end( recipients.constEnd() );
101 
102  for( KeyIDList::ConstIterator it = recipients.constBegin();
103  it != end; ++it ) {
104  cmd += " -r 0x";
105  cmd += (*it);
106  }
107  }
108 
109  clear();
110  input = block.text();
111 
112  if (signonly)
113  {
114  input.append("\n");
115  //input.replace(QRegExp("[ \t]+\n"), "\n"); //strip trailing whitespace
116  input = input.trimmed(); // PORT: check if that change was ok!
117  }
118  //We have to do this otherwise it's all in vain
119 
120  exitStatus = run(cmd.data(), passphrase);
121  block.setError( error );
122 
123  if(exitStatus != 0)
124  status = ERROR;
125 
126  // now parse the returned info
127  if(error.contains("Cannot unlock private key") )
128  {
129  errMsg = i18n("The passphrase you entered is invalid.");
130  status |= ERROR;
131  status |= BADPHRASE;
132  }
133 //if(!ignoreUntrusted)
134 //{
135  QByteArray aStr;
136  index = -1;
137  while((index = error.indexOf("WARNING: The above key",index+1)) != -1 )
138  {
139  int index2 = error.indexOf("But you previously",index);
140  int index3 = error.indexOf("WARNING: The above key",index+1);
141  if(index2 == -1 || (index2 > index3 && index3 != -1))
142  {
143  // the key wasn't valid, no encryption to this person
144  // extract the person
145  index2 = error.indexOf('\n',index);
146  index3 = error.indexOf('\n',index2+1);
147  aStr += error.mid(index2+1, index3-index2-1);
148  aStr += ", ";
149  }
150  }
151  if(!aStr.isEmpty())
152  {
153  aStr.truncate(aStr.length()-2);
154  if(error.contains("No valid keys found") )
155  errMsg = i18n("The key(s) you want to encrypt your message "
156  "to are not trusted. No encryption done.");
157  else
158  errMsg = i18n("The following key(s) are not trusted:\n%1\n"
159  "Their owner(s) will not be able to decrypt the message.",
160  QString::fromLocal8Bit( aStr ));
161  status |= ERROR;
162  status |= BADKEYS;
163  }
164 //}
165  if((index = error.indexOf("No encryption keys found for")) != -1 )
166  {
167  index = error.indexOf(':',index);
168  int index2 = error.indexOf('\n',index);
169 
170  errMsg = i18n("Missing encryption key(s) for:\n%1",
171  QString::fromLocal8Bit(error.mid(index,index2-index)));
172 // errMsg = QString("Missing encryption key(s) for: %1")
173 // .arg(error.mid(index,index2-index));
174  status |= ERROR;
175  status |= MISSINGKEY;
176  }
177 
178  if(signonly) {
179  // dash-escape the input
180  if (input[0] == '-')
181  input = "- " + input;
182  for ( int idx = 0 ; (idx = input.indexOf("\n-", idx)) != -1 ; idx += 4 )
183  input.replace(idx, 2, "\n- -");
184 
185  output = "-----BEGIN PGP SIGNED MESSAGE-----\n\n" + input + '\n' + output;
186  }
187 
188  block.setProcessedText( output );
189  block.setStatus( status );
190  return status;
191 }
192 
193 
194 int
195 Base5::decrypt( Block& block, const char *passphrase )
196 {
197  clear();
198  input = block.text();
199  int exitStatus = run("pgpv -f +batchmode=1", passphrase);
200  if( !output.isEmpty() )
201  block.setProcessedText( output );
202  block.setError( error );
203 
204  if(exitStatus == -1) {
205  errMsg = i18n("Error running PGP");
206  status = ERROR;
207  block.setStatus( status );
208  return status;
209  }
210 
211  // lets parse the returned information.
212  int index = error.indexOf("Cannot decrypt message");
213  if(index != -1)
214  {
215  //kDebug( 5326 ) <<"message is encrypted";
216  status |= ENCRYPTED;
217 
218  // ok. we have an encrypted message. Is the passphrase bad,
219  // or do we not have the secret key?
220  if(error.contains("Need a pass phrase") )
221  {
222  if(passphrase != 0)
223  {
224  errMsg = i18n("Bad passphrase; could not decrypt.");
225  kDebug( 5326 ) <<"Base: passphrase is bad";
226  status |= BADPHRASE;
227  status |= ERROR;
228  }
229  }
230  else
231  {
232  // we don't have the secret key
233  status |= NO_SEC_KEY;
234  status |= ERROR;
235  errMsg = i18n("You do not have the secret key needed to decrypt this message.");
236  kDebug( 5326 ) <<"Base: no secret key for this message";
237  }
238  // check for persons
239 #if 0
240  // ##### FIXME: This information is anyway currently not used
241  // I'll change it to always determine the recipients.
242  index = error.indexOf("can only be decrypted by:");
243  if(index != -1)
244  {
245  index = error.indexOf('\n',index);
246  int end = error.indexOf("\n\n",index);
247 
248  mRecipients.clear();
249  int index2;
250  while( (index2 = error.indexOf('\n',index+1)) <= end )
251  {
252  QByteArray item = error.mid(index+1,index2-index-1);
253  item.trimmed();
254  mRecipients.append(item);
255  index = index2;
256  }
257  }
258 #endif
259  }
260  index = error.indexOf("Good signature");
261  if(index != -1)
262  {
263  //kDebug( 5326 ) <<"good signature";
264  status |= SIGNED;
265  status |= GOODSIG;
266 
267  // get key ID of signer
268  index = error.indexOf("Key ID ", index) + 7;
269  block.setSignatureKeyId( error.mid(index, 8) );
270 
271  // get signer
272  index = error.indexOf('"',index) + 1;
273  int index2 = error.indexOf('"', index);
274  block.setSignatureUserId( QLatin1String(error.mid(index, index2-index)) );
275 
277  block.setSignatureDate( "" );
278  }
279  index = error.indexOf("BAD signature");
280  if(index != -1)
281  {
282  //kDebug( 5326 ) <<"BAD signature";
283  status |= SIGNED;
284  status |= ERROR;
285 
286  // get key ID of signer
287  index = error.indexOf("Key ID ", index) + 7;
288  block.setSignatureKeyId( error.mid(index, 8) );
289 
290  // get signer
291  index = error.indexOf('"',index) + 1;
292  int index2 = error.indexOf('"', index);
293  block.setSignatureUserId( QLatin1String(error.mid(index, index2-index)) );
294 
296  block.setSignatureDate( "" );
297  }
298  index = error.indexOf("Signature by unknown key");
299  if(index != -1)
300  {
301  index = error.indexOf("keyid: 0x",index) + 9;
302  block.setSignatureKeyId( error.mid(index, 8) );
303  block.setSignatureUserId( QString() );
304  // FIXME: not a very good solution...
305  status |= SIGNED;
306  status |= GOODSIG;
307 
309  block.setSignatureDate( "" );
310  }
311 
312  //kDebug( 5326 ) <<"status =" << status;
313  block.setStatus( status );
314  return status;
315 }
316 
317 
318 Key*
319 Base5::readPublicKey( const KeyID& keyId, const bool readTrust, Key* key )
320 {
321  status = 0;
322  int exitStatus = run( QByteArray(QByteArray("pgpk -ll 0x") + keyId), 0, true );
323 
324  if(exitStatus != 0) {
325  status = ERROR;
326  return 0;
327  }
328 
329  key = parseSingleKey( output, key );
330 
331  if( key == 0 )
332  {
333  return 0;
334  }
335 
336  if( readTrust )
337  {
338  exitStatus = run( QByteArray(QByteArray("pgpk -c 0x") + keyId), 0, true );
339 
340  if(exitStatus != 0) {
341  status = ERROR;
342  return 0;
343  }
344 
345  parseTrustDataForKey( key, output );
346  }
347 
348  return key;
349 }
350 
351 
352 KeyList
353 Base5::publicKeys( const QStringList & patterns )
354 {
355  int exitStatus = 0;
356 
357  QByteArray cmd = "pgpk -ll";
358 
359  QStringList::ConstIterator end( patterns.end() );
360 
361 
362  for ( QStringList::ConstIterator it = patterns.constBegin();
363  it != end; ++it ) {
364  cmd += ' ';
365  cmd += KShell::quoteArg( *it ).toLocal8Bit();
366  }
367  status = 0;
368  exitStatus = run( cmd, 0, true );
369 
370  if(exitStatus != 0) {
371  status = ERROR;
372  return KeyList();
373  }
374 
375  // now we need to parse the output for public keys
376  KeyList keys = parseKeyList( output, false );
377 
378  // sort the list of public keys
379  std::sort( keys.begin(), keys.end(), KeyCompare );
380 
381  return keys;
382 }
383 
384 
385 KeyList
386 Base5::secretKeys( const QStringList & patterns )
387 {
388  QByteArray cmd = "pgpk -ll";
389  QStringList::ConstIterator end( patterns.constEnd() );
390  for ( QStringList::ConstIterator it = patterns.constBegin();
391  it != end; ++it ) {
392  cmd += ' ';
393  cmd += KShell::quoteArg( *it ).toLocal8Bit();
394  }
395  status = 0;
396  int exitStatus = run( cmd, 0, true );
397 
398  if(exitStatus != 0) {
399  status = ERROR;
400  return KeyList();
401  }
402 
403  // now we need to parse the output for secret keys
404  KeyList keys = parseKeyList( output, true );
405 
406  // sort the list of public keys
407  std::sort( keys.begin(), keys.end(), KeyCompare );
408 
409  return keys;
410 }
411 
412 
413 QByteArray Base5::getAsciiPublicKey(const KeyID& keyID)
414 {
415  if (keyID.isEmpty())
416  return QByteArray();
417 
418  status = 0;
419  int exitStatus = run( QByteArray(QByteArray("pgpk -xa 0x") + keyID), 0, true );
420 
421  if(exitStatus != 0) {
422  status = ERROR;
423  return QByteArray();
424  }
425 
426  return output;
427 }
428 
429 
430 int
431 Base5::signKey(const KeyID& keyID, const char *passphrase)
432 {
433  if(passphrase == 0) return false;
434  QByteArray cmd;
435 
436  cmd = "pgpk -s -f +batchmode=1 0x";
437  cmd += keyID;
438  cmd += addUserId();
439 
440  status = 0;
441  int exitStatus = run(cmd.data(), passphrase);
442 
443  if (exitStatus != 0)
444  status = ERROR;
445 
446  return status;
447 }
448 
449 //-- private functions --------------------------------------------------------
450 
451 Key*
452 Base5::parseKeyData( const QByteArray& output, int& offset, Key* key /* = 0 */ )
453 // This function parses the data for a single key which is output by PGP 5
454 // with the following command line:
455 // pgpk -ll
456 // It expects the key data to start at offset and returns the start of
457 // the next key's data in offset.
458 {
459  if( ( strncmp( output.data() + offset, "pub", 3 ) != 0 ) &&
460  ( strncmp( output.data() + offset, "sec", 3 ) != 0 ) )
461  {
462  kDebug( 5326 ) <<"Unknown key type or corrupt key data.";
463  return 0;
464  }
465 
466  if( key == 0 )
467  key = new Key();
468  else
469  key->clear();
470 
471  Subkey *subkey = 0;
472  bool primaryKey = true;
473 
474  while( true )
475  {
476  int eol;
477 
478  // search the end of the current line
479  eol = output.indexOf( '\n', offset );
480  if( ( eol == -1 ) || ( eol == offset ) )
481  break;
482 
483  //kDebug( 5326 ) <<"Parsing:" << output.mid(offset, eol-offset);
484 
485  if( !strncmp( output.data() + offset, "pub", 3 ) ||
486  !strncmp( output.data() + offset, "sec", 3 ) ||
487  !strncmp( output.data() + offset, "sub", 3 ) )
488  { // line contains key data
489  //kDebug( 5326 )<<"Key data:";
490  int pos, pos2;
491 
492  subkey = new Subkey( "", false );
493  key->addSubkey( subkey );
494 
495  // Key Flags
496  /* From the PGP 5 manual page for pgpk:
497  Following this column is a single character which
498  describes other attributes of the object:
499 
500  @ The object is disabled
501  + The object is axiomatically trusted (i.e., it's
502  your key)
503  */
504  switch( output[offset+3] )
505  {
506  case ' ': // nothing special
507  break;
508  case '@': // disabled key
509  subkey->setDisabled( true );
510  key->setDisabled( true );
511  break;
512  default: // all other flags are ignored
513  //kDebug( 5326 ) <<"Unknown key flag.";
514  ;
515  }
516 
517  // Key Length
518  pos = offset + 4;
519  while( output[pos] == ' ' )
520  pos++;
521  pos2 = output.indexOf( ' ', pos );
522  subkey->setKeyLength( output.mid( pos, pos2-pos ).toUInt() );
523  //kDebug( 5326 ) <<"Key Length:"<<subkey->keyLength();
524 
525  // Key ID
526  pos = pos2 + 1;
527  while( output[pos] == ' ' )
528  pos++;
529  pos += 2; // skip the '0x'
530  pos2 = output.indexOf( ' ', pos );
531  subkey->setKeyID( output.mid( pos, pos2-pos ) );
532  //kDebug( 5326 ) <<"Key ID:"<<subkey->keyID();
533 
534  // Creation Date
535  pos = pos2 + 1;
536  while( output[pos] == ' ' )
537  pos++;
538  pos2 = output.indexOf( ' ', pos );
539  int year = output.mid( pos, 4 ).toInt();
540  int month = output.mid( pos+5, 2 ).toInt();
541  int day = output.mid( pos+8, 2 ).toInt();
542  QDateTime dt( QDate( year, month, day ), QTime( 00, 00 ) );
543  QDateTime epoch( QDate( 1970, 01, 01 ), QTime( 00, 00 ) );
544  // The calculated creation date isn't exactly correct because QDateTime
545  // doesn't know anything about timezones and always assumes local time
546  // although epoch is of course UTC. But as PGP 5 anyway doesn't print
547  // the time this doesn't matter too much.
548  subkey->setCreationDate( epoch.secsTo( dt ) );
549 
550  // Expiration Date
551  // if the primary key has been revoked the expiration date is not printed
552  if( primaryKey || !key->revoked() )
553  {
554  pos = pos2 + 1;
555  while( output[pos] == ' ' )
556  pos++;
557  pos2 = output.indexOf( ' ', pos );
558  if( output[pos] == '-' )
559  { // key doesn't expire
560  subkey->setExpirationDate( -1 );
561  }
562  else if( !strncmp( output.data() + pos, "*REVOKED*", 9 ) )
563  { // key has been revoked
564  subkey->setRevoked( true );
565  key->setRevoked( true );
566  }
567  else
568  {
569  int year = output.mid( pos, 4 ).toInt();
570  int month = output.mid( pos+5, 2 ).toInt();
571  int day = output.mid( pos+8, 2 ).toInt();
572  QDateTime dt( QDate( year, month, day ), QTime( 00, 00 ) );
573  subkey->setCreationDate( epoch.secsTo( dt ) );
574  // has the key already expired?
575  if( QDateTime::currentDateTime() >= dt )
576  {
577  subkey->setExpired( true );
578  key->setExpired( true );
579  }
580  }
581  }
582  else if( key->revoked() )
583  subkey->setRevoked( true );
584 
585  // Key algorithm (RSA, DSS, Diffie-Hellman)
586  bool sign = false;
587  bool encr = false;
588  pos = pos2 + 1;
589  while( output[pos] == ' ' )
590  pos++;
591  pos2 = output.indexOf( ' ', pos );
592  if( !strncmp( output.data() + pos, "RSA", 3 ) )
593  {
594  sign = true;
595  encr = true;
596  }
597  else if( !strncmp( output.data() + pos, "DSS", 3 ) )
598  sign = true;
599  else if( !strncmp( output.data() + pos, "Diffie-Hellman", 14 ) )
600  encr = true;
601  else
602  kDebug( 5326 )<<"Unknown key algorithm";
603 
604  // set key capabilities of the subkey
605  subkey->setCanEncrypt( encr );
606  subkey->setCanSign( sign );
607  subkey->setCanCertify( sign );
608 
609  if( primaryKey )
610  {
611  // Global key capabilities
612  bool canSign = false;
613  bool canEncr = false;
614  pos = pos2 + 1;
615  while( output[pos] == ' ' )
616  pos++;
617  pos2 = eol;
618  if( !strncmp( output.data() + pos, "Sign & Encrypt", 14 ) )
619  {
620  canSign = true;
621  canEncr = true;
622  }
623  else if( !strncmp( output.data() + pos, "Sign only", 9 ) )
624  canSign = true;
625  else if( !strncmp( output.data() + pos, "Encrypt only", 12 ) )
626  canEncr = true;
627  else
628  kDebug( 5326 )<<"Unknown key capability";
629 
630  // set the global key capabilities
631  if( !key->expired() && !key->revoked() )
632  {
633  key->setCanEncrypt( canEncr );
634  key->setCanSign( canSign );
635  key->setCanCertify( canSign );
636  }
637  //kDebug( 5326 )<<"Key capabilities:"<<(key->canEncrypt()?"E":"")<<(key->canSign()?"SC":"");
638  primaryKey = false;
639  }
640  }
641  else if( !strncmp( output.data() + offset, "f16", 3 ) ||
642  !strncmp( output.data() + offset, "f20", 3 ) )
643  { // line contains a fingerprint
644  /* Examples:
645  f16 Fingerprint16 = DE 2A 77 08 78 64 7C 42 72 75 B1 A7 3E 42 3F 79
646  f20 Fingerprint20 = 226F 4B63 6DA2 7389 91D1 2A49 D58A 3EC1 5214 181E
647 
648  */
649  int pos = output.indexOf( '=', offset+3 ) + 2;
650  QByteArray fingerprint = output.mid( pos, eol-pos );
651  // remove white space from the fingerprint
652  for ( int idx = 0 ; (idx = fingerprint.indexOf(' ', idx)) != -1 ; )
653  fingerprint.replace( idx, 1, "" );
654  assert( subkey != 0 );
655  subkey->setFingerprint( fingerprint );
656  //kDebug( 5326 )<<"Fingerprint:"<<fingerprint;
657  }
658  else if( !strncmp( output.data() + offset, "uid", 3 ) )
659  { // line contains a uid
660  int pos = offset+5;
661  QByteArray uid = output.mid( pos, eol-pos );
662  key->addUserID( QLatin1String(uid) );
663  // displaying of uids which contain non-ASCII characters is broken in
664  // PGP 5.0i; it shows these characters as \ooo and truncates the uid
665  // because it doesn't take the 3 extra characters per non-ASCII char
666  // into account. Example (with an UTF-8 encoded &ouml;):
667  // uid Ingo Kl\303\266cker <ingo.kloecker@epo
668  // because of this and because we anyway don't know which charset was
669  // used to encode the uid we don't try to decode it
670  }
671  else if ( !strncmp( output.data() + offset, "sig", 3 ) ||
672  !strncmp( output.data() + offset, "SIG", 3 ) ||
673  !strncmp( output.data() + offset, "ret", 3 ) )
674  { // line contains a signature
675  // SIG = sig with own key; ret = sig with revoked key
676  // we ignore it for now
677  }
678 
679  offset = eol + 1;
680  }
681 
682  return key;
683 }
684 
685 
686 Key*
687 Base5::parseSingleKey( const QByteArray& output, Key* key /* = 0 */ )
688 {
689  int offset;
690 
691  // search start of header line
692  if( !strncmp( output.data(), "Type Bits", 9 ) )
693  offset = 0;
694  else
695  {
696  offset = output.indexOf( "\nType Bits" ) + 1;
697  if( offset == 0 )
698  return 0;
699  }
700 
701  // key data begins in the next line
702  offset = output.indexOf( '\n', offset ) + 1;
703  if( offset == -1 )
704  return 0;
705 
706  key = parseKeyData( output, offset, key );
707 
708  //kDebug( 5326 ) <<"finished parsing keys";
709 
710  return key;
711 }
712 
713 
714 KeyList
715 Base5::parseKeyList( const QByteArray& output, bool onlySecretKeys )
716 {
717  KeyList keys;
718  Key *key = 0;
719  int offset;
720 
721  // search start of header line
722  if( !strncmp( output.data(), "Type Bits", 9 ) )
723  offset = 0;
724  else
725  {
726  offset = output.indexOf( "\nType Bits" ) + 1;
727  if( offset == 0 )
728  return keys;
729  }
730 
731  // key data begins in the next line
732  offset = output.indexOf( '\n', offset ) + 1;
733  if( offset == -1 )
734  return keys;
735 
736  do
737  {
738  key = parseKeyData( output, offset );
739  if( key != 0 )
740  {
741  // if only secret keys should be read test if the key is secret
742  if( !onlySecretKeys || !key->secret() )
743  keys.append( key );
744  // skip the blank line which separates the keys
745  offset++;
746  }
747  }
748  while( key != 0 );
749 
750  //kDebug( 5326 ) <<"finished parsing keys";
751 
752  return keys;
753 }
754 
755 
756 void
757 Base5::parseTrustDataForKey( Key* key, const QByteArray& str )
758 {
759  if( ( key == 0 ) || str.isEmpty() )
760  return;
761 
762  QByteArray keyID = "0x" + key->primaryKeyID();
763  UserIDList userIDs = key->userIDs();
764 
765  // search the start of the trust data
766  int offset = str.indexOf( "\n\n KeyID" ) + 9;
767  if( offset == -1 + 9 )
768  return;
769 
770  offset = str.indexOf( '\n', offset ) + 1;
771  if( offset == -1 + 1 )
772  return;
773 
774  bool ultimateTrust = false;
775  if( !strncmp( str.data() + offset+13, "ultimate", 8 ) )
776  ultimateTrust = true;
777 
778  while( true )
779  { // loop over all trust information about this key
780 
781  int eol;
782 
783  // search the end of the current line
784  if( ( eol = str.indexOf( '\n', offset ) ) == -1 )
785  break;
786 
787  if( str[offset+23] != ' ' )
788  { // line contains a validity value for a user ID
789 
790  // determine the validity
791  Validity validity = KPGP_VALIDITY_UNKNOWN;
792  if( !strncmp( str.data() + offset+23, "complete", 8 ) )
793  if( ultimateTrust )
794  validity = KPGP_VALIDITY_ULTIMATE;
795  else
796  validity = KPGP_VALIDITY_FULL;
797  else if( !strncmp( str.data() + offset+23, "marginal", 8 ) )
798  validity = KPGP_VALIDITY_MARGINAL;
799  else if( !strncmp( str.data() + offset+23, "invalid", 7 ) )
800  validity = KPGP_VALIDITY_UNDEFINED;
801 
802  // determine the user ID
803  int pos = offset + 33;
804  QString uid = QLatin1String(str.mid( pos, eol-pos ));
805 
806  // set the validity of the corresponding user ID
807  for( UserIDList::Iterator it = userIDs.begin(); it != userIDs.end(); ++it )
808  if( (*it)->text() == uid )
809  {
810  kDebug( 5326 )<<"Setting the validity of"<<uid<<" to"<<validity;
811  (*it)->setValidity( validity );
812  break;
813  }
814  }
815 
816  offset = eol + 1;
817  }
818 }
819 
820 
821 } // 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
QByteArray::toInt
int toInt(bool *ok, int base) const
Kpgp::Block::setSignatureDate
void setSignatureDate(const QByteArray &date)
Definition: kpgpblock.h:278
Kpgp::Base5::publicKeys
virtual KeyList publicKeys(const QStringList &patterns=QStringList())
Returns the list of public keys in the users public keyring.
Definition: kpgpbase5.cpp:353
QByteArray::trimmed
QByteArray trimmed() const
Kpgp::Module::encryptToSelf
bool encryptToSelf(void) const
Definition: kpgp.cpp:173
QByteArray
Kpgp::Base::output
QByteArray output
Definition: kpgpbase.h:97
Kpgp::NO_SEC_KEY
Definition: kpgpblock.h:56
Kpgp::Module::user
const KeyID user() const
Returns the actual key ID of the currently set key.
Definition: kpgp.cpp:160
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
Kpgp::Base5::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: kpgpbase5.cpp:319
QByteArray::isEmpty
bool isEmpty() const
Kpgp::KPGP_VALIDITY_FULL
Definition: kpgpkey.h:38
Kpgp::Block
Definition: kpgpblock.h:89
Kpgp::Base5::secretKeys
virtual KeyList secretKeys(const QStringList &patterns=QStringList())
Returns the list of secret keys in the users secret keyring.
Definition: kpgpbase5.cpp:386
Kpgp::Base5::getAsciiPublicKey
virtual QByteArray getAsciiPublicKey(const KeyID &keyID)
Returns the ascii armored data of the public key with the given key id.
Definition: kpgpbase5.cpp:413
Kpgp::Base::addUserId
QByteArray addUserId()
Definition: kpgpbase.cpp:688
QByteArray::length
int length() const
Kpgp::Base::errMsg
QString errMsg
Definition: kpgpbase.h:99
QTime
Kpgp::BADPHRASE
Definition: kpgpblock.h:54
Kpgp::Module::getKpgp
static Kpgp::Module * getKpgp()
return the actual pgp object
Definition: kpgp.cpp:1067
Kpgp::Base5::signKey
virtual int signKey(const KeyID &keyID, const char *passphrase)
Signs the given key with the currently set user key.
Definition: kpgpbase5.cpp:431
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
Kpgp::Key::revoked
bool revoked() const
Returns true if the key has been revoked.
Definition: kpgpkey.h:692
QString::fromLocal8Bit
QString fromLocal8Bit(const char *str, int size)
Kpgp::KeyCompare
bool KeyCompare(Key *left, Key *right)
Definition: kpgpkey.h:845
Kpgp::Base::run
virtual int run(const char *cmd, const char *passphrase=0, bool onlyReadFromPGP=false)
Definition: kpgpbase.cpp:67
Kpgp::Block::setSignatureUserId
void setSignatureUserId(const QString &userId)
Definition: kpgpblock.h:254
kpgpbase.h
Kpgp::Base5::~Base5
virtual ~Base5()
Definition: kpgpbase5.cpp:44
QList::isEmpty
bool isEmpty() const
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::Key::expired
bool expired() const
Returns true if the key has expired.
Definition: kpgpkey.h:697
QList< UserID * >::Iterator
typedef Iterator
Kpgp::BADKEYS
Definition: kpgpblock.h:55
QDate
QByteArray::truncate
void truncate(int pos)
Kpgp::KPGP_VALIDITY_UNDEFINED
Definition: kpgpkey.h:35
QString
QList
Kpgp::KeyIDList
Definition: kpgpkey.h:57
Kpgp::ENCRYPTED
Definition: kpgpblock.h:49
Kpgp::OK
Definition: kpgpblock.h:46
QByteArray::mid
QByteArray mid(int pos, int len) const
Kpgp::UserIDList
QList< UserID * > UserIDList
Definition: kpgpkey.h:138
QStringList
Kpgp::Base5::clearsign
virtual int clearsign(Block &block, const char *passphrase)
Clearsigns the message with the currently set key.
Definition: kpgpbase5.cpp:57
Kpgp::Base5::encsign
virtual int encsign(Block &block, const KeyIDList &recipients, const char *passphrase=0)
Encrypts and signs the message with the given keys.
Definition: kpgpbase5.cpp:64
QByteArray::append
QByteArray & append(char ch)
QList::end
iterator end()
Kpgp::KPGP_VALIDITY_MARGINAL
Definition: kpgpkey.h:37
Kpgp::Base5::Base5
Base5()
Definition: kpgpbase5.cpp:38
QDateTime::currentDateTime
QDateTime currentDateTime()
Kpgp::Block::setSignatureKeyId
void setSignatureKeyId(const QByteArray &keyId)
Definition: kpgpblock.h:266
Kpgp::MISSINGKEY
Definition: kpgpblock.h:57
Kpgp::Block::text
QByteArray text() const
Definition: kpgpblock.h:193
QLatin1String
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
Definition: kpgpbase.h:30
Kpgp::Base::input
QByteArray input
Definition: kpgpbase.h:96
Kpgp::Key::setExpired
void setExpired(const bool expired)
Sets the flag if the key has expired to expired .
Definition: kpgpkey.h:737
Kpgp::Base5::encrypt
virtual int encrypt(Block &block, const KeyIDList &recipients)
Encrypts the message with the given keys.
Definition: kpgpbase5.cpp:50
Kpgp::Block::setProcessedText
void setProcessedText(const QByteArray &str)
Definition: kpgpblock.h:209
QList< KeyID >::ConstIterator
typedef ConstIterator
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::Base5::decrypt
virtual int decrypt(Block &block, const char *passphrase=0)
Decrypts the message.
Definition: kpgpbase5.cpp:195
Kpgp::ERROR
Definition: kpgpblock.h:48
Kpgp::KPGP_VALIDITY_UNKNOWN
Definition: kpgpkey.h:34
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.h
QList::constEnd
const_iterator constEnd() const
QList::constBegin
const_iterator constBegin() const
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
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