diff --git a/src/rnp/rnpcfg.h b/src/rnp/rnpcfg.h index c9478bbd8..4fcde1d5b 100644 --- a/src/rnp/rnpcfg.h +++ b/src/rnp/rnpcfg.h @@ -52,28 +52,27 @@ #define CFG_RECIPIENTS "recipients" /* list of encrypted data recipients */ #define CFG_SIGNERS "signers" /* list of signers */ #define CFG_HOMEDIR "homedir" /* home directory - folder with keyrings and so on */ -#define CFG_KEYFILE "keyfile" /* path to the file with key(s), used instead of keyring */ -#define CFG_PASSFD "pass-fd" /* password file descriptor */ -#define CFG_PASSWD "password" /* password as command-line constant */ -#define CFG_PASSWORDC "passwordc" /* number of passwords for symmetric encryption */ -#define CFG_USERINPUTFD "user-input-fd" /* user input file descriptor */ -#define CFG_NUMTRIES "numtries" /* number of password request tries, or 'unlimited' */ -#define CFG_EXPIRATION "expiration" /* signature expiration time */ -#define CFG_CREATION "creation" /* signature validity start */ -#define CFG_CIPHER "cipher" /* symmetric encryption algorithm as string */ -#define CFG_HASH "hash" /* hash algorithm used, string like 'SHA1'*/ -#define CFG_WEAK_HASH "weak-hash" /* allow weak algorithms */ -#define CFG_S2K_ITER "s2k-iter" /* number of S2K hash iterations to perform */ -#define CFG_S2K_MSEC "s2k-msec" /* number of milliseconds S2K should target */ -#define CFG_ENCRYPT_PK "encrypt_pk" /* public key should be used during encryption */ -#define CFG_ENCRYPT_SK "encrypt_sk" /* password encryption should be used */ -#define CFG_IO_RESS "ress" /* results stream */ -#define CFG_NUMBITS "numbits" /* number of bits in generated key */ -#define CFG_EXPERT "expert" /* expert key generation mode */ -#define CFG_ZLEVEL "zlevel" /* compression level: 0..9 (0 for no compression) */ -#define CFG_ZALG "zalg" /* compression algorithm: zip, zlib or bzip2 */ -#define CFG_AEAD "aead" /* if nonzero then AEAD enryption mode, int */ -#define CFG_AEAD_CHUNK "aead_chunk" /* AEAD chunk size bits, int from 0 to 56 */ +#define CFG_KEYFILE "keyfile" /* path to the file with key(s), used instead of keyring */ +#define CFG_PASSFD "pass-fd" /* password file descriptor */ +#define CFG_PASSWD "password" /* password as command-line constant */ +#define CFG_PASSWORDC "passwordc" /* number of passwords for symmetric encryption */ +#define CFG_NUMTRIES "numtries" /* number of password request tries, or 'unlimited' */ +#define CFG_EXPIRATION "expiration" /* signature expiration time */ +#define CFG_CREATION "creation" /* signature validity start */ +#define CFG_CIPHER "cipher" /* symmetric encryption algorithm as string */ +#define CFG_HASH "hash" /* hash algorithm used, string like 'SHA1'*/ +#define CFG_WEAK_HASH "weak-hash" /* allow weak algorithms */ +#define CFG_S2K_ITER "s2k-iter" /* number of S2K hash iterations to perform */ +#define CFG_S2K_MSEC "s2k-msec" /* number of milliseconds S2K should target */ +#define CFG_ENCRYPT_PK "encrypt_pk" /* public key should be used during encryption */ +#define CFG_ENCRYPT_SK "encrypt_sk" /* password encryption should be used */ +#define CFG_IO_RESS "ress" /* results stream */ +#define CFG_NUMBITS "numbits" /* number of bits in generated key */ +#define CFG_EXPERT "expert" /* expert key generation mode */ +#define CFG_ZLEVEL "zlevel" /* compression level: 0..9 (0 for no compression) */ +#define CFG_ZALG "zalg" /* compression algorithm: zip, zlib or bzip2 */ +#define CFG_AEAD "aead" /* if nonzero then AEAD enryption mode, int */ +#define CFG_AEAD_CHUNK "aead_chunk" /* AEAD chunk size bits, int from 0 to 56 */ #define CFG_KEYSTORE_DISABLED \ "disable_keystore" /* indicates whether keystore must be initialized */ #define CFG_FORCE "force" /* force command to succeed operation */ diff --git a/src/rnpkeys/tui.cpp b/src/rnpkeys/tui.cpp index 73f26dc2d..5d3dca773 100644 --- a/src/rnpkeys/tui.cpp +++ b/src/rnpkeys/tui.cpp @@ -365,18 +365,6 @@ cli_rnp_set_generate_params(rnp_cfg &cfg, bool subkey) cfg.set_int(CFG_KG_SUBKEY_BITS, cfg.get_int(CFG_NUMBITS)); } else { FILE *input = stdin; - if (cfg.has(CFG_USERINPUTFD)) { - int inputfd = dup(cfg.get_int(CFG_USERINPUTFD)); - if (inputfd != -1) { - input = rnp_fdopen(inputfd, "r"); - if (!input) { - close(inputfd); - } - } - } - if (!input) { - return false; - } if (subkey) { res = rnpkeys_ask_generate_params_subkey(cfg, input); } else { diff --git a/src/tests/generatekey.cpp b/src/tests/generatekey.cpp index b846ebb4b..6d050033e 100644 --- a/src/tests/generatekey.cpp +++ b/src/tests/generatekey.cpp @@ -582,6 +582,7 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp) bool ret = false; int pipefd[2] = {-1, -1}; int user_input_pipefd[2] = {-1, -1}; + int saved_stdin = -1; size_t rsp_len; if (pipe(pipefd) == -1) { @@ -605,13 +606,27 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp) } close(user_input_pipefd[1]); - /* Mock user-input*/ - ctx->cfg().set_int(CFG_USERINPUTFD, user_input_pipefd[0]); + /* Replace stdin with our pipe */ + saved_stdin = dup(STDIN_FILENO); + if (dup2(user_input_pipefd[0], STDIN_FILENO) == -1) { + ret = false; + goto end; + } + + fprintf(stderr, "saved_stdin: %i\n", saved_stdin); if (!rnp_cmd(ctx, CMD_GENERATE_KEY, NULL)) { ret = false; goto end; } + if (dup2(saved_stdin, STDIN_FILENO) == -1) { + ret = false; + goto end; + } + if (fcntl(STDIN_FILENO, F_SETFD, FD_CLOEXEC) == -1) { + ret = false; + goto end; + } ops.copy(ctx->cfg()); ret = true; end: @@ -619,6 +634,7 @@ ask_expert_details(cli_rnp_t *ctx, rnp_cfg &ops, const char *rsp) if (user_input_pipefd[0]) { close(user_input_pipefd[0]); } + close(saved_stdin); return ret; } diff --git a/src/tests/support.h b/src/tests/support.h index 620692450..0c174eabc 100644 --- a/src/tests/support.h +++ b/src/tests/support.h @@ -59,6 +59,8 @@ #ifdef _WIN32 #define pipe(fds) _pipe(fds, 256, O_BINARY) +#define dup(fd) _dup(fd) +#define dup2(fd1, fd2) _dup2(fd1, fd2) int setenv(const char *name, const char *value, int overwrite); int unsetenv(const char *name); #endif