aboutsummaryrefslogtreecommitdiffstats
path: root/sm
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--sm/ChangeLog8
-rw-r--r--sm/call-agent.c33
-rw-r--r--sm/gpgsm.c108
3 files changed, 99 insertions, 50 deletions
diff --git a/sm/ChangeLog b/sm/ChangeLog
index 55a539ad6..149ba4786 100644
--- a/sm/ChangeLog
+++ b/sm/ChangeLog
@@ -1,3 +1,11 @@
+2006-08-29 Werner Koch <[email protected]>
+
+ * call-agent.c (gpgsm_agent_pkdecrypt): Allow decryption using
+ complete S-expressions as implemented by the current gpg-agent.
+
+ * gpgsm.c (main): Implement --output for encrypt, decrypt, sign
+ and export.
+
2006-07-03 Werner Koch <[email protected]>
* certreqgen.c (proc_parameters): Print the component label of a
diff --git a/sm/call-agent.c b/sm/call-agent.c
index 85ec78c63..61332144e 100644
--- a/sm/call-agent.c
+++ b/sm/call-agent.c
@@ -300,7 +300,7 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
membuf_t data;
struct cipher_parm_s cipher_parm;
size_t n, len;
- char *buf, *endp;
+ char *p, *buf, *endp;
size_t ciphertextlen;
if (!keygrip || strlen(keygrip) != 40 || !ciphertext || !r_buf || !r_buflen)
@@ -349,21 +349,36 @@ gpgsm_agent_pkdecrypt (ctrl_t ctrl, const char *keygrip, const char *desc,
return map_assuan_err (rc);
}
- put_membuf (&data, "", 1); /* make sure it is 0 terminated */
+ put_membuf (&data, "", 1); /* Make sure it is 0 terminated. */
buf = get_membuf (&data, &len);
if (!buf)
return gpg_error (GPG_ERR_ENOMEM);
- /* FIXME: We would better a return a full S-exp and not just a part */
- assert (len);
- len--; /* remove the terminating 0 */
- n = strtoul (buf, &endp, 10);
+ assert (len); /* (we forced Nul termination.) */
+
+ if (*buf == '(')
+ {
+ if (len < 13 || memcmp (buf, "(5:value", 8) ) /* "(5:valueN:D)\0" */
+ return gpg_error (GPG_ERR_INV_SEXP);
+ len -= 11; /* Count only the data of the second part. */
+ p = buf + 8; /* Skip leading parenthesis and the value tag. */
+ }
+ else
+ {
+ /* For compatibility with older gpg-agents handle the old style
+ incomplete S-exps. */
+ len--; /* Do not count the Nul. */
+ p = buf;
+ }
+
+ n = strtoul (p, &endp, 10);
if (!n || *endp != ':')
return gpg_error (GPG_ERR_INV_SEXP);
endp++;
- if (endp-buf+n > len)
- return gpg_error (GPG_ERR_INV_SEXP); /* oops len does not
- match internal len*/
+ if (endp-p+n > len)
+ return gpg_error (GPG_ERR_INV_SEXP); /* Oops: Inconsistent S-Exp. */
+
memmove (buf, endp, n);
+
*r_buflen = n;
*r_buf = buf;
return 0;
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index 5363b8ad6..0855a0062 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -1420,31 +1420,42 @@ main ( int argc, char **argv)
run_protect_tool (argc, argv);
break;
- case aEncr: /* encrypt the given file */
- set_binary (stdin);
- set_binary (stdout);
- if (!argc)
- gpgsm_encrypt (&ctrl, recplist, 0, stdout); /* from stdin */
- else if (argc == 1)
- gpgsm_encrypt (&ctrl, recplist, open_read (*argv), stdout); /* from file */
- else
- wrong_args ("--encrypt [datafile]");
+ case aEncr: /* Encrypt the given file. */
+ {
+ FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-");
+
+ set_binary (stdin);
+
+ if (!argc) /* Source is stdin. */
+ gpgsm_encrypt (&ctrl, recplist, 0, fp);
+ else if (argc == 1) /* Source is the given file. */
+ gpgsm_encrypt (&ctrl, recplist, open_read (*argv), fp);
+ else
+ wrong_args ("--encrypt [datafile]");
+
+ if (fp != stdout)
+ fclose (fp);
+ }
break;
- case aSign: /* sign the given file */
- /* FIXME: We don't handle --output yet. We should also allow
- to concatenate multiple files for signing because that is
- what gpg does.*/
- set_binary (stdin);
- set_binary (stdout);
- if (!argc)
- gpgsm_sign (&ctrl, signerlist,
- 0, detached_sig, stdout); /* create from stdin */
- else if (argc == 1)
- gpgsm_sign (&ctrl, signerlist,
- open_read (*argv), detached_sig, stdout); /* from file */
- else
- wrong_args ("--sign [datafile]");
+ case aSign: /* Sign the given file. */
+ {
+ FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-");
+
+ /* Fixme: We should also allow to concatenate multiple files for
+ signing because that is what gpg does.*/
+ set_binary (stdin);
+ if (!argc) /* Create from stdin. */
+ gpgsm_sign (&ctrl, signerlist, 0, detached_sig, fp);
+ else if (argc == 1) /* From file. */
+ gpgsm_sign (&ctrl, signerlist,
+ open_read (*argv), detached_sig, fp);
+ else
+ wrong_args ("--sign [datafile]");
+
+ if (fp != stdout)
+ fclose (fp);
+ }
break;
case aSignEncr: /* sign and encrypt the given file */
@@ -1484,14 +1495,19 @@ main ( int argc, char **argv)
break;
case aDecrypt:
- set_binary (stdin);
- set_binary (stdout);
- if (!argc)
- gpgsm_decrypt (&ctrl, 0, stdout); /* from stdin */
- else if (argc == 1)
- gpgsm_decrypt (&ctrl, open_read (*argv), stdout); /* from file */
- else
- wrong_args ("--decrypt [filename]");
+ {
+ FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-");
+
+ set_binary (stdin);
+ if (!argc)
+ gpgsm_decrypt (&ctrl, 0, fp); /* from stdin */
+ else if (argc == 1)
+ gpgsm_decrypt (&ctrl, open_read (*argv), fp); /* from file */
+ else
+ wrong_args ("--decrypt [filename]");
+ if (fp != stdout)
+ fclose (fp);
+ }
break;
case aDeleteKey:
@@ -1556,19 +1572,29 @@ main ( int argc, char **argv)
break;
case aExport:
- set_binary (stdout);
- for (sl=NULL; argc; argc--, argv++)
- add_to_strlist (&sl, *argv);
- gpgsm_export (&ctrl, sl, stdout);
- free_strlist(sl);
+ {
+ FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-");
+
+ for (sl=NULL; argc; argc--, argv++)
+ add_to_strlist (&sl, *argv);
+ gpgsm_export (&ctrl, sl, fp);
+ free_strlist(sl);
+ if (fp != stdout)
+ fclose (fp);
+ }
break;
case aExportSecretKeyP12:
- set_binary (stdout);
- if (argc == 1)
- gpgsm_p12_export (&ctrl, *argv, stdout);
- else
- wrong_args ("--export-secret-key-p12 KEY-ID");
+ {
+ FILE *fp = open_fwrite (opt.outfile?opt.outfile:"-");
+
+ if (argc == 1)
+ gpgsm_p12_export (&ctrl, *argv, stdout);
+ else
+ wrong_args ("--export-secret-key-p12 KEY-ID");
+ if (fp != stdout)
+ fclose (fp);
+ }
break;
case aSendKeys: