mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
See ChangeLog: Tue Jan 19 19:34:58 CET 1999 Werner Koch
This commit is contained in:
parent
befacf7efa
commit
ce650acf1f
19 changed files with 363 additions and 112 deletions
|
@ -1,3 +1,12 @@
|
|||
Tue Jan 19 19:34:58 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
|
||||
|
||||
* export.c (export_pubkeys_stream): New.
|
||||
(do_export_stream): New.
|
||||
* g10.c (aSendKeys): New command.
|
||||
* hkp.c (hkp_export): New.
|
||||
|
||||
* compress.c (do_uncompress): Hack for algo 1 and 1.1.3
|
||||
|
||||
Sun Jan 17 11:04:33 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
|
||||
|
||||
* textfilter.c (text_filter): Now uses iobuf_read_line().
|
||||
|
|
|
@ -146,8 +146,14 @@ do_uncompress( compress_filter_context_t *zfx, z_stream *zs,
|
|||
if( !n )
|
||||
zs->next_in = zfx->inbuf;
|
||||
for( p=zfx->inbuf+n; n < zfx->inbufsize; n++, p++ ) {
|
||||
if( (c=iobuf_get(a)) == -1 )
|
||||
break;
|
||||
if( (c=iobuf_get(a)) == -1 ) {
|
||||
/* If we use the undocumented feature to suppress
|
||||
* the zlib header, we have to give inflate an
|
||||
* extra dummy byte to read */
|
||||
if( zfx->algo != 1 || zfx->algo1hack )
|
||||
break;
|
||||
zfx->algo1hack = 1;
|
||||
}
|
||||
*p = c & 0xff;
|
||||
}
|
||||
zs->avail_in = n;
|
||||
|
|
67
g10/export.c
67
g10/export.c
|
@ -35,6 +35,8 @@
|
|||
#include "i18n.h"
|
||||
|
||||
static int do_export( STRLIST users, int secret, int onlyrfc );
|
||||
static int do_export_stream( IOBUF out, STRLIST users,
|
||||
int secret, int onlyrfc, int *any );
|
||||
|
||||
/****************
|
||||
* Export the public keys (to standard out or --output).
|
||||
|
@ -48,6 +50,21 @@ export_pubkeys( STRLIST users, int onlyrfc )
|
|||
return do_export( users, 0, onlyrfc );
|
||||
}
|
||||
|
||||
/****************
|
||||
* Export to an already opened stream; return -1 if no keys have
|
||||
* been exported
|
||||
*/
|
||||
int
|
||||
export_pubkeys_stream( IOBUF out, STRLIST users, int onlyrfc )
|
||||
{
|
||||
int any, rc;
|
||||
|
||||
rc = do_export_stream( out, users, 0, onlyrfc, &any );
|
||||
if( !rc && !any )
|
||||
rc = -1;
|
||||
return rc;
|
||||
}
|
||||
|
||||
int
|
||||
export_seckeys( STRLIST users )
|
||||
{
|
||||
|
@ -57,30 +74,46 @@ export_seckeys( STRLIST users )
|
|||
static int
|
||||
do_export( STRLIST users, int secret, int onlyrfc )
|
||||
{
|
||||
int rc = 0;
|
||||
armor_filter_context_t afx;
|
||||
compress_filter_context_t zfx;
|
||||
IOBUF out = NULL;
|
||||
int any, rc;
|
||||
armor_filter_context_t afx;
|
||||
|
||||
memset( &afx, 0, sizeof afx);
|
||||
|
||||
rc = open_outfile( NULL, 0, &out );
|
||||
if( rc )
|
||||
return rc;
|
||||
|
||||
if( opt.armor ) {
|
||||
afx.what = secret?5:1;
|
||||
iobuf_push_filter( out, armor_filter, &afx );
|
||||
}
|
||||
rc = do_export_stream( out, users, secret, onlyrfc, &any );
|
||||
|
||||
if( rc || !any )
|
||||
iobuf_cancel(out);
|
||||
else
|
||||
iobuf_close(out);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
do_export_stream( IOBUF out, STRLIST users, int secret, int onlyrfc, int *any )
|
||||
{
|
||||
int rc = 0;
|
||||
compress_filter_context_t zfx;
|
||||
PACKET pkt;
|
||||
KBNODE keyblock = NULL;
|
||||
KBNODE kbctx, node;
|
||||
KBPOS kbpos;
|
||||
STRLIST sl;
|
||||
int all = !users;
|
||||
int any=0;
|
||||
|
||||
memset( &afx, 0, sizeof afx);
|
||||
*any = 0;
|
||||
memset( &zfx, 0, sizeof zfx);
|
||||
init_packet( &pkt );
|
||||
|
||||
if( (rc = open_outfile( NULL, 0, &out )) )
|
||||
goto leave;
|
||||
|
||||
|
||||
if( opt.armor ) {
|
||||
afx.what = secret?5:1;
|
||||
iobuf_push_filter( out, armor_filter, &afx );
|
||||
}
|
||||
if( opt.compress_keys && opt.compress )
|
||||
iobuf_push_filter( out, compress_filter, &zfx );
|
||||
|
||||
|
@ -157,7 +190,7 @@ do_export( STRLIST users, int secret, int onlyrfc )
|
|||
goto leave;
|
||||
}
|
||||
}
|
||||
any++;
|
||||
++*any;
|
||||
}
|
||||
if( rc == -1 )
|
||||
rc = 0;
|
||||
|
@ -166,11 +199,7 @@ do_export( STRLIST users, int secret, int onlyrfc )
|
|||
if( all == 2 )
|
||||
enum_keyblocks( 2, &kbpos, &keyblock ); /* close */
|
||||
release_kbnode( keyblock );
|
||||
if( rc || !any )
|
||||
iobuf_cancel(out);
|
||||
else
|
||||
iobuf_close(out);
|
||||
if( !any )
|
||||
if( !*any )
|
||||
log_info(_("WARNING: nothing exported\n"));
|
||||
return rc;
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@ typedef struct {
|
|||
byte *outbuf;
|
||||
unsigned outbufsize;
|
||||
int algo; /* compress algo */
|
||||
int algo1hack;
|
||||
} compress_filter_context_t;
|
||||
|
||||
|
||||
|
|
10
g10/g10.c
10
g10/g10.c
|
@ -43,6 +43,7 @@
|
|||
#include "i18n.h"
|
||||
#include "status.h"
|
||||
#include "g10defs.h"
|
||||
#include "hkp.h"
|
||||
|
||||
#ifndef IS_G10MAINT
|
||||
#define IS_G10 1
|
||||
|
@ -83,6 +84,7 @@ enum cmd_and_opt_values { aNull = 0,
|
|||
aListKeys,
|
||||
aListSigs,
|
||||
aListSecretKeys,
|
||||
aSendKeys,
|
||||
aExport,
|
||||
aExportAll,
|
||||
aExportSecret,
|
||||
|
@ -184,6 +186,7 @@ static ARGPARSE_OPTS opts[] = {
|
|||
{ aGenRevoke, "gen-revoke",256, N_("generate a revocation certificate")},
|
||||
#endif
|
||||
{ aExport, "export" , 256, N_("export keys") },
|
||||
{ aSendKeys, "send-keys" , 256, N_("export keys to a key server") },
|
||||
{ aExportAll, "export-all" , 256, "@" },
|
||||
{ aExportSecret, "export-secret-keys" , 256, "@" },
|
||||
{ aImport, "import", 256 , N_("import/merge keys")},
|
||||
|
@ -639,6 +642,7 @@ main( int argc, char **argv )
|
|||
case aListPackets: set_cmd( &cmd, aListPackets); break;
|
||||
case aImport: set_cmd( &cmd, aImport); break;
|
||||
case aFastImport: set_cmd( &cmd, aFastImport); break;
|
||||
case aSendKeys: set_cmd( &cmd, aSendKeys); break;
|
||||
case aExport: set_cmd( &cmd, aExport); break;
|
||||
case aExportAll: set_cmd( &cmd, aExportAll); break;
|
||||
case aListKeys: set_cmd( &cmd, aListKeys); break;
|
||||
|
@ -1098,10 +1102,14 @@ main( int argc, char **argv )
|
|||
|
||||
case aExport:
|
||||
case aExportAll:
|
||||
case aSendKeys:
|
||||
sl = NULL;
|
||||
for( ; argc; argc--, argv++ )
|
||||
add_to_strlist( &sl, *argv );
|
||||
export_pubkeys( sl, (cmd == aExport) );
|
||||
if( cmd == aSendKeys )
|
||||
hkp_export( sl );
|
||||
else
|
||||
export_pubkeys( sl, (cmd == aExport) );
|
||||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
|
|
116
g10/hkp.c
116
g10/hkp.c
|
@ -22,6 +22,7 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
@ -30,9 +31,12 @@
|
|||
#include "ttyio.h"
|
||||
#include "i18n.h"
|
||||
#include "options.h"
|
||||
#include "filter.h"
|
||||
#include "http.h"
|
||||
#include "main.h"
|
||||
|
||||
static int urlencode_filter( void *opaque, int control,
|
||||
IOBUF a, byte *buf, size_t *ret_len);
|
||||
|
||||
/****************
|
||||
* Try to import the key with KEYID from a keyserver but ask the user
|
||||
|
@ -58,17 +62,119 @@ hkp_ask_import( u32 *keyid )
|
|||
* nicer one */
|
||||
sprintf( request, "x-hkp://%s:11371/pks/lookup?op=get&search=0x%08lX",
|
||||
opt.keyserver_name, (ulong)keyid[1] );
|
||||
rc = open_http_document( &hd, request, 0 );
|
||||
rc = http_open_document( &hd, request, 0 );
|
||||
if( rc ) {
|
||||
log_info("can't get key from keyserver: %s\n", g10_errstr(rc) );
|
||||
goto leave;
|
||||
}
|
||||
rc = import_keys_stream( hd.fp_read , 0 );
|
||||
close_http_document( &hd );
|
||||
else {
|
||||
rc = import_keys_stream( hd.fp_read , 0 );
|
||||
http_close( &hd );
|
||||
}
|
||||
|
||||
leave:
|
||||
m_free( request );
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
hkp_export( STRLIST users )
|
||||
{
|
||||
int rc;
|
||||
armor_filter_context_t afx;
|
||||
IOBUF temp = iobuf_temp();
|
||||
struct http_context hd;
|
||||
char *request;
|
||||
unsigned int status;
|
||||
|
||||
if( !opt.keyserver_name ) {
|
||||
log_error("no keyserver known (use option --keyserver)\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
iobuf_push_filter( temp, urlencode_filter, NULL );
|
||||
|
||||
memset( &afx, 0, sizeof afx);
|
||||
afx.what = 1;
|
||||
iobuf_push_filter( temp, armor_filter, &afx );
|
||||
|
||||
rc = export_pubkeys_stream( temp, users, 1 );
|
||||
if( rc == -1 ) {
|
||||
iobuf_close(temp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
iobuf_flush_temp( temp );
|
||||
|
||||
request = m_alloc( strlen( opt.keyserver_name ) + 100 );
|
||||
sprintf( request, "x-hkp://%s:11371/pks/add", opt.keyserver_name );
|
||||
rc = http_open( &hd, HTTP_REQ_POST, request , 0 );
|
||||
if( rc ) {
|
||||
log_error("can't connect to `%s': %s\n",
|
||||
opt.keyserver_name, g10_errstr(rc) );
|
||||
iobuf_close(temp);
|
||||
m_free( request );
|
||||
return rc;
|
||||
}
|
||||
|
||||
sprintf( request, "Content-Length: %u\n",
|
||||
(unsigned)iobuf_get_temp_length(temp) + 9 );
|
||||
iobuf_writestr( hd.fp_write, request );
|
||||
m_free( request );
|
||||
http_start_data( &hd );
|
||||
|
||||
iobuf_writestr( hd.fp_write, "keytext=" );
|
||||
iobuf_write( hd.fp_write, iobuf_get_temp_buffer(temp),
|
||||
iobuf_get_temp_length(temp) );
|
||||
iobuf_put( hd.fp_write, '\n' );
|
||||
iobuf_close(temp);
|
||||
|
||||
rc = http_wait_response( &hd, &status );
|
||||
if( rc ) {
|
||||
log_error("error sending to `%s': %s\n",
|
||||
opt.keyserver_name, g10_errstr(rc) );
|
||||
}
|
||||
else {
|
||||
#if 1
|
||||
if( opt.verbose ) {
|
||||
int c;
|
||||
while( (c=iobuf_get(hd.fp_read)) != EOF )
|
||||
putchar( c );
|
||||
}
|
||||
#endif
|
||||
if( (status/100) == 2 )
|
||||
log_info("success sending to `%s' (status=%u)\n",
|
||||
opt.keyserver_name, status );
|
||||
else
|
||||
log_error("failed sending to `%s': status=%u\n",
|
||||
opt.keyserver_name, status );
|
||||
}
|
||||
http_close( &hd );
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int
|
||||
urlencode_filter( void *opaque, int control,
|
||||
IOBUF a, byte *buf, size_t *ret_len)
|
||||
{
|
||||
size_t size = *ret_len;
|
||||
int rc=0;
|
||||
|
||||
if( control == IOBUFCTRL_FLUSH ) {
|
||||
const byte *p;
|
||||
for(p=buf; size; p++, size-- ) {
|
||||
if( isalnum(*p) || *p == '-' )
|
||||
iobuf_put( a, *p );
|
||||
else if( *p == ' ' )
|
||||
iobuf_put( a, '+' );
|
||||
else {
|
||||
char numbuf[5];
|
||||
sprintf(numbuf, "%%%02X", *p );
|
||||
iobuf_writestr(a, numbuf );
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( control == IOBUFCTRL_DESC )
|
||||
*(char**)buf = "urlencode_filter";
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
|
||||
int hkp_ask_import( u32 *keyid );
|
||||
int hkp_export( STRLIST users );
|
||||
|
||||
|
||||
#endif /*G10_HKP_H*/
|
||||
|
|
|
@ -930,7 +930,7 @@ generate_keypair()
|
|||
if( algo == PUBKEY_ALGO_DSA )
|
||||
tty_printf(_("Note that this key cannot be used for "
|
||||
"encryption. You may want to use\n"
|
||||
"the command \"--add-key\" to generate a "
|
||||
"the command \"--edit-key\" to generate a "
|
||||
"secondary key for this purpose.\n") );
|
||||
}
|
||||
|
||||
|
|
|
@ -110,8 +110,10 @@ KBNODE make_mpi_comment_node( const char *s, MPI a );
|
|||
/*-- import.c --*/
|
||||
int import_keys( const char *filename, int fast );
|
||||
int import_keys_stream( IOBUF inp, int fast );
|
||||
|
||||
/*-- export.c --*/
|
||||
int export_pubkeys( STRLIST users, int onlyrfc );
|
||||
int export_pubkeys_stream( IOBUF out, STRLIST users, int onlyrfc );
|
||||
int export_seckeys( STRLIST users );
|
||||
|
||||
/* dearmor.c --*/
|
||||
|
|
|
@ -99,6 +99,8 @@ init_signals()
|
|||
do_sigaction( SIGSEGV, &nact );
|
||||
nact.sa_handler = got_usr_signal;
|
||||
sigaction( SIGUSR1, &nact, NULL );
|
||||
nact.sa_handler = SIG_IGN;
|
||||
sigaction( SIGPIPE, &nact, NULL );
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue