mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
added some trust model stuff
This commit is contained in:
parent
1ce26aa6d6
commit
4ec1775f3e
@ -45,8 +45,8 @@ CONFIG_HEADER_IN = config.h.in
|
|||||||
mkinstalldirs = $(top_srcdir)/scripts/mkinstalldirs
|
mkinstalldirs = $(top_srcdir)/scripts/mkinstalldirs
|
||||||
CONFIG_HEADER = ./config.h
|
CONFIG_HEADER = ./config.h
|
||||||
DIST_COMMON = README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
|
DIST_COMMON = README AUTHORS COPYING ChangeLog INSTALL Makefile.am \
|
||||||
Makefile.in NEWS README TODO acconfig.h config.h.in configure.in \
|
Makefile.in NEWS README TODO acconfig.h config.h.in configure \
|
||||||
stamp-h.in
|
configure.in stamp-h.in
|
||||||
|
|
||||||
|
|
||||||
PACKAGE = @PACKAGE@
|
PACKAGE = @PACKAGE@
|
||||||
|
11
NEWS
11
NEWS
@ -1,4 +1,15 @@
|
|||||||
|
|
||||||
|
* New option "--quick-random" which uses a much quicker random
|
||||||
|
number generator. Keys generated while this option is in effect
|
||||||
|
are flags with "INSECURE!" in the user-id. This is a development
|
||||||
|
only option.
|
||||||
|
|
||||||
|
* Read support for new version packets (OpenPGP).
|
||||||
|
|
||||||
|
* Comment packets are now of coorect OpenPGP type 16. Old comment
|
||||||
|
packets writen by G10 are detected because they always start with
|
||||||
|
a hash which is an invalid version byte.
|
||||||
|
|
||||||
* The string "(INSECURE!)" is appended to a new user-id if this
|
* The string "(INSECURE!)" is appended to a new user-id if this
|
||||||
is generated on a system without a good random number generator.
|
is generated on a system without a good random number generator.
|
||||||
|
|
||||||
|
@ -412,7 +412,7 @@ selftest()
|
|||||||
void
|
void
|
||||||
blowfish_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
|
blowfish_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
|
||||||
{
|
{
|
||||||
int i, j, k;
|
int i, j;
|
||||||
u32 data, datal, datar;
|
u32 data, datal, datar;
|
||||||
static int initialized;
|
static int initialized;
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ md_read( MD_HANDLE a, int algo )
|
|||||||
if( algo == DIGEST_ALGO_MD5 )
|
if( algo == DIGEST_ALGO_MD5 )
|
||||||
return md5_read( &a->md5 );
|
return md5_read( &a->md5 );
|
||||||
}
|
}
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -73,7 +73,6 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static void Init( MD5_CONTEXT *mdContext);
|
|
||||||
static void Transform(u32 *buf,u32 *in);
|
static void Transform(u32 *buf,u32 *in);
|
||||||
|
|
||||||
static byte PADDING[64] = {
|
static byte PADDING[64] = {
|
||||||
|
@ -67,7 +67,7 @@ string_to_cipher_algo( const char *string )
|
|||||||
int i;
|
int i;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
for(i=0; s=cipher_names[i].name; i++ )
|
for(i=0; (s=cipher_names[i].name); i++ )
|
||||||
if( !stricmp( s, string ) )
|
if( !stricmp( s, string ) )
|
||||||
return cipher_names[i].algo;
|
return cipher_names[i].algo;
|
||||||
return 0;
|
return 0;
|
||||||
@ -83,7 +83,7 @@ string_to_pubkey_algo( const char *string )
|
|||||||
int i;
|
int i;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
for(i=0; s=pubkey_names[i].name; i++ )
|
for(i=0; (s=pubkey_names[i].name); i++ )
|
||||||
if( !stricmp( s, string ) )
|
if( !stricmp( s, string ) )
|
||||||
return pubkey_names[i].algo;
|
return pubkey_names[i].algo;
|
||||||
return 0;
|
return 0;
|
||||||
@ -98,7 +98,7 @@ string_to_digest_algo( const char *string )
|
|||||||
int i;
|
int i;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
for(i=0; s=digest_names[i].name; i++ )
|
for(i=0; (s=digest_names[i].name); i++ )
|
||||||
if( !stricmp( s, string ) )
|
if( !stricmp( s, string ) )
|
||||||
return digest_names[i].algo;
|
return digest_names[i].algo;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -319,8 +319,6 @@ check_prime( MPI prime )
|
|||||||
int i;
|
int i;
|
||||||
unsigned x;
|
unsigned x;
|
||||||
int count=0;
|
int count=0;
|
||||||
MPI result;
|
|
||||||
MPI val_2;
|
|
||||||
|
|
||||||
/* check against small primes */
|
/* check against small primes */
|
||||||
for(i=0; (x = small_prime_numbers[i]); i++ ) {
|
for(i=0; (x = small_prime_numbers[i]); i++ ) {
|
||||||
@ -431,7 +429,7 @@ m_out_of_n( char *array, int m, int n )
|
|||||||
array[i] = 1;
|
array[i] = 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(j=1; j < n; j++ ) {
|
for(j=1; j < n; j++ ) {
|
||||||
|
@ -30,6 +30,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "cipher.h"
|
#include "cipher.h"
|
||||||
|
#include "ttyio.h"
|
||||||
|
|
||||||
struct cache {
|
struct cache {
|
||||||
int len;
|
int len;
|
||||||
@ -41,6 +42,18 @@ static struct cache cache[3];
|
|||||||
|
|
||||||
|
|
||||||
static void fill_buffer( byte *buffer, size_t length, int level );
|
static void fill_buffer( byte *buffer, size_t length, int level );
|
||||||
|
static int quick_test;
|
||||||
|
|
||||||
|
|
||||||
|
int
|
||||||
|
quick_random_gen( int onoff )
|
||||||
|
{
|
||||||
|
int last = quick_test;
|
||||||
|
if( onoff != -1 )
|
||||||
|
quick_test = onoff;
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
* Fill the buffer with LENGTH bytes of cryptologic strong
|
* Fill the buffer with LENGTH bytes of cryptologic strong
|
||||||
@ -95,14 +108,13 @@ open_device( const char *name, int minor )
|
|||||||
static void
|
static void
|
||||||
fill_buffer( byte *buffer, size_t length, int level )
|
fill_buffer( byte *buffer, size_t length, int level )
|
||||||
{
|
{
|
||||||
FILE *fp;
|
|
||||||
static int fd_urandom = -1;
|
static int fd_urandom = -1;
|
||||||
static int fd_random = -1;
|
static int fd_random = -1;
|
||||||
int fd;
|
int fd;
|
||||||
int n;
|
int n;
|
||||||
int warn=0;
|
int warn=0;
|
||||||
|
|
||||||
if( level == 2 ) {
|
if( level == 2 && !quick_test ) {
|
||||||
if( fd_random == -1 )
|
if( fd_random == -1 )
|
||||||
fd_random = open_device( "/dev/random", 8 );
|
fd_random = open_device( "/dev/random", 8 );
|
||||||
fd = fd_random;
|
fd = fd_random;
|
||||||
|
@ -19,8 +19,8 @@ AC_ARG_ENABLE(m-debug,
|
|||||||
[ --enable-m-debug Enable debugging of memory allocation])
|
[ --enable-m-debug Enable debugging of memory allocation])
|
||||||
if test "$enableval" = y || test "$enableval" = yes; then
|
if test "$enableval" = y || test "$enableval" = yes; then
|
||||||
AC_DEFINE(M_DEBUG)
|
AC_DEFINE(M_DEBUG)
|
||||||
CFLAGS=-g
|
|
||||||
fi
|
fi
|
||||||
|
CFLAGS="-g -Wall"
|
||||||
|
|
||||||
dnl some additional macros
|
dnl some additional macros
|
||||||
|
|
||||||
|
@ -40,6 +40,7 @@ g10_SOURCES = g10.c \
|
|||||||
seckey-cert.c \
|
seckey-cert.c \
|
||||||
seskey.c \
|
seskey.c \
|
||||||
sign.c \
|
sign.c \
|
||||||
|
import.c \
|
||||||
comment.c \
|
comment.c \
|
||||||
sig-check.c
|
sig-check.c
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ g10_SOURCES = g10.c \
|
|||||||
seckey-cert.c \
|
seckey-cert.c \
|
||||||
seskey.c \
|
seskey.c \
|
||||||
sign.c \
|
sign.c \
|
||||||
|
import.c \
|
||||||
comment.c \
|
comment.c \
|
||||||
sig-check.c
|
sig-check.c
|
||||||
|
|
||||||
@ -103,7 +104,8 @@ g10_OBJECTS = g10.o build-packet.o compress.o encode.o encr-data.o \
|
|||||||
free-packet.o getkey.o pkclist.o skclist.o ringedit.o kbnode.o keygen.o \
|
free-packet.o getkey.o pkclist.o skclist.o ringedit.o kbnode.o keygen.o \
|
||||||
mainproc.o armor.o mdfilter.o textfilter.o cipher.o elg.o rsa.o \
|
mainproc.o armor.o mdfilter.o textfilter.o cipher.o elg.o rsa.o \
|
||||||
openfile.o keyid.o trustdb.o parse-packet.o passphrase.o plaintext.o \
|
openfile.o keyid.o trustdb.o parse-packet.o passphrase.o plaintext.o \
|
||||||
pubkey-enc.o seckey-cert.o seskey.o sign.o comment.o sig-check.o
|
pubkey-enc.o seckey-cert.o seskey.o sign.o import.o comment.o \
|
||||||
|
sig-check.o
|
||||||
EXTRA_g10_SOURCES =
|
EXTRA_g10_SOURCES =
|
||||||
g10_LDADD = $(LDADD)
|
g10_LDADD = $(LDADD)
|
||||||
DIST_COMMON = Makefile.am Makefile.in
|
DIST_COMMON = Makefile.am Makefile.in
|
||||||
@ -123,17 +125,17 @@ $(srcdir)/.deps/cipher.P $(srcdir)/.deps/comment.P \
|
|||||||
$(srcdir)/.deps/compress.P $(srcdir)/.deps/elg.P \
|
$(srcdir)/.deps/compress.P $(srcdir)/.deps/elg.P \
|
||||||
$(srcdir)/.deps/encode.P $(srcdir)/.deps/encr-data.P \
|
$(srcdir)/.deps/encode.P $(srcdir)/.deps/encr-data.P \
|
||||||
$(srcdir)/.deps/free-packet.P $(srcdir)/.deps/g10.P \
|
$(srcdir)/.deps/free-packet.P $(srcdir)/.deps/g10.P \
|
||||||
$(srcdir)/.deps/getkey.P $(srcdir)/.deps/kbnode.P \
|
$(srcdir)/.deps/getkey.P $(srcdir)/.deps/import.P \
|
||||||
$(srcdir)/.deps/keygen.P $(srcdir)/.deps/keyid.P \
|
$(srcdir)/.deps/kbnode.P $(srcdir)/.deps/keygen.P \
|
||||||
$(srcdir)/.deps/mainproc.P $(srcdir)/.deps/mdfilter.P \
|
$(srcdir)/.deps/keyid.P $(srcdir)/.deps/mainproc.P \
|
||||||
$(srcdir)/.deps/openfile.P $(srcdir)/.deps/parse-packet.P \
|
$(srcdir)/.deps/mdfilter.P $(srcdir)/.deps/openfile.P \
|
||||||
$(srcdir)/.deps/passphrase.P $(srcdir)/.deps/pkclist.P \
|
$(srcdir)/.deps/parse-packet.P $(srcdir)/.deps/passphrase.P \
|
||||||
$(srcdir)/.deps/plaintext.P $(srcdir)/.deps/pubkey-enc.P \
|
$(srcdir)/.deps/pkclist.P $(srcdir)/.deps/plaintext.P \
|
||||||
$(srcdir)/.deps/ringedit.P $(srcdir)/.deps/rsa.P \
|
$(srcdir)/.deps/pubkey-enc.P $(srcdir)/.deps/ringedit.P \
|
||||||
$(srcdir)/.deps/seckey-cert.P $(srcdir)/.deps/seskey.P \
|
$(srcdir)/.deps/rsa.P $(srcdir)/.deps/seckey-cert.P \
|
||||||
$(srcdir)/.deps/sig-check.P $(srcdir)/.deps/sign.P \
|
$(srcdir)/.deps/seskey.P $(srcdir)/.deps/sig-check.P \
|
||||||
$(srcdir)/.deps/skclist.P $(srcdir)/.deps/textfilter.P \
|
$(srcdir)/.deps/sign.P $(srcdir)/.deps/skclist.P \
|
||||||
$(srcdir)/.deps/trustdb.P
|
$(srcdir)/.deps/textfilter.P $(srcdir)/.deps/trustdb.P
|
||||||
SOURCES = $(g10_SOURCES)
|
SOURCES = $(g10_SOURCES)
|
||||||
OBJECTS = $(g10_OBJECTS)
|
OBJECTS = $(g10_OBJECTS)
|
||||||
|
|
||||||
|
15
g10/armor.c
15
g10/armor.c
@ -275,7 +275,7 @@ check_input( armor_filter_context_t *afx, IOBUF a )
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int c;
|
int c;
|
||||||
size_t n = 0, nn=0, nn_limit=0;
|
size_t n = 0, nn=0;
|
||||||
struct fhdr_struct fhdr;
|
struct fhdr_struct fhdr;
|
||||||
|
|
||||||
assert( DIM(afx->helpbuf) >= 50 );
|
assert( DIM(afx->helpbuf) >= 50 );
|
||||||
@ -339,7 +339,7 @@ fake_packet( armor_filter_context_t *afx, IOBUF a,
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
int c;
|
int c;
|
||||||
size_t n = 0, nn=0, nn_limit=0;
|
size_t n = 0;
|
||||||
struct fhdr_struct *fhdr = afx->fake;
|
struct fhdr_struct *fhdr = afx->fake;
|
||||||
byte *helpbuf = afx->helpbuf;
|
byte *helpbuf = afx->helpbuf;
|
||||||
int helpidx = afx->helpidx;
|
int helpidx = afx->helpidx;
|
||||||
@ -347,7 +347,6 @@ fake_packet( armor_filter_context_t *afx, IOBUF a,
|
|||||||
byte *tempbuf = afx->tempbuf;
|
byte *tempbuf = afx->tempbuf;
|
||||||
int tempidx = afx->tempidx;
|
int tempidx = afx->tempidx;
|
||||||
int templen = afx->templen;
|
int templen = afx->templen;
|
||||||
int defer=1;
|
|
||||||
|
|
||||||
/* FIXME: have to read one ahead or do some other mimic to
|
/* FIXME: have to read one ahead or do some other mimic to
|
||||||
* get rid of the lf before the "begin signed message"
|
* get rid of the lf before the "begin signed message"
|
||||||
@ -417,7 +416,7 @@ radix64_read( armor_filter_context_t *afx, IOBUF a, size_t *retn,
|
|||||||
int c, c2;
|
int c, c2;
|
||||||
int checkcrc=0;
|
int checkcrc=0;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
size_t n = 0, nn=0;
|
size_t n = 0;
|
||||||
int idx, i;
|
int idx, i;
|
||||||
u32 crc;
|
u32 crc;
|
||||||
|
|
||||||
@ -450,7 +449,7 @@ radix64_read( armor_filter_context_t *afx, IOBUF a, size_t *retn,
|
|||||||
idx = (idx+1) % 4;
|
idx = (idx+1) % 4;
|
||||||
}
|
}
|
||||||
for(i=0; i < n; i++ )
|
for(i=0; i < n; i++ )
|
||||||
crc = (crc << 8) ^ crc_table[(crc >> 16)&0xff ^ buf[i]];
|
crc = (crc << 8) ^ crc_table[((crc >> 16)&0xff) ^ buf[i]];
|
||||||
crc &= 0x00ffffff;
|
crc &= 0x00ffffff;
|
||||||
afx->crc = crc;
|
afx->crc = crc;
|
||||||
afx->idx = idx;
|
afx->idx = idx;
|
||||||
@ -533,7 +532,7 @@ armor_filter( void *opaque, int control,
|
|||||||
{
|
{
|
||||||
size_t size = *ret_len;
|
size_t size = *ret_len;
|
||||||
armor_filter_context_t *afx = opaque;
|
armor_filter_context_t *afx = opaque;
|
||||||
int rc=0, i, c, c2;
|
int rc=0, i, c;
|
||||||
byte radbuf[3];
|
byte radbuf[3];
|
||||||
int idx, idx2;
|
int idx, idx2;
|
||||||
size_t n=0;
|
size_t n=0;
|
||||||
@ -553,7 +552,7 @@ armor_filter( void *opaque, int control,
|
|||||||
}
|
}
|
||||||
else if( control == IOBUFCTRL_UNDERFLOW ) {
|
else if( control == IOBUFCTRL_UNDERFLOW ) {
|
||||||
if( size < 20 )
|
if( size < 20 )
|
||||||
log_bug(NULL); /* supplied buffer maybe too short */
|
BUG(); /* supplied buffer maybe too short */
|
||||||
|
|
||||||
if( afx->inp_eof ) {
|
if( afx->inp_eof ) {
|
||||||
*ret_len = 0;
|
*ret_len = 0;
|
||||||
@ -608,7 +607,7 @@ armor_filter( void *opaque, int control,
|
|||||||
radbuf[i] = afx->radbuf[i];
|
radbuf[i] = afx->radbuf[i];
|
||||||
|
|
||||||
for(i=0; i < size; i++ )
|
for(i=0; i < size; i++ )
|
||||||
crc = (crc << 8) ^ crc_table[(crc >> 16)&0xff ^ buf[i]];
|
crc = (crc << 8) ^ crc_table[((crc >> 16)&0xff) ^ buf[i]];
|
||||||
crc &= 0x00ffffff;
|
crc &= 0x00ffffff;
|
||||||
|
|
||||||
for( ; size; buf++, size-- ) {
|
for( ; size; buf++, size-- ) {
|
||||||
|
@ -50,7 +50,8 @@ static int calc_header_length( u32 len );
|
|||||||
static int write_16(IOBUF inp, u16 a);
|
static int write_16(IOBUF inp, u16 a);
|
||||||
static int write_32(IOBUF inp, u32 a);
|
static int write_32(IOBUF inp, u32 a);
|
||||||
static int write_header( IOBUF out, int ctb, u32 len );
|
static int write_header( IOBUF out, int ctb, u32 len );
|
||||||
static int write_header2( IOBUF out, int ctb, u32 len, int blkmode );
|
static int write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode );
|
||||||
|
static int write_new_header( IOBUF out, int ctb, u32 len, int hdrlen );
|
||||||
static int write_version( IOBUF out, int ctb );
|
static int write_version( IOBUF out, int ctb );
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
@ -67,7 +68,10 @@ build_packet( IOBUF out, PACKET *pkt )
|
|||||||
if( DBG_PACKET )
|
if( DBG_PACKET )
|
||||||
log_debug("build_packet() type=%d\n", pkt->pkttype );
|
log_debug("build_packet() type=%d\n", pkt->pkttype );
|
||||||
assert( pkt->pkt.generic );
|
assert( pkt->pkt.generic );
|
||||||
ctb = 0x80 | ((pkt->pkttype & 15)<<2);
|
if( pkt->pkttype > 15 ) /* new format */
|
||||||
|
ctb = 0xc0 | (pkt->pkttype & 0x3f);
|
||||||
|
else
|
||||||
|
ctb = 0x80 | ((pkt->pkttype & 15)<<2);
|
||||||
switch( pkt->pkttype ) {
|
switch( pkt->pkttype ) {
|
||||||
case PKT_USER_ID:
|
case PKT_USER_ID:
|
||||||
rc = do_user_id( out, ctb, pkt->pkt.user_id );
|
rc = do_user_id( out, ctb, pkt->pkt.user_id );
|
||||||
@ -164,7 +168,10 @@ do_public_cert( IOBUF out, int ctb, PKT_public_cert *pkc )
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
IOBUF a = iobuf_temp();
|
IOBUF a = iobuf_temp();
|
||||||
|
|
||||||
write_version( a, ctb );
|
if( !pkc->version )
|
||||||
|
iobuf_put( a, 3 );
|
||||||
|
else
|
||||||
|
iobuf_put( a, pkc->version );
|
||||||
write_32(a, pkc->timestamp );
|
write_32(a, pkc->timestamp );
|
||||||
write_16(a, pkc->valid_days );
|
write_16(a, pkc->valid_days );
|
||||||
iobuf_put(a, pkc->pubkey_algo );
|
iobuf_put(a, pkc->pubkey_algo );
|
||||||
@ -182,7 +189,7 @@ do_public_cert( IOBUF out, int ctb, PKT_public_cert *pkc )
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_header(out, ctb, iobuf_get_temp_length(a) );
|
write_header2(out, ctb, iobuf_get_temp_length(a), pkc->hdrbytes, 1 );
|
||||||
if( iobuf_write_temp( out, a ) )
|
if( iobuf_write_temp( out, a ) )
|
||||||
rc = G10ERR_WRITE_FILE;
|
rc = G10ERR_WRITE_FILE;
|
||||||
|
|
||||||
@ -202,6 +209,7 @@ hash_public_cert( MD_HANDLE md, PKT_public_cert *pkc )
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
int c;
|
int c;
|
||||||
IOBUF a = iobuf_temp();
|
IOBUF a = iobuf_temp();
|
||||||
|
FILE *fp = fopen("dump.pkc", "a");
|
||||||
|
|
||||||
/* build the packet */
|
/* build the packet */
|
||||||
init_packet(&pkt);
|
init_packet(&pkt);
|
||||||
@ -209,9 +217,11 @@ hash_public_cert( MD_HANDLE md, PKT_public_cert *pkc )
|
|||||||
pkt.pkt.public_cert = pkc;
|
pkt.pkt.public_cert = pkc;
|
||||||
if( (rc = build_packet( a, &pkt )) )
|
if( (rc = build_packet( a, &pkt )) )
|
||||||
log_fatal("build public_cert for hashing failed: %s\n", g10_errstr(rc));
|
log_fatal("build public_cert for hashing failed: %s\n", g10_errstr(rc));
|
||||||
while( (c=iobuf_get(a)) != -1 )
|
while( (c=iobuf_get(a)) != -1 ) {
|
||||||
|
putc( c, fp);
|
||||||
md_putc( md, c );
|
md_putc( md, c );
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
iobuf_cancel(a);
|
iobuf_cancel(a);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,7 +232,10 @@ do_secret_cert( IOBUF out, int ctb, PKT_secret_cert *skc )
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
IOBUF a = iobuf_temp();
|
IOBUF a = iobuf_temp();
|
||||||
|
|
||||||
write_version( a, ctb );
|
if( !skc->version )
|
||||||
|
iobuf_put( a, 3 );
|
||||||
|
else
|
||||||
|
iobuf_put( a, skc->version );
|
||||||
write_32(a, skc->timestamp );
|
write_32(a, skc->timestamp );
|
||||||
write_16(a, skc->valid_days );
|
write_16(a, skc->valid_days );
|
||||||
iobuf_put(a, skc->pubkey_algo );
|
iobuf_put(a, skc->pubkey_algo );
|
||||||
@ -262,7 +275,7 @@ do_secret_cert( IOBUF out, int ctb, PKT_secret_cert *skc )
|
|||||||
goto leave;
|
goto leave;
|
||||||
}
|
}
|
||||||
|
|
||||||
write_header(out, ctb, iobuf_get_temp_length(a) );
|
write_header2(out, ctb, iobuf_get_temp_length(a), skc->hdrbytes, 1 );
|
||||||
if( iobuf_write_temp( out, a ) )
|
if( iobuf_write_temp( out, a ) )
|
||||||
rc = G10ERR_WRITE_FILE;
|
rc = G10ERR_WRITE_FILE;
|
||||||
|
|
||||||
@ -365,7 +378,7 @@ do_compressed( IOBUF out, int ctb, PKT_compressed *cd )
|
|||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
/* we must use the old convention and don't use blockmode */
|
/* we must use the old convention and don't use blockmode */
|
||||||
write_header2(out, ctb, 0, 0 );
|
write_header2(out, ctb, 0, 0, 0 );
|
||||||
iobuf_put(out, cd->algorithm );
|
iobuf_put(out, cd->algorithm );
|
||||||
|
|
||||||
/* This is all. The caller has to write the real data */
|
/* This is all. The caller has to write the real data */
|
||||||
@ -433,7 +446,6 @@ do_onepass_sig( IOBUF out, int ctb, PKT_onepass_sig *ops )
|
|||||||
if( iobuf_write_temp( out, a ) )
|
if( iobuf_write_temp( out, a ) )
|
||||||
rc = G10ERR_WRITE_FILE;
|
rc = G10ERR_WRITE_FILE;
|
||||||
|
|
||||||
leave:
|
|
||||||
iobuf_close(a);
|
iobuf_close(a);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -482,20 +494,39 @@ calc_header_length( u32 len )
|
|||||||
static int
|
static int
|
||||||
write_header( IOBUF out, int ctb, u32 len )
|
write_header( IOBUF out, int ctb, u32 len )
|
||||||
{
|
{
|
||||||
return write_header2( out, ctb, len, 1 );
|
return write_header2( out, ctb, len, 0, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************
|
||||||
|
* if HDRLEN is > 0, try to build a header of this length.
|
||||||
|
* we need this, so hat we can hash packets without reading them again.
|
||||||
|
*/
|
||||||
static int
|
static int
|
||||||
write_header2( IOBUF out, int ctb, u32 len, int blkmode )
|
write_header2( IOBUF out, int ctb, u32 len, int hdrlen, int blkmode )
|
||||||
{
|
{
|
||||||
if( !len )
|
if( ctb & 0x40 )
|
||||||
ctb |= 3;
|
return write_new_header( out, ctb, len, hdrlen );
|
||||||
else if( len < 256 )
|
|
||||||
;
|
if( hdrlen ) {
|
||||||
else if( len < 65536 )
|
if( !len )
|
||||||
ctb |= 1;
|
ctb |= 3;
|
||||||
else
|
else if( hdrlen == 2 && len < 256 )
|
||||||
ctb |= 2;
|
;
|
||||||
|
else if( hdrlen == 3 && len < 65536 )
|
||||||
|
ctb |= 1;
|
||||||
|
else
|
||||||
|
ctb |= 2;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( !len )
|
||||||
|
ctb |= 3;
|
||||||
|
else if( len < 256 )
|
||||||
|
;
|
||||||
|
else if( len < 65536 )
|
||||||
|
ctb |= 1;
|
||||||
|
else
|
||||||
|
ctb |= 2;
|
||||||
|
}
|
||||||
if( iobuf_put(out, ctb ) )
|
if( iobuf_put(out, ctb ) )
|
||||||
return -1;
|
return -1;
|
||||||
if( !len ) {
|
if( !len ) {
|
||||||
@ -515,6 +546,36 @@ write_header2( IOBUF out, int ctb, u32 len, int blkmode )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
write_new_header( IOBUF out, int ctb, u32 len, int hdrlen )
|
||||||
|
{
|
||||||
|
if( hdrlen )
|
||||||
|
log_bug("can't cope with hdrlen yet\n");
|
||||||
|
|
||||||
|
if( iobuf_put(out, ctb ) )
|
||||||
|
return -1;
|
||||||
|
if( !len ) {
|
||||||
|
log_bug("can't write partial headers yet\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if( len < 192 ) {
|
||||||
|
if( iobuf_put(out, len ) )
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else if( len < 8384 ) {
|
||||||
|
len -= 192;
|
||||||
|
if( iobuf_put( out, (len / 256) + 192) )
|
||||||
|
return -1;
|
||||||
|
if( iobuf_put( out, (len % 256) ) )
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
log_bug("need a partial header to code a length %lu\n", (ulong)len);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
write_version( IOBUF out, int ctb )
|
write_version( IOBUF out, int ctb )
|
||||||
{
|
{
|
||||||
|
@ -41,7 +41,6 @@ static void
|
|||||||
init_compress( compress_filter_context_t *zfx, z_stream *zs )
|
init_compress( compress_filter_context_t *zfx, z_stream *zs )
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
byte *inbuf, *outbuf;
|
|
||||||
int level;
|
int level;
|
||||||
|
|
||||||
|
|
||||||
@ -102,9 +101,6 @@ static void
|
|||||||
init_uncompress( compress_filter_context_t *zfx, z_stream *zs )
|
init_uncompress( compress_filter_context_t *zfx, z_stream *zs )
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
byte *inbuf, *outbuf;
|
|
||||||
int level;
|
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
* PGP uses a windowsize of 13 bits. Using a negative value for
|
* PGP uses a windowsize of 13 bits. Using a negative value for
|
||||||
@ -175,7 +171,7 @@ compress_filter( void *opaque, int control,
|
|||||||
size_t size = *ret_len;
|
size_t size = *ret_len;
|
||||||
compress_filter_context_t *zfx = opaque;
|
compress_filter_context_t *zfx = opaque;
|
||||||
z_stream *zs = zfx->opaque;
|
z_stream *zs = zfx->opaque;
|
||||||
int zrc, rc=0;
|
int rc=0;
|
||||||
|
|
||||||
if( control == IOBUFCTRL_UNDERFLOW ) {
|
if( control == IOBUFCTRL_UNDERFLOW ) {
|
||||||
if( !zfx->status ) {
|
if( !zfx->status ) {
|
||||||
|
@ -265,7 +265,7 @@ encrypt_filter( void *opaque, int control,
|
|||||||
int rc=0;
|
int rc=0;
|
||||||
|
|
||||||
if( control == IOBUFCTRL_UNDERFLOW ) { /* decrypt */
|
if( control == IOBUFCTRL_UNDERFLOW ) { /* decrypt */
|
||||||
log_bug(NULL); /* not used */
|
BUG(); /* not used */
|
||||||
}
|
}
|
||||||
else if( control == IOBUFCTRL_FLUSH ) { /* encrypt */
|
else if( control == IOBUFCTRL_FLUSH ) { /* encrypt */
|
||||||
if( !efx->header_okay ) {
|
if( !efx->header_okay ) {
|
||||||
@ -317,7 +317,7 @@ write_pubkey_enc_from_list( PKC_LIST pkc_list, DEK *dek, IOBUF out )
|
|||||||
else if( enc->pubkey_algo == PUBKEY_ALGO_RSA )
|
else if( enc->pubkey_algo == PUBKEY_ALGO_RSA )
|
||||||
g10_rsa_encrypt( pkc, enc, dek );
|
g10_rsa_encrypt( pkc, enc, dek );
|
||||||
else
|
else
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
/* and write it */
|
/* and write it */
|
||||||
init_packet(&pkt);
|
init_packet(&pkt);
|
||||||
pkt.pkttype = PKT_PUBKEY_ENC;
|
pkt.pkttype = PKT_PUBKEY_ENC;
|
||||||
|
69
g10/g10.c
69
g10/g10.c
@ -22,6 +22,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "packet.h"
|
#include "packet.h"
|
||||||
@ -35,11 +36,13 @@
|
|||||||
#include "cipher.h"
|
#include "cipher.h"
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
#include "trustdb.h"
|
#include "trustdb.h"
|
||||||
|
#include "ttyio.h"
|
||||||
|
|
||||||
enum cmd_values { aNull = 0,
|
enum cmd_values { aNull = 0,
|
||||||
aSym, aStore, aEncr, aPrimegen, aKeygen, aSign, aSignEncr,
|
aSym, aStore, aEncr, aPrimegen, aKeygen, aSign, aSignEncr,
|
||||||
aPrintMDs, aSignKey, aClearsig, aListPackets, aEditSig,
|
aPrintMDs, aSignKey, aClearsig, aListPackets, aEditSig,
|
||||||
aKMode, aKModeC, aChangePass,
|
aKMode, aKModeC, aChangePass, aImport, aListTrustDB,
|
||||||
|
aListTrustPath,
|
||||||
aTest };
|
aTest };
|
||||||
|
|
||||||
|
|
||||||
@ -88,6 +91,15 @@ strusage( int level )
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
wrong_args( const char *text)
|
||||||
|
{
|
||||||
|
fputs("Usage: g10 [options] ",stderr);
|
||||||
|
fputs(text,stderr);
|
||||||
|
putc('\n',stderr);
|
||||||
|
exit(2);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
set_debug(void)
|
set_debug(void)
|
||||||
{
|
{
|
||||||
@ -174,11 +186,15 @@ main( int argc, char **argv )
|
|||||||
{ 527, "cipher-algo", 2 , "select default cipher algorithm" },
|
{ 527, "cipher-algo", 2 , "select default cipher algorithm" },
|
||||||
{ 528, "pubkey-algo", 2 , "select default puplic key algorithm" },
|
{ 528, "pubkey-algo", 2 , "select default puplic key algorithm" },
|
||||||
{ 529, "digest-algo", 2 , "select default message digest algorithm" },
|
{ 529, "digest-algo", 2 , "select default message digest algorithm" },
|
||||||
|
{ 530, "import", 0 , "put public keys into the trustdb" },
|
||||||
|
{ 531, "list-trustdb",0 , "\r"},
|
||||||
|
{ 532, "quick-random", 0, "\r"},
|
||||||
|
{ 533, "list-trust-path",0, "\r"},
|
||||||
|
|
||||||
{0} };
|
{0} };
|
||||||
ARGPARSE_ARGS pargs;
|
ARGPARSE_ARGS pargs;
|
||||||
IOBUF a;
|
IOBUF a;
|
||||||
int rc;
|
int rc=0;
|
||||||
int orig_argc;
|
int orig_argc;
|
||||||
char **orig_argv;
|
char **orig_argv;
|
||||||
const char *fname, *fname_print;
|
const char *fname, *fname_print;
|
||||||
@ -316,9 +332,10 @@ main( int argc, char **argv )
|
|||||||
case 529:
|
case 529:
|
||||||
opt.def_digest_algo = string_to_digest_algo(pargs.r.ret_str);
|
opt.def_digest_algo = string_to_digest_algo(pargs.r.ret_str);
|
||||||
break;
|
break;
|
||||||
|
case 530: set_cmd( &cmd, aImport); break;
|
||||||
|
case 531: set_cmd( &cmd, aListTrustDB); break;
|
||||||
break;
|
case 532: quick_random_gen(1); break;
|
||||||
|
case 533: set_cmd( &cmd, aListTrustPath); break;
|
||||||
default : errors++; pargs.err = configfp? 1:2; break;
|
default : errors++; pargs.err = configfp? 1:2; break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -393,11 +410,15 @@ main( int argc, char **argv )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( cmd != aPrimegen && cmd != aPrintMDs ) {
|
switch( cmd ) {
|
||||||
rc = check_trustdb(0);
|
case aPrimegen:
|
||||||
if( rc )
|
case aPrintMDs:
|
||||||
log_error("failed to initialize the TrustDB: %s\n", g10_errstr(rc));
|
break;
|
||||||
|
case aListTrustDB: rc = init_trustdb( argc? 1:0 ); break;
|
||||||
|
default: rc = init_trustdb(1); break;
|
||||||
}
|
}
|
||||||
|
if( rc )
|
||||||
|
log_error("failed to initialize the TrustDB: %s\n", g10_errstr(rc));
|
||||||
|
|
||||||
|
|
||||||
switch( cmd ) {
|
switch( cmd ) {
|
||||||
@ -487,7 +508,7 @@ main( int argc, char **argv )
|
|||||||
int i, seq=0;
|
int i, seq=0;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
while( s=get_keyring(seq++) ) {
|
while( (s=get_keyring(seq++)) ) {
|
||||||
if( !(a = iobuf_open(s)) ) {
|
if( !(a = iobuf_open(s)) ) {
|
||||||
log_error("can't open '%s'\n", s);
|
log_error("can't open '%s'\n", s);
|
||||||
continue;
|
continue;
|
||||||
@ -554,6 +575,32 @@ main( int argc, char **argv )
|
|||||||
|
|
||||||
case aTest: do_test( argc? atoi(*argv): 0 ); break;
|
case aTest: do_test( argc? atoi(*argv): 0 ); break;
|
||||||
|
|
||||||
|
case aImport:
|
||||||
|
if( !argc )
|
||||||
|
usage(1);
|
||||||
|
for( ; argc; argc--, argv++ ) {
|
||||||
|
rc = import_pubkeys( *argv );
|
||||||
|
if( rc )
|
||||||
|
log_error("import from '%s' failed: %s\n",
|
||||||
|
*argv, g10_errstr(rc) );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case aListTrustDB:
|
||||||
|
if( !argc )
|
||||||
|
list_trustdb(NULL);
|
||||||
|
else {
|
||||||
|
for( ; argc; argc--, argv++ )
|
||||||
|
list_trustdb( *argv );
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case aListTrustPath:
|
||||||
|
if( argc != 2 )
|
||||||
|
wrong_args("--list-trust-path <maxdepth> <username>");
|
||||||
|
list_trust_path( atoi(*argv), argv[1] );
|
||||||
|
break;
|
||||||
|
|
||||||
case aListPackets:
|
case aListPackets:
|
||||||
opt.list_packets=1;
|
opt.list_packets=1;
|
||||||
default:
|
default:
|
||||||
@ -631,8 +678,6 @@ print_mds( const char *fname )
|
|||||||
if( ferror(fp) )
|
if( ferror(fp) )
|
||||||
log_error("%s: %s\n", fname, strerror(errno) );
|
log_error("%s: %s\n", fname, strerror(errno) );
|
||||||
else {
|
else {
|
||||||
byte *p;
|
|
||||||
|
|
||||||
md_final(md);
|
md_final(md);
|
||||||
printf( "%s: MD5 =", fname ); print_hex(md_read(md, DIGEST_ALGO_MD5), 16 );
|
printf( "%s: MD5 =", fname ); print_hex(md_read(md, DIGEST_ALGO_MD5), 16 );
|
||||||
printf("\n%s: RMD160 =", fname ); print_hex(md_read(md, DIGEST_ALGO_RMD160), 20 );
|
printf("\n%s: RMD160 =", fname ); print_hex(md_read(md, DIGEST_ALGO_RMD160), 20 );
|
||||||
|
146
g10/import.c
Normal file
146
g10/import.c
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
/* import.c
|
||||||
|
* Copyright (c) 1998 by Werner Koch (dd9jn)
|
||||||
|
*
|
||||||
|
* This file is part of G10.
|
||||||
|
*
|
||||||
|
* G10 is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* G10 is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <config.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "options.h"
|
||||||
|
#include "packet.h"
|
||||||
|
#include "errors.h"
|
||||||
|
#include "keydb.h"
|
||||||
|
#include "memory.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "trustdb.h"
|
||||||
|
|
||||||
|
|
||||||
|
/****************
|
||||||
|
* Import the public keys from the given filename.
|
||||||
|
* Import is a somewhat misleading name, as we (only) add informations
|
||||||
|
* about the public keys into aout trustdb.
|
||||||
|
*
|
||||||
|
* NOTE: this function is not really needed and will be changed to
|
||||||
|
* a function which reads a plain textfile, describing a public
|
||||||
|
* key and its associated ownertrust. This can be used (together
|
||||||
|
* with the export function) to make a backup of the assigned
|
||||||
|
* ownertrusts.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
import_pubkeys( const char *filename )
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
PACKET pkt;
|
||||||
|
int save_mode;
|
||||||
|
ulong offset;
|
||||||
|
IOBUF iobuf = NULL;
|
||||||
|
|
||||||
|
init_packet(&pkt);
|
||||||
|
save_mode = set_packet_list_mode(0);
|
||||||
|
|
||||||
|
if( !(iobuf = iobuf_open( filename )) ) {
|
||||||
|
rc = G10ERR_KEYRING_OPEN;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
|
||||||
|
while( !(rc=search_packet(iobuf, &pkt, PKT_PUBLIC_CERT, &offset)) ) {
|
||||||
|
PKT_public_cert *pkc = pkt.pkt.public_cert;
|
||||||
|
u32 keyid[2];
|
||||||
|
int otrust;
|
||||||
|
|
||||||
|
assert( pkt.pkttype == PKT_PUBLIC_CERT );
|
||||||
|
|
||||||
|
keyid_from_pkc( pkc, keyid );
|
||||||
|
rc = get_ownertrust( pkc, &otrust );
|
||||||
|
if( rc && rc != -1 ) {
|
||||||
|
log_error("error getting otrust of %08lX: %s\n",
|
||||||
|
keyid[1], g10_errstr(rc) );
|
||||||
|
}
|
||||||
|
else if( rc == -1 ) { /* No pubkey in trustDB: Insert */
|
||||||
|
rc = insert_trust_record( pkc );
|
||||||
|
if( rc ) {
|
||||||
|
log_error("failed to insert it into the trustdb: %s\n",
|
||||||
|
g10_errstr(rc) );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rc = get_ownertrust( pkc, &otrust );
|
||||||
|
if( rc )
|
||||||
|
log_fatal("failed to reread the pubkey record: %s\n",
|
||||||
|
g10_errstr(rc) );
|
||||||
|
log_info("key %08lX inserted in trustdb (localid=%lu)\n",
|
||||||
|
keyid[1], pkc->local_id );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
log_info("key %08lX already in trustdb (localid=%lu)\n",
|
||||||
|
keyid[1], pkc->local_id );
|
||||||
|
|
||||||
|
free_packet(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
iobuf_close(iobuf);
|
||||||
|
if( !(iobuf = iobuf_open( filename )) ) {
|
||||||
|
rc = G10ERR_KEYRING_OPEN;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
|
||||||
|
while( !(rc=search_packet(iobuf, &pkt, PKT_PUBLIC_CERT, &offset)) ) {
|
||||||
|
PKT_public_cert *pkc = pkt.pkt.public_cert;
|
||||||
|
u32 keyid[2];
|
||||||
|
int trustlevel;
|
||||||
|
|
||||||
|
assert( pkt.pkttype == PKT_PUBLIC_CERT );
|
||||||
|
|
||||||
|
keyid_from_pkc( pkc, keyid );
|
||||||
|
rc = check_pkc_trust( pkc, &trustlevel );
|
||||||
|
if( rc ) {
|
||||||
|
log_error("error checking trust of %08lX: %s\n",
|
||||||
|
keyid[1], g10_errstr(rc) );
|
||||||
|
}
|
||||||
|
else if( trustlevel & TRUST_NO_PUBKEY ) {
|
||||||
|
/* No pubkey in trustDB: Insert and check again */
|
||||||
|
rc = insert_trust_record( pkc );
|
||||||
|
if( rc ) {
|
||||||
|
log_error("failed to insert it into the trustdb: %s\n",
|
||||||
|
g10_errstr(rc) );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
rc = check_pkc_trust( pkc, &trustlevel );
|
||||||
|
if( rc )
|
||||||
|
log_fatal("trust check after insert failed: %s\n",
|
||||||
|
g10_errstr(rc) );
|
||||||
|
if( trustlevel & TRUST_NO_PUBKEY )
|
||||||
|
BUG();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
free_packet(&pkt);
|
||||||
|
}
|
||||||
|
|
||||||
|
leave:
|
||||||
|
iobuf_close(iobuf);
|
||||||
|
free_packet(&pkt);
|
||||||
|
set_packet_list_mode(save_mode);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
17
g10/keydb.h
17
g10/keydb.h
@ -72,6 +72,17 @@ struct skc_list {
|
|||||||
int mark;
|
int mark;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* structure to collect all informations which can be used to
|
||||||
|
* identify a public key */
|
||||||
|
typedef struct pubkey_find_info *PUBKEY_FIND_INFO;
|
||||||
|
struct pubkey_find_info {
|
||||||
|
u32 keyid[2];
|
||||||
|
unsigned nbits;
|
||||||
|
byte pubkey_algo;
|
||||||
|
byte fingerprint[20];
|
||||||
|
char userid[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/*-- pkclist.c --*/
|
/*-- pkclist.c --*/
|
||||||
void release_pkc_list( PKC_LIST pkc_list );
|
void release_pkc_list( PKC_LIST pkc_list );
|
||||||
@ -128,9 +139,9 @@ void clear_kbnode_flags( KBNODE n );
|
|||||||
/*-- ringedit.c --*/
|
/*-- ringedit.c --*/
|
||||||
int add_keyblock_resource( const char *filename, int force, int secret );
|
int add_keyblock_resource( const char *filename, int force, int secret );
|
||||||
int get_keyblock_handle( const char *filename, int secret, KBPOS *kbpos );
|
int get_keyblock_handle( const char *filename, int secret, KBPOS *kbpos );
|
||||||
int search_keyblock( PACKET *pkt, KBPOS *kbpos, int secret );
|
int find_keyblock( PUBKEY_FIND_INFO info, KBPOS *kbpos );
|
||||||
int search_keyblock_byname( KBPOS *kbpos, const char *username );
|
int find_keyblock_byname( KBPOS *kbpos, const char *username );
|
||||||
int search_secret_keyblock_byname( KBPOS *kbpos, const char *username );
|
int find_secret_keyblock_byname( KBPOS *kbpos, const char *username );
|
||||||
int lock_keyblock( KBPOS *kbpos );
|
int lock_keyblock( KBPOS *kbpos );
|
||||||
void unlock_keyblock( KBPOS *kbpos );
|
void unlock_keyblock( KBPOS *kbpos );
|
||||||
int read_keyblock( KBPOS *kbpos, KBNODE *ret_root );
|
int read_keyblock( KBPOS *kbpos, KBNODE *ret_root );
|
||||||
|
26
g10/keygen.c
26
g10/keygen.c
@ -113,7 +113,7 @@ write_selfsig( KBNODE root, KBNODE pub_root, PKT_secret_cert *skc )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( !node )
|
if( !node )
|
||||||
log_bug(NULL); /* no user id packet in tree */
|
BUG(); /* no user id packet in tree */
|
||||||
uid = node->pkt->pkt.user_id;
|
uid = node->pkt->pkt.user_id;
|
||||||
/* get the pkc packet from the pub_tree */
|
/* get the pkc packet from the pub_tree */
|
||||||
for( kbctx=NULL; (node=walk_kbtree( pub_root, &kbctx)) ; ) {
|
for( kbctx=NULL; (node=walk_kbtree( pub_root, &kbctx)) ; ) {
|
||||||
@ -121,7 +121,7 @@ write_selfsig( KBNODE root, KBNODE pub_root, PKT_secret_cert *skc )
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( !node )
|
if( !node )
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
pkc = node->pkt->pkt.public_cert;
|
pkc = node->pkt->pkt.public_cert;
|
||||||
|
|
||||||
/* and make the signature */
|
/* and make the signature */
|
||||||
@ -149,12 +149,11 @@ gen_elg(unsigned nbits, KBNODE pub_root, KBNODE sec_root, DEK *dek,
|
|||||||
PKT_public_cert *pkc;
|
PKT_public_cert *pkc;
|
||||||
ELG_public_key pk;
|
ELG_public_key pk;
|
||||||
ELG_secret_key sk;
|
ELG_secret_key sk;
|
||||||
unsigned nbytes;
|
|
||||||
|
|
||||||
elg_generate( &pk, &sk, nbits );
|
elg_generate( &pk, &sk, nbits );
|
||||||
|
|
||||||
skc = m_alloc( sizeof *skc );
|
skc = m_alloc_clear( sizeof *skc );
|
||||||
pkc = m_alloc( sizeof *pkc );
|
pkc = m_alloc_clear( sizeof *pkc );
|
||||||
skc->timestamp = pkc->timestamp = make_timestamp();
|
skc->timestamp = pkc->timestamp = make_timestamp();
|
||||||
skc->valid_days = pkc->valid_days = 0; /* fixme: make it configurable*/
|
skc->valid_days = pkc->valid_days = 0; /* fixme: make it configurable*/
|
||||||
skc->pubkey_algo = pkc->pubkey_algo = PUBKEY_ALGO_ELGAMAL;
|
skc->pubkey_algo = pkc->pubkey_algo = PUBKEY_ALGO_ELGAMAL;
|
||||||
@ -217,8 +216,8 @@ gen_rsa(unsigned nbits, IOBUF pub_io, IOBUF sec_io, DEK *dek,
|
|||||||
|
|
||||||
rsa_generate( &pk, &sk, nbits );
|
rsa_generate( &pk, &sk, nbits );
|
||||||
|
|
||||||
skc = m_alloc( sizeof *skc );
|
skc = m_alloc_clear( sizeof *skc );
|
||||||
pkc = m_alloc( sizeof *pkc );
|
pkc = m_alloc_clear( sizeof *pkc );
|
||||||
skc->timestamp = pkc->timestamp = make_timestamp();
|
skc->timestamp = pkc->timestamp = make_timestamp();
|
||||||
skc->valid_days = pkc->valid_days = 0; /* fixme: make it configurable*/
|
skc->valid_days = pkc->valid_days = 0; /* fixme: make it configurable*/
|
||||||
skc->pubkey_algo = pkc->pubkey_algo = PUBKEY_ALGO_RSA;
|
skc->pubkey_algo = pkc->pubkey_algo = PUBKEY_ALGO_RSA;
|
||||||
@ -297,8 +296,6 @@ generate_keypair()
|
|||||||
char *pub_fname = NULL;
|
char *pub_fname = NULL;
|
||||||
char *sec_fname = NULL;
|
char *sec_fname = NULL;
|
||||||
char *uid = NULL;
|
char *uid = NULL;
|
||||||
IOBUF pub_io = NULL;
|
|
||||||
IOBUF sec_io = NULL;
|
|
||||||
KBNODE pub_root = NULL;
|
KBNODE pub_root = NULL;
|
||||||
KBNODE sec_root = NULL;
|
KBNODE sec_root = NULL;
|
||||||
PKT_secret_cert *skc = NULL;
|
PKT_secret_cert *skc = NULL;
|
||||||
@ -473,9 +470,14 @@ generate_keypair()
|
|||||||
p = stpcpy(stpcpy(stpcpy(p," ("), acomment),")");
|
p = stpcpy(stpcpy(stpcpy(p," ("), acomment),")");
|
||||||
if( *amail )
|
if( *amail )
|
||||||
p = stpcpy(stpcpy(stpcpy(p," <"), amail),">");
|
p = stpcpy(stpcpy(stpcpy(p," <"), amail),">");
|
||||||
#ifndef HAVE_DEV_RANDOM
|
|
||||||
strcpy(p, " (INSECURE!)" );
|
/* append a warning if we do not have dev/random
|
||||||
|
* or it is switched into quick testmode */
|
||||||
|
#ifdef HAVE_DEV_RANDOM
|
||||||
|
if( quick_random_gen(-1) )
|
||||||
#endif
|
#endif
|
||||||
|
strcpy(p, " (INSECURE!)" );
|
||||||
|
|
||||||
|
|
||||||
tty_printf("You selected this USER-ID:\n \"%s\"\n\n", uid);
|
tty_printf("You selected this USER-ID:\n \"%s\"\n\n", uid);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
@ -570,7 +572,7 @@ generate_keypair()
|
|||||||
else if( algo == PUBKEY_ALGO_DSA )
|
else if( algo == PUBKEY_ALGO_DSA )
|
||||||
rc = gen_dsa(nbits, pub_root, sec_root, dek, &skc );
|
rc = gen_dsa(nbits, pub_root, sec_root, dek, &skc );
|
||||||
else
|
else
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
if( !rc )
|
if( !rc )
|
||||||
write_uid(pub_root, uid );
|
write_uid(pub_root, uid );
|
||||||
if( !rc )
|
if( !rc )
|
||||||
|
@ -106,7 +106,6 @@ static MD_HANDLE
|
|||||||
v3_elg_fingerprint_md_skc( PKT_secret_cert *skc )
|
v3_elg_fingerprint_md_skc( PKT_secret_cert *skc )
|
||||||
{
|
{
|
||||||
PKT_public_cert pkc;
|
PKT_public_cert pkc;
|
||||||
byte *p;
|
|
||||||
|
|
||||||
pkc.pubkey_algo = skc->pubkey_algo;
|
pkc.pubkey_algo = skc->pubkey_algo;
|
||||||
pkc.timestamp = skc->timestamp;
|
pkc.timestamp = skc->timestamp;
|
||||||
|
@ -48,7 +48,7 @@ int edit_keysigs( const char *username );
|
|||||||
int change_passphrase( const char *username );
|
int change_passphrase( const char *username );
|
||||||
|
|
||||||
/*-- sig-check.c --*/
|
/*-- sig-check.c --*/
|
||||||
int check_key_signature( KBNODE root, KBNODE node );
|
int check_key_signature( KBNODE root, KBNODE node, int *is_selfsig );
|
||||||
|
|
||||||
/*-- keygen.c --*/
|
/*-- keygen.c --*/
|
||||||
void generate_keypair(void);
|
void generate_keypair(void);
|
||||||
@ -77,5 +77,8 @@ void g10_elg_sign( PKT_secret_cert *skc, PKT_signature *sig, MD_HANDLE md );
|
|||||||
void g10_rsa_encrypt( PKT_public_cert *pkc, PKT_pubkey_enc *enc, DEK *dek );
|
void g10_rsa_encrypt( PKT_public_cert *pkc, PKT_pubkey_enc *enc, DEK *dek );
|
||||||
void g10_rsa_sign( PKT_secret_cert *skc, PKT_signature *sig, MD_HANDLE md );
|
void g10_rsa_sign( PKT_secret_cert *skc, PKT_signature *sig, MD_HANDLE md );
|
||||||
|
|
||||||
|
/*-- import.c --*/
|
||||||
|
int import_pubkeys( const char *filename );
|
||||||
|
|
||||||
|
|
||||||
#endif /*G10_MAIN_H*/
|
#endif /*G10_MAIN_H*/
|
||||||
|
@ -110,7 +110,6 @@ add_secret_cert( CTX c, PACKET *pkt )
|
|||||||
static int
|
static int
|
||||||
add_user_id( CTX c, PACKET *pkt )
|
add_user_id( CTX c, PACKET *pkt )
|
||||||
{
|
{
|
||||||
u32 keyid[2];
|
|
||||||
KBNODE node, n1, n2;
|
KBNODE node, n1, n2;
|
||||||
|
|
||||||
if( !c->cert ) {
|
if( !c->cert ) {
|
||||||
@ -142,7 +141,6 @@ add_user_id( CTX c, PACKET *pkt )
|
|||||||
static int
|
static int
|
||||||
add_signature( CTX c, PACKET *pkt )
|
add_signature( CTX c, PACKET *pkt )
|
||||||
{
|
{
|
||||||
u32 keyid[2];
|
|
||||||
KBNODE node, n1, n2;
|
KBNODE node, n1, n2;
|
||||||
|
|
||||||
if( !c->cert ) {
|
if( !c->cert ) {
|
||||||
@ -329,7 +327,7 @@ do_check_sig( CTX c, KBNODE node )
|
|||||||
if( c->cert->pkt->pkt.public_cert->mfx.md )
|
if( c->cert->pkt->pkt.public_cert->mfx.md )
|
||||||
md = md_copy( c->cert->pkt->pkt.public_cert->mfx.md );
|
md = md_copy( c->cert->pkt->pkt.public_cert->mfx.md );
|
||||||
else
|
else
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
md_write( md, n1->pkt->pkt.user_id->name, n1->pkt->pkt.user_id->len);
|
md_write( md, n1->pkt->pkt.user_id->name, n1->pkt->pkt.user_id->len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -356,7 +354,7 @@ static void
|
|||||||
print_userid( PACKET *pkt )
|
print_userid( PACKET *pkt )
|
||||||
{
|
{
|
||||||
if( !pkt )
|
if( !pkt )
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
if( pkt->pkttype != PKT_USER_ID ) {
|
if( pkt->pkttype != PKT_USER_ID ) {
|
||||||
printf("ERROR: unexpected packet type %d", pkt->pkttype );
|
printf("ERROR: unexpected packet type %d", pkt->pkttype );
|
||||||
return;
|
return;
|
||||||
@ -493,9 +491,7 @@ proc_packets( IOBUF a )
|
|||||||
{
|
{
|
||||||
CTX c = m_alloc_clear( sizeof *c );
|
CTX c = m_alloc_clear( sizeof *c );
|
||||||
PACKET *pkt = m_alloc( sizeof *pkt );
|
PACKET *pkt = m_alloc( sizeof *pkt );
|
||||||
int rc, result;
|
int rc;
|
||||||
int lvl0, lvl1;
|
|
||||||
u32 keyid[2];
|
|
||||||
int newpkt;
|
int newpkt;
|
||||||
|
|
||||||
c->iobuf = a;
|
c->iobuf = a;
|
||||||
|
10
g10/packet.h
10
g10/packet.h
@ -42,9 +42,8 @@ typedef enum {
|
|||||||
PKT_PLAINTEXT =11, /* plaintext data with filename and mode */
|
PKT_PLAINTEXT =11, /* plaintext data with filename and mode */
|
||||||
PKT_RING_TRUST =12, /* keyring trust packet */
|
PKT_RING_TRUST =12, /* keyring trust packet */
|
||||||
PKT_USER_ID =13, /* user id packet */
|
PKT_USER_ID =13, /* user id packet */
|
||||||
PKT_COMMENT =14, /* comment packet */
|
|
||||||
PKT_PUBKEY_SUBCERT=14, /* subkey certificate (OpenPGP) */
|
PKT_PUBKEY_SUBCERT=14, /* subkey certificate (OpenPGP) */
|
||||||
PKT_NEW_COMMENT =16 /* new comment packet (OpenPGP) */
|
PKT_COMMENT =16 /* new comment packet (OpenPGP) */
|
||||||
} pkttype_t;
|
} pkttype_t;
|
||||||
|
|
||||||
typedef struct packet_struct PACKET;
|
typedef struct packet_struct PACKET;
|
||||||
@ -74,6 +73,7 @@ typedef struct {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
u32 keyid[2]; /* 64 bit keyid */
|
u32 keyid[2]; /* 64 bit keyid */
|
||||||
|
ulong local_id; /* internal use, valid if > 0 */
|
||||||
u32 timestamp; /* signature made */
|
u32 timestamp; /* signature made */
|
||||||
byte sig_class; /* sig classification, append for MD calculation*/
|
byte sig_class; /* sig classification, append for MD calculation*/
|
||||||
byte pubkey_algo; /* algorithm used for public key scheme */
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
||||||
@ -96,9 +96,11 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
u32 timestamp; /* certificate made */
|
u32 timestamp; /* certificate made */
|
||||||
u16 valid_days; /* valid for this number of days */
|
u16 valid_days; /* valid for this number of days */
|
||||||
|
byte hdrbytes; /* number of header bytes */
|
||||||
|
byte version;
|
||||||
byte pubkey_algo; /* algorithm used for public key scheme */
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
||||||
md_filter_context_t mfx;
|
md_filter_context_t mfx;
|
||||||
u32 local_id; /* internal use, valid if > 0 */
|
ulong local_id; /* internal use, valid if > 0 */
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
MPI p; /* prime */
|
MPI p; /* prime */
|
||||||
@ -115,6 +117,8 @@ typedef struct {
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
u32 timestamp; /* certificate made */
|
u32 timestamp; /* certificate made */
|
||||||
u16 valid_days; /* valid for this number of days */
|
u16 valid_days; /* valid for this number of days */
|
||||||
|
byte hdrbytes; /* number of header bytes */
|
||||||
|
byte version;
|
||||||
byte pubkey_algo; /* algorithm used for public key scheme */
|
byte pubkey_algo; /* algorithm used for public key scheme */
|
||||||
union {
|
union {
|
||||||
struct {
|
struct {
|
||||||
|
@ -50,6 +50,7 @@ static int parse_certificate( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
byte *hdr, int hdrlen, PACKET *packet );
|
byte *hdr, int hdrlen, PACKET *packet );
|
||||||
static int parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen,
|
static int parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen,
|
||||||
PACKET *packet );
|
PACKET *packet );
|
||||||
|
static void parse_subkey( IOBUF inp, int pkttype, unsigned long pktlen );
|
||||||
static void parse_comment( IOBUF inp, int pkttype, unsigned long pktlen );
|
static void parse_comment( IOBUF inp, int pkttype, unsigned long pktlen );
|
||||||
static void parse_trust( IOBUF inp, int pkttype, unsigned long pktlen );
|
static void parse_trust( IOBUF inp, int pkttype, unsigned long pktlen );
|
||||||
static int parse_plaintext( IOBUF inp, int pkttype, unsigned long pktlen,
|
static int parse_plaintext( IOBUF inp, int pkttype, unsigned long pktlen,
|
||||||
@ -58,7 +59,7 @@ static int parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
PACKET *packet );
|
PACKET *packet );
|
||||||
static int parse_encrypted( IOBUF inp, int pkttype, unsigned long pktlen,
|
static int parse_encrypted( IOBUF inp, int pkttype, unsigned long pktlen,
|
||||||
PACKET *packet );
|
PACKET *packet );
|
||||||
|
#if 0
|
||||||
static u16
|
static u16
|
||||||
checksum( byte *p )
|
checksum( byte *p )
|
||||||
{
|
{
|
||||||
@ -70,6 +71,7 @@ checksum( byte *p )
|
|||||||
a += *p++;
|
a += *p++;
|
||||||
return a;
|
return a;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static unsigned short
|
static unsigned short
|
||||||
read_16(IOBUF inp)
|
read_16(IOBUF inp)
|
||||||
@ -143,10 +145,11 @@ search_packet( IOBUF inp, PACKET *pkt, int pkttype, ulong *retpos )
|
|||||||
static int
|
static int
|
||||||
parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos, int *skip )
|
parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos, int *skip )
|
||||||
{
|
{
|
||||||
int rc, ctb, pkttype, lenbytes;
|
int rc, c, ctb, pkttype, lenbytes;
|
||||||
unsigned long pktlen;
|
unsigned long pktlen;
|
||||||
byte hdr[5];
|
byte hdr[5];
|
||||||
int hdrlen;
|
int hdrlen;
|
||||||
|
int pgp3 = 0;
|
||||||
|
|
||||||
*skip = 0;
|
*skip = 0;
|
||||||
assert( !pkt->pkt.generic );
|
assert( !pkt->pkt.generic );
|
||||||
@ -157,22 +160,49 @@ parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos, int *skip )
|
|||||||
hdrlen=0;
|
hdrlen=0;
|
||||||
hdr[hdrlen++] = ctb;
|
hdr[hdrlen++] = ctb;
|
||||||
if( !(ctb & 0x80) ) {
|
if( !(ctb & 0x80) ) {
|
||||||
log_error("invalid packet at '%s'\n", iobuf_where(inp) );
|
log_error("%s: invalid packet (ctb=%02x)\n", iobuf_where(inp), ctb );
|
||||||
return G10ERR_INVALID_PACKET;
|
return G10ERR_INVALID_PACKET;
|
||||||
}
|
}
|
||||||
/* we handle the pgp 3 extensions here, so that we can skip such packets*/
|
|
||||||
pkttype = ctb & 0x40 ? (ctb & 0x3f) : ((ctb>>2)&0xf);
|
|
||||||
lenbytes = (ctb & 0x40) || ((ctb&3)==3)? 0 : (1<<(ctb & 3));
|
|
||||||
pktlen = 0;
|
pktlen = 0;
|
||||||
if( !lenbytes ) {
|
pgp3 = !!(ctb & 0x40);
|
||||||
pktlen = 0; /* don't know the value */
|
if( pgp3 ) {
|
||||||
if( pkttype != PKT_COMPRESSED )
|
pkttype = ctb & 0x3f;
|
||||||
iobuf_set_block_mode(inp, 1);
|
if( (c = iobuf_get(inp)) == -1 ) {
|
||||||
|
log_error("%s: 1st length byte missing\n", iobuf_where(inp) );
|
||||||
|
return G10ERR_INVALID_PACKET;
|
||||||
|
}
|
||||||
|
hdr[hdrlen++] = c;
|
||||||
|
if( c < 192 )
|
||||||
|
pktlen = c;
|
||||||
|
else if( c < 224 ) {
|
||||||
|
pktlen = (c - 192) * 256;
|
||||||
|
if( (c = iobuf_get(inp)) == -1 ) {
|
||||||
|
log_error("%s: 2nd length byte missing\n", iobuf_where(inp) );
|
||||||
|
return G10ERR_INVALID_PACKET;
|
||||||
|
}
|
||||||
|
hdr[hdrlen++] = c;
|
||||||
|
pktlen += c + 192;
|
||||||
|
}
|
||||||
|
else { /* partial body length */
|
||||||
|
pktlen = 1 << (c & 0x1f);
|
||||||
|
log_debug("partial body length of %lu bytes\n", pktlen );
|
||||||
|
iobuf_set_partial_block_mode(inp, pktlen);
|
||||||
|
pktlen = 0;/* to indicate partial length */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for( ; lenbytes; lenbytes-- ) {
|
pkttype = (ctb>>2)&0xf;
|
||||||
pktlen <<= 8;
|
lenbytes = ((ctb&3)==3)? 0 : (1<<(ctb & 3));
|
||||||
pktlen |= hdr[hdrlen++] = iobuf_get_noeof(inp);
|
if( !lenbytes ) {
|
||||||
|
pktlen = 0; /* don't know the value */
|
||||||
|
if( pkttype != PKT_COMPRESSED )
|
||||||
|
iobuf_set_block_mode(inp, 1);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for( ; lenbytes; lenbytes-- ) {
|
||||||
|
pktlen <<= 8;
|
||||||
|
pktlen |= hdr[hdrlen++] = iobuf_get_noeof(inp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,10 +213,10 @@ parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos, int *skip )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if( DBG_PACKET )
|
if( DBG_PACKET )
|
||||||
log_debug("parse_packet(iob=%d): type=%d length=%lu\n",
|
log_debug("parse_packet(iob=%d): type=%d length=%lu%s\n",
|
||||||
iobuf_id(inp), pkttype, pktlen );
|
iobuf_id(inp), pkttype, pktlen, pgp3?" (pgp3)":"" );
|
||||||
pkt->pkttype = pkttype;
|
pkt->pkttype = pkttype;
|
||||||
rc = G10ERR_UNKNOWN_PACKET; /* default to no error */
|
rc = G10ERR_UNKNOWN_PACKET; /* default error */
|
||||||
switch( pkttype ) {
|
switch( pkttype ) {
|
||||||
case PKT_PUBLIC_CERT:
|
case PKT_PUBLIC_CERT:
|
||||||
pkt->pkt.public_cert = m_alloc_clear(sizeof *pkt->pkt.public_cert );
|
pkt->pkt.public_cert = m_alloc_clear(sizeof *pkt->pkt.public_cert );
|
||||||
@ -211,6 +241,9 @@ parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos, int *skip )
|
|||||||
case PKT_USER_ID:
|
case PKT_USER_ID:
|
||||||
rc = parse_user_id(inp, pkttype, pktlen, pkt );
|
rc = parse_user_id(inp, pkttype, pktlen, pkt );
|
||||||
break;
|
break;
|
||||||
|
case PKT_PUBKEY_SUBCERT:
|
||||||
|
parse_subkey(inp, pkttype, pktlen);
|
||||||
|
break;
|
||||||
case PKT_COMMENT:
|
case PKT_COMMENT:
|
||||||
parse_comment(inp, pkttype, pktlen);
|
parse_comment(inp, pkttype, pktlen);
|
||||||
break;
|
break;
|
||||||
@ -234,12 +267,43 @@ parse( IOBUF inp, PACKET *pkt, int reqtype, ulong *retpos, int *skip )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_hex_line( int c, int *i )
|
||||||
|
{
|
||||||
|
if( *i && !(*i%8) ) {
|
||||||
|
if( *i && !(*i%24) )
|
||||||
|
printf("\n%4d:", *i );
|
||||||
|
else
|
||||||
|
putchar(' ');
|
||||||
|
}
|
||||||
|
if( c == -1 )
|
||||||
|
printf(" EOF" );
|
||||||
|
else
|
||||||
|
printf(" %02x", c );
|
||||||
|
++*i;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
skip_packet( IOBUF inp, int pkttype, unsigned long pktlen )
|
skip_packet( IOBUF inp, int pkttype, unsigned long pktlen )
|
||||||
{
|
{
|
||||||
if( list_mode )
|
if( list_mode ) {
|
||||||
printf(":unknown packet: type %2d, length %lu\n", pkttype, pktlen );
|
printf(":unknown packet: type %2d, length %lu\n", pkttype, pktlen );
|
||||||
|
if( pkttype ) {
|
||||||
|
int c, i=0 ;
|
||||||
|
printf("dump:");
|
||||||
|
if( iobuf_in_block_mode(inp) ) {
|
||||||
|
while( (c=iobuf_get(inp)) != -1 )
|
||||||
|
dump_hex_line(c, &i);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for( ; pktlen; pktlen-- )
|
||||||
|
dump_hex_line(iobuf_get(inp), &i);
|
||||||
|
}
|
||||||
|
putchar('\n');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
skip_rest(inp,pktlen);
|
skip_rest(inp,pktlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,7 +342,7 @@ parse_publickey( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
|
|||||||
k->keyid[1] = read_32(inp); pktlen -= 4;
|
k->keyid[1] = read_32(inp); pktlen -= 4;
|
||||||
k->pubkey_algo = iobuf_get_noeof(inp); pktlen--;
|
k->pubkey_algo = iobuf_get_noeof(inp); pktlen--;
|
||||||
if( list_mode )
|
if( list_mode )
|
||||||
printf(":public key packet: keyid %08lX%08lX\n",
|
printf(":public key encoded packet: keyid %08lX%08lX\n",
|
||||||
k->keyid[0], k->keyid[1]);
|
k->keyid[0], k->keyid[1]);
|
||||||
if( k->pubkey_algo == PUBKEY_ALGO_ELGAMAL ) {
|
if( k->pubkey_algo == PUBKEY_ALGO_ELGAMAL ) {
|
||||||
n = pktlen;
|
n = pktlen;
|
||||||
@ -394,7 +458,6 @@ parse_onepass_sig( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
PKT_onepass_sig *ops )
|
PKT_onepass_sig *ops )
|
||||||
{
|
{
|
||||||
int version;
|
int version;
|
||||||
unsigned n;
|
|
||||||
|
|
||||||
if( pktlen < 13 ) {
|
if( pktlen < 13 ) {
|
||||||
log_error("packet(%d) too short\n", pkttype);
|
log_error("packet(%d) too short\n", pkttype);
|
||||||
@ -461,22 +524,27 @@ parse_certificate( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
timestamp = read_32(inp); pktlen -= 4;
|
timestamp = read_32(inp); pktlen -= 4;
|
||||||
if( is_v4 )
|
if( is_v4 )
|
||||||
valid_period = 0;
|
valid_period = 0;
|
||||||
else
|
else {
|
||||||
valid_period = read_16(inp); pktlen -= 2;
|
valid_period = read_16(inp); pktlen -= 2;
|
||||||
|
}
|
||||||
algorithm = iobuf_get_noeof(inp); pktlen--;
|
algorithm = iobuf_get_noeof(inp); pktlen--;
|
||||||
if( list_mode )
|
if( list_mode )
|
||||||
printf(":%s key certification packet:\n"
|
printf(":%s key packet:\n"
|
||||||
"\tversion %d, created %lu, valid for %hu days\n",
|
"\tversion %d, created %lu, valid for %hu days\n",
|
||||||
pkttype == PKT_PUBLIC_CERT? "public": "secret",
|
pkttype == PKT_PUBLIC_CERT? "public": "secret",
|
||||||
version, timestamp, valid_period );
|
version, timestamp, valid_period );
|
||||||
if( pkttype == PKT_SECRET_CERT ) {
|
if( pkttype == PKT_SECRET_CERT ) {
|
||||||
pkt->pkt.secret_cert->timestamp = timestamp;
|
pkt->pkt.secret_cert->timestamp = timestamp;
|
||||||
pkt->pkt.secret_cert->valid_days = valid_period;
|
pkt->pkt.secret_cert->valid_days = valid_period;
|
||||||
|
pkt->pkt.secret_cert->hdrbytes = hdrlen;
|
||||||
|
pkt->pkt.secret_cert->version = version;
|
||||||
pkt->pkt.secret_cert->pubkey_algo = algorithm;
|
pkt->pkt.secret_cert->pubkey_algo = algorithm;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
pkt->pkt.public_cert->timestamp = timestamp;
|
pkt->pkt.public_cert->timestamp = timestamp;
|
||||||
pkt->pkt.public_cert->valid_days = valid_period;
|
pkt->pkt.public_cert->valid_days = valid_period;
|
||||||
|
pkt->pkt.public_cert->hdrbytes = hdrlen;
|
||||||
|
pkt->pkt.public_cert->version = version;
|
||||||
pkt->pkt.public_cert->pubkey_algo = algorithm;
|
pkt->pkt.public_cert->pubkey_algo = algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,7 +554,7 @@ parse_certificate( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
n = pktlen; elg_g = mpi_read(inp, &n, 0 ); pktlen -=n;
|
n = pktlen; elg_g = mpi_read(inp, &n, 0 ); pktlen -=n;
|
||||||
n = pktlen; elg_y = mpi_read(inp, &n, 0 ); pktlen -=n;
|
n = pktlen; elg_y = mpi_read(inp, &n, 0 ); pktlen -=n;
|
||||||
if( list_mode ) {
|
if( list_mode ) {
|
||||||
printf( "\telg p: ");
|
printf( "\telg p: ");
|
||||||
mpi_print(stdout, elg_p, mpi_print_mode );
|
mpi_print(stdout, elg_p, mpi_print_mode );
|
||||||
printf("\n\telg g: ");
|
printf("\n\telg g: ");
|
||||||
mpi_print(stdout, elg_g, mpi_print_mode );
|
mpi_print(stdout, elg_g, mpi_print_mode );
|
||||||
@ -502,7 +570,6 @@ parse_certificate( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
else {
|
else {
|
||||||
PKT_secret_cert *cert = pkt->pkt.secret_cert;
|
PKT_secret_cert *cert = pkt->pkt.secret_cert;
|
||||||
byte temp[8];
|
byte temp[8];
|
||||||
byte *mpibuf;
|
|
||||||
|
|
||||||
pkt->pkt.secret_cert->d.elg.p = elg_p;
|
pkt->pkt.secret_cert->d.elg.p = elg_p;
|
||||||
pkt->pkt.secret_cert->d.elg.g = elg_g;
|
pkt->pkt.secret_cert->d.elg.g = elg_g;
|
||||||
@ -558,7 +625,6 @@ parse_certificate( IOBUF inp, int pkttype, unsigned long pktlen,
|
|||||||
else {
|
else {
|
||||||
PKT_secret_cert *cert = pkt->pkt.secret_cert;
|
PKT_secret_cert *cert = pkt->pkt.secret_cert;
|
||||||
byte temp[8];
|
byte temp[8];
|
||||||
byte *mpibuf;
|
|
||||||
|
|
||||||
pkt->pkt.secret_cert->d.rsa.rsa_n = rsa_pub_mod;
|
pkt->pkt.secret_cert->d.rsa.rsa_n = rsa_pub_mod;
|
||||||
pkt->pkt.secret_cert->d.rsa.rsa_e = rsa_pub_exp;
|
pkt->pkt.secret_cert->d.rsa.rsa_e = rsa_pub_exp;
|
||||||
@ -636,6 +702,39 @@ parse_user_id( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *packet )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
parse_subkey( IOBUF inp, int pkttype, unsigned long pktlen )
|
||||||
|
{
|
||||||
|
int version;
|
||||||
|
|
||||||
|
version = iobuf_get_noeof(inp); pktlen--;
|
||||||
|
if( pkttype == PKT_PUBKEY_SUBCERT && version == '#' ) {
|
||||||
|
/* early versions of G10 use old comments packets; luckily all those
|
||||||
|
* comments are are started by a hash */
|
||||||
|
if( list_mode ) {
|
||||||
|
printf(":old comment packet: \"" );
|
||||||
|
for( ; pktlen; pktlen-- ) {
|
||||||
|
int c;
|
||||||
|
c = iobuf_get_noeof(inp);
|
||||||
|
if( c >= ' ' && c <= 'z' )
|
||||||
|
putchar(c);
|
||||||
|
else
|
||||||
|
printf("\\x%02x", c );
|
||||||
|
}
|
||||||
|
printf("\"\n");
|
||||||
|
}
|
||||||
|
skip_rest(inp, pktlen);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( list_mode )
|
||||||
|
printf(":public subkey packet: \"" );
|
||||||
|
skip_rest(inp, pktlen);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
parse_comment( IOBUF inp, int pkttype, unsigned long pktlen )
|
parse_comment( IOBUF inp, int pkttype, unsigned long pktlen )
|
||||||
{
|
{
|
||||||
@ -749,7 +848,6 @@ static int
|
|||||||
parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *pkt )
|
parse_compressed( IOBUF inp, int pkttype, unsigned long pktlen, PACKET *pkt )
|
||||||
{
|
{
|
||||||
PKT_compressed *zd;
|
PKT_compressed *zd;
|
||||||
int algorithm;
|
|
||||||
|
|
||||||
/* pktlen is here 0, but data follows
|
/* pktlen is here 0, but data follows
|
||||||
* (this should be the last object in a file or
|
* (this should be the last object in a file or
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
@ -56,7 +56,7 @@ do_we_trust( PKT_public_cert *pkc, int trustlevel )
|
|||||||
log_fatal("trust check after insert failed: %s\n",
|
log_fatal("trust check after insert failed: %s\n",
|
||||||
g10_errstr(rc) );
|
g10_errstr(rc) );
|
||||||
if( trustlevel & TRUST_NO_PUBKEY )
|
if( trustlevel & TRUST_NO_PUBKEY )
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +84,6 @@ int
|
|||||||
build_pkc_list( STRLIST remusr, PKC_LIST *ret_pkc_list )
|
build_pkc_list( STRLIST remusr, PKC_LIST *ret_pkc_list )
|
||||||
{
|
{
|
||||||
PKC_LIST pkc_list = NULL;
|
PKC_LIST pkc_list = NULL;
|
||||||
PKC_LIST pkc_rover = NULL;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if( !remusr ) { /* ask!!! */
|
if( !remusr ) { /* ask!!! */
|
||||||
|
121
g10/ringedit.c
121
g10/ringedit.c
@ -68,7 +68,12 @@ typedef struct resource_table_struct RESTBL;
|
|||||||
static RESTBL resource_table[MAX_RESOURCES];
|
static RESTBL resource_table[MAX_RESOURCES];
|
||||||
|
|
||||||
|
|
||||||
|
static int search( PACKET *pkt, KBPOS *kbpos, int secret );
|
||||||
|
|
||||||
|
|
||||||
static int keyring_search( PACKET *pkt, KBPOS *kbpos, IOBUF iobuf );
|
static int keyring_search( PACKET *pkt, KBPOS *kbpos, IOBUF iobuf );
|
||||||
|
static int keyring_search2( PUBKEY_FIND_INFO info, KBPOS *kbpos,
|
||||||
|
const char *fname);
|
||||||
static int keyring_read( KBPOS *kbpos, KBNODE *ret_root );
|
static int keyring_read( KBPOS *kbpos, KBNODE *ret_root );
|
||||||
static int keyring_insert( KBPOS *kbpos, KBNODE root );
|
static int keyring_insert( KBPOS *kbpos, KBNODE root );
|
||||||
static int keyring_delete( KBPOS *kbpos );
|
static int keyring_delete( KBPOS *kbpos );
|
||||||
@ -138,6 +143,37 @@ get_keyblock_handle( const char *filename, int secret, KBPOS *kbpos )
|
|||||||
return -1; /* not found */
|
return -1; /* not found */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/****************
|
||||||
|
* Find a keyblock from the informations provided in INFO
|
||||||
|
* This can only be used fro public keys
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
find_keyblock( PUBKEY_FIND_INFO info, KBPOS *kbpos )
|
||||||
|
{
|
||||||
|
int i, rc, last_rc=-1;
|
||||||
|
|
||||||
|
for(i=0; i < MAX_RESOURCES; i++ ) {
|
||||||
|
if( resource_table[i].used && !resource_table[i].secret ) {
|
||||||
|
/* note: here we have to add different search functions,
|
||||||
|
* depending on the type of the resource */
|
||||||
|
rc = keyring_search2( info, kbpos, resource_table[i].fname );
|
||||||
|
if( !rc ) {
|
||||||
|
kbpos->resno = i;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if( rc != -1 ) {
|
||||||
|
log_error("error searching resource %d: %s\n",
|
||||||
|
i, g10_errstr(rc));
|
||||||
|
last_rc = rc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return last_rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
* Search a keyblock which starts with the given packet and put all
|
* Search a keyblock which starts with the given packet and put all
|
||||||
* informations into KBPOS, which can be used later to access this key block.
|
* informations into KBPOS, which can be used later to access this key block.
|
||||||
@ -149,8 +185,8 @@ get_keyblock_handle( const char *filename, int secret, KBPOS *kbpos )
|
|||||||
*
|
*
|
||||||
* Returns: 0 if found, -1 if not found or an errorcode.
|
* Returns: 0 if found, -1 if not found or an errorcode.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
search_keyblock( PACKET *pkt, KBPOS *kbpos, int secret )
|
search( PACKET *pkt, KBPOS *kbpos, int secret )
|
||||||
{
|
{
|
||||||
int i, rc, last_rc=-1;
|
int i, rc, last_rc=-1;
|
||||||
|
|
||||||
@ -179,7 +215,7 @@ search_keyblock( PACKET *pkt, KBPOS *kbpos, int secret )
|
|||||||
* of the keyblock.
|
* of the keyblock.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
search_keyblock_byname( KBPOS *kbpos, const char *username )
|
find_keyblock_byname( KBPOS *kbpos, const char *username )
|
||||||
{
|
{
|
||||||
PACKET pkt;
|
PACKET pkt;
|
||||||
PKT_public_cert *pkc = m_alloc_clear( sizeof *pkc );
|
PKT_public_cert *pkc = m_alloc_clear( sizeof *pkc );
|
||||||
@ -194,7 +230,7 @@ search_keyblock_byname( KBPOS *kbpos, const char *username )
|
|||||||
init_packet( &pkt );
|
init_packet( &pkt );
|
||||||
pkt.pkttype = PKT_PUBLIC_CERT;
|
pkt.pkttype = PKT_PUBLIC_CERT;
|
||||||
pkt.pkt.public_cert = pkc;
|
pkt.pkt.public_cert = pkc;
|
||||||
rc = search_keyblock( &pkt, kbpos, 0 );
|
rc = search( &pkt, kbpos, 0 );
|
||||||
free_public_cert(pkc);
|
free_public_cert(pkc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -204,7 +240,7 @@ search_keyblock_byname( KBPOS *kbpos, const char *username )
|
|||||||
* of the keyblock. This function does not unprotect the secret key.
|
* of the keyblock. This function does not unprotect the secret key.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
search_secret_keyblock_byname( KBPOS *kbpos, const char *username )
|
find_secret_keyblock_byname( KBPOS *kbpos, const char *username )
|
||||||
{
|
{
|
||||||
PACKET pkt;
|
PACKET pkt;
|
||||||
PKT_secret_cert *skc = m_alloc_clear( sizeof *skc );
|
PKT_secret_cert *skc = m_alloc_clear( sizeof *skc );
|
||||||
@ -219,7 +255,7 @@ search_secret_keyblock_byname( KBPOS *kbpos, const char *username )
|
|||||||
init_packet( &pkt );
|
init_packet( &pkt );
|
||||||
pkt.pkttype = PKT_SECRET_CERT;
|
pkt.pkttype = PKT_SECRET_CERT;
|
||||||
pkt.pkt.secret_cert = skc;
|
pkt.pkt.secret_cert = skc;
|
||||||
rc = search_keyblock( &pkt, kbpos, 1 );
|
rc = search( &pkt, kbpos, 1 );
|
||||||
free_secret_cert(skc);
|
free_secret_cert(skc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
@ -229,13 +265,11 @@ search_secret_keyblock_byname( KBPOS *kbpos, const char *username )
|
|||||||
* Lock the keyblock; wait until it's available
|
* Lock the keyblock; wait until it's available
|
||||||
* This function may change the internal data in kbpos, in cases
|
* This function may change the internal data in kbpos, in cases
|
||||||
* when the to be locked keyblock has been modified.
|
* when the to be locked keyblock has been modified.
|
||||||
* fixme: remove this function and add an option to search_keyblock()?
|
* fixme: remove this function and add an option to search()?
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
lock_keyblock( KBPOS *kbpos )
|
lock_keyblock( KBPOS *kbpos )
|
||||||
{
|
{
|
||||||
int rc;
|
|
||||||
|
|
||||||
if( !check_pos(kbpos) )
|
if( !check_pos(kbpos) )
|
||||||
return G10ERR_GENERAL;
|
return G10ERR_GENERAL;
|
||||||
return 0;
|
return 0;
|
||||||
@ -248,7 +282,7 @@ void
|
|||||||
unlock_keyblock( KBPOS *kbpos )
|
unlock_keyblock( KBPOS *kbpos )
|
||||||
{
|
{
|
||||||
if( !check_pos(kbpos) )
|
if( !check_pos(kbpos) )
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
@ -389,7 +423,7 @@ keyring_search( PACKET *req, KBPOS *kbpos, IOBUF iobuf )
|
|||||||
break; /* found */
|
break; /* found */
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
free_packet(&pkt);
|
free_packet(&pkt);
|
||||||
}
|
}
|
||||||
if( !rc )
|
if( !rc )
|
||||||
@ -401,6 +435,68 @@ keyring_search( PACKET *req, KBPOS *kbpos, IOBUF iobuf )
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************
|
||||||
|
* search one keyring, return 0 if found, -1 if not found or an errorcode.
|
||||||
|
* this version uses the finger print and other informations
|
||||||
|
*/
|
||||||
|
static int
|
||||||
|
keyring_search2( PUBKEY_FIND_INFO info, KBPOS *kbpos, const char *fname )
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
PACKET pkt;
|
||||||
|
int save_mode;
|
||||||
|
ulong offset;
|
||||||
|
IOBUF iobuf;
|
||||||
|
|
||||||
|
init_packet(&pkt);
|
||||||
|
save_mode = set_packet_list_mode(0);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if( iobuf_seek( iobuf, 0 ) ) {
|
||||||
|
log_error("can't rewind keyring file: %s\n", g10_errstr(rc));
|
||||||
|
rc = G10ERR_KEYRING_OPEN;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
iobuf = iobuf_open( fname );
|
||||||
|
if( !iobuf ) {
|
||||||
|
log_error("can't open '%s'\n", fname );
|
||||||
|
rc = G10ERR_OPEN_FILE;
|
||||||
|
goto leave;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
while( !(rc=search_packet(iobuf, &pkt, PKT_PUBLIC_CERT, &offset)) ) {
|
||||||
|
PKT_public_cert *pkc = pkt.pkt.public_cert;
|
||||||
|
u32 keyid[2];
|
||||||
|
|
||||||
|
assert( pkt.pkttype == PKT_PUBLIC_CERT );
|
||||||
|
keyid_from_pkc( pkc, keyid );
|
||||||
|
if( keyid[0] == info->keyid[0] && keyid[1] == info->keyid[1]
|
||||||
|
&& pkc->pubkey_algo == info->pubkey_algo ) {
|
||||||
|
/* fixme: shall we check nbits too? (good for rsa keys) */
|
||||||
|
/* fixme: check userid???? */
|
||||||
|
size_t len;
|
||||||
|
byte *fp = fingerprint_from_pkc( pkc, &len );
|
||||||
|
|
||||||
|
if( !memcmp( fp, info->fingerprint, len ) ) {
|
||||||
|
m_free(fp);
|
||||||
|
break; /* found */
|
||||||
|
}
|
||||||
|
m_free(fp);
|
||||||
|
}
|
||||||
|
free_packet(&pkt);
|
||||||
|
}
|
||||||
|
if( !rc )
|
||||||
|
kbpos->offset = offset;
|
||||||
|
|
||||||
|
leave:
|
||||||
|
iobuf_close(iobuf);
|
||||||
|
free_packet(&pkt);
|
||||||
|
set_packet_list_mode(save_mode);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
keyring_read( KBPOS *kbpos, KBNODE *ret_root )
|
keyring_read( KBPOS *kbpos, KBNODE *ret_root )
|
||||||
@ -562,7 +658,6 @@ keyring_delete( KBPOS *kbpos )
|
|||||||
{
|
{
|
||||||
RESTBL *rentry;
|
RESTBL *rentry;
|
||||||
IOBUF fp;
|
IOBUF fp;
|
||||||
KBNODE kbctx, node;
|
|
||||||
int rc;
|
int rc;
|
||||||
u32 len;
|
u32 len;
|
||||||
int ctb;
|
int ctb;
|
||||||
@ -588,7 +683,7 @@ keyring_delete( KBPOS *kbpos )
|
|||||||
/*log_debug("writing a dummy packet of length %lu\n", (ulong)len);*/
|
/*log_debug("writing a dummy packet of length %lu\n", (ulong)len);*/
|
||||||
|
|
||||||
if( len < 2 )
|
if( len < 2 )
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
|
|
||||||
if( len < 256 ) {
|
if( len < 256 ) {
|
||||||
ctb = 0x80;
|
ctb = 0x80;
|
||||||
|
@ -60,7 +60,7 @@ static int
|
|||||||
check_elg( PKT_secret_cert *cert )
|
check_elg( PKT_secret_cert *cert )
|
||||||
{
|
{
|
||||||
byte *buffer;
|
byte *buffer;
|
||||||
u16 n, csum=0;
|
u16 csum=0;
|
||||||
int res;
|
int res;
|
||||||
unsigned nbytes;
|
unsigned nbytes;
|
||||||
u32 keyid[2];
|
u32 keyid[2];
|
||||||
@ -73,7 +73,7 @@ check_elg( PKT_secret_cert *cert )
|
|||||||
BLOWFISH_context *blowfish_ctx=NULL;
|
BLOWFISH_context *blowfish_ctx=NULL;
|
||||||
|
|
||||||
switch( cert->d.elg.protect_algo ) {
|
switch( cert->d.elg.protect_algo ) {
|
||||||
case CIPHER_ALGO_NONE: log_bug(NULL); break;
|
case CIPHER_ALGO_NONE: BUG(); break;
|
||||||
case CIPHER_ALGO_BLOWFISH:
|
case CIPHER_ALGO_BLOWFISH:
|
||||||
keyid_from_skc( cert, keyid );
|
keyid_from_skc( cert, keyid );
|
||||||
dek = get_passphrase_hash( keyid, NULL );
|
dek = get_passphrase_hash( keyid, NULL );
|
||||||
@ -142,7 +142,7 @@ protect_elg( PKT_secret_cert *cert, DEK *dek )
|
|||||||
BLOWFISH_context *blowfish_ctx=NULL;
|
BLOWFISH_context *blowfish_ctx=NULL;
|
||||||
|
|
||||||
switch( cert->d.elg.protect_algo ) {
|
switch( cert->d.elg.protect_algo ) {
|
||||||
case CIPHER_ALGO_NONE: log_bug(NULL); break;
|
case CIPHER_ALGO_NONE: BUG(); break;
|
||||||
case CIPHER_ALGO_BLOWFISH:
|
case CIPHER_ALGO_BLOWFISH:
|
||||||
blowfish_ctx = m_alloc_secure( sizeof *blowfish_ctx );
|
blowfish_ctx = m_alloc_secure( sizeof *blowfish_ctx );
|
||||||
blowfish_setkey( blowfish_ctx, dek->key, dek->keylen );
|
blowfish_setkey( blowfish_ctx, dek->key, dek->keylen );
|
||||||
@ -171,7 +171,7 @@ static int
|
|||||||
check_rsa( PKT_secret_cert *cert )
|
check_rsa( PKT_secret_cert *cert )
|
||||||
{
|
{
|
||||||
byte *buffer;
|
byte *buffer;
|
||||||
u16 n, csum=0;
|
u16 csum=0;
|
||||||
int res;
|
int res;
|
||||||
unsigned nbytes;
|
unsigned nbytes;
|
||||||
u32 keyid[2];
|
u32 keyid[2];
|
||||||
@ -183,7 +183,7 @@ check_rsa( PKT_secret_cert *cert )
|
|||||||
|
|
||||||
switch( cert->d.rsa.protect_algo ) {
|
switch( cert->d.rsa.protect_algo ) {
|
||||||
/* FIXME: use test variables to check for the correct key */
|
/* FIXME: use test variables to check for the correct key */
|
||||||
case CIPHER_ALGO_NONE: log_bug(NULL); break;
|
case CIPHER_ALGO_NONE: BUG(); break;
|
||||||
case CIPHER_ALGO_BLOWFISH:
|
case CIPHER_ALGO_BLOWFISH:
|
||||||
keyid_from_skc( cert, keyid );
|
keyid_from_skc( cert, keyid );
|
||||||
dek = get_passphrase_hash( keyid, NULL );
|
dek = get_passphrase_hash( keyid, NULL );
|
||||||
|
13
g10/seskey.c
13
g10/seskey.c
@ -46,7 +46,7 @@ make_session_key( DEK *dek )
|
|||||||
randomize_buffer( dek->key, dek->keylen, 1 );
|
randomize_buffer( dek->key, dek->keylen, 1 );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: log_bug("invalid algo %d in make_session_key()\n");
|
default: log_bug("invalid algo %d in make_session_key()\n", dek->algo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +116,8 @@ encode_rmd160_value( byte *md, unsigned len, unsigned nbits )
|
|||||||
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
|
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x24, 0x03,
|
||||||
0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
|
0x02, 0x01, 0x05, 0x00, 0x04, 0x14 };
|
||||||
int nframe = (nbits+7) / 8;
|
int nframe = (nbits+7) / 8;
|
||||||
byte *p;
|
|
||||||
MPI frame;
|
MPI frame;
|
||||||
int i,n,c;
|
int i,n;
|
||||||
|
|
||||||
if( (nbits % BITS_PER_MPI_LIMB) || nframe < 42 || len != 20 )
|
if( (nbits % BITS_PER_MPI_LIMB) || nframe < 42 || len != 20 )
|
||||||
log_bug("can't encode a %d bit MD into a %d bits frame\n",len*8, nbits);
|
log_bug("can't encode a %d bit MD into a %d bits frame\n",len*8, nbits);
|
||||||
@ -156,9 +155,8 @@ encode_sha1_value( byte *md, unsigned len, unsigned nbits )
|
|||||||
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
|
{ 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03,
|
||||||
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
|
0x02, 0x1a, 0x05, 0x00, 0x04, 0x14 };
|
||||||
int nframe = (nbits+7) / 8;
|
int nframe = (nbits+7) / 8;
|
||||||
byte *p;
|
|
||||||
MPI frame;
|
MPI frame;
|
||||||
int i,n,c;
|
int i,n;
|
||||||
|
|
||||||
if( (nbits % BITS_PER_MPI_LIMB) || nframe < 42 || len != 20 )
|
if( (nbits % BITS_PER_MPI_LIMB) || nframe < 42 || len != 20 )
|
||||||
log_bug("can't encode a %d bit MD into a %d bits frame\n",len*8, nbits);
|
log_bug("can't encode a %d bit MD into a %d bits frame\n",len*8, nbits);
|
||||||
@ -197,9 +195,8 @@ encode_md5_value( byte *md, unsigned len, unsigned nbits )
|
|||||||
{ 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
|
{ 0x30, 0x20, 0x30, 0x0c, 0x06, 0x08, 0x2a, 0x86,0x48,
|
||||||
0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 };
|
0x86, 0xf7, 0x0d, 0x02, 0x05, 0x05, 0x00, 0x04, 0x10 };
|
||||||
int nframe = (nbits+7) / 8;
|
int nframe = (nbits+7) / 8;
|
||||||
byte *p;
|
|
||||||
MPI frame;
|
MPI frame;
|
||||||
int i,n,c;
|
int i,n;
|
||||||
|
|
||||||
if( (nbits % BITS_PER_MPI_LIMB) || nframe < 38 || len != 16 )
|
if( (nbits % BITS_PER_MPI_LIMB) || nframe < 38 || len != 16 )
|
||||||
log_bug("can't encode a %d bit MD into a %d bits frame\n",len*8, nbits);
|
log_bug("can't encode a %d bit MD into a %d bits frame\n",len*8, nbits);
|
||||||
@ -236,7 +233,7 @@ encode_md_value( MD_HANDLE md, unsigned nbits )
|
|||||||
case DIGEST_ALGO_SHA1:
|
case DIGEST_ALGO_SHA1:
|
||||||
return encode_sha1_value( md_read(md, DIGEST_ALGO_SHA1), 20, nbits );
|
return encode_sha1_value( md_read(md, DIGEST_ALGO_SHA1), 20, nbits );
|
||||||
default:
|
default:
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ signature_check( PKT_signature *sig, MD_HANDLE digest )
|
|||||||
md_putc( digest, a & 0xff );
|
md_putc( digest, a & 0xff );
|
||||||
}
|
}
|
||||||
md_final( digest );
|
md_final( digest );
|
||||||
dp = md_read( digest, 0 );
|
dp = md_read( digest, DIGEST_ALGO_RMD160 );
|
||||||
for(i=19; i >= 0; i--, dp++ )
|
for(i=19; i >= 0; i--, dp++ )
|
||||||
if( mpi_getbyte( result, i ) != *dp ) {
|
if( mpi_getbyte( result, i ) != *dp ) {
|
||||||
rc = G10ERR_BAD_SIGN;
|
rc = G10ERR_BAD_SIGN;
|
||||||
@ -187,7 +187,7 @@ signature_check( PKT_signature *sig, MD_HANDLE digest )
|
|||||||
md_putc( digest, a & 0xff );
|
md_putc( digest, a & 0xff );
|
||||||
}
|
}
|
||||||
md_final( digest );
|
md_final( digest );
|
||||||
dp = md_read( digest, 0 );
|
dp = md_read( digest, DIGEST_ALGO_MD5 );
|
||||||
for(i=15; i >= 0; i--, dp++ )
|
for(i=15; i >= 0; i--, dp++ )
|
||||||
if( mpi_getbyte( result, i ) != *dp ) {
|
if( mpi_getbyte( result, i ) != *dp ) {
|
||||||
rc = G10ERR_BAD_SIGN;
|
rc = G10ERR_BAD_SIGN;
|
||||||
@ -220,7 +220,7 @@ signature_check( PKT_signature *sig, MD_HANDLE digest )
|
|||||||
* check the signature pointed to by NODE. This is a key signatures
|
* check the signature pointed to by NODE. This is a key signatures
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
check_key_signature( KBNODE root, KBNODE node )
|
check_key_signature( KBNODE root, KBNODE node, int *is_selfsig )
|
||||||
{
|
{
|
||||||
KBNODE unode;
|
KBNODE unode;
|
||||||
MD_HANDLE md;
|
MD_HANDLE md;
|
||||||
@ -229,6 +229,8 @@ check_key_signature( KBNODE root, KBNODE node )
|
|||||||
int algo;
|
int algo;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
if( is_selfsig )
|
||||||
|
*is_selfsig = 0;
|
||||||
assert( node->pkt->pkttype == PKT_SIGNATURE );
|
assert( node->pkt->pkttype == PKT_SIGNATURE );
|
||||||
assert( (node->pkt->pkt.signature->sig_class&~3) == 0x10 );
|
assert( (node->pkt->pkt.signature->sig_class&~3) == 0x10 );
|
||||||
assert( root->pkt->pkttype == PKT_PUBLIC_CERT );
|
assert( root->pkt->pkttype == PKT_PUBLIC_CERT );
|
||||||
@ -250,6 +252,13 @@ check_key_signature( KBNODE root, KBNODE node )
|
|||||||
if( unode && unode->pkt->pkttype == PKT_USER_ID ) {
|
if( unode && unode->pkt->pkttype == PKT_USER_ID ) {
|
||||||
PKT_user_id *uid = unode->pkt->pkt.user_id;
|
PKT_user_id *uid = unode->pkt->pkt.user_id;
|
||||||
|
|
||||||
|
if( is_selfsig ) {
|
||||||
|
u32 keyid[2];
|
||||||
|
|
||||||
|
keyid_from_pkc( pkc, keyid );
|
||||||
|
if( keyid[0] == sig->keyid[0] && keyid[1] == sig->keyid[1] )
|
||||||
|
*is_selfsig = 1;
|
||||||
|
}
|
||||||
md = md_open( algo, 0 );
|
md = md_open( algo, 0 );
|
||||||
hash_public_cert( md, pkc );
|
hash_public_cert( md, pkc );
|
||||||
md_write( md, uid->name, uid->len );
|
md_write( md, uid->name, uid->len );
|
||||||
|
19
g10/sign.c
19
g10/sign.c
@ -52,7 +52,7 @@ complete_sig( PKT_signature *sig, PKT_secret_cert *skc, MD_HANDLE md )
|
|||||||
else if( sig->pubkey_algo == PUBKEY_ALGO_RSA )
|
else if( sig->pubkey_algo == PUBKEY_ALGO_RSA )
|
||||||
g10_rsa_sign( skc, sig, md );
|
g10_rsa_sign( skc, sig, md );
|
||||||
else
|
else
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
|
|
||||||
/* fixme: should we check wether the signature is okay? */
|
/* fixme: should we check wether the signature is okay? */
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
|
|||||||
PACKET pkt;
|
PACKET pkt;
|
||||||
PKT_plaintext *pt = NULL;
|
PKT_plaintext *pt = NULL;
|
||||||
u32 filesize;
|
u32 filesize;
|
||||||
int last_rc, rc = 0;
|
int rc = 0;
|
||||||
PKC_LIST pkc_list = NULL;
|
PKC_LIST pkc_list = NULL;
|
||||||
SKC_LIST skc_list = NULL;
|
SKC_LIST skc_list = NULL;
|
||||||
SKC_LIST skc_rover = NULL;
|
SKC_LIST skc_rover = NULL;
|
||||||
@ -318,7 +318,7 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
|
|||||||
}
|
}
|
||||||
#endif/*HAVE_RSA_CIPHER*/
|
#endif/*HAVE_RSA_CIPHER*/
|
||||||
else
|
else
|
||||||
log_bug(NULL);
|
BUG();
|
||||||
|
|
||||||
md_close( md );
|
md_close( md );
|
||||||
|
|
||||||
@ -428,7 +428,7 @@ check_all_keysigs( KBNODE keyblock )
|
|||||||
int sigrc;
|
int sigrc;
|
||||||
|
|
||||||
tty_printf("sig");
|
tty_printf("sig");
|
||||||
switch( (rc = check_key_signature( keyblock, node )) ) {
|
switch( (rc = check_key_signature( keyblock, node,NULL)) ) {
|
||||||
case 0: node->flag = 0; sigrc = '!'; break;
|
case 0: node->flag = 0; sigrc = '!'; break;
|
||||||
case G10ERR_BAD_SIGN: inv_sigs++; node->flag = 1; sigrc = '-'; break;
|
case G10ERR_BAD_SIGN: inv_sigs++; node->flag = 1; sigrc = '-'; break;
|
||||||
case G10ERR_NO_PUBKEY: no_key++; node->flag = 2; sigrc = '?'; break;
|
case G10ERR_NO_PUBKEY: no_key++; node->flag = 2; sigrc = '?'; break;
|
||||||
@ -478,7 +478,6 @@ remove_keysigs( KBNODE keyblock, int all )
|
|||||||
&& node->pkt->pkttype == PKT_SIGNATURE
|
&& node->pkt->pkttype == PKT_SIGNATURE
|
||||||
&& (node->pkt->pkt.signature->sig_class&~3) == 0x10 ) {
|
&& (node->pkt->pkt.signature->sig_class&~3) == 0x10 ) {
|
||||||
PKT_signature *sig = node->pkt->pkt.signature;
|
PKT_signature *sig = node->pkt->pkt.signature;
|
||||||
int sigrc;
|
|
||||||
|
|
||||||
if( all ) {
|
if( all ) {
|
||||||
/* fixme: skip self-sig */
|
/* fixme: skip self-sig */
|
||||||
@ -546,14 +545,13 @@ sign_key( const char *username, STRLIST locusr )
|
|||||||
KBNODE kbctx, node;
|
KBNODE kbctx, node;
|
||||||
KBPOS kbpos;
|
KBPOS kbpos;
|
||||||
PKT_public_cert *pkc;
|
PKT_public_cert *pkc;
|
||||||
int any;
|
|
||||||
u32 pkc_keyid[2];
|
u32 pkc_keyid[2];
|
||||||
char *answer;
|
char *answer;
|
||||||
|
|
||||||
memset( &mfx, 0, sizeof mfx);
|
memset( &mfx, 0, sizeof mfx);
|
||||||
|
|
||||||
/* search the userid */
|
/* search the userid */
|
||||||
rc = search_keyblock_byname( &kbpos, username );
|
rc = find_keyblock_byname( &kbpos, username );
|
||||||
if( rc ) {
|
if( rc ) {
|
||||||
log_error("user '%s' not found\n", username );
|
log_error("user '%s' not found\n", username );
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -687,12 +685,10 @@ edit_keysigs( const char *username )
|
|||||||
KBNODE kbctx, node;
|
KBNODE kbctx, node;
|
||||||
KBPOS kbpos;
|
KBPOS kbpos;
|
||||||
PKT_public_cert *pkc;
|
PKT_public_cert *pkc;
|
||||||
int any;
|
|
||||||
u32 pkc_keyid[2];
|
u32 pkc_keyid[2];
|
||||||
char *answer;
|
|
||||||
|
|
||||||
/* search the userid */
|
/* search the userid */
|
||||||
rc = search_keyblock_byname( &kbpos, username );
|
rc = find_keyblock_byname( &kbpos, username );
|
||||||
if( rc ) {
|
if( rc ) {
|
||||||
log_error("user '%s' not found\n", username );
|
log_error("user '%s' not found\n", username );
|
||||||
goto leave;
|
goto leave;
|
||||||
@ -755,13 +751,12 @@ change_passphrase( const char *username )
|
|||||||
KBNODE kbctx, node;
|
KBNODE kbctx, node;
|
||||||
KBPOS kbpos;
|
KBPOS kbpos;
|
||||||
PKT_secret_cert *skc;
|
PKT_secret_cert *skc;
|
||||||
int any;
|
|
||||||
u32 skc_keyid[2];
|
u32 skc_keyid[2];
|
||||||
char *answer;
|
char *answer;
|
||||||
int changed=0;
|
int changed=0;
|
||||||
|
|
||||||
/* search the userid */
|
/* search the userid */
|
||||||
rc = search_secret_keyblock_byname( &kbpos, username );
|
rc = find_secret_keyblock_byname( &kbpos, username );
|
||||||
if( rc ) {
|
if( rc ) {
|
||||||
log_error("secret key for user '%s' not found\n", username );
|
log_error("secret key for user '%s' not found\n", username );
|
||||||
goto leave;
|
goto leave;
|
||||||
|
@ -49,7 +49,6 @@ int
|
|||||||
build_skc_list( STRLIST locusr, SKC_LIST *ret_skc_list, int unlock )
|
build_skc_list( STRLIST locusr, SKC_LIST *ret_skc_list, int unlock )
|
||||||
{
|
{
|
||||||
SKC_LIST skc_list = NULL;
|
SKC_LIST skc_list = NULL;
|
||||||
SKC_LIST skc_rover = NULL;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if( !locusr ) { /* use the default one */
|
if( !locusr ) { /* use the default one */
|
||||||
|
859
g10/trustdb.c
859
g10/trustdb.c
File diff suppressed because it is too large
Load Diff
@ -34,8 +34,12 @@
|
|||||||
|
|
||||||
|
|
||||||
/*-- trustdb.c --*/
|
/*-- trustdb.c --*/
|
||||||
int check_trustdb( int level );
|
void list_trustdb(const char *username);
|
||||||
|
void list_trust_path( int max_depth, const char *username );
|
||||||
|
int init_trustdb( int level );
|
||||||
int check_pkc_trust( PKT_public_cert *pkc, int *r_trustlevel );
|
int check_pkc_trust( PKT_public_cert *pkc, int *r_trustlevel );
|
||||||
|
int get_ownertrust( PKT_public_cert *pkc, int *r_otrust );
|
||||||
|
int insert_trust_record( PKT_public_cert *pkc );
|
||||||
int verify_private_data(void);
|
int verify_private_data(void);
|
||||||
int sign_private_data(void);
|
int sign_private_data(void);
|
||||||
|
|
||||||
|
@ -78,6 +78,7 @@ int check_pubkey_algo( int algo );
|
|||||||
int check_digest_algo( int algo );
|
int check_digest_algo( int algo );
|
||||||
|
|
||||||
/*-- random.c --*/
|
/*-- random.c --*/
|
||||||
|
int quick_random_gen( int onoff );
|
||||||
void randomize_buffer( byte *buffer, size_t length, int level );
|
void randomize_buffer( byte *buffer, size_t length, int level );
|
||||||
byte get_random_byte( int level );
|
byte get_random_byte( int level );
|
||||||
|
|
||||||
|
@ -53,5 +53,6 @@
|
|||||||
#define G10ERR_RESOURCE_LIMIT 31
|
#define G10ERR_RESOURCE_LIMIT 31
|
||||||
#define G10ERR_INV_KEYRING 32
|
#define G10ERR_INV_KEYRING 32
|
||||||
#define G10ERR_TRUSTDB 33 /* a problem with the trustdb */
|
#define G10ERR_TRUSTDB 33 /* a problem with the trustdb */
|
||||||
|
#define G10ERR_BAD_CERT 34 /* bad certicate */
|
||||||
|
|
||||||
#endif /*G10_ERRORS_H*/
|
#endif /*G10_ERRORS_H*/
|
||||||
|
@ -93,6 +93,7 @@ u32 iobuf_get_filelength( IOBUF a );
|
|||||||
const char *iobuf_get_fname( IOBUF a );
|
const char *iobuf_get_fname( IOBUF a );
|
||||||
|
|
||||||
void iobuf_set_block_mode( IOBUF a, size_t n );
|
void iobuf_set_block_mode( IOBUF a, size_t n );
|
||||||
|
void iobuf_set_partial_block_mode( IOBUF a, size_t len );
|
||||||
int iobuf_in_block_mode( IOBUF a );
|
int iobuf_in_block_mode( IOBUF a );
|
||||||
|
|
||||||
/* get a byte form the iobuf; must check for eof prior to this function
|
/* get a byte form the iobuf; must check for eof prior to this function
|
||||||
|
@ -41,7 +41,6 @@ int mpi_debug_mode;
|
|||||||
|
|
||||||
#define BITS_PER_MPI_LIMB (8*SIZEOF_UNSIGNED_LONG)
|
#define BITS_PER_MPI_LIMB (8*SIZEOF_UNSIGNED_LONG)
|
||||||
#define BYTES_PER_MPI_LIMB SIZEOF_UNSIGNED_LONG
|
#define BYTES_PER_MPI_LIMB SIZEOF_UNSIGNED_LONG
|
||||||
#define BYTES_PER_MPI_LIMB2 (2*SIZEOF_UNSIGNED_LONG)
|
|
||||||
typedef unsigned long int mpi_limb_t;
|
typedef unsigned long int mpi_limb_t;
|
||||||
typedef signed long int mpi_limb_signed_t;
|
typedef signed long int mpi_limb_signed_t;
|
||||||
|
|
||||||
|
@ -58,20 +58,38 @@ typedef struct {
|
|||||||
/*-- logger.c --*/
|
/*-- logger.c --*/
|
||||||
void log_set_pid( int pid );
|
void log_set_pid( int pid );
|
||||||
int log_get_errorcount( int clear );
|
int log_get_errorcount( int clear );
|
||||||
void printstr( int level, const char *fmt, ... );
|
|
||||||
void log_bug( const char *fmt, ... );
|
|
||||||
void log_fatal( const char *fmt, ... );
|
|
||||||
void log_error( const char *fmt, ... );
|
|
||||||
void log_info( const char *fmt, ... );
|
|
||||||
void log_debug( const char *fmt, ... );
|
|
||||||
void log_hexdump( const char *text, char *buf, size_t len );
|
void log_hexdump( const char *text, char *buf, size_t len );
|
||||||
void log_mpidump( const char *text, MPI a );
|
void log_mpidump( const char *text, MPI a );
|
||||||
|
|
||||||
|
#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )
|
||||||
|
void printstr( int level, const char *fmt, ... )
|
||||||
|
__attribute__ ((format (printf,2,3)));
|
||||||
|
void log_bug( const char *fmt, ... )
|
||||||
|
__attribute__ ((noreturn, format (printf,1,2)));
|
||||||
|
void log_bug0( void ) __attribute__ ((noreturn));
|
||||||
|
void log_fatal( const char *fmt, ... )
|
||||||
|
__attribute__ ((noreturn, format (printf,1,2)));
|
||||||
|
void log_error( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
|
||||||
|
void log_info( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
|
||||||
|
void log_debug( const char *fmt, ... ) __attribute__ ((format (printf,1,2)));
|
||||||
|
#else
|
||||||
|
void printstr( int level, const char *fmt, ... );
|
||||||
|
void log_bug( const char *fmt, ... );
|
||||||
|
void log_bug0( void );
|
||||||
|
void log_fatal( const char *fmt, ... );
|
||||||
|
void log_error( const char *fmt, ... );
|
||||||
|
void log_info( const char *fmt, ... );
|
||||||
|
void log_debug( const char *fmt, ... );
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*-- errors.c --*/
|
/*-- errors.c --*/
|
||||||
const char * g10_errstr( int no );
|
const char * g10_errstr( int no );
|
||||||
|
|
||||||
/*-- argparse.c --*/
|
/*-- argparse.c --*/
|
||||||
int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
|
int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
|
||||||
|
int optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
|
||||||
|
ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts);
|
||||||
void usage( int level );
|
void usage( int level );
|
||||||
const char *default_strusage( int level );
|
const char *default_strusage( int level );
|
||||||
|
|
||||||
@ -112,5 +130,6 @@ char *strlwr(char *a);
|
|||||||
#define STR2(v) STR(v)
|
#define STR2(v) STR(v)
|
||||||
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
#define DIM(v) (sizeof(v)/sizeof((v)[0]))
|
||||||
#define DIMof(type,member) DIM(((type *)0)->member)
|
#define DIMof(type,member) DIM(((type *)0)->member)
|
||||||
|
#define BUG() log_bug0()
|
||||||
|
|
||||||
#endif /*G10_UTIL_H*/
|
#endif /*G10_UTIL_H*/
|
||||||
|
@ -32,8 +32,7 @@
|
|||||||
unsigned
|
unsigned
|
||||||
mpi_get_nbits( MPI a )
|
mpi_get_nbits( MPI a )
|
||||||
{
|
{
|
||||||
unsigned nbits;
|
unsigned n;
|
||||||
unsigned n, count = 0;
|
|
||||||
|
|
||||||
if( a->nlimbs ) {
|
if( a->nlimbs ) {
|
||||||
mpi_limb_t alimb = a->d[a->nlimbs-1];
|
mpi_limb_t alimb = a->d[a->nlimbs-1];
|
||||||
|
@ -193,7 +193,7 @@ void mpih_sqr_n_basecase( mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t size );
|
|||||||
void mpih_sqr_n( mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t size,
|
void mpih_sqr_n( mpi_ptr_t prodp, mpi_ptr_t up, mpi_size_t size,
|
||||||
mpi_ptr_t tspace);
|
mpi_ptr_t tspace);
|
||||||
|
|
||||||
/*-- mpihelp-mul_1.c (or xxx/cpu/*.S) --*/
|
/*-- mpihelp-mul_1.c (or xxx/cpu/ *.S) --*/
|
||||||
mpi_limb_t mpihelp_mul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
|
mpi_limb_t mpihelp_mul_1( mpi_ptr_t res_ptr, mpi_ptr_t s1_ptr,
|
||||||
mpi_size_t s1_size, mpi_limb_t s2_limb);
|
mpi_size_t s1_size, mpi_limb_t s2_limb);
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ mpi_powm( MPI res, MPI base, MPI exp, MPI mod)
|
|||||||
mpi_ptr_t xp_marker=NULL;
|
mpi_ptr_t xp_marker=NULL;
|
||||||
int assign_rp=0;
|
int assign_rp=0;
|
||||||
mpi_ptr_t tspace = NULL;
|
mpi_ptr_t tspace = NULL;
|
||||||
mpi_size_t tsize;
|
mpi_size_t tsize=0; /* to avoid compiler warning, fixme: check */
|
||||||
|
|
||||||
esize = exp->nlimbs;
|
esize = exp->nlimbs;
|
||||||
msize = mod->nlimbs;
|
msize = mod->nlimbs;
|
||||||
|
@ -41,36 +41,23 @@
|
|||||||
int
|
int
|
||||||
mpi_write( IOBUF out, MPI a )
|
mpi_write( IOBUF out, MPI a )
|
||||||
{
|
{
|
||||||
int i;
|
int rc;
|
||||||
unsigned nbits = a->nlimbs * BITS_PER_MPI_LIMB;
|
unsigned nbits = mpi_get_nbits(a);
|
||||||
mpi_limb_t limb;
|
byte *p, *buf;
|
||||||
|
unsigned n;
|
||||||
|
|
||||||
/* fixme: use a->nbits if valid */
|
|
||||||
if( nbits > MAX_EXTERN_MPI_BITS )
|
if( nbits > MAX_EXTERN_MPI_BITS )
|
||||||
log_bug("mpi_encode: mpi too large (%u bits)\n", nbits);
|
log_bug("mpi_encode: mpi too large (%u bits)\n", nbits);
|
||||||
|
|
||||||
iobuf_put(out, (nbits >>8) );
|
iobuf_put(out, (nbits >>8) );
|
||||||
iobuf_put(out, (nbits) );
|
iobuf_put(out, (nbits) );
|
||||||
for(i=a->nlimbs-1; i >= 0; i-- ) {
|
|
||||||
limb = a->d[i];
|
p = buf = mpi_get_buffer( a, &n, NULL );
|
||||||
#if BYTES_PER_MPI_LIMB == 4
|
for( ; !*p && n; p++, n-- )
|
||||||
iobuf_put(out, (limb >> 24) );
|
;
|
||||||
iobuf_put(out, (limb >> 16) );
|
rc = iobuf_write( out, p, n );
|
||||||
iobuf_put(out, (limb >> 8) );
|
m_free(buf);
|
||||||
iobuf_put(out, (limb ) );
|
return rc;
|
||||||
#elif BYTES_PER_MPI_LIMB == 8
|
|
||||||
iobuf_put(out, (limb >> 56) );
|
|
||||||
iobuf_put(out, (limb >> 48) );
|
|
||||||
iobuf_put(out, (limb >> 40) );
|
|
||||||
iobuf_put(out, (limb >> 32) );
|
|
||||||
iobuf_put(out, (limb >> 24) );
|
|
||||||
iobuf_put(out, (limb >> 16) );
|
|
||||||
iobuf_put(out, (limb >> 8) );
|
|
||||||
iobuf_put(out, (limb ) );
|
|
||||||
#else
|
|
||||||
#error Make this function work with other LIMB sizes
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -225,13 +212,22 @@ mpi_print( FILE *fp, MPI a, int mode )
|
|||||||
if( a == MPI_NULL )
|
if( a == MPI_NULL )
|
||||||
return fprintf(fp, "[MPI_NULL]");
|
return fprintf(fp, "[MPI_NULL]");
|
||||||
if( !mode )
|
if( !mode )
|
||||||
n += fprintf(fp, "[%d bits]", a->nlimbs * BITS_PER_MPI_LIMB );
|
n += fprintf(fp, "[%u bits]", mpi_get_nbits(a) );
|
||||||
else {
|
else {
|
||||||
if( a->sign )
|
if( a->sign )
|
||||||
putc('-', fp);
|
putc('-', fp);
|
||||||
|
#if BYTES_PER_MPI_LIMB == 2
|
||||||
|
#define X "4"
|
||||||
|
#elif BYTES_PER_MPI_LIMB == 4
|
||||||
|
#define X "8"
|
||||||
|
#elif BYTES_PER_MPI_LIMB == 8
|
||||||
|
#define X "16"
|
||||||
|
#else
|
||||||
|
#error please define the format here
|
||||||
|
#endif
|
||||||
for(i=a->nlimbs; i > 0 ; i-- ) {
|
for(i=a->nlimbs; i > 0 ; i-- ) {
|
||||||
n += fprintf(fp, i!=a->nlimbs? "%0" STR2(BYTES_PER_MPI_LIMB2)
|
n += fprintf(fp, i!=a->nlimbs? "%0" X "lX":"%lX", (ulong)a->d[i-1]);
|
||||||
"lX":"%lX", (unsigned long)a->d[i-1] );
|
#undef X
|
||||||
}
|
}
|
||||||
if( !a->nlimbs )
|
if( !a->nlimbs )
|
||||||
putc('0', fp );
|
putc('0', fp );
|
||||||
|
@ -45,7 +45,7 @@ mpi_alloc( unsigned nlimbs )
|
|||||||
MPI a;
|
MPI a;
|
||||||
|
|
||||||
if( DBG_MEMORY )
|
if( DBG_MEMORY )
|
||||||
log_debug("mpi_alloc(%lu)\n", nlimbs*BITS_PER_MPI_LIMB );
|
log_debug("mpi_alloc(%u)\n", nlimbs*BITS_PER_MPI_LIMB );
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
a = m_debug_alloc( sizeof *a, info );
|
a = m_debug_alloc( sizeof *a, info );
|
||||||
a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 0, info ) : NULL;
|
a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 0, info ) : NULL;
|
||||||
@ -77,7 +77,7 @@ mpi_alloc_secure( unsigned nlimbs )
|
|||||||
MPI a;
|
MPI a;
|
||||||
|
|
||||||
if( DBG_MEMORY )
|
if( DBG_MEMORY )
|
||||||
log_debug("mpi_alloc_secure(%lu)\n", nlimbs*BITS_PER_MPI_LIMB );
|
log_debug("mpi_alloc_secure(%u)\n", nlimbs*BITS_PER_MPI_LIMB );
|
||||||
#ifdef M_DEBUG
|
#ifdef M_DEBUG
|
||||||
a = m_debug_alloc( sizeof *a, info );
|
a = m_debug_alloc( sizeof *a, info );
|
||||||
a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 1, info ) : NULL;
|
a->d = nlimbs? mpi_debug_alloc_limb_space( nlimbs, 1, info ) : NULL;
|
||||||
|
@ -188,7 +188,6 @@ int
|
|||||||
optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
|
optfile_parse( FILE *fp, const char *filename, unsigned *lineno,
|
||||||
ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
|
ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts)
|
||||||
{
|
{
|
||||||
char *s, *s2;
|
|
||||||
int state, i, c;
|
int state, i, c;
|
||||||
int index=0;
|
int index=0;
|
||||||
char keyword[100];
|
char keyword[100];
|
||||||
|
@ -33,6 +33,8 @@ g10_errstr( int err )
|
|||||||
|
|
||||||
#define X(n,s) case G10ERR_##n : p = s; break;
|
#define X(n,s) case G10ERR_##n : p = s; break;
|
||||||
switch( err ) {
|
switch( err ) {
|
||||||
|
case -1: p = "eof"; break;
|
||||||
|
case 0: p = "okay"; break;
|
||||||
X(GENERAL, "General error")
|
X(GENERAL, "General error")
|
||||||
X(UNKNOWN_PACKET, "Unknown packet type")
|
X(UNKNOWN_PACKET, "Unknown packet type")
|
||||||
X(UNKNOWN_VERSION,"Unknown version")
|
X(UNKNOWN_VERSION,"Unknown version")
|
||||||
@ -46,6 +48,7 @@ g10_errstr( int err )
|
|||||||
X(NO_PUBKEY ,"Public key not found")
|
X(NO_PUBKEY ,"Public key not found")
|
||||||
X(CIPHER_ALGO ,"Unknown cipher algorithm")
|
X(CIPHER_ALGO ,"Unknown cipher algorithm")
|
||||||
X(KEYRING_OPEN ,"Can't open the keyring")
|
X(KEYRING_OPEN ,"Can't open the keyring")
|
||||||
|
X(INVALID_PACKET ,"Invalid packet")
|
||||||
X(BAD_RING ,"Broken keyring")
|
X(BAD_RING ,"Broken keyring")
|
||||||
X(NO_USER_ID ,"No such user id found")
|
X(NO_USER_ID ,"No such user id found")
|
||||||
X(NO_SECKEY ,"Secret key not available")
|
X(NO_SECKEY ,"Secret key not available")
|
||||||
@ -61,8 +64,10 @@ g10_errstr( int err )
|
|||||||
X(NI_PUBKEY ,"Unimplemented pubkey algorithm")
|
X(NI_PUBKEY ,"Unimplemented pubkey algorithm")
|
||||||
X(NI_CIPHER ,"Unimplemented cipher algorithm")
|
X(NI_CIPHER ,"Unimplemented cipher algorithm")
|
||||||
X(SIG_CLASS ,"Unknown signature class")
|
X(SIG_CLASS ,"Unknown signature class")
|
||||||
|
X(TRUSTDB ,"TrustDB error")
|
||||||
|
X(BAD_CERT ,"Bad certificate")
|
||||||
|
|
||||||
default: p = buf; sprintf(buf, "Error code %d", err); break;
|
default: p = buf; sprintf(buf, "g10err=%d", err); break;
|
||||||
}
|
}
|
||||||
#undef X
|
#undef X
|
||||||
return p;
|
return p;
|
||||||
|
106
util/iobuf.c
106
util/iobuf.c
@ -40,6 +40,7 @@ typedef struct {
|
|||||||
int usage;
|
int usage;
|
||||||
size_t size;
|
size_t size;
|
||||||
size_t count;
|
size_t count;
|
||||||
|
int partial; /* 1 = partial header, 2 in last partial packet */
|
||||||
int eof;
|
int eof;
|
||||||
} block_filter_ctx_t;
|
} block_filter_ctx_t;
|
||||||
|
|
||||||
@ -143,20 +144,64 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
rc = -1;
|
rc = -1;
|
||||||
while( !rc && size ) {
|
while( !rc && size ) {
|
||||||
if( !a->size ) { /* get the length bytes */
|
if( !a->size ) { /* get the length bytes */
|
||||||
c = iobuf_get(chain);
|
if( a->partial == 2 ) {
|
||||||
a->size = c << 8;
|
|
||||||
c = iobuf_get(chain);
|
|
||||||
a->size |= c;
|
|
||||||
if( c == -1 ) {
|
|
||||||
log_error("block_filter: error reading length info\n");
|
|
||||||
rc = G10ERR_READ_FILE;
|
|
||||||
}
|
|
||||||
if( !a->size ) {
|
|
||||||
a->eof = 1;
|
a->eof = 1;
|
||||||
if( !n )
|
if( !n )
|
||||||
rc = -1;
|
rc = -1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
else if( a->partial ) {
|
||||||
|
if( (c = iobuf_get(chain)) == -1 ) {
|
||||||
|
log_error("block_filter: 1st length byte missing\n");
|
||||||
|
rc = G10ERR_READ_FILE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( c < 192 ) {
|
||||||
|
a->size = c;
|
||||||
|
a->partial = 2;
|
||||||
|
if( !a->size ) {
|
||||||
|
a->eof = 1;
|
||||||
|
if( !n )
|
||||||
|
rc = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if( c < 224 ) {
|
||||||
|
a->size = (c - 192) * 256;
|
||||||
|
if( (c = iobuf_get(chain)) == -1 ) {
|
||||||
|
log_error("block_filter: 2nd length byte missing\n");
|
||||||
|
rc = G10ERR_READ_FILE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
a->size += c + 192;
|
||||||
|
a->partial = 2;
|
||||||
|
if( !a->size ) {
|
||||||
|
a->eof = 1;
|
||||||
|
if( !n )
|
||||||
|
rc = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { /* next partial body length */
|
||||||
|
a->size = 1 << (c & 0x1f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
c = iobuf_get(chain);
|
||||||
|
a->size = c << 8;
|
||||||
|
c = iobuf_get(chain);
|
||||||
|
a->size |= c;
|
||||||
|
if( c == -1 ) {
|
||||||
|
log_error("block_filter: error reading length info\n");
|
||||||
|
rc = G10ERR_READ_FILE;
|
||||||
|
}
|
||||||
|
if( !a->size ) {
|
||||||
|
a->eof = 1;
|
||||||
|
if( !n )
|
||||||
|
rc = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(; !rc && size && a->size; size--, a->size-- ) {
|
for(; !rc && size && a->size; size--, a->size-- ) {
|
||||||
@ -176,6 +221,7 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
else if( control == IOBUFCTRL_FLUSH ) {
|
else if( control == IOBUFCTRL_FLUSH ) {
|
||||||
size_t avail, n;
|
size_t avail, n;
|
||||||
|
|
||||||
|
assert( !a->partial );
|
||||||
for(p=buf; !rc && size; ) {
|
for(p=buf; !rc && size; ) {
|
||||||
n = size;
|
n = size;
|
||||||
avail = a->size - a->count;
|
avail = a->size - a->count;
|
||||||
@ -205,7 +251,9 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
else if( control == IOBUFCTRL_INIT ) {
|
else if( control == IOBUFCTRL_INIT ) {
|
||||||
if( DBG_IOBUF )
|
if( DBG_IOBUF )
|
||||||
log_debug("init block_filter %p\n", a );
|
log_debug("init block_filter %p\n", a );
|
||||||
if( a->usage == 1 )
|
if( a->partial )
|
||||||
|
a->count = 0;
|
||||||
|
else if( a->usage == 1 )
|
||||||
a->count = a->size = 0;
|
a->count = a->size = 0;
|
||||||
else
|
else
|
||||||
a->count = a->size; /* force first length bytes */
|
a->count = a->size; /* force first length bytes */
|
||||||
@ -216,8 +264,12 @@ block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len)
|
|||||||
}
|
}
|
||||||
else if( control == IOBUFCTRL_FREE ) {
|
else if( control == IOBUFCTRL_FREE ) {
|
||||||
if( a->usage == 2 ) { /* write the end markers */
|
if( a->usage == 2 ) { /* write the end markers */
|
||||||
iobuf_writebyte(chain, 0);
|
if( a->partial ) {
|
||||||
iobuf_writebyte(chain, 0);
|
}
|
||||||
|
else {
|
||||||
|
iobuf_writebyte(chain, 0);
|
||||||
|
iobuf_writebyte(chain, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if( a->size ) {
|
else if( a->size ) {
|
||||||
log_error("block_filter: pending bytes!\n");
|
log_error("block_filter: pending bytes!\n");
|
||||||
@ -784,7 +836,10 @@ iobuf_seek( IOBUF a, ulong newpos )
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
a->ntotal = newpos;
|
a->ntotal = newpos;
|
||||||
/* FIXME: flush all buffers (and remove filters?)*/
|
/* remove filters, but the last */
|
||||||
|
while( a->chain )
|
||||||
|
iobuf_pop_filter( a, a->filter, NULL );
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -800,8 +855,6 @@ iobuf_seek( IOBUF a, ulong newpos )
|
|||||||
const char *
|
const char *
|
||||||
iobuf_get_fname( IOBUF a )
|
iobuf_get_fname( IOBUF a )
|
||||||
{
|
{
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
for( ; a; a = a->chain )
|
for( ; a; a = a->chain )
|
||||||
if( !a->chain && a->filter == file_filter ) {
|
if( !a->chain && a->filter == file_filter ) {
|
||||||
file_filter_ctx_t *b = a->filter_ov;
|
file_filter_ctx_t *b = a->filter_ov;
|
||||||
@ -832,6 +885,27 @@ iobuf_set_block_mode( IOBUF a, size_t n )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************
|
||||||
|
* enable patial block mode as descriped in the OpenPGP draft.
|
||||||
|
* LEN is the first length
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
iobuf_set_partial_block_mode( IOBUF a, size_t len )
|
||||||
|
{
|
||||||
|
block_filter_ctx_t *ctx = m_alloc_clear( sizeof *ctx );
|
||||||
|
|
||||||
|
assert( a->usage == 1 || a->usage == 2 );
|
||||||
|
ctx->usage = a->usage;
|
||||||
|
if( !len ) {
|
||||||
|
iobuf_pop_filter(a, block_filter, NULL );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ctx->partial = 1;
|
||||||
|
ctx->size = len;
|
||||||
|
iobuf_push_filter(a, block_filter, ctx );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/****************
|
/****************
|
||||||
* Checks wether the stream is in block mode
|
* Checks wether the stream is in block mode
|
||||||
@ -841,7 +915,7 @@ int
|
|||||||
iobuf_in_block_mode( IOBUF a )
|
iobuf_in_block_mode( IOBUF a )
|
||||||
{
|
{
|
||||||
if( a && a->filter == block_filter )
|
if( a && a->filter == block_filter )
|
||||||
return 1; /* yes */
|
return 1; /* yes */
|
||||||
return 0; /* no */
|
return 0; /* no */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,17 +120,19 @@ log_bug( const char *fmt, ... )
|
|||||||
va_list arg_ptr ;
|
va_list arg_ptr ;
|
||||||
|
|
||||||
fprintf(stderr, "\nInternal Error%s: ", pidstring ) ;
|
fprintf(stderr, "\nInternal Error%s: ", pidstring ) ;
|
||||||
if( fmt ) {
|
va_start( arg_ptr, fmt ) ;
|
||||||
va_start( arg_ptr, fmt ) ;
|
vfprintf(stderr,fmt,arg_ptr) ;
|
||||||
vfprintf(stderr,fmt,arg_ptr) ;
|
va_end(arg_ptr);
|
||||||
va_end(arg_ptr);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
fputs("Ohhh jeeee ...\n", stderr);
|
|
||||||
fflush(stderr);
|
fflush(stderr);
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
log_bug0()
|
||||||
|
{
|
||||||
|
log_bug("Ohhhh jeeee ...\n");
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
log_debug( const char *fmt, ... )
|
log_debug( const char *fmt, ... )
|
||||||
{
|
{
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
#include <unistd.h>
|
||||||
#ifdef HAVE_TCGETATTR
|
#ifdef HAVE_TCGETATTR
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#endif
|
#endif
|
||||||
@ -99,7 +100,6 @@ do_get( const char *prompt, int hidden )
|
|||||||
char *buf;
|
char *buf;
|
||||||
byte cbuf[1];
|
byte cbuf[1];
|
||||||
int c, n, i;
|
int c, n, i;
|
||||||
FILE *fp;
|
|
||||||
#ifdef HAVE_TCGETATTR
|
#ifdef HAVE_TCGETATTR
|
||||||
struct termios termsave;
|
struct termios termsave;
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user