summaryrefslogtreecommitdiffstats
path: root/g13
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2009-10-19 11:18:46 +0200
committerWerner Koch <wk@gnupg.org>2009-10-19 11:18:46 +0200
commit97be197d31314ce89b91683e6440c4630075296d (patch)
treeffe2d357588e22e0b06bdb16574ffca72c0d7412 /g13
parentRemoved audit.h cruft which forced us to link against libksba. (diff)
downloadgnupg2-97be197d31314ce89b91683e6440c4630075296d.tar.xz
gnupg2-97be197d31314ce89b91683e6440c4630075296d.zip
[g13] Add RECIPEINT and CREATE command.
[sm] Chnage --include-certs default
Diffstat (limited to 'g13')
-rw-r--r--g13/call-gpg.c21
-rw-r--r--g13/call-gpg.h1
-rw-r--r--g13/create.c15
-rw-r--r--g13/create.h3
-rw-r--r--g13/g13.c35
-rw-r--r--g13/server.c66
6 files changed, 83 insertions, 58 deletions
diff --git a/g13/call-gpg.c b/g13/call-gpg.c
index 6e5c55f40..c6b0abe30 100644
--- a/g13/call-gpg.c
+++ b/g13/call-gpg.c
@@ -43,7 +43,7 @@ start_gpg (ctrl_t ctrl, int input_fd, int output_fd, assuan_context_t *r_ctx)
gpg_error_t err;
assuan_context_t ctx = NULL;
const char *pgmname;
- const char *argv[7];
+ const char *argv[10];
int no_close_list[5];
int i;
char line[ASSUAN_LINELENGTH];
@@ -86,6 +86,8 @@ start_gpg (ctrl_t ctrl, int input_fd, int output_fd, assuan_context_t *r_ctx)
argv[i++] = "--debug=1024";
argv[i++] = "-z";
argv[i++] = "0";
+ argv[i++] = "--trust-model";
+ argv[i++] = "always";
argv[i++] = NULL;
i = 0;
@@ -326,7 +328,7 @@ start_reader (int fd, membuf_t *mb, pth_t *r_tid, gpg_error_t *err_addr)
*/
gpg_error_t
gpg_encrypt_blob (ctrl_t ctrl, const void *plain, size_t plainlen,
- void **r_ciph, size_t *r_ciphlen)
+ strlist_t keys, void **r_ciph, size_t *r_ciphlen)
{
gpg_error_t err;
assuan_context_t ctx;
@@ -336,6 +338,8 @@ gpg_encrypt_blob (ctrl_t ctrl, const void *plain, size_t plainlen,
pth_t reader_tid = NULL;
gpg_error_t writer_err, reader_err;
membuf_t reader_mb;
+ char line[ASSUAN_LINELENGTH];
+ strlist_t sl;
*r_ciph = NULL;
*r_ciphlen = 0;
@@ -376,13 +380,16 @@ gpg_encrypt_blob (ctrl_t ctrl, const void *plain, size_t plainlen,
outbound_fds[0] = -1; /* The thread owns the FD now. */
/* Run the encryption. */
- err = assuan_transact (ctx, "RECIPIENT alpha@example.net",
- NULL, NULL, NULL, NULL, NULL, NULL);
- if (err)
+ for (sl = keys; sl; sl = sl->next)
{
- log_error ("the engine's RECIPIENT command failed: %s <%s>\n",
+ snprintf (line, sizeof line, "RECIPIENT -- %s", sl->d);
+ err = assuan_transact (ctx, line, NULL, NULL, NULL, NULL, NULL, NULL);
+ if (err)
+ {
+ log_error ("the engine's RECIPIENT command failed: %s <%s>\n",
gpg_strerror (err), gpg_strsource (err));
- goto leave;
+ goto leave;
+ }
}
err = assuan_transact (ctx, "ENCRYPT", NULL, NULL, NULL, NULL, NULL, NULL);
diff --git a/g13/call-gpg.h b/g13/call-gpg.h
index ffc5f29b5..339544d50 100644
--- a/g13/call-gpg.h
+++ b/g13/call-gpg.h
@@ -22,6 +22,7 @@
gpg_error_t gpg_encrypt_blob (ctrl_t ctrl,
const void *plain, size_t plainlen,
+ strlist_t keys,
void **r_ciph, size_t *r_ciphlen);
gpg_error_t gpg_decrypt_blob (ctrl_t ctrl, const void *ciph, size_t ciphlen,
void **r_plain, size_t *r_plainlen);
diff --git a/g13/create.c b/g13/create.c
index 9de9edc0b..bde67579e 100644
--- a/g13/create.c
+++ b/g13/create.c
@@ -106,12 +106,13 @@ create_new_keyblob (ctrl_t ctrl, int is_detached,
concatenation of both with the CMS packet being the last. */
static gpg_error_t
encrypt_keyblob (ctrl_t ctrl, void *keyblob, size_t keybloblen,
+ strlist_t keys,
void **r_encblob, size_t *r_encbloblen)
{
gpg_error_t err;
/* FIXME: For now we only implement OpenPGP. */
- err = gpg_encrypt_blob (ctrl, keyblob, keybloblen,
+ err = gpg_encrypt_blob (ctrl, keyblob, keybloblen, keys,
r_encblob, r_encbloblen);
return err;
@@ -217,10 +218,11 @@ write_keyblob (const char *filename,
/* Create a new container under the name FILENAME and intialize it
- using the current settings. If the file already exists an error is
- returned. */
+ using the current settings. KEYS is a list of public keys to which
+ the container will be encrypted. If the file already exists an
+ error is returned. */
gpg_error_t
-g13_create_container (ctrl_t ctrl, const char *filename)
+g13_create_container (ctrl_t ctrl, const char *filename, strlist_t keys)
{
gpg_error_t err;
dotlock_t lock;
@@ -233,6 +235,9 @@ g13_create_container (ctrl_t ctrl, const char *filename)
tupledesc_t tuples = NULL;
unsigned int dummy_rid;
+ if (!keys)
+ return gpg_error (GPG_ERR_NO_PUBKEY);
+
/* A quick check to see that no container with that name already
exists. */
if (!access (filename, F_OK))
@@ -284,7 +289,7 @@ g13_create_container (ctrl_t ctrl, const char *filename)
goto leave;
/* Encrypt that keyblob. */
- err = encrypt_keyblob (ctrl, keyblob, keybloblen,
+ err = encrypt_keyblob (ctrl, keyblob, keybloblen, keys,
&enckeyblob, &enckeybloblen);
if (err)
goto leave;
diff --git a/g13/create.h b/g13/create.h
index d533c0852..cc4ddfd08 100644
--- a/g13/create.h
+++ b/g13/create.h
@@ -20,7 +20,8 @@
#ifndef G13_CREATE_H
#define G13_CREATE_H
-gpg_error_t g13_create_container (ctrl_t ctrl, const char *filename);
+gpg_error_t g13_create_container (ctrl_t ctrl, const char *filename,
+ strlist_t keys);
#endif /*G13_CREATE_H*/
diff --git a/g13/g13.c b/g13/g13.c
index 5838b13fa..754371df2 100644
--- a/g13/g13.c
+++ b/g13/g13.c
@@ -47,6 +47,7 @@ enum cmd_and_opt_values {
aNull = 0,
oQuiet = 'q',
oVerbose = 'v',
+ oRecipient = 'r',
aGPGConfList = 500,
aGPGConfTest,
@@ -91,8 +92,6 @@ enum cmd_and_opt_values {
oDryRun,
oNoDetach,
- oRecipient,
-
oNoRandomSeedFile,
oFakedSystemTime
};
@@ -308,30 +307,6 @@ set_cmd (enum cmd_and_opt_values *ret_cmd, enum cmd_and_opt_values new_cmd)
}
-/* Helper to add recipients to a list. */
-static int
-add_encryption_key (ctrl_t ctrl, const char *name,
- void /*FIXME*/ *keylist, int is_cms)
-{
- /* FIXME: Decide whether to add a CMS or OpenPGP key and then add
- the key to a list. */
- /* int rc = foo_add_to_certlist (ctrl, name, 0, recplist, is_encrypt_to); */
- /* if (rc) */
- /* { */
- /* if (recp_required) */
- /* { */
- /* log_error ("can't encrypt to `%s': %s\n", name, gpg_strerror (rc)); */
- /* gpgsm_status2 (ctrl, STATUS_INV_RECP, */
- /* get_inv_recpsgnr_code (rc), name, NULL); */
- /* } */
- /* else */
- /* log_info (_("NOTE: won't be able to encrypt to `%s': %s\n"), */
- /* name, gpg_strerror (rc)); */
- /* } */
- return 0; /* Key is good. */
-}
-
-
int
main ( int argc, char **argv)
{
@@ -664,18 +639,20 @@ main ( int argc, char **argv)
/* Parse all given encryption keys. This does a lookup of the keys
and stops if any of the given keys was not found. */
+#if 0 /* Currently not implemented. */
if (!nokeysetup)
{
strlist_t sl;
int failed = 0;
for (sl = recipients; sl; sl = sl->next)
- if (add_encryption_key (&ctrl, sl->d, NULL /* FIXME*/, 0))
+ if (check_encryption_key ())
failed = 1;
if (failed)
g13_exit (1);
}
-
+#endif /*0*/
+
/* Dispatch command. */
switch (cmd)
{
@@ -715,7 +692,7 @@ main ( int argc, char **argv)
if (argc != 1)
wrong_args ("--create filename");
start_idle_task ();
- err = g13_create_container (&ctrl, argv[0]);
+ err = g13_create_container (&ctrl, argv[0], recipients);
if (err)
log_error ("error creating a new container: %s <%s>\n",
gpg_strerror (err), gpg_strsource (err));
diff --git a/g13/server.c b/g13/server.c
index 585b9e7aa..e9b9a0a33 100644
--- a/g13/server.c
+++ b/g13/server.c
@@ -29,9 +29,9 @@
#include <assuan.h>
#include "i18n.h"
#include "keyblob.h"
-#include "./server.h"
-#include "./mount.h"
-
+#include "server.h"
+#include "mount.h"
+#include "create.h"
/* Local data for this server module. A pointer to this is stored in
the CTRL object of each connection. */
@@ -42,6 +42,7 @@ struct server_local_s
char *containername; /* Malloced active containername. */
+ strlist_t recipients; /* List of recipients. */
};
@@ -187,6 +188,8 @@ reset_notify (assuan_context_t ctx)
xfree (ctrl->server_local->containername);
ctrl->server_local->containername = NULL;
+ FREE_STRLIST (ctrl->server_local->recipients);
+
assuan_close_input_fd (ctx);
assuan_close_output_fd (ctx);
}
@@ -359,17 +362,12 @@ static gpg_error_t
cmd_recipient (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
- gpg_error_t err;
+ gpg_error_t err = 0;
- (void)ctrl;
- err = gpg_error (GPG_ERR_NOT_IMPLEMENTED);
- /* err = gpgsm_add_to_certlist (ctrl, line, 0, */
- /* &ctrl->server_local->recplist, 0); */
- /* if (err) */
- /* { */
- /* gpgsm_status2 (ctrl, STATUS_INV_RECP, */
- /* get_inv_recpsgnr_code (rc), line, NULL); */
- /* } */
+ line = skip_options (line);
+
+ if (!add_to_strlist_try (&ctrl->server_local->recipients, line))
+ err = gpg_error_from_syserror ();
return leave_cmd (ctx, err);
}
@@ -386,6 +384,7 @@ cmd_signer (assuan_context_t ctx, char *line)
gpg_error_t err;
(void)ctrl;
+ (void)line;
err = gpg_error (GPG_ERR_NOT_IMPLEMENTED);
return leave_cmd (ctx, err);
@@ -402,16 +401,50 @@ cmd_create (assuan_context_t ctx, char *line)
{
ctrl_t ctrl = assuan_get_pointer (ctx);
gpg_error_t err;
-
- (void)ctrl;
+ char *p, *pend;
+ size_t len;
/* First we close the active container. */
xfree (ctrl->server_local->containername);
ctrl->server_local->containername = NULL;
+ /* Parse the line. */
+ line = skip_options (line);
+ for (p=line; *p && !spacep (p); p++)
+ ;
+ pend = p;
+ while (spacep(p))
+ p++;
+ if (*p || pend == line)
+ {
+ err = gpg_error (GPG_ERR_ASS_SYNTAX);
+ goto leave;
+ }
+ *pend = 0;
+
+ /* Unescape the line and check for embedded Nul bytes. */
+ len = percent_plus_unescape_inplace (line, 0);
+ line[len] = 0;
+ if (!len || memchr (line, 0, len))
+ {
+ err = gpg_error (GPG_ERR_INV_NAME);
+ goto leave;
+ }
+ /* Create container. */
+ err = g13_create_container (ctrl, line, ctrl->server_local->recipients);
- err = gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+ if (!err)
+ {
+ FREE_STRLIST (ctrl->server_local->recipients);
+
+ /* Store the filename. */
+ ctrl->server_local->containername = xtrystrdup (line);
+ if (!ctrl->server_local->containername)
+ err = gpg_error_from_syserror ();
+
+ }
+ leave:
return leave_cmd (ctx, err);
}
@@ -617,6 +650,7 @@ g13_server (ctrl_t ctrl)
log_info ("Assuan accept problem: %s\n", gpg_strerror (err));
leave:
+ reset_notify (ctx); /* Release all items hold by SERVER_LOCAL. */
if (ctrl->server_local)
{
xfree (ctrl->server_local);