2 years agodoc: Remove non-implemented option --skip-hidden-recipients.
Werner Koch [Wed, 8 Jun 2016 16:03:43 +0000 (18:03 +0200)]
doc: Remove non-implemented option --skip-hidden-recipients.


GnuPG-bug-id: 1394

Note that --try-secret-key was already removed with commit

Signed-off-by: Werner Koch <>
3 years agodoc: Explain that gpg-preset-passphrase can't be used.
Werner Koch [Fri, 22 Apr 2016 07:57:38 +0000 (09:57 +0200)]
doc: Explain that gpg-preset-passphrase can't be used.


3 years agopo: Fix misleading german translation.
Justus Winter [Fri, 1 Apr 2016 14:38:24 +0000 (16:38 +0200)]
po: Fix misleading german translation.

GnuPG-bug-id: 2239
Signed-off-by: Justus Winter <>
3 years agog10: Make sure to have the directory for trustdb.
NIIBE Yutaka [Fri, 12 Feb 2016 01:00:31 +0000 (10:00 +0900)]
g10: Make sure to have the directory for trustdb.

* g10/tdbio.c (tdbio_set_dbname): Return earlier if !CREATE.  Check
the directory and create it if none before calling take_write_lock.


Thanks to Marc Deslauriers for the bug report and his patch.

GnuPG-bug-id: 2246

Signed-off-by: NIIBE Yutaka <>
(backport from master
 commit 2f3e42047d17313eeb38d354048f343158402a8d)

3 years agoFix possible sign extension problem with newer compilers.
Werner Koch [Mon, 1 Feb 2016 17:06:14 +0000 (18:06 +0100)]
Fix possible sign extension problem with newer compilers.

* cipher/des.c (READ_64BIT_DATA): Cast to u32 before shifting by 24.
* cipher/blowfish.c (do_encrypt_block): Ditto.
(do_decrypt_block): Ditto.
* cipher/camellia.c (CAMELLIA_RR8): Ditto.
* cipher/cast5.c (do_encrypt_block): Ditto.
(do_decrypt_block): Ditto.
(do_cast_setkey): Ditto.
* cipher/twofish.c (INPACK): Ditto.
* util/iobuf.c (block_filter): Ditto.

For cipher/des.c
Reported-by: Balint Reczey <>
See commit 57af33d9e7c9b20b413b96882e670e75a67a5e65 for details.

Signed-off-by: Werner Koch <>
3 years agog10: Fix iobuf API of filter function for alignment.
NIIBE Yutaka [Tue, 26 Jan 2016 06:38:27 +0000 (15:38 +0900)]
g10: Fix iobuf API of filter function for alignment.

* include/iobuf.h (struct iobuf_struct): Remove DESC.
* util/iobuf.c (iobuf_desc): New.
(print_chain, iobuf_close, iobuf_open, iobuf_fdopen, iobuf_sockopen)
(iobuf_create, iobuf_append, iobuf_openrw, iobuf_ioctl)
(iobuf_push_filter2, pop_filter, underflow): Use iobuf_desc.
(file_filter, sock_filter, block_filter): Fill the description.
* g10/armor.c, g10/cipher.c, g10/compress-bz2.c, g10/compress.c,
g10/encode.c, g10/encr-data.c, g10/mdfilter.c, g10/pipemode.c,
g10/progress.c, g10/textfilter.c: Likewise.


Newer GCC warns against possible alignment difference of pointers.
This change can silence those warnings.

Signed-off-by: NIIBE Yutaka <>
(backported from 2.1 commit 3f52c7da3940ec06572270d511000dc7fe9c27d2)

3 years agoFix possible AIX problem with sysconf in rndunix.
Werner Koch [Fri, 15 Jan 2016 14:51:37 +0000 (15:51 +0100)]
Fix possible AIX problem with sysconf in rndunix.

* cipher/rndunix.c [HAVE_STDINT_H]: Include stdint.h.
(start_gatherer): Detect misbehaving sysconf.

GnuPG-bug-id: 1778
for the reason of this patch. There is no concrete bug report but this
chnage should not harm.

Signed-off-by: Werner Koch <>
3 years agoFix to support git worktree.
NIIBE Yutaka [Wed, 13 Jan 2016 08:22:37 +0000 (17:22 +0900)]
Fix to support git worktree.

* Use -e for testing .git.

Signed-off-by: NIIBE Yutaka <>
(backport commit of 96237b9a63a50aed1884cb06f84279b977d6a8fa)

3 years agopo: Update Japanese translation.
NIIBE Yutaka [Mon, 21 Dec 2015 12:27:53 +0000 (21:27 +0900)]
po: Update Japanese translation.

3 years agoPost release updates.
Werner Koch [Sun, 20 Dec 2015 08:01:18 +0000 (09:01 +0100)]
Post release updates.


3 years agoRelease 1.4.20 gnupg-1.4.20
Werner Koch [Sat, 19 Dec 2015 14:42:22 +0000 (15:42 +0100)]
Release 1.4.20

3 years agow32: Avoid warning when using newer mingw versions.
Werner Koch [Sat, 19 Dec 2015 15:54:57 +0000 (16:54 +0100)]
w32: Avoid warning when using newer mingw versions.

* g10/tdbio.c (ftruncate): Do not define if already defined.

Signed-off-by: Werner Koch <>
3 years agopo: Auto-update
Werner Koch [Sat, 19 Dec 2015 14:39:45 +0000 (15:39 +0100)]
po: Auto-update


3 years agopo: Update German translation
Werner Koch [Sat, 19 Dec 2015 15:53:45 +0000 (16:53 +0100)]
po: Update German translation


Signed-off-by: Werner Koch <>
3 years agopo: Update Russian translation
Ineiev [Sat, 19 Dec 2015 14:32:58 +0000 (15:32 +0100)]
po: Update Russian translation


Signed-off-by: Werner Koch <>
3 years agogpg: Add option --weak-digest to gpg and gpgv.
Daniel Kahn Gillmor [Tue, 27 Oct 2015 04:01:32 +0000 (00:01 -0400)]
gpg: Add option --weak-digest to gpg and gpgv.

* g10/options.h: Add weak_digests linked list to opts.
* g10/main.h: Declare weakhash linked list struct and
additional_weak_digest() function to insert newly-declared weak
digests into opts.
* g10/misc.c: (additional_weak_digest): New function.
(print_digest_algo_note): Check for deprecated digests.
* g10/sig-check.c: (do_check): Reject all weak digests.
* g10/gpg.c: Add --weak-digest option to gpg.
* doc/gpg.texi: Document gpg --weak-digest option.
* g10/gpgv.c: Add --weak-digest option to gpgv.
* doc/gpgv.texi: Document gpgv --weak-digest option.

gpg and gpgv treat signatures made over MD5 as unreliable, unless the
user supplies --allow-weak-digests to gpg.  Signatures over any other
digest are considered acceptable.

Despite SHA-1 being a mandatory-to-implement digest algorithm in RFC
4880, the collision-resistance of SHA-1 is weaker than anyone would
like it to be.

Some operators of high-value targets that depend on OpenPGP signatures
may wish to require their signers to use a stronger digest algorithm
than SHA1, even if the OpenPGP ecosystem at large cannot deprecate
SHA1 entirely today.

This changeset adds a new "--weak-digest DIGEST" option for both gpg
and gpgv, which makes it straightforward for anyone to treat any
signature or certification made over the specified digest as

This option can be supplied multiple times if the operator wishes to
deprecate multiple digest algorithms, and will be ignored completely
if the operator supplies --allow-weak-digests (as before).

MD5 is always considered weak, regardless of any further
--weak-digest options supplied.

Signed-off-by: Daniel Kahn Gillmor <>
(this is a rough cherry-pick of applying the following commits to

3 years agogpg: Reject signatures made with MD5.
Werner Koch [Tue, 27 Oct 2015 04:01:31 +0000 (00:01 -0400)]
gpg: Reject signatures made with MD5.

* g10/gpg.c: Add option --allow-weak-digest-algos.
(main): Set option also in PGP2 mode.
* g10/options.h (struct opt): Add flags.allow_weak_digest_algos.
* g10/sig-check.c (do_check): Reject MD5 signatures.
* tests/openpgp/gpg.conf.tmpl: Add allow_weak_digest_algos.
(cherry picked from commit f90cfe6b66269de0154d810c5cee1fe9a5af475c)

Resolved conflicts:
g10/gpg.c - adjust.
tests/openpgp/ - no changes

3 years agogpg: Change default cipher for --symmetric from CAST5 to AES-128.
Werner Koch [Mon, 18 Aug 2014 09:45:00 +0000 (11:45 +0200)]
gpg: Change default cipher for --symmetric from CAST5 to AES-128.

* g10/main.h (DEFAULT_CIPHER_ALGO): Change to AES or CAST5 or 3DES
depending on configure options.
* g10/gpg.c (main): Set opt.s2k_cipher_algo to DEFAULT_CIPHER_ALGO.


(cherry picked from commit 57df1121c18b004dd763b35eabf7b51fc9e8ec38)
Signed-off-by: Werner Koch <>
3 years agoPass DBUS_SESSION_BUS_ADDRESS for gnome3
Daniel Kahn Gillmor [Tue, 18 Aug 2015 11:34:57 +0000 (13:34 +0200)]

* g10/passphrase.c (stdenvnames): Add DBUS_SESSION_BUS_ADDRESS.

pinentry-gnome3 talks to the gcr prompter via dbus.  Without this
environment variable, it can't find the correct session to talk to.

3 years agogpg: Avoid cluttering stdout with trustdb info in verbose mode.
Werner Koch [Fri, 8 May 2015 14:30:04 +0000 (16:30 +0200)]
gpg: Avoid cluttering stdout with trustdb info in verbose mode.

* g10/trustdb.c (validate_keys): Call dump_key_array only in debug

I guess that is a left-over from an early attempt to output
information on the trustdb for use by other tools.  Maybe related to
the former --list-trust-path command.  Sending it to stdout is
probably useful so we do this now only in debug mode.

Signed-off-by: Werner Koch <>
Backported to STABLE-BRANCH-1-4 from
b03a2647299a6c8764a2574590cbaccdff9e497d by dkg

3 years agogpg: Silence a compiler warning.
Werner Koch [Thu, 18 Sep 2014 13:08:51 +0000 (15:08 +0200)]
gpg: Silence a compiler warning.

* g10/parse-packet.c (enum_sig_subpkt): Replace hack.


GCC 5 failure reported by Kevin Locke <>

(backport from master commit 6a0c3fa19cfcdd590b96691e8a8ffb48fb5e0ec4)

3 years agopo: Update Japanese translation.
NIIBE Yutaka [Thu, 17 Sep 2015 08:05:37 +0000 (17:05 +0900)]
po: Update Japanese translation.

3 years agopo: Fix Spanish translation
NIIBE Yutaka [Tue, 8 Sep 2015 00:14:20 +0000 (09:14 +0900)]
po: Fix Spanish translation

3 years agoObsolete option --no-sig-create-check.
Werner Koch [Mon, 31 Aug 2015 21:55:16 +0000 (23:55 +0200)]
Obsolete option --no-sig-create-check.

* cipher/rsa.c (rsa_sign): Verify after sign.
* g10/gpg.c (opts): Make --no-sig-create-check a NOP.
* g10/options.h (opt): Remove field "no_sig_create_check".
* g10/sign.c (do_sign): Do check only for DSA.

Signed-off-by: Werner Koch <>
3 years agog10: Fix a race condition initially creating trustdb.
NIIBE Yutaka [Tue, 16 Jun 2015 03:01:28 +0000 (12:01 +0900)]
g10: Fix a race condition initially creating trustdb.

* g10/tdbio.c (take_write_lock, tdbio_set_dbname): Fix message.

3 years agog10: Fix a race condition initially creating trustdb.
NIIBE Yutaka [Mon, 15 Jun 2015 05:38:05 +0000 (14:38 +0900)]
g10: Fix a race condition initially creating trustdb.

* g10/tdbio.c (take_write_lock, release_write_lock): New.
(put_record_into_cache, tdbio_sync, tdbio_end_transaction): Use
new lock functions.
(tdbio_set_dbname): Fix the race.
(open_db): Don't call dotlock_create.


(backported from 2.1 commit fe5c6edaed78839303d67e01e141cfc6b5de9aec)
GnuPG-bug-id: 1675

4 years agog10: detects public key encryption packet error properly.
NIIBE Yutaka [Tue, 19 May 2015 01:47:42 +0000 (10:47 +0900)]
g10: detects public key encryption packet error properly.

g10/mainproc.c (proc_pubkey_enc): Only allow relevant algorithms for


(backported from 2.1 commit c771963140cad7c1c25349bcde27e427effc0058)

4 years agog10: Improve handling of no corresponding public key.
NIIBE Yutaka [Tue, 19 May 2015 01:14:09 +0000 (10:14 +0900)]
g10: Improve handling of no corresponding public key.

* g10/getkey.c (get_seckey): Return G10ERR_NO_PUBKEY when it's not
exact match.


In the situation of corrupted .gnupg/ where only private subkey is
available but no corresponding public key of the subkey, the code
returned public primary key which caused mysterious error (for a
user).  This fix detects an error earlier.

GnuPG-bug-id: 1422
Debian-Bug-Id: #638619

4 years agog10: fix cmp_public_key and cmp_secret_keys.
NIIBE Yutaka [Thu, 30 Apr 2015 08:20:08 +0000 (17:20 +0900)]
g10: fix cmp_public_key and cmp_secret_keys.

* g10/free-packet.c (cmp_public_keys, cmp_secret_keys): Compare opaque
data at the first entry of the array when it's unknown algo.
* mpi/mpi-cmp.c (mpi_cmp): Backport libgcrypt 1.5.0's semantics.


(backported from 2.0 commit 43429c7869152f301157e4b24790b3801dce0f0a)

GnuPG-bug-id: 1962

4 years agogpg: Fix DoS while parsing mangled secret key packets.
Werner Koch [Sun, 5 Apr 2015 17:42:59 +0000 (19:42 +0200)]
gpg: Fix DoS while parsing mangled secret key packets.

* g10/parse-packet.c (parse_key): Check PKTLEN before calling mpi_read
et al.

Due to the missing length checks PKTLEN may turn negative.  Because
PKTLEN is an unsigned int the malloc in read_rest would try to malloc
a too large number and terminate the process with "error reading rest
of packet: Cannot allocate memory".

Reported-by: Hanno Böck.
Signed-off-by: Werner Koch <>
(backported from 2.0 commit 0aac920f23fd07e152fdb7385299c92bb9a4ade3)

4 years agogpg: Remove left-over debug message.
Werner Koch [Thu, 26 Feb 2015 08:38:58 +0000 (09:38 +0100)]
gpg: Remove left-over debug message.

* g10/armor.c (check_input): Remove log_debug.

4 years agoPost release updates
Werner Koch [Fri, 27 Feb 2015 09:01:08 +0000 (10:01 +0100)]
Post release updates


4 years agoRelease 1.4.19. gnupg-1.4.19
Werner Koch [Fri, 27 Feb 2015 08:33:58 +0000 (09:33 +0100)]
Release 1.4.19.

4 years agopo: Auto-update
Werner Koch [Fri, 27 Feb 2015 08:06:46 +0000 (09:06 +0100)]
po: Auto-update


4 years agopo: Update German translation
Werner Koch [Fri, 27 Feb 2015 08:05:21 +0000 (09:05 +0100)]
po: Update German translation

4 years agopo: Update French translation
David Prévot [Mon, 3 Nov 2014 03:24:29 +0000 (23:24 -0400)]
po: Update French translation

4 years agopo: Update Czech translation
Roman Pavlik [Tue, 25 Nov 2014 20:22:30 +0000 (16:22 -0400)]
po: Update Czech translation

4 years agopo: Update Dutch translation
Frans Spiesschaert [Mon, 24 Nov 2014 20:28:08 +0000 (16:28 -0400)]
po: Update Dutch translation

4 years agopo: Update Spanish translation
Manuel \"Venturi\" Porras Peralta [Sat, 22 Nov 2014 19:42:36 +0000 (15:42 -0400)]
po: Update Spanish translation

4 years agopo: Update Polish translation
Jakub Bogusz [Fri, 21 Nov 2014 21:06:59 +0000 (17:06 -0400)]
po: Update Polish translation

4 years agopo: Update Russian translation
Ineiev [Thu, 26 Feb 2015 20:06:38 +0000 (21:06 +0100)]
po: Update Russian translation

4 years agopo: Update Ukrainian translation
Yuri Chornoivan [Thu, 26 Feb 2015 20:04:57 +0000 (21:04 +0100)]
po: Update Ukrainian translation

4 years agopo: Update Italian translation.
Milo Casagrande [Thu, 26 Feb 2015 20:02:57 +0000 (21:02 +0100)]
po: Update Italian translation.

4 years agoUpdate Chinese (traditional) translation
Jedi Lin [Fri, 21 Nov 2014 21:42:44 +0000 (17:42 -0400)]
Update Chinese (traditional) translation

4 years agoFix for building without DNS support.
Werner Koch [Thu, 26 Feb 2015 19:00:17 +0000 (20:00 +0100)]
Fix for building without DNS support.

* util/cert.c (get_cert) [!USE_DNS_CERT]: Add want_ipgp.

4 years agopo,intl: Update to 0.19.3.
Werner Koch [Thu, 26 Feb 2015 18:01:30 +0000 (19:01 +0100)]
po,intl: Update to 0.19.3.

4 years agoSwitch to a hash and CERT record based PKA system.
Werner Koch [Thu, 26 Feb 2015 15:34:44 +0000 (16:34 +0100)]
Switch to a hash and CERT record based PKA system.

* util/pka.c: Rewrite.
(get_pka_info): Add arg fprbuflen.  Change callers to pass this.
* util/strgutil.c (ascii_strlwr): New.
* Remove option --disable-dns-pka.
(USE_DNS_PKA): Remove ac_define.
* g10/getkey.c (parse_auto_key_locate): Always include PKA.

Note that although PKA is now always build, it will only work if
support for looking up via DNS has not been disabled.

The new PKA only works with the IPGP DNS certtype and shall be used
only to retrieve the fingerprint and optional the key for the first
time.  Due to the security problems with DNSSEC the former assumption
to validate the key using DNSSEC is not anymore justified.  Instead an
additional layer (e.g. Trust-On-First-Use) needs to be implemented to
track change to the key.  Having a solid way of getting a key matching
a mail address is however a must have.

More work needs to go into a redefinition of the --verify-options
pka-lookups and pka-trust-increase.  The auto-key-locate mechanism
should also be able to continue key fetching with another method once
the fingerprint has been retrieved with PKA.

Signed-off-by: Werner Koch <>
This is a backport from master.
(backported from commit 2fc27c8696f5cf2ddf3212397ea49bff115d617b)

4 years agoMove two functions from g10/ to util/.
Werner Koch [Thu, 26 Feb 2015 15:08:02 +0000 (16:08 +0100)]
Move two functions from g10/ to util/.

* g10/misc.c (has_invalid_email_chars, is_valid_mailbox): Move to ...
* util/strgutil.c: here.

Signed-off-by: Werner Koch <>
4 years agoAdd new function strconcat.
Werner Koch [Thu, 26 Feb 2015 15:05:19 +0000 (16:05 +0100)]
Add new function strconcat.

* include/util.h (GNUPG_GCC_A_SENTINEL): New.
* util/strgutil.c (do_strconcat, strconcat): New.

Signed-off-by: Werner Koch <>
4 years agoAdd convenience function to hash a buffer.
Werner Koch [Thu, 26 Feb 2015 14:35:49 +0000 (15:35 +0100)]
Add convenience function to hash a buffer.

* cipher/sha1.c (sha1_hash_buffer): New.

Signed-off-by: Werner Koch <>
4 years agoAllow requesting only an IPGP certtype with dns_cert().
Werner Koch [Thu, 26 Feb 2015 14:17:56 +0000 (15:17 +0100)]
Allow requesting only an IPGP certtype with dns_cert().

* util/cert.c (get_cert): Add arg want_ipgp.  Change callers.

Signed-off-by: Werner Koch <>
4 years agodoc: Fix name of keep-ownertrust.
Werner Koch [Thu, 26 Feb 2015 14:06:00 +0000 (15:06 +0100)]
doc: Fix name of keep-ownertrust.


Reported-by: Guilhem Moulin <>
4 years agompi: Avoid data-dependent timing variations in mpi_powm.
NIIBE Yutaka [Thu, 26 Feb 2015 12:00:05 +0000 (21:00 +0900)]
mpi: Avoid data-dependent timing variations in mpi_powm.

* include/mpi.h, mpi/mpiutils.c (mpi_set_cond): New.
* mpi/mpi-pow.c (SIZE_PRECOMP): Rename from SIZE_B_2I3.
(mpi_powm): Access all data in the table and use mpi_set_cond.


Access to the precomputed table was indexed by a portion of EXPO,
which could be mounted by a side channel attack.  This change fixes
this particular data-dependent access pattern.

4 years agodoc: Add warning note about not acting as an oracle to --batch.
Werner Koch [Mon, 23 Feb 2015 12:10:57 +0000 (13:10 +0100)]
doc: Add warning note about not acting as an oracle to --batch.


4 years agoProtect against NULL return of mpi_get_opaque.
Werner Koch [Mon, 23 Feb 2015 10:04:35 +0000 (11:04 +0100)]
Protect against NULL return of mpi_get_opaque.

* g10/seckey-cert.c (do_check): Call BUG for NULL return of

This is the suggested addition from commit 6f03218.  We better run
into an fatal error than into a segv.

Signed-off-by: Werner Koch <>
4 years agogpg: Fix segv due to NULL value stored as opaque MPI
Daniel Kahn Gillmor [Sun, 22 Feb 2015 04:10:37 +0000 (23:10 -0500)]
gpg: Fix segv due to NULL value stored as opaque MPI

* g10/build-packet.c (do_secret_key): Check for NULL return from
* g10/keyid.c (hash_public_key): Ditto.

This is a backport of 76c8122adfed0f0f443cce7bda702ba2b39661b3 from
master to the STABLE-BRANCH-1-4

On the STABLE-BRANCH-1-4, we may also want to patch g10/seckey-cert.c,
but that has not been done in this patch.

This fix extends commmit 0835d2f44ef62eab51fce6a927908f544e01cf8f.

  gpg2 --export --no-default-keyring --keyring TESTDATA

With TESTDATA being below after unpacking.



Reported-by: Jodie Cunningham
[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Remove an unused variable.
Werner Koch [Sun, 22 Feb 2015 04:10:36 +0000 (23:10 -0500)]
gpg: Remove an unused variable.

* g10/import.c (import): Remove need_armor.

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agocurl-shim: clean up varargs
Daniel Kahn Gillmor [Sun, 22 Feb 2015 04:10:35 +0000 (23:10 -0500)]
curl-shim: clean up varargs

* keyserver/curl-shim.c (curl_easy_setopt) : ensure that va_end is


stdarg(3) says:
      Each invocation of va_start() must be matched by a
      corresponding invocation of va_end() in the same function.

Observed by Joshua Rogers <>

Debian-Bug-Id: #773475

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Print better diagnostics for keyserver operations.
Werner Koch [Sun, 22 Feb 2015 04:10:34 +0000 (23:10 -0500)]
gpg: Print better diagnostics for keyserver operations.

* g10/armor.c (parse_key_failed_line): New.
(check_input): Watch out for gpgkeys_ error lines.
* g10/filter.h (armor_filter_context_t): Add field key_failed_code.
* g10/import.c (import): Add arg r_gpgkeys_err.
(import_keys_internal): Ditto.
(import_keys_stream): Ditto.
* g10/keyserver.c (keyserver_errstr): New.
(keyserver_spawn): Detect "KEY " lines while sending.  Get gpgkeys_err
while receiving keys.
(keyserver_work): Add kludge for better error messages.

GnuPG-bug-id: 1832

Note that these changes can be backported to 1.4 but they don't make
sense for 2.1 due to the removal of the keyserver helpers.  The error
reporting could be improved even more but given that this is an old
GnuPG branch it is not justified to put too much effort into it.

Signed-off-by: Werner Koch <>
[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agoUse inline functions to convert buffer data to scalars.
Werner Koch [Sun, 22 Feb 2015 04:10:32 +0000 (23:10 -0500)]
Use inline functions to convert buffer data to scalars.

* include/host2net.h (buf16_to_ulong, buf16_to_uint): New.
(buf16_to_ushort, buf16_to_u16): New.
(buf32_to_size_t, buf32_to_ulong, buf32_to_uint, buf32_to_u32): New.

This fixes sign extension on shift problems.  Hanno Böck found a case
with an invalid read due to this problem.  To fix that almost all uses
of "<< 24" and "<< 8" are changed by this patch to use an inline
function from host2net.h.

(back ported from commit 2183683bd633818dd031b090b5530951de76f392)

Signed-off-by: Werner Koch <>
[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agodoc: Change remaining http links to to https
Werner Koch [Sun, 22 Feb 2015 04:10:31 +0000 (23:10 -0500)]
doc: Change remaining http links to to https

GnuPG-bug-id: 1830

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Prevent an invalid memory read using a garbled keyring.
Werner Koch [Sun, 22 Feb 2015 04:10:30 +0000 (23:10 -0500)]
gpg: Prevent an invalid memory read using a garbled keyring.

* g10/keyring.c (keyring_get_keyblock): Whitelist allowed packet

The keyring DB code did not reject packets which don't belong into a
keyring.  If for example the keyblock contains a literal data packet
it is expected that the processing code stops at the data packet and
reads from the input stream which is referenced from the data packets.
Obviously the keyring processing code does not and cannot do that.
However, when exporting this messes up the IOBUF and leads to an
invalid read of sizeof (int).

We now skip all packets which are not allowed in a keyring.

Reported-by: Hanno Böck <>
(back ported from commit f0f71a721ccd7ab9e40b8b6b028b59632c0cc648)

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Fix a NULL-deref in export due to invalid packet lengths.
Werner Koch [Sun, 22 Feb 2015 04:10:29 +0000 (23:10 -0500)]
gpg: Fix a NULL-deref in export due to invalid packet lengths.

* g10/build-packet.c (write_fake_data): Take care of a NULL stored as
opaque MPI.

Reported-by: Hanno Böck <>
(back ported from commit 0835d2f44ef62eab51fce6a927908f544e01cf8f)

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Fix a NULL-deref due to empty ring trust packets.
Werner Koch [Sun, 22 Feb 2015 04:10:28 +0000 (23:10 -0500)]
gpg: Fix a NULL-deref due to empty ring trust packets.

* g10/parse-packet.c (parse_trust): Always allocate a packet.

Reported-by: Hanno Böck <>
Signed-off-by: Werner Koch <>
(back ported from commit 39978487863066e59bb657f5fe4e8baab510da7e)

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Limit the size of key packets to a sensible value.
Werner Koch [Sun, 22 Feb 2015 04:10:27 +0000 (23:10 -0500)]
gpg: Limit the size of key packets to a sensible value.

* g10/parse-packet.c (MAX_KEY_PACKET_LENGTH): New.
(parse_key): Limit the size of a key packet to 256k.
(parse_user_id): Use macro for the packet size limit.
(parse_attribute): Ditto.
(parse_comment): Ditto.

Without that it is possible to force gpg to allocate large amounts of
memory by using a bad encoded MPI.  This would be an too easy DoS.
Another way to mitigate would be to change the MPI read function to
allocate memory dynamically while reading the MPI.  However, that
complicates and possibly slows down the code.  A too large key packet
is in any case a sign for broken data and thus gpg should not use it.

Reported-by: Hanno Böck
GnuPG-bug-id: 1823
Signed-off-by: Werner Koch <>
(back ported from commit 382ba4b137b42d5f25a7e256bb7c053ee5ac7b64)

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Allow predefined names as answer to the keygen.algo prompt.
Werner Koch [Sun, 22 Feb 2015 04:10:26 +0000 (23:10 -0500)]
gpg: Allow predefined names as answer to the keygen.algo prompt.

* g10/keygen.c (ask_algo): Add list of strings.

Signed-off-by: Werner Koch <>
(backported from commit b1d5ed6ac842469afcb84868d0f6641dc286a6c7)

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agogpg: Print a warning if the subkey expiration may not be what you want.
Werner Koch [Sun, 22 Feb 2015 04:10:25 +0000 (23:10 -0500)]
gpg: Print a warning if the subkey expiration may not be what you want.

* g10/keyedit.c (subkey_expire_warning): New.
keyedit_menu): Call it when needed.
GnuPG-bug-id: 1715

The heuristic to detect a problem is not very advanced but it should
catch the most common cases.

(backported from commit ae3d1bbb65b65cf3c57bb14886be120f5e31635d)

[dkg: rebased to STABLE-BRANCH-1-4]
Signed-off-by: Daniel Kahn Gillmor <>
4 years agoUse ciphertext blinding for Elgamal decryption.
Werner Koch [Mon, 11 Aug 2014 14:15:40 +0000 (16:15 +0200)]
Use ciphertext blinding for Elgamal decryption.

* cipher/elgamal.c (USE_BLINDING): New.
(decrypt): Rewrite to use ciphertext blinding.

CVE-id: CVE-2014-3591

As a countermeasure to a new side-channel attacks on sliding windows
exponentiation we blind the ciphertext for Elgamal decryption.  This
is similar to what we are doing with RSA.

Unfortunately, the performance impact of Elgamal blinding is quite
noticeable: For a 3072 bit Elgamal key the decryption used to take
13ms; with the blinding it takes 24ms.  This has been measured using
time(1), calling gpg with a 100 byte message, and having gpg modified
to run the pubkey_decrypt function 100 times and finally scale the
result (using an i5-2410M CPU @ 2.30GHz TP 220).

4 years agoUpdate automake helper files.
Werner Koch [Mon, 19 Jan 2015 16:25:57 +0000 (17:25 +0100)]
Update automake helper files.


4 years agoModernize to automake 1.14.
Werner Koch [Mon, 19 Jan 2015 17:59:13 +0000 (18:59 +0100)]
Modernize to automake 1.14.

* (AUTOMAKE_OPTIONS): Move to ...
* (AM_INIT_AUTOMAKE): here and add serial-tests.

* keyserver/ Replace INCLUDES by AM_CPPFLAGS.
* mpi/ Ditto.
* util/ Ditto.
* keyserver/ Ditto.  Adjusted other things.

* m4/intl.m4, m4/po.m4: Use autoconf's AC_PROG_MKDIR_P.

4 years agoFix a problem with select and high fds.
Werner Koch [Mon, 19 Jan 2015 15:46:05 +0000 (16:46 +0100)]
Fix a problem with select and high fds.

* cipher/rndlinux.c (rndlinux_gather_random): Check fd before using

If on systems where the maximum number of fds may be dynamically
configured to a value of FD_MAXSIZE or higher and the RNG is first
used after more than FD_SETSIZE-1 descriptors are in use, we disable
the progress messages from the RNG.  A better solution would be too
use poll but that requires more tests.

The same problem exists in rndunix.c - however this rng is only used
on old Unices and I assume that they don't feature dynamically
configured maximum fd sizes.

(from Libgcrypt commit 9487099071af4478d2882e633a0ade805801d6fa)

This may fix
GnuPG-bug-id: 1818

4 years agodoc: Formatting fixes.
Werner Koch [Thu, 18 Apr 2013 12:40:43 +0000 (14:40 +0200)]
doc: Formatting fixes.

* doc/gpl.texi: Fix enumerate and re-indent examples.


Cherry-pick a part of ff6115227a1ced14e2fb3d160a12181b9dfbc502.

Reported-by: Ian Abbott
Signed-off-by: Werner Koch <>
4 years agoavoid future chance of using uninitialized memory
Daniel Kahn Gillmor [Fri, 19 Dec 2014 22:53:36 +0000 (17:53 -0500)]
avoid future chance of using uninitialized memory

* util/iobuf.c: (iobuf_open): initialize len


Cherry-pick 367b073ab5f439ccf0750461d10c69f36998bd62.

In iobuf_open, IOBUFCTRL_DESC and IOBUFCTRL_INIT commands are invoked
(via file_filter()) on fcx, passing in a pointer to an uninitialized

With these two commands, file_filter doesn't actually do anything with
the value of len, so there's no actual risk of use of uninitialized
memory in the code as it stands.

However, some static analysis tools might flag this situation with a
warning, and initializing the value doesn't hurt anything, so i think
this trivial cleanup is warranted.

Debian-Bug-Id: 773469

4 years agodoc: Fix memory leak in yat2m.
Werner Koch [Mon, 22 Dec 2014 11:44:13 +0000 (12:44 +0100)]
doc: Fix memory leak in yat2m.

* doc/yat2m.c (write_th): Free NAME.

Reported-by: Joshua Rogers <>
4 years agogpg: Fix possible read of unallocated memory
Werner Koch [Fri, 12 Dec 2014 09:41:25 +0000 (10:41 +0100)]
gpg: Fix possible read of unallocated memory

* g10/parse-packet.c (can_handle_critical): Check content length
before calling can_handle_critical_notation.

The problem was found by Jan Bee and gniibe proposed the used fix.

This bug can't be exploited: Only if the announced length of the
notation is 21 or 32 a memcmp against fixed strings using that length
would be done.  The compared data is followed by the actual signature
and thus it is highly likely that not even read of unallocated memory
will happen.  Nevertheless such a bug needs to be fixed.

Signed-off-by: Werner Koch <>
4 years agoscd: Fix possibly inhibited checkpin of the admin pin.
Werner Koch [Fri, 12 Dec 2014 19:08:45 +0000 (20:08 +0100)]
scd: Fix possibly inhibited checkpin of the admin pin.

* scd/app-openpgp.c (do_check_pin): Do not check a byte of a released

Signed-off-by: Werner Koch <>
4 years agoscd: fix get_public_key for OpenPGPcard v1.0.
Joshua Rogers [Sat, 20 Dec 2014 00:38:53 +0000 (11:38 +1100)]
scd: fix get_public_key for OpenPGPcard v1.0.

* scd/app-openpgp.c (get_public_key): correctly close 'fp' upon use.


Inside the get_public_key function, 'fp' was opened using popen, but
incorrectly closed using fclose.

Debian-Bug-Id: 773474

4 years agogpg: release DEK soon after its use.
NIIBE Yutaka [Fri, 12 Dec 2014 08:41:56 +0000 (17:41 +0900)]
gpg: release DEK soon after its use.

* g10/keygen.c (generate_subkeypair): Release DEK soon.


This fixes the out_of_core error in the test case of adding
RSA-4096 subkey to RSA-4096 primary key with configuration:

    s2k-cipher-algo S10

Debian-bug-id: 772780

4 years agodoc: Do not install gnupg.7
Werner Koch [Mon, 24 Nov 2014 19:01:45 +0000 (20:01 +0100)]
doc: Do not install gnupg.7

GnuPG-bug-id: 1770

4 years agogpg: Fix use of uninit.value in listing sig subpkts.
Werner Koch [Mon, 24 Nov 2014 18:41:46 +0000 (19:41 +0100)]
gpg: Fix use of uninit.value in listing sig subpkts.

* g10/parse-packet.c (dump_sig_subpkt): Print regex subpacket

We may not use "%s" to print an arbitrary buffer.  At least "%.*s"
should have been used.  However, it is in general preferable to escape
control characters while printf user data.

Reported-by: Hanno Böck
Signed-off-by: Werner Koch <>
(backported from commit 596ae9f5433ca3b0e01f7acbe06fd2e424c42ae8)

4 years agogpg: Fix off-by-one read in the attribute subpacket parser.
Werner Koch [Mon, 24 Nov 2014 18:38:04 +0000 (19:38 +0100)]
gpg: Fix off-by-one read in the attribute subpacket parser.

* g10/parse-packet.c (parse_attribute_subpkts): Check that the
attribute packet is large enough for the subpacket type.

Reported-by: Hanno Böck
Signed-off-by: Werner Koch <>
(backported from commit 0988764397f99db4efef1eabcdb8072d6159af76)

4 years agogpg: Fix a NULL-deref for invalid input data.
Werner Koch [Mon, 24 Nov 2014 18:32:47 +0000 (19:32 +0100)]
gpg: Fix a NULL-deref for invalid input data.

* g10/mainproc.c (proc_encrypted): Take care of canceled passpharse

GnuPG-bug-id: 1761
Signed-off-by: Werner Koch <>
(backported from commit 32e85668b82f6fbcb824eea9548970804fb41d9e)

4 years agogpg: Make the use of "--verify FILE" for detached sigs harder.
Werner Koch [Fri, 14 Nov 2014 08:36:19 +0000 (09:36 +0100)]
gpg: Make the use of "--verify FILE" for detached sigs harder.

* g10/openfile.c (open_sigfile): Factor some code out to ...
(get_matching_datafile): new function.
* g10/plaintext.c (hash_datafiles): Do not try to find matching file
in batch mode.
* g10/mainproc.c (check_sig_and_print): Print a warning if a possibly
matching data file is not used by a standard signatures.

Allowing to use the abbreviated form for detached signatures is a long
standing bug which has only been noticed by the public with the
release of 2.1.0.  :-(

What we do is to remove the ability to check detached signature in
--batch using the one file abbreviated mode.  This should exhibit
problems in scripts which use this insecure practice.  We also print a
warning if a matching data file exists but was not considered because
the detached signature was actually a standard signature:

  gpgv: Good signature from "Werner Koch (dist sig)"
  gpgv: WARNING: not a detached signature; \
  file 'gnupg-2.1.0.tar.bz2' was NOT verified!

We can only print a warning because it is possible that a standard
signature is indeed to be verified but by coincidence a file with a
matching name is stored alongside the standard signature.

Reported-by: Simon Nicolussi (to gnupg-users on Nov 7)
Signed-off-by: Werner Koch <>
(backported from commit 69384568f66a48eff3968bb1714aa13925580e9f)

Updated doc/gpg.texi.

4 years agogpg: Add import option "keep-ownertrust".
Werner Koch [Wed, 12 Nov 2014 08:56:40 +0000 (09:56 +0100)]
gpg: Add import option "keep-ownertrust".

* g10/options.h (IMPORT_KEEP_OWNERTTRUST): New.
* g10/import.c (parse_import_options): Add "keep-ownertrust".
(import_one): Act upon new option.

This option is in particular useful to convert from a pubring.gpg to
the new pubring.kbx in GnuPG 2.1 or vice versa:

gpg1 --export | gpg2 --import-options keep-ownertrust --import

(cherry-picked from commit da95d0d37841b34e2f3d7047f14ab4d98a7c0c56)

4 years agodoc: Minor fix
Werner Koch [Fri, 3 Oct 2014 18:21:28 +0000 (20:21 +0200)]
doc: Minor fix


Thanks to dkg for the reminder.

4 years agompi: Fix compiler warning.
Werner Koch [Fri, 3 Oct 2014 16:28:58 +0000 (18:28 +0200)]
mpi: Fix compiler warning.

* mpi/mpi-inv.c (mpi_invm): Do not return a value.

4 years agogpg: Add build and runtime support for larger RSA keys
Daniel Kahn Gillmor [Fri, 3 Oct 2014 16:01:11 +0000 (12:01 -0400)]
gpg: Add build and runtime support for larger RSA keys

* Added --enable-large-secmem option.
* g10/options.h: Add opt.flags.large_rsa.
* g10/gpg.c: Contingent on configure option: adjust secmem size,
add gpg --enable-large-rsa, bound to opt.flags.large_rsa.
* g10/keygen.c: Adjust max RSA size based on opt.flags.large_rsa
* doc/gpg.texi: Document --enable-large-rsa.


Some older implementations built and used RSA keys up to 16Kib, but
the larger secret keys now fail when used by more recent GnuPG, due to
secure memory limitations.

Building with ./configure --enable-large-secmem will make gpg
capable of working with those secret keys, as well as permitting the
use of a new gpg option --enable-large-rsa, which let gpg generate RSA
keys up to 8Kib when used with --batch --gen-key.

Debian-bug-id: 739424

Minor edits by wk.

GnuPG-bug-id: 1732

4 years agodoc: Cleanup gpg.texi.
Werner Koch [Mon, 29 Sep 2014 09:28:55 +0000 (11:28 +0200)]
doc: Cleanup gpg.texi.


We don't need the gpgone and gpgtwoone macros anymore.

4 years agodoc: Final update from master (gnupg 2.1)
Werner Koch [Mon, 29 Sep 2014 09:11:30 +0000 (11:11 +0200)]
doc: Final update from master (gnupg 2.1)

* doc/ (sources_from_trunk): Remove.
(update-source): Make it a dummy.
* doc/gpg.texi: Update.
* doc/yat2m.c: Update.

Maintaining 3 versions in of the gpg manual in one file is getting
more complicated with 2.1.  Thus we stop this now and keep the manual
for 1.4 separate.

4 years agoAllow use of --debug-level=LEVEL without '='.
Werner Koch [Thu, 25 Sep 2014 07:47:28 +0000 (09:47 +0200)]
Allow use of --debug-level=LEVEL without '='.

* g10/gpg.c (opts): Fix "debug-level".

4 years agompi: Improve mpi_invm to detect bad input.
Werner Koch [Thu, 11 Sep 2014 15:06:16 +0000 (17:06 +0200)]
mpi: Improve mpi_invm to detect bad input.

* mpi/mpi-inv.c (mpi_invm): Return 0 for bad input.

Without this patch the function may enter an endless loop.  This is a
backport from libgcrypt.

GnuPG-bug-id: 1713

4 years agompi: Suppress set-but-unused-variables warnings.
Werner Koch [Wed, 20 Aug 2014 11:25:17 +0000 (13:25 +0200)]
mpi: Suppress set-but-unused-variables warnings.

* include/types.h (GNUPG_GCC_ATTR_UNUSED): Define for gcc >= 3.5.
* mpi/mpih-div.c (mpihelp_divmod_1, mpihelp_mod_1): Mark dummy as
* mpi/mpi-internal.h (UDIV_QRNND_PREINV): Mark _ql as unused.

Due to the use of macros and longlong.h, we use variables which are
only used by some architectures.  At least gcc 4.7.2 prints new
warnings about set but not used variables.  This patch silences them.

4 years agoFix strict-alias warnings for rijndael.c
Werner Koch [Wed, 20 Aug 2014 10:22:35 +0000 (12:22 +0200)]
Fix strict-alias warnings for rijndael.c

* cipher/rijndael.c (do_setkey, prepare_decryption): Use u32_a_t cast.

This extends commit 0ad1458f827c7602ef7f1a4652af05641fd02b62

4 years agogpg: Allow compressed data with algorithm 0.
Werner Koch [Wed, 20 Aug 2014 10:05:16 +0000 (12:05 +0200)]
gpg: Allow compressed data with algorithm 0.

* g10/mainproc.c (proc_compressed): Remove superfluous check for
an algorithm number of 0.

(backport from commit 88633bf3d417aeb5ea0f75508aba8e32adc8acef)

GnuPG-bug-id: 1326, 1684

4 years agogpg: Fix regression due to the keyserver import filter.
Werner Koch [Wed, 6 Aug 2014 15:11:21 +0000 (17:11 +0200)]
gpg: Fix regression due to the keyserver import filter.

* g10/keyserver.c (keyserver_retrieval_filter): Change args.  Rewrite
to take subpakets in account.
* g10/import.c (import_one, import_secret_one): Pass keyblock to

GnuPG-bug-id: 1680

Resolved conflicts:
g10/main.h - s/import_filter/import_filter_t/g

4 years agoAdd kbnode_t for easier backporting.
Werner Koch [Wed, 6 Aug 2014 15:09:15 +0000 (17:09 +0200)]
Add kbnode_t for easier backporting.

* g10/global.h (kbnode_t): New.

4 years agoPost release updates
Werner Koch [Wed, 25 Jun 2014 12:33:34 +0000 (14:33 +0200)]
Post release updates


4 years agoRelease 1.4.18 gnupg-1.4.18
Werner Koch [Wed, 25 Jun 2014 12:33:34 +0000 (14:33 +0200)]
Release 1.4.18

4 years agoLimit keysize for unattended key generation to useful values.
Werner Koch [Wed, 25 Jun 2014 18:25:28 +0000 (20:25 +0200)]
Limit keysize for unattended key generation to useful values.

* g10/keygen.c (gen_elg): Enforce keysize 1024 to 4096.
(gen_rsa): Enforce keysize 1024 to 4096.
(gen_dsa): Enforce keysize 768 to 3072.

It was possible to create 16k RSA keys in batch mode. In addition to
the silliness of such keys, they have the major drawback that GnuPG,
with its limited amount of specially secured memory areas, the use of
such keys may lead to an "out of secure memory" condition.

4 years agoMake screening of keyserver result work with multi-key commands.
Werner Koch [Wed, 25 Jun 2014 12:33:34 +0000 (14:33 +0200)]
Make screening of keyserver result work with multi-key commands.

* g10/keyserver.c (ks_retrieval_filter_arg_s): new.
(keyserver_retrieval_filter): Use new struct and check all
(keyserver_spawn): Pass filter arg suing the new struct.

This is a fix for commit 52303043.

The old code did only work for a single key.  It failed as soon as
several keys are specified ("gpg --refresh-keys" or "gpg --recv-key A
B C").