aboutsummaryrefslogtreecommitdiffstats
path: root/g10
diff options
context:
space:
mode:
Diffstat (limited to 'g10')
-rw-r--r--g10/ChangeLog9
-rw-r--r--g10/compress.c10
-rw-r--r--g10/export.c65
-rw-r--r--g10/filter.h1
-rw-r--r--g10/g10.c10
-rw-r--r--g10/hkp.c116
-rw-r--r--g10/hkp.h1
-rw-r--r--g10/keygen.c2
-rw-r--r--g10/main.h2
-rw-r--r--g10/signal.c2
10 files changed, 191 insertions, 27 deletions
diff --git a/g10/ChangeLog b/g10/ChangeLog
index f5a694a8b..c9137ed01 100644
--- a/g10/ChangeLog
+++ b/g10/ChangeLog
@@ -1,3 +1,12 @@
+Tue Jan 19 19:34:58 CET 1999 Werner Koch <[email protected]>
+
+ * 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 <[email protected]>
* textfilter.c (text_filter): Now uses iobuf_read_line().
diff --git a/g10/compress.c b/g10/compress.c
index 5aad678d6..accca02cc 100644
--- a/g10/compress.c
+++ b/g10/compress.c
@@ -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;
diff --git a/g10/export.c b/g10/export.c
index 6b4b41cdd..3cd297f70 100644
--- a/g10/export.c
+++ b/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;
+ 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;
- IOBUF out = NULL;
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;
}
diff --git a/g10/filter.h b/g10/filter.h
index ebd58e370..df436be74 100644
--- a/g10/filter.h
+++ b/g10/filter.h
@@ -67,6 +67,7 @@ typedef struct {
byte *outbuf;
unsigned outbufsize;
int algo; /* compress algo */
+ int algo1hack;
} compress_filter_context_t;
diff --git a/g10/g10.c b/g10/g10.c
index 7e714262f..872749881 100644
--- a/g10/g10.c
+++ b/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;
diff --git a/g10/hkp.c b/g10/hkp.c
index 79632d712..11f701116 100644
--- a/g10/hkp.c
+++ b/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 );
+ }
+
+ 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 );
- leave:
+ 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;
+}
diff --git a/g10/hkp.h b/g10/hkp.h
index 6ea555204..b062cfa26 100644
--- a/g10/hkp.h
+++ b/g10/hkp.h
@@ -23,6 +23,7 @@
int hkp_ask_import( u32 *keyid );
+int hkp_export( STRLIST users );
#endif /*G10_HKP_H*/
diff --git a/g10/keygen.c b/g10/keygen.c
index 2b5d34d3b..7431d8c61 100644
--- a/g10/keygen.c
+++ b/g10/keygen.c
@@ -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") );
}
diff --git a/g10/main.h b/g10/main.h
index 94ace8ea2..2aa946bb2 100644
--- a/g10/main.h
+++ b/g10/main.h
@@ -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 --*/
diff --git a/g10/signal.c b/g10/signal.c
index 1f599d9d0..364fb47a4 100644
--- a/g10/signal.c
+++ b/g10/signal.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
}