/[winpt]/trunk/Gnupg/parse-packet.c
ViewVC logotype

Diff of /trunk/Gnupg/parse-packet.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 309 by twoaday, Sat Apr 7 11:07:07 2007 UTC revision 313 by twoaday, Sun May 13 09:43:51 2007 UTC
# Line 21  Line 21 
21  #ifdef HAVE_CONFIG_H  #ifdef HAVE_CONFIG_H
22  #include <config.h>  #include <config.h>
23  #endif  #endif
   
 #include <stdio.h>  
24  #include <stdio.h>  #include <stdio.h>
25  #include <stdlib.h>  #include <stdlib.h>
26  #include <string.h>  #include <string.h>
# Line 105  buffer_to_u32( const unsigned char *buff Line 103  buffer_to_u32( const unsigned char *buff
103      return a;      return a;
104  }  }
105    
106    int
107    set_packet_list_mode( int mode )
108    {
109        int old = list_mode;
110        list_mode = mode;
111        mpi_print_mode = 0;
112        return old;
113    }
114    
115  static void  static void
116  unknown_pubkey_warning( int algo )  unknown_pubkey_warning( int algo )
# Line 117  unknown_pubkey_warning( int algo ) Line 123  unknown_pubkey_warning( int algo )
123      }      }
124  }  }
125    
 static const char *  
 strtimestamp( unsigned long stamp )  
 {  
     static char buffer[11+5];  
     struct tm *tp;  
     time_t atime = stamp;  
       
     if (atime < 0) {  
         strcpy (buffer, "????" "-??" "-??");  
     }  
     else {  
         tp = gmtime( &atime );  
         sprintf(buffer,"%04d-%02d-%02d",  
                 1900+tp->tm_year, tp->tm_mon+1, tp->tm_mday );  
     }  
     return buffer;  
 }  
   
 static const char *  
 strtimevalue( unsigned long value )  
 {  
     static char buffer[30];  
     unsigned int years, days, hours, minutes;  
       
     value /= 60;  
     minutes = value % 60;  
     value /= 60;  
     hours = value % 24;  
     value /= 24;  
     days = value % 365;  
     value /= 365;  
     years = value;  
       
     sprintf(buffer,"%uy%ud%uh%um", years, days, hours, minutes );  
     if( years )  
         return buffer;  
     if( days )  
         return strchr( buffer, 'y' ) + 1;  
     return strchr( buffer, 'd' ) + 1;  
 }  
   
126    
127  static gpg_mpi_t  static gpg_mpi_t
128  mpi_read( gpg_iobuf_t inp, size_t *ret_n, int flags )  mpi_read( gpg_iobuf_t inp, size_t *ret_n, int flags )
# Line 735  parse( gpg_iobuf_t inp, PACKET *pkt, int Line 700  parse( gpg_iobuf_t inp, PACKET *pkt, int
700          /* with a some probability this is caused by a problem in the          /* with a some probability this is caused by a problem in the
701           * the uncompressing layer - in some error cases it just loops           * the uncompressing layer - in some error cases it just loops
702           * and spits out 0xff bytes. */           * and spits out 0xff bytes. */
703          /*printf ("%s: garbled packet detected\n", gpg_iobuf_where(inp));*/          printf ("%s: garbled packet detected\n", gpg_iobuf_where(inp) );
704          rc = G10ERR_INVALID_PACKET;          rc = G10ERR_INVALID_PACKET;
705          goto leave;          goto leave;
706      }      }
# Line 1078  leave: Line 1043  leave:
1043      return rc;      return rc;
1044  }  }
1045    
 static void  
 dump_sig_subpkt( int hashed, int type, int critical,  
                  const byte *buffer, size_t buflen, size_t length )  
 {  
     const char *p=NULL;  
     int i;  
       
     /* The CERT has warning out with explains how to use GNUPG to  
      * detect the ARRs - we print our old message here when it is a faked  
      * ARR and add an additional notice */  
     if ( type == SIGSUBPKT_ARR && !hashed ) {  
         printf("\tsubpkt %d len %u (additional recipient request)\n"  
                "WARNING: PGP versions > 5.0 and < 6.5.8 will automagically "  
                "encrypt to this key and thereby reveal the plaintext to "  
                "the owner of this ARR key. Detailed info follows:\n",  
                type, (unsigned)length );  
     }  
       
       
     printf("\t%s%ssubpkt %d len %u (", /*)*/  
            critical ? "critical ":"",  
            hashed ? "hashed ":"", type, (unsigned)length );  
     buffer++;  
     length--;  
     if( length > buflen ) {  
         printf("too short: buffer is only %u)\n", (unsigned)buflen );  
         return;  
     }  
     switch( type ) {  
     case SIGSUBPKT_SIG_CREATED:  
         if( length >= 4 )  
             printf("sig created %s", strtimestamp( buffer_to_u32(buffer) ) );  
         break;  
     case SIGSUBPKT_SIG_EXPIRE:  
         if( length >= 4 )  
             printf("sig expires after %s",  
                    strtimevalue( buffer_to_u32(buffer) ) );  
         break;  
     case SIGSUBPKT_EXPORTABLE:  
         if( length )  
             printf("%sexportable", *buffer? "":"not ");  
         break;  
     case SIGSUBPKT_TRUST:  
         if(length!=2)  
             p="[invalid trust signature]";  
         else  
             printf("trust signature of level %d, amount %d",buffer[0],buffer[1]);  
         break;  
     case SIGSUBPKT_REGEXP:  
         if(!length)  
             p="[invalid regexp]";  
         else  
             printf("regular expression: \"%s\"",buffer);  
         break;  
     case SIGSUBPKT_REVOCABLE:  
         if( length )  
             printf("%srevocable", *buffer? "":"not ");  
         break;  
     case SIGSUBPKT_KEY_EXPIRE:  
         if( length >= 4 )  
             printf("key expires after %s",  
                    strtimevalue( buffer_to_u32(buffer) ) );  
         break;  
     case SIGSUBPKT_PREF_SYM:  
         fputs("pref-sym-algos:", stdout );  
         for( i=0; i < length; i++ )  
             printf(" %d", buffer[i] );  
         break;  
     case SIGSUBPKT_REV_KEY:  
         fputs("revocation key: ", stdout );  
         if( length < 22 )  
             p = "[too short]";  
         else {  
             printf("c=%02x a=%d f=", buffer[0], buffer[1] );  
             for( i=2; i < length; i++ )  
                 printf("%02X", buffer[i] );  
         }  
         break;  
     case SIGSUBPKT_ISSUER:  
         if( length >= 8 )  
             printf("issuer key ID %08lX%08lX",  
                    (ulong)buffer_to_u32(buffer),  
                    (ulong)buffer_to_u32(buffer+4) );  
         break;  
     case SIGSUBPKT_NOTATION:  
     {  
         fputs("notation: ", stdout );  
         if( length < 8 )  
             p = "[too short]";  
         else if( !(*buffer & 0x80) )  
             p = "[not human readable]";  
         else {  
             const byte *s = buffer;  
             size_t n1, n2;  
               
             n1 = (s[4] << 8) | s[5];  
             n2 = (s[6] << 8) | s[7];  
             s += 8;  
             if( 8+n1+n2 != length )  
                 p = "[error]";  
             else {  
                 print_string( stdout, s, n1, ')' );  
                 putc( '=', stdout );  
                 print_string( stdout, s+n1, n2, ')' );  
             }  
         }  
     }  
     break;  
     case SIGSUBPKT_PREF_HASH:  
         fputs("pref-hash-algos:", stdout );  
         for( i=0; i < length; i++ )  
             printf(" %d", buffer[i] );  
         break;  
     case SIGSUBPKT_PREF_COMPR:  
         fputs("pref-zip-algos:", stdout );  
         for( i=0; i < length; i++ )  
             printf(" %d", buffer[i] );  
         break;  
     case SIGSUBPKT_KS_FLAGS:  
         fputs("key server preferences:",stdout);  
         for(i=0;i<length;i++)  
             printf(" %02X", buffer[i]);  
         break;  
     case SIGSUBPKT_PREF_KS:  
         p = "preferred key server";  
         break;  
     case SIGSUBPKT_PRIMARY_UID:  
         p = "primary user ID";  
         break;  
     case SIGSUBPKT_POLICY:  
         fputs("policy: ", stdout );  
         print_string( stdout, buffer, length, ')' );  
         break;  
     case SIGSUBPKT_KEY_FLAGS:  
         fputs ( "key flags:", stdout );  
         for( i=0; i < length; i++ )  
             printf(" %02X", buffer[i] );  
         break;  
     case SIGSUBPKT_SIGNERS_UID:  
         p = "signer's user ID";  
         break;  
     case SIGSUBPKT_REVOC_REASON:  
         if( length ) {  
             printf("revocation reason 0x%02x (", *buffer );  
             print_string( stdout, buffer+1, length-1, ')' );  
             p = ")";  
         }  
         break;  
     case SIGSUBPKT_ARR:  
         fputs("Big Brother's key (ignored): ", stdout );  
         if( length < 22 )  
             p = "[too short]";  
         else {  
             printf("c=%02x a=%d f=", buffer[0], buffer[1] );  
             for( i=2; i < length; i++ )  
                 printf("%02X", buffer[i] );  
         }  
         break;  
     case SIGSUBPKT_FEATURES:  
         fputs ( "features:", stdout );  
         for( i=0; i < length; i++ )  
             printf(" %02x", buffer[i] );  
         break;  
     case SIGSUBPKT_PRIV_VERIFY_CACHE:  
         p = "obsolete verification cache";  
         break;  
     default: p = "?"; break;  
     }  
       
     printf("%s)\n", p? p: "");  
 }  
1046    
1047  /****************  /****************
1048   * Returns: >= 0 offset into buffer   * Returns: >= 0 offset into buffer
# Line 1414  enum_sig_subpkt( const subpktarea_t *pkt Line 1208  enum_sig_subpkt( const subpktarea_t *pkt
1208                  }                  }
1209              }              }
1210          }          }
         else if( reqtype < 0 ) /* list packets */  
             dump_sig_subpkt( reqtype == SIGSUBPKT_LIST_HASHED,  
                              type, *critical, buffer, buflen, n );  
1211          else if( type == reqtype ) { /* found */          else if( type == reqtype ) { /* found */
1212              buffer++;              buffer++;
1213              n--;              n--;
# Line 2683  gpg_keyid_from_pk( PKT_public_key * pk, Line 2474  gpg_keyid_from_pk( PKT_public_key * pk,
2474    
2475    
2476  u32  u32
2477  gpg_keyid_from_sk( PKT_secret_key * sk, byte *fprint )  gpg_keyid_from_sk (PKT_secret_key * sk, byte *fprint)
2478  {  {
2479      PKT_public_key pk;      PKT_public_key pk;
2480      int npkey = pubkey_get_npkey( sk->pubkey_algo );      int npkey = pubkey_get_npkey( sk->pubkey_algo );

Legend:
Removed from v.309  
changed lines
  Added in v.313

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26