28#include <tqdatetime.h> 
   49Base6::decrypt( Block& block, 
const TQString &passphrase )
 
   56  exitStatus = run( PGP6 
" +batchmode +language=C -f", passphrase);
 
   57  if( !output.isEmpty() )
 
   58    block.setProcessedText( output );
 
   59  block.setError( error );
 
   61  if(exitStatus == -1) {
 
   62    errMsg = i18n(
"error running PGP");
 
   64    block.setStatus( status );
 
   69  if( error.find(
"File is encrypted.") != -1)
 
   73    if((index = error.find(
"Key for user ID")) != -1)
 
   76      index  = error.find(
':', index) + 2;
 
   77      index2 = error.find(
'\n', index);
 
   78      block.setRequiredUserId( error.mid(index, index2 - index) );
 
   85      if (!passphrase || !output.length())
 
   87    errMsg = i18n(
"Bad passphrase; could not decrypt.");
 
   93    else if( error.find(
"You do not have the secret key needed to decrypt this file.") != -1)
 
   95      errMsg = i18n(
"You do not have the secret key for this message.");
 
  126  if(((index = error.find(
"File is signed.")) != -1)
 
  127    || (error.find(
"Good signature") != -1 ))
 
  132    if( ( index2 = error.find( 
"Signature made", index ) ) != -1 )
 
  135      int eol = error.find( 
'\n', index2 );
 
  136      block.setSignatureDate( error.mid( index2, eol-index2 ) );
 
  137      kdDebug(5100) << 
"Message was signed on '" << block.signatureDate() << 
"'\n";
 
  140      block.setSignatureDate( TQCString() );
 
  142    if( error.find(
"signature not checked") != -1)
 
  144      index = error.find(
"KeyID:",index);
 
  145      block.setSignatureKeyId( error.mid(index+9,8) );
 
  146      block.setSignatureUserId( TQString() );
 
  147      status |= UNKNOWN_SIG;
 
  150    else if((index = error.find(
"Good signature")) != -1 )
 
  154      index = error.find(
'"',index)+1;
 
  155      index2 = error.find(
'"', index);
 
  156      block.setSignatureUserId( error.mid(index, index2-index) );
 
  159      index = error.find(
"KeyID:",index2);
 
  161        block.setSignatureKeyId( TQCString() );
 
  163        block.setSignatureKeyId( error.mid(index+9,8) );
 
  165    else if( error.find(
"Can't find the right public key") != -1 )
 
  170      status |= UNKNOWN_SIG;
 
  172      block.setSignatureUserId( i18n(
"??? (file ~/.pgp/pubring.pkr not found)") );
 
  173      block.setSignatureKeyId( 
"???" );
 
  178      block.setSignatureUserId( TQString() );
 
  179      block.setSignatureKeyId( TQCString() );
 
  183  block.setStatus( status );
 
  189Base6::readPublicKey( 
const KeyID& keyID,
 
  190                      const bool readTrust ,
 
  196  exitStatus = run( PGP6 
" +batchmode -compatible +verbose=0 +language=C -kvvc " 
  197                    "0x" + keyID, 0, 
true );
 
  199  if(exitStatus != 0) {
 
  204  key = parseSingleKey( output, key );
 
  213    exitStatus = run( PGP6 
" +batchmode -compatible +verbose=0 +language=C -kc " 
  214                      "0x" + keyID, 0, 
true );
 
  216    if(exitStatus != 0) {
 
  221    parseTrustDataForKey( key, output );
 
  229Base6::publicKeys( 
const TQStringList & patterns )
 
  231  return doGetPublicKeys( PGP6 
" +batchmode -compatible +verbose=0 " 
  232                          "+language=C -kvvc", patterns );
 
  346Base6::secretKeys( 
const TQStringList & patterns )
 
  348  return publicKeys( patterns );
 
  357  exitStatus = run( PGP6, 0, 
true );
 
  359  if(exitStatus == -1) {
 
  360    errMsg = i18n(
"error running PGP");
 
  365  if( error.find(
"Version 6") != -1)
 
  377Base6::parseKeyData( 
const TQCString& output, 
int& offset, Key* key  )
 
  384  if( ( strncmp( output.data() + offset, 
"DSS", 3 ) != 0 ) &&
 
  385      ( strncmp( output.data() + offset, 
"RSA", 3 ) != 0 ) )
 
  387    kdDebug(5100) << 
"Unknown key type or corrupt key data.\n";
 
  392  bool firstLine = 
true;
 
  393  bool canSign = 
false;
 
  394  bool canEncr = 
false;
 
  402    if( ( eol = output.find( 
'\n', offset ) ) == -1 )
 
  407    if( firstLine && ( !strncmp( output.data() + offset, 
"DSS", 3 ) ||
 
  408                       !strncmp( output.data() + offset, 
"RSA", 3 ) ) )
 
  431      if( !strncmp( output.data() + offset, 
"DSS", 3 ) )
 
  433      if( !strncmp( output.data() + offset, 
"RSA", 3 ) )
 
  446      subkey = 
new Subkey( 
"", 
false );
 
  447      key->addSubkey( subkey );
 
  449      subkey->setExpirationDate( -1 );
 
  452      switch( output[offset+3] )
 
  457        subkey->setDisabled( 
true );
 
  458        key->setDisabled( 
true );
 
  461        kdDebug(5100) << 
"Unknown key flag.\n";
 
  466      while( output[pos] == 
' ' )
 
  468      pos2 = output.find( 
' ', pos );
 
  469      subkey->setKeyLength( output.mid( pos, pos2-pos ).toUInt() );
 
  474      while( output[pos] == 
' ' )
 
  477      pos2 = output.find( 
' ', pos );
 
  478      subkey->setKeyID( output.mid( pos, pos2-pos ) );
 
  483      while( output[pos] == 
' ' )
 
  485      pos2 = output.find( 
' ', pos );
 
  486      int year = output.mid( pos, 4 ).toInt();
 
  487      int month = output.mid( pos+5, 2 ).toInt();
 
  488      int day = output.mid( pos+8, 2 ).toInt();
 
  489      TQDateTime dt( TQDate( year, month, day ), TQTime( 00, 00 ) );
 
  490      TQDateTime epoch( TQDate( 1970, 01, 01 ), TQTime( 00, 00 ) );
 
  495      subkey->setCreationDate( epoch.secsTo( dt ) );
 
  499      while( output[pos] == 
' ' )
 
  503        if( !strncmp( output.data() + pos, 
"*** KEY REVOKED ***", 19 ) )
 
  507          subkey->setRevoked( 
true );
 
  508          key->setRevoked( 
true );
 
  512        else if( !strncmp( output.data() + pos, 
"*** KEY EXPIRED ***", 19 ) )
 
  516          subkey->setExpired( 
true );
 
  517          key->setExpired( 
true );
 
  521        else if( !strncmp( output.data() + pos, 
"expires ", 8 ) )
 
  524          int year = output.mid( pos, 4 ).toInt();
 
  525          int month = output.mid( pos+5, 2 ).toInt();
 
  526          int day = output.mid( pos+8, 2 ).toInt();
 
  527          TQDateTime dt( TQDate( year, month, day ), TQTime( 00, 00 ) );
 
  529          subkey->setExpirationDate( epoch.secsTo( dt ) );
 
  533        else if( !strncmp( output.data() + pos, 
"*** DEFAULT SIGNING KEY ***", 27 ) )
 
  540          TQCString uid = output.mid( pos, eol-pos );
 
  541          key->addUserID( uid );
 
  547      subkey->setCanEncrypt( encr );
 
  548      subkey->setCanSign( sign );
 
  549      subkey->setCanCertify( sign );
 
  554    else if( !strncmp( output.data() + offset, 
"DSS", 3 ) ||
 
  555             !strncmp( output.data() + offset, 
" DH", 3 ) ||
 
  556             !strncmp( output.data() + offset, 
"RSA", 3 ) )
 
  569      if( !strncmp( output.data() + offset, 
"DSS", 3 ) )
 
  571      if( !strncmp( output.data() + offset, 
" DH", 3 ) )
 
  573      if( !strncmp( output.data() + offset, 
"RSA", 3 ) )
 
  583      while( output[pos] == 
' ' )
 
  585      pos2 = output.find( 
' ', pos );
 
  589      while( output[pos] == 
' ' )
 
  591      pos2 = output.find( 
' ', pos );
 
  595      while( output[pos] == 
' ' )
 
  597      pos2 = output.find( 
' ', pos );
 
  601      while( output[pos] == 
' ' )
 
  605        if( !strncmp( output.data() + pos, 
"*** KEY REVOKED ***", 19 ) )
 
  612        else if( !strncmp( output.data() + pos, 
"*** KEY EXPIRED ***", 19 ) )
 
  619        else if( !strncmp( output.data() + pos, 
"expires ", 8 ) )
 
  624        else if( !strncmp( output.data() + pos, 
"*** DEFAULT SIGNING KEY ***", 27 ) )
 
  631          TQCString uid = output.mid( pos, eol-pos );
 
  632          key->addUserID( uid );
 
  638      canSign = canSign || sign;
 
  639      canEncr = canEncr || encr;
 
  641    else if( !strncmp( output.data() + offset, 
"Unknown type", 12 ) )
 
  643      kdDebug(5100)<<
"Unknown key type.\n";
 
  645    else if( output[offset] == 
' ' )
 
  651      int pos = offset + 1;
 
  652      while( output[pos] == 
' ' )
 
  655      if( !strncmp( output.data() + pos, 
"Key fingerprint = ", 18 ) )
 
  663        TQCString fingerprint = output.mid( pos, eol-pos );
 
  665    for ( 
int idx = 0 ; (idx = fingerprint.find(
' ', idx)) >= 0 ; )
 
  666      fingerprint.replace( idx, 1, 
"" );
 
  669        assert( subkey != 0 );
 
  670        subkey->setFingerprint( fingerprint );
 
  678        key->addUserID( output.mid( pos, eol-pos ) );
 
  681    else if( !strncmp( output.data() + offset, 
"sig", 3 ) )
 
  695    key->setCanEncrypt( canEncr );
 
  696    key->setCanSign( canSign );
 
  697    key->setCanCertify( canSign );
 
  706Base6::parseSingleKey( 
const TQCString& output, Key* key  )
 
  711  if( !strncmp( output.data(), 
"Type bits", 9 ) )
 
  715    offset = output.find( 
"\nType bits" );
 
  723  offset = output.find( 
'\n', offset ) + 1;
 
  727  key = parseKeyData( output, offset, key );
 
  736Base6::parseKeyList( 
const TQCString& output, 
bool secretKeys )
 
  738  kdDebug(5100) << 
"Kpgp::Base6::parseKeyList()" << endl;
 
  744  if( !strncmp( output.data(), 
"Type bits", 9 ) )
 
  748    offset = output.find( 
"\nType bits" ) + 1;
 
  754  offset = output.find( 
'\n', offset ) + 1;
 
  760    key = parseKeyData( output, offset );
 
  763      key->setSecret( secretKeys );
 
  776Base6::parseTrustDataForKey( Key* key, 
const TQCString& str )
 
  778  if( ( key == 0 ) || str.isEmpty() )
 
  781  TQCString keyID = 
"0x" + key->primaryKeyID();
 
  782  UserIDList userIDs = key->userIDs();
 
  785  int offset = str.find( 
"\n\n  KeyID" );
 
  789  offset = str.find( 
'\n', offset ) + 1;
 
  793  bool ultimateTrust = 
false;
 
  794  if( !strncmp( str.data() + offset+13, 
"ultimate", 8 ) )
 
  795    ultimateTrust = 
true;
 
  803    if( ( eol = str.find( 
'\n', offset ) ) == -1 )
 
  806    if( str[offset+23] != 
' ' )
 
  810      Validity validity = KPGP_VALIDITY_UNKNOWN;
 
  811      if( !strncmp( str.data() + offset+23, 
"complete", 8 ) )
 
  813          validity = KPGP_VALIDITY_ULTIMATE;
 
  815          validity = KPGP_VALIDITY_FULL;
 
  816      else if( !strncmp( str.data() + offset+23, 
"marginal", 8 ) )
 
  817        validity = KPGP_VALIDITY_MARGINAL;
 
  818      else if( !strncmp( str.data() + offset+23, 
"invalid", 7 ) )
 
  819        validity = KPGP_VALIDITY_UNDEFINED;
 
  822      int pos = offset + 33;
 
  823      TQString uid = str.mid( pos, eol-pos );
 
  826      for( UserIDListIterator it( userIDs ); it.current(); ++it )
 
  827        if( (*it)->text() == uid )
 
  829          kdDebug(5100)<<
"Setting the validity of "<<uid<<
" to "<<validity<<endl;
 
  830          (*it)->setValidity( validity );