diff --git a/sm/ChangeLog b/sm/ChangeLog index ffa46e7b4..604bbd334 100644 --- a/sm/ChangeLog +++ b/sm/ChangeLog @@ -1,5 +1,17 @@ 2001-12-14 Werner Koch + * verify.c (gpgsm_verify): Add hash debug helpers + * sign.c (gpgsm_sign): Ditto. + + * base64.c (base64_reader_cb): Reset the linelen when we need to + skip the line and adjusted test; I somehow forgot about DeMorgan. + + * server.c (cmd_encrypt,cmd_decrypt,cmd_sign,cmd_verify) + (cmd_import): Close the FDs on success. + (close_message_fd): New. + (input_notify): Setting autodetect_encoding to 0 after initializing + it to 0 is pretty pointless. Easy to fix. + * gpgsm.c (main): New option --debug-wait n, so that it is possible to attach gdb when used in server mode. diff --git a/sm/base64.c b/sm/base64.c index a176c70b2..4d1620975 100644 --- a/sm/base64.c +++ b/sm/base64.c @@ -170,10 +170,10 @@ base64_reader_cb (void *cb_value, char *buffer, size_t count, size_t *nread) if (parm->assume_pem) { /* wait for the header line */ - if (!parm->have_lf || strncmp (parm->line, "-----BEGIN ", 11) - || strncmp (parm->line+11, "PGP ", 4)) - goto next; parm->linelen = parm->readpos = 0; + if (!parm->have_lf || strncmp (parm->line, "-----BEGIN ", 11) + || !strncmp (parm->line+11, "PGP ", 4)) + goto next; parm->is_pem = 1; } else if (parm->assume_base64) diff --git a/sm/server.c b/sm/server.c index a4c06318b..f1d0031d2 100644 --- a/sm/server.c +++ b/sm/server.c @@ -82,6 +82,16 @@ rc_to_assuan_status (int rc) return rc; } +static void +close_message_fd (CTRL ctrl) +{ + if (ctrl->server_local->message_fd != -1) + { + close (ctrl->server_local->message_fd); + ctrl->server_local->message_fd = -1; + } +} + static void reset_notify (ASSUAN_CONTEXT ctx) { @@ -89,6 +99,7 @@ reset_notify (ASSUAN_CONTEXT ctx) gpgsm_release_certlist (ctrl->server_local->recplist); ctrl->server_local->recplist = NULL; + close_message_fd (ctrl); } @@ -107,7 +118,7 @@ input_notify (ASSUAN_CONTEXT ctx, const char *line) else if (strstr (line, "--binary")) ; else - ctrl->autodetect_encoding = 0; + ctrl->autodetect_encoding = 1; } static void @@ -188,6 +199,10 @@ cmd_encrypt (ASSUAN_CONTEXT ctx, char *line) { gpgsm_release_certlist (ctrl->server_local->recplist); ctrl->server_local->recplist = NULL; + /* close and reset the fd */ + close_message_fd (ctrl); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); } return rc_to_assuan_status (rc); } @@ -220,6 +235,14 @@ cmd_decrypt (ASSUAN_CONTEXT ctx, char *line) rc = gpgsm_decrypt (ctrl, inp_fd, out_fp); fclose (out_fp); + if (!rc) + { + /* close and reset the fd */ + close_message_fd (ctrl); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); + } + return rc_to_assuan_status (rc); } @@ -245,6 +268,13 @@ cmd_verify (ASSUAN_CONTEXT ctx, char *line) rc = gpgsm_verify (assuan_get_pointer (ctx), fd, ctrl->server_local->message_fd); + if (!rc) + { + /* close and reset the fd */ + close_message_fd (ctrl); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); + } return rc_to_assuan_status (rc); } @@ -258,6 +288,7 @@ cmd_verify (ASSUAN_CONTEXT ctx, char *line) static int cmd_sign (ASSUAN_CONTEXT ctx, char *line) { + CTRL ctrl = assuan_get_pointer (ctx); int inp_fd, out_fd; FILE *out_fp; int detached; @@ -278,6 +309,14 @@ cmd_sign (ASSUAN_CONTEXT ctx, char *line) rc = gpgsm_sign (assuan_get_pointer (ctx), inp_fd, detached, out_fp); fclose (out_fp); + if (!rc) + { + /* close and reset the fd */ + close_message_fd (ctrl); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); + } + return rc_to_assuan_status (rc); } @@ -291,6 +330,7 @@ cmd_sign (ASSUAN_CONTEXT ctx, char *line) static int cmd_import (ASSUAN_CONTEXT ctx, char *line) { + CTRL ctrl = assuan_get_pointer (ctx); int rc; int fd = assuan_get_input_fd (ctx); @@ -299,6 +339,13 @@ cmd_import (ASSUAN_CONTEXT ctx, char *line) rc = gpgsm_import (assuan_get_pointer (ctx), fd); + if (!rc) + { + /* close and reset the fd */ + close_message_fd (ctrl); + assuan_close_input_fd (ctx); + assuan_close_output_fd (ctx); + } return rc_to_assuan_status (rc); } diff --git a/sm/sign.c b/sm/sign.c index fb64f15de..945c9a6aa 100644 --- a/sm/sign.c +++ b/sm/sign.c @@ -218,6 +218,9 @@ gpgsm_sign (CTRL ctrl, int data_fd, int detached, FILE *out_fp) log_error ("md_open failed: %s\n", gcry_strerror (-1)); goto leave; } + if (DBG_HASHING) + gcry_md_start_debug (data_md, "sign.data"); + for (i=0; (algoid=ksba_cms_get_digest_algo_list (cms, i)); i++) { algo = gcry_md_map_name (algoid); @@ -290,6 +293,9 @@ gpgsm_sign (CTRL ctrl, int data_fd, int detached, FILE *out_fp) algo = GCRY_MD_SHA1; signer = 0; md = gcry_md_open (algo, 0); + if (DBG_HASHING) + gcry_md_start_debug (md, "sign.attr"); + if (!md) { log_error ("md_open failed: %s\n", gcry_strerror (-1)); diff --git a/sm/verify.c b/sm/verify.c index 526b23d97..8a999da14 100644 --- a/sm/verify.c +++ b/sm/verify.c @@ -216,6 +216,8 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd) log_error ("md_open failed: %s\n", gcry_strerror (-1)); goto leave; } + if (DBG_HASHING) + gcry_md_start_debug (data_md, "vrfy.data"); is_detached = 0; do @@ -375,6 +377,9 @@ gpgsm_verify (CTRL ctrl, int in_fd, int data_fd) log_error ("md_open failed: %s\n", gcry_strerror (-1)); goto next_signer; } + if (DBG_HASHING) + gcry_md_start_debug (md, "vrfy.attr"); + ksba_cms_set_hash_function (cms, HASH_FNC, md); rc = ksba_cms_hash_signed_attrs (cms, signer); if (rc)