From c8e8915a2051b889b21aa0f99c9aa03fbb8c1f32 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 6 Nov 2016 18:27:22 -0500 Subject: [PATCH] Add pwmd_genkey() to take care of pinentry. --- configure.ac | 6 +++--- doc/libpwmd.3 | 46 +++++++++++++++++++++++++++++++++++++++------- src/libpwmd.c | 29 ++++++++++++++++++++++++----- src/libpwmd.h.in | 21 +++++++++++++++++++++ src/pwmc.c | 29 ++++++++++++++++++++++------- 5 files changed, 109 insertions(+), 22 deletions(-) diff --git a/configure.ac b/configure.ac index dbb2689d..dd8569b4 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. AC_PREREQ(2.60) -AC_INIT(libpwmd, 8.0.1-dev, [Ben Kibbey bjk@luxsci.net]) +AC_INIT(libpwmd, 8.1.0-dev, [Ben Kibbey bjk@luxsci.net]) AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_AUX_DIR(build) AC_CANONICAL_TARGET @@ -28,9 +28,9 @@ AC_SUBST(VER_MINOR_HEX) AC_SUBST(VER_PATCH_HEX) VER_STRING="\"$VERSION\"" AC_SUBST(VER_STRING) -LIBTOOL_CUR=1 +LIBTOOL_CUR=2 LIBTOOL_REV=0 -LIBTOOL_AGE=0 +LIBTOOL_AGE=1 AC_SUBST(LIBTOOL_CUR) AC_SUBST(LIBTOOL_REV) AC_SUBST(LIBTOOL_AGE) diff --git a/doc/libpwmd.3 b/doc/libpwmd.3 index a61ffe19..309dff96 100644 --- a/doc/libpwmd.3 +++ b/doc/libpwmd.3 @@ -1,4 +1,4 @@ -.TH "libpwmd.h" 3 "Sat Sep 24 2016" "Version 8.0.0" "libpwmd" \" -*- nroff -*- +.TH "libpwmd.h" 3 "Sun Nov 6 2016" "Version 8.0.1" "libpwmd" \" -*- nroff -*- .ad l .nh .SH NAME @@ -157,7 +157,7 @@ libgpg-error returns an error code as a bitmask of an error source and the error .RI "#define \fBGPG_ERR_SOURCE_DEFAULT\fP GPG_ERR_SOURCE_USER_2" .br .ti -1c -.RI "#define \fBLIBPWMD_VERSION\fP 0x080000" +.RI "#define \fBLIBPWMD_VERSION\fP 0x080001" .br .ti -1c .RI "#define \fBLIBPWMD_VERSION_MAJOR\fP 8" @@ -166,10 +166,10 @@ libgpg-error returns an error code as a bitmask of an error source and the error .RI "#define \fBLIBPWMD_VERSION_MINOR\fP 0" .br .ti -1c -.RI "#define \fBLIBPWMD_VERSION_PATCH\fP 0" +.RI "#define \fBLIBPWMD_VERSION_PATCH\fP 1" .br .ti -1c -.RI "#define \fBLIBPWMD_VERSION_STR\fP '8\&.0\&.0\-dev'" +.RI "#define \fBLIBPWMD_VERSION_STR\fP '8\&.0\&.1\-dev'" .br .ti -1c .RI "#define \fBPWMD_FEATURE_PINENTRY\fP" @@ -268,6 +268,9 @@ libgpg-error returns an error code as a bitmask of an error source and the error .RI "LIBPWMD_API gpg_error_t \fBpwmd_process\fP (\fBpwm_t\fP *pwm)" .br .ti -1c +.RI "LIBPWMD_API gpg_error_t \fBpwmd_genkey\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)" +.br +.ti -1c .RI "LIBPWMD_API gpg_error_t \fBpwmd_save\fP (\fBpwm_t\fP *pwm, const char *args, \fBpwmd_inquire_cb_t\fP callback, void *user)" .br .ti -1c @@ -312,7 +315,7 @@ libgpg-error returns an error code as a bitmask of an error source and the error .in -1c .SH "Constant Details" .PP -.SS "#define LIBPWMD_VERSION 0x080000" +.SS "#define LIBPWMD_VERSION 0x080001" .PP Version information\&. The version of this library\&. @@ -324,11 +327,11 @@ Version information\&. The major release number of this library\&. .PP Version information\&. The minor release number of this library\&. -.SS "#define LIBPWMD_VERSION_PATCH 0" +.SS "#define LIBPWMD_VERSION_PATCH 1" .PP Version information\&. The patch level of this library\&. -.SS "#define LIBPWMD_VERSION_STR '8\&.0\&.0\-dev'" +.SS "#define LIBPWMD_VERSION_STR '8\&.0\&.1\-dev'" .PP Version information\&. A string representation of the version of this library\&. @@ -956,6 +959,35 @@ Nothing\&. .RE .PP +.SS "LIBPWMD_API gpg_error_t pwmd_genkey (\fBpwm_t\fP * pwm, const char * args, \fBpwmd_inquire_cb_t\fP callback, void * user)" + +.PP +Generate a new key\&. Generate a new signing or encryption key or both\&. This will only generate a key without saving the XML document to disk\&. +.PP +The inquire \fIcallback\fP function should be used when a GENKEY option specified in \fIargs\fP inquires data\&. +.PP +\fBParameters:\fP +.RS 4 +\fIpwm\fP A handle\&. +.br +\fIargs\fP Any GENKEY protocol command options or NULL\&. +.br +\fIcallback\fP A callback function to invoke when pwmd inquires data from the client\&. +.br +\fIuser\fP User data passed to the \fIcallback\fP function\&. +.RE +.PP +\fBReturns:\fP +.RS 4 +0 on success or an error code\&. +.RE +.PP +\fBSee also:\fP +.RS 4 +\fBPWMD_OPTION_OVERRIDE_INQUIRE\fP, \fBPWMD_OPTION_NO_PINENTRY\fP, \fBPWMD_OPTION_LOCAL_PINENTRY\fP, \fBpwmd_command()\fP, \fBPinentry Details\fP +.RE +.PP + .SS "LIBPWMD_API void* pwmd_get_pointer (\fBpwm_t\fP * pwm)" .PP diff --git a/src/libpwmd.c b/src/libpwmd.c index 31a51e43..0fbb6a88 100644 --- a/src/libpwmd.c +++ b/src/libpwmd.c @@ -71,6 +71,13 @@ #include #endif +enum + { + PWMD_WHICH_SAVE, + PWMD_WHICH_PASSWD, + PWMD_WHICH_GENKEY + }; + #define FINISH(rc) (gpg_err_source(rc) == GPG_ERR_SOURCE_UNKNOWN) \ ? gpg_error(rc) : rc @@ -1525,7 +1532,7 @@ pwmd_open (pwm_t * pwm, const char *filename, pwmd_inquire_cb_t cb, static gpg_error_t do_pwmd_save_passwd (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, - void *data, int save) + void *data, int which) { gpg_error_t rc = 0; int no_pinentry = 0; @@ -1541,8 +1548,14 @@ do_pwmd_save_passwd (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, rc = send_pinentry_options (pwm); if (!rc) - rc = pwmd_command (pwm, NULL, NULL, cb, data, - save ? "SAVE %s" : "PASSWD %s", args ? args : ""); + { + if (which == PWMD_WHICH_SAVE) + rc = pwmd_command (pwm, NULL, NULL, cb, data, "SAVE %s", args ? args : ""); + else if (which == PWMD_WHICH_PASSWD) + rc = pwmd_command (pwm, NULL, NULL, cb, data, "PASSWD %s", args ? args : ""); + else if (which == PWMD_WHICH_GENKEY) + rc = pwmd_command (pwm, NULL, NULL, cb, data, "GENKEY %s", args ? args : ""); + } pwmd_free (pwm->passphrase_hint); pwmd_free (pwm->passphrase_info); @@ -1553,13 +1566,19 @@ do_pwmd_save_passwd (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, gpg_error_t pwmd_passwd (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) { - return do_pwmd_save_passwd (pwm, args, cb, data, 0); + return do_pwmd_save_passwd (pwm, args, cb, data, PWMD_WHICH_PASSWD); } gpg_error_t pwmd_save (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) { - return do_pwmd_save_passwd (pwm, args, cb, data, 1); + return do_pwmd_save_passwd (pwm, args, cb, data, PWMD_WHICH_SAVE); +} + +gpg_error_t +pwmd_genkey (pwm_t * pwm, const char *args, pwmd_inquire_cb_t cb, void *data) +{ + return do_pwmd_save_passwd (pwm, args, cb, data, PWMD_WHICH_GENKEY); } static gpg_error_t diff --git a/src/libpwmd.h.in b/src/libpwmd.h.in index 0273eb59..adc2941d 100644 --- a/src/libpwmd.h.in +++ b/src/libpwmd.h.in @@ -879,6 +879,27 @@ LIBPWMD_API gpg_error_t pwmd_open (pwm_t *pwm, const char *filename, LIBPWMD_API gpg_error_t pwmd_process (pwm_t *pwm); +/*! \brief Generate a new key. + + * Generate a new signing or encryption key or both. This will only + * generate a key without saving the XML document to disk. + * + * The inquire \a callback function should be used when a GENKEY option + * specified in \a args inquires data. + * + * \param pwm A handle. + * \param args Any GENKEY protocol command options or NULL. + * \param callback A callback function to invoke when pwmd inquires data from + * the client. + * \param user User data passed to the \a callback function. + * \return 0 on success or an error code. + * \see \ref PWMD_OPTION_OVERRIDE_INQUIRE, \ref PWMD_OPTION_NO_PINENTRY, + * \ref PWMD_OPTION_LOCAL_PINENTRY, \ref pwmd_command(), \ref pinentry + */ +LIBPWMD_API gpg_error_t pwmd_genkey (pwm_t *pwm, const char *args, + pwmd_inquire_cb_t callback, void *user); + + /*! \brief Save a file on the pwmd server. * * This will send the SAVE command and write any changes to the document to diff --git a/src/pwmc.c b/src/pwmc.c index db146d0c..571d7427 100644 --- a/src/pwmc.c +++ b/src/pwmc.c @@ -91,9 +91,17 @@ static int interactive; #define DEFAULT_STATUS_IGNORE "KEEPALIVE,GPGME,PASSPHRASE_INFO,PASSPHRASE_HINT" #define DEFAULT_PIN_TIMEOUT 30 #define DEFAULT_PIN_TRIES 3 + #define FINISH(rc) (gpg_err_source(rc) == GPG_ERR_SOURCE_UNKNOWN) \ ? gpg_error(rc) : rc +enum + { + SAVE_WHICH_SAVE, + SAVE_WHICH_PASSWD, + SAVE_WHICH_GENKEY + }; + static int no_pinentry; static pwm_t *pwm; static char *filename; @@ -399,7 +407,7 @@ inquire_cb (void *user, const char *keyword, gpg_error_t rc, || (sign && sign_keyfile)) { int fd; - + if (sign) fd = open (sign_keyfile, O_RDONLY); else @@ -969,6 +977,9 @@ help_command (const char *line) " .set help | []\n" " set option to \n" "\n" + " .genkey [args]\n" + " generate a new key\n" + "\n" " .save [args]\n" " write changes of the file to disk\n" "\n" @@ -1159,7 +1170,7 @@ set_command (const char *line) } static gpg_error_t -do_save_passwd_command (const char *line, int do_save) +do_save_passwd_command (const char *line, int which) { struct inquire_s *inq = NULL; gpg_error_t rc; @@ -1186,10 +1197,12 @@ do_save_passwd_command (const char *line, int do_save) if (!rc) { - if (do_save) + if (which == SAVE_WHICH_SAVE) rc = pwmd_save (pwm, line, inquire_cb, inq); - else + else if (which == SAVE_WHICH_PASSWD) rc = pwmd_passwd (pwm, line, inquire_cb, inq); + else + rc = pwmd_genkey (pwm, line, inquire_cb, inq); } pwmd_setopt (pwm, PWMD_OPTION_LOCAL_PINENTRY, local); @@ -1206,7 +1219,7 @@ do_save_passwd_command (const char *line, int do_save) static gpg_error_t save_command (const char *line) { - return do_save_passwd_command (line, 1); + return do_save_passwd_command (line, SAVE_WHICH_SAVE); } static void @@ -1568,9 +1581,11 @@ parse_dotcommand (const char *line, char **result, else if (!strncmp (p, ".set", 4)) rc = set_command (p + 4); else if (!strncmp (p, ".save", 5)) - rc = do_save_passwd_command (p + 5, 1); + rc = do_save_passwd_command (p + 5, SAVE_WHICH_SAVE); else if (!strncmp (p, ".passwd", 7)) - rc = do_save_passwd_command (p + 7, 0); + rc = do_save_passwd_command (p + 7, SAVE_WHICH_PASSWD); + else if (!strncmp (p, ".genkey", 7)) + rc = do_save_passwd_command (p + 7, SAVE_WHICH_GENKEY); else if (!strncmp (p, ".listkeys", 9)) rc = listkeys_command (p+9); else -- 2.11.4.GIT