From 00c501d296da287bec2fd6a0e3912abfbde90a98 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 13 Sep 2016 18:57:38 +0200 Subject: core: New function gpgme_op_create_key. * src/engine-backend.h (engine_ops): Change prototype of genkey. * src/engine-gpgsm.c (gpgsm_genkey): Change accordingly. * src/engine-gpg.c (gpg_genkey): Change it to a dispatcher. (gpg_createkey_from_param): New for the old functionality. (gpg_createkey_legacy): New. Stub for now. (gpg_createkey): New. (gpg_addkey): New. Stub for now. (gpg_adduid): New. Stub for now. * src/engine.c (_gpgme_engine_op_genkey): Add new args. * src/genkey.c (op_data_t): Add field ERROR_CODE. (parse_error): New. (genkey_status_handler): Parse ERROR status line. (genkey_start): Use NULL/0 for the new args. (createkey_start): New. (gpgme_op_createkey_start, gpgme_op_createkey): New. * src/gpgme.def, src/libgpgme.vers: Add gpgme_op_createkey_start and gpgme_op_createkey. * src/gpgme.h.in (_gpgme_op_genkey_result): Add fields PUBKEY and SECKEY. (GPGME_CREATE_SIGN): New. (GPGME_CREATE_ENCR): New. (GPGME_CREATE_CERT): New. (GPGME_CREATE_AUTH): New. (GPGME_CREATE_NOPASSWD): New. (GPGME_CREATE_SELFSIGNED): New. (GPGME_CREATE_NOSTORE): New. (GPGME_CREATE_WANTPUB): New. (GPGME_CREATE_WANTSEC): New. (GPGME_CREATE_FORCE): New. * tests/run-genkey.c: New. * tests/Makefile.am (noinst_PROGRAMS): Add it. -- This function uses the new --quick-gen-key API of gpg. A limited compatibility mode to use older gpg versions and gpgsm will eventually be provided. Not all flags are currently implemented. ./run-genkey --unprotected --force test@example.com Create a new standard key with the given user id. --force is used to allow creating more than one key with that user id in the keyring. ./run-genkey --unprotected --force \ test@example.com default default 2145826800 Creates a new standard key with an expiration date of 2037-12-31. ./run-genkey --unprotected --force \ test@example.com future-default default 2145826800 Create a standard key using the fugure default algorithms. Signed-off-by: Werner Koch --- src/gpgme.h.in | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) (limited to 'src/gpgme.h.in') diff --git a/src/gpgme.h.in b/src/gpgme.h.in index 00a4bed3..0fdc9276 100644 --- a/src/gpgme.h.in +++ b/src/gpgme.h.in @@ -1815,6 +1815,18 @@ gpgme_error_t gpgme_op_export_keys (gpgme_ctx_t ctx, * Key generation. */ +/* Flags for the key creation functions. */ +#define GPGME_CREATE_SIGN (1 << 0) /* Allow usage: signing. */ +#define GPGME_CREATE_ENCR (1 << 1) /* Allow usage: encryption. */ +#define GPGME_CREATE_CERT (1 << 2) /* Allow usage: certification. */ +#define GPGME_CREATE_AUTH (1 << 3) /* Allow usage: authentication. */ +#define GPGME_CREATE_NOPASSWD (1 << 7) /* Create w/o passphrase. */ +#define GPGME_CREATE_SELFSIGNED (1 << 8) /* Create self-signed cert. */ +#define GPGME_CREATE_NOSTORE (1 << 9) /* Do not store the key. */ +#define GPGME_CREATE_WANTPUB (1 << 10) /* Return the public key. */ +#define GPGME_CREATE_WANTSEC (1 << 11) /* Return the secret key. */ +#define GPGME_CREATE_FORCE (1 << 12) /* Force creation. */ + struct _gpgme_op_genkey_result { /* A primary key was generated. */ @@ -1828,6 +1840,14 @@ struct _gpgme_op_genkey_result /* The fingerprint of the generated key. */ char *fpr; + + /* A memory data object with the created public key. Only set when + * GPGME_CREATE_WANTPUB has been used. */ + gpgme_data_t pubkey; + + /* A memory data object with the created secret key. Only set when + * GPGME_CREATE_WANTSEC has been used. */ + gpgme_data_t seckey; }; typedef struct _gpgme_op_genkey_result *gpgme_genkey_result_t; @@ -1839,7 +1859,39 @@ gpgme_error_t gpgme_op_genkey_start (gpgme_ctx_t ctx, const char *parms, gpgme_error_t gpgme_op_genkey (gpgme_ctx_t ctx, const char *parms, gpgme_data_t pubkey, gpgme_data_t seckey); -/* Retrieve a pointer to the result of the genkey operation. */ +/* Generate a key pair using the modern interface. */ +gpgme_error_t gpgme_op_createkey_start (gpgme_ctx_t ctx, + const char *userid, + const char *algo, + unsigned long reserved, + unsigned long expires, + gpgme_key_t certkey, + unsigned int flags); +gpgme_error_t gpgme_op_createkey (gpgme_ctx_t ctx, + const char *userid, + const char *algo, + unsigned long reserved, + unsigned long expires, + gpgme_key_t certkey, + unsigned int flags); +/* Add a new subkey to KEY. */ +gpgme_error_t gpgme_op_createsubkey_start (gpgme_ctx_t ctx, + gpgme_key_t key, + const char *algo, + unsigned long reserved, + unsigned long expires, + unsigned int flags); +gpgme_error_t gpgme_op_createsubkey (gpgme_ctx_t ctx, + gpgme_key_t key, + const char *algo, + unsigned long reserved, + unsigned long expires, + unsigned int flags); + + + +/* Retrieve a pointer to the result of a genkey, createkey, or + * createsubkey operation. */ gpgme_genkey_result_t gpgme_op_genkey_result (gpgme_ctx_t ctx); @@ -2177,7 +2229,7 @@ typedef struct gpgme_conf_arg } *gpgme_conf_arg_t; -/* The flags of a configuration option. See the gpg-conf +/* The flags of a configuration option. See the gpgconf documentation for details. */ #define GPGME_CONF_GROUP (1 << 0) #define GPGME_CONF_OPTIONAL (1 << 1) -- cgit v1.2.3