summaryrefslogtreecommitdiff
path: root/security/netpgp/patches/patch-src_lib_keyring.c
diff options
context:
space:
mode:
authorkhorben <khorben@pkgsrc.org>2018-03-15 19:37:30 +0000
committerkhorben <khorben@pkgsrc.org>2018-03-15 19:37:30 +0000
commitdd7488cd5cbb99b55b18e04e51cb27afc22d534e (patch)
tree18ef54f62c34a1553638d3d5fff9604355331237 /security/netpgp/patches/patch-src_lib_keyring.c
parent8bf710a0c41df672bf02640d9f9bd684cd014046 (diff)
downloadpkgsrc-dd7488cd5cbb99b55b18e04e51cb27afc22d534e.tar.gz
Do not ask for a passphrase when empty
Originally submitted on tech-pkg@ as: [PATCH 06/11] Do not ask for a passphrase when empty Only modified for consistency with the coding style; as also applied in NetBSD's src repository. Tested on NetBSD/amd64.
Diffstat (limited to 'security/netpgp/patches/patch-src_lib_keyring.c')
-rw-r--r--security/netpgp/patches/patch-src_lib_keyring.c65
1 files changed, 50 insertions, 15 deletions
diff --git a/security/netpgp/patches/patch-src_lib_keyring.c b/security/netpgp/patches/patch-src_lib_keyring.c
index 5e8407b1fef..d8d3a7887c1 100644
--- a/security/netpgp/patches/patch-src_lib_keyring.c
+++ b/security/netpgp/patches/patch-src_lib_keyring.c
@@ -1,21 +1,56 @@
-$NetBSD: patch-src_lib_keyring.c,v 1.1 2017/02/20 01:09:11 khorben Exp $
+$NetBSD: patch-src_lib_keyring.c,v 1.2 2018/03/15 19:37:30 khorben Exp $
-Do not crash when listing keys without a keyring
+Do not crash when listing keys without a keyring.
+Do not ask for a passphrase when empty.
---- src/lib/keyring.c.orig 2017-02-20 01:03:25.000000000 +0000
+--- src/lib/keyring.c.orig 2018-03-15 19:31:30.000000000 +0000
+++ src/lib/keyring.c
-@@ -993,9 +993,12 @@ pgp_keyring_list(pgp_io_t *io, const pgp
+@@ -226,7 +226,7 @@ typedef struct {
+ pgp_seckey_t *seckey;
+ } decrypt_t;
+
+-static pgp_cb_ret_t
++static pgp_cb_ret_t
+ decrypt_cb(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
{
- pgp_key_t *key;
- unsigned n;
-+ unsigned keyc = (keyring != NULL) ? keyring->keyc : 0;
+ const pgp_contents_t *content = &pkt->u;
+@@ -292,6 +292,20 @@ decrypt_cb(const pgp_packet_t *pkt, pgp_
+ return PGP_RELEASE_MEMORY;
+ }
+
++static pgp_cb_ret_t
++decrypt_cb_empty(const pgp_packet_t *pkt, pgp_cbdata_t *cbinfo)
++{
++ const pgp_contents_t *content = &pkt->u;
++
++ switch (pkt->tag) {
++ case PGP_GET_PASSPHRASE:
++ *content->skey_passphrase.passphrase = netpgp_strdup("");
++ return PGP_KEEP_MEMORY;
++ default:
++ return decrypt_cb(pkt, cbinfo);
++ }
++}
++
+ /**
+ \ingroup Core_Keys
+ \brief Decrypts secret key from given keydata with given passphrase
+@@ -306,8 +320,18 @@ pgp_decrypt_seckey(const pgp_key_t *key,
+ const int printerrors = 1;
+ decrypt_t decrypt;
-- (void) fprintf(io->res, "%u key%s\n", keyring->keyc,
-- (keyring->keyc == 1) ? "" : "s");
-+ (void) fprintf(io->res, "%u key%s\n", keyc, (keyc == 1) ? "" : "s");
-+ if (keyring == NULL) {
-+ return 1;
++ /* first try with an empty passphrase */
+ (void) memset(&decrypt, 0x0, sizeof(decrypt));
+ decrypt.key = key;
++ stream = pgp_new(sizeof(*stream));
++ pgp_keydata_reader_set(stream, key);
++ pgp_set_callback(stream, decrypt_cb_empty, &decrypt);
++ stream->readinfo.accumulate = 1;
++ pgp_parse(stream, !printerrors);
++ if (decrypt.seckey != NULL) {
++ return decrypt.seckey;
+ }
- for (n = 0, key = keyring->keys; n < keyring->keyc; ++n, ++key) {
- if (pgp_is_key_secret(key)) {
- pgp_print_keydata(io, keyring, key, "sec",
++ /* ask for a passphrase */
+ decrypt.passfp = passfp;
+ stream = pgp_new(sizeof(*stream));
+ pgp_keydata_reader_set(stream, key);