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> |
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 ) |
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 ) |
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 |
} |
} |
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 |
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--; |
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 ); |