From bbfa7c42337bb619e6af20bf051fe0755ed5a9fd Mon Sep 17 00:00:00 2001 From: Tobias Mueller Date: Tue, 20 Feb 2018 17:34:14 +0100 Subject: python: Fix crash by leaving struct members intact * lang/python/setup.py.in: Copy gpgme.h instead of parsing it. -- The python bindings tried to parse deprecated functions out of gpgme.h. This fails for the current gpgme.h in that it removes an entire field in the key sig struct (_obsolete_class). Hence, the fields were off by an int and the bindings accessed struct members via the wrong offset. That caused python program to crash. At least on 32bit platforms, the crash can be easily triggered by accessing key.uids[0].signatures. On 64bit platforms the compiler probably aligns the struct so that the missing 4 bytes are not noticed. With this change, the python bindings will expose all functions that gpgme exposes, including the deprecated ones. Credits go to Justus Winter for debugging and identying the issue. Signed-off-by: Tobias Mueller GnuPG-bug-id: 3892 --- lang/python/setup.py.in | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'lang') diff --git a/lang/python/setup.py.in b/lang/python/setup.py.in index f9dda20f..2595073f 100755 --- a/lang/python/setup.py.in +++ b/lang/python/setup.py.in @@ -152,25 +152,8 @@ class BuildExtFirstHack(build): sink.write(content) def _generate_gpgme_h(self, source_name, sink_name): - if up_to_date(source_name, sink_name): - return - print("Using gpgme.h from {}".format(source_name)) - - deprec_func = re.compile(r'^(.*typedef.*|.*\(.*\)|[^#]+\s+.+)' - + r'\s*_GPGME_DEPRECATED(_OUTSIDE_GPGME)?\(.*\);\s*', - re.S) - line_break = re.compile(';|\\$|\\x0c|^\s*#|{') - - with open(sink_name, "w") as sink, open(source_name) as source: - text = '' - for line in source: - text += re.sub(' class ', ' _py_obsolete_class ', line) - if line_break.search(line): - if not deprec_func.search(text): - sink.write(text) - text = '' - sink.write(text) + shutil.copy2(source_name, sink_name) def _generate_errors_i(self): -- cgit v1.2.3 From 67b4dafb6d3fe2b5ab889417126ca5d509c0e3ca Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Wed, 18 Apr 2018 19:30:50 +0200 Subject: doc: Update copyright years and change two URLs. -- Signed-off-by: Werner Koch --- lang/python/README | 12 ++++++------ lang/python/README.org | 9 ++++----- 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'lang') diff --git a/lang/python/README b/lang/python/README index 49e88205..99da4dd7 100644 --- a/lang/python/README +++ b/lang/python/README @@ -1,6 +1,6 @@ - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ - GPG - GPGME BINDINGS FOR PYTHON - ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ + GPG - GPGME BINDINGS FOR PYTHON + ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Table of Contents @@ -13,7 +13,7 @@ Table of Contents The "gpg" module is a python interface to the GPGME library: -[https://www.gnupg.org/related_software/gpgme/] +[https://www.gnupg.org/software/gpgme/] "gpg" offers two interfaces, one is a high-level, curated, and idiomatic interface that is implemented as a shim on top of the low-level @@ -36,8 +36,8 @@ functionality of the underlying library. 2 Bugs ══════ - Please report bugs using our bug tracker using the category 'gpgme', - and topic 'python': [https://bugs.gnupg.org/gnupg/] + Please report bugs using our bug tracker [https://bugs.gnupg.org] with + tag (aka project) 'gpgme'. 3 Authors diff --git a/lang/python/README.org b/lang/python/README.org index 22e7d1f8..cba99669 100644 --- a/lang/python/README.org +++ b/lang/python/README.org @@ -1,8 +1,8 @@ #+TITLE: gpg - GPGME bindings for Python - +#+OPTIONS: author:nil The "gpg" module is a python interface to the GPGME library: -https://www.gnupg.org/related_software/gpgme/ +[[https://www.gnupg.org/software/gpgme/]] "gpg" offers two interfaces, one is a high-level, curated, and idiomatic interface that is implemented as a shim on top of the @@ -21,9 +21,8 @@ https://lists.gnupg.org/mailman/listinfo/gnupg-devel * Bugs -Please report bugs using our bug tracker using the category 'gpgme', -and topic 'python': -https://bugs.gnupg.org/gnupg/ +Please report bugs using our bug tracker +[[https://bugs.gnupg.org]] with tag (aka project) 'gpgme'. * Authors -- cgit v1.2.3 From 0adaf7bafd352f1c3a1e797493780150e3bb0adc Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Thu, 19 Apr 2018 10:44:01 +0200 Subject: cpp: Add origin and last_update * NEWS: mention interface change. * lang/cpp/src/key.cpp (Key::origin, Key::lastUpdate): New. * lang/cpp/src/key.h (Key::Origin): New enum. --- lang/cpp/src/key.cpp | 31 +++++++++++++++++++++++++++++++ lang/cpp/src/key.h | 21 +++++++++++++++++++++ 2 files changed, 52 insertions(+) (limited to 'lang') diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 0e86a19e..838033c5 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -981,6 +981,37 @@ Error Key::addUid(const char *uid) return ret; } +Key::Origin Key::origin() const +{ + if (isNull()) { + return OriginUnknown; + } + switch (key->origin) { + case GPGME_KEYORG_KS: + return OriginKS; + case GPGME_KEYORG_DANE: + return OriginDane; + case GPGME_KEYORG_WKD: + return OriginWKD; + case GPGME_KEYORG_URL: + return OriginURL; + case GPGME_KEYORG_FILE: + return OriginFile; + case GPGME_KEYORG_SELF: + return OriginSelf; + case GPGME_KEYORG_OTHER: + return OriginOther; + case GPGME_KEYORG_UNKNOWN: + default: + return OriginUnknown; + } +} + +time_t Key::lastUpdate() const +{ + return static_cast(key ? key->last_update : 0); +} + std::ostream &operator<<(std::ostream &os, const UserID &uid) { os << "GpgME::UserID("; diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index c3c711c1..07ddc256 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -178,6 +178,27 @@ public: */ static Key locate(const char *mbox); + /* @enum Origin + * @brief The Origin of the key. */ + enum Origin : unsigned int { + OriginUnknown = 0, + OriginKS = 1, + OriginDane = 3, + OriginWKD = 4, + OriginURL = 5, + OriginFile = 6, + OriginSelf = 7, + OriginOther = 31, + }; + /*! Get the origin of the key. + * + * @returns the Origin. */ + Origin origin() const; + + /*! Get the last update time. + * + * @returns the last update time. */ + time_t lastUpdate() const; private: gpgme_key_t impl() const { -- cgit v1.2.3 From d65d6329319bff8cc555999fc92a20e151762a10 Mon Sep 17 00:00:00 2001 From: Andre Heinecke Date: Thu, 19 Apr 2018 11:56:15 +0200 Subject: cpp: Add origin and last_update to UserID * NEWS: Mention it. * lang/cpp/src/key.cpp, lang/cpp/src/key.h (UserID::lastUpdate), (UserID::origin): New. (gpgme_origin_to_pp_origin): New helper. --- lang/cpp/src/key.cpp | 56 ++++++++++++++++++++++++++++++++++------------------ lang/cpp/src/key.h | 10 ++++++++++ 2 files changed, 47 insertions(+), 19 deletions(-) (limited to 'lang') diff --git a/lang/cpp/src/key.cpp b/lang/cpp/src/key.cpp index 838033c5..034286f0 100644 --- a/lang/cpp/src/key.cpp +++ b/lang/cpp/src/key.cpp @@ -967,6 +967,42 @@ Error UserID::revoke() return ret; } +static Key::Origin gpgme_origin_to_pp_origin (const unsigned int origin) +{ + switch (origin) { + case GPGME_KEYORG_KS: + return Key::OriginKS; + case GPGME_KEYORG_DANE: + return Key::OriginDane; + case GPGME_KEYORG_WKD: + return Key::OriginWKD; + case GPGME_KEYORG_URL: + return Key::OriginURL; + case GPGME_KEYORG_FILE: + return Key::OriginFile; + case GPGME_KEYORG_SELF: + return Key::OriginSelf; + case GPGME_KEYORG_OTHER: + return Key::OriginOther; + case GPGME_KEYORG_UNKNOWN: + default: + return Key::OriginUnknown; + } +} + +Key::Origin UserID::origin() const +{ + if (isNull()) { + return Key::OriginUnknown; + } + return gpgme_origin_to_pp_origin(uid->origin); +} + +time_t UserID::lastUpdate() const +{ + return static_cast(uid ? uid->last_update : 0); +} + Error Key::addUid(const char *uid) { if (isNull()) { @@ -986,25 +1022,7 @@ Key::Origin Key::origin() const if (isNull()) { return OriginUnknown; } - switch (key->origin) { - case GPGME_KEYORG_KS: - return OriginKS; - case GPGME_KEYORG_DANE: - return OriginDane; - case GPGME_KEYORG_WKD: - return OriginWKD; - case GPGME_KEYORG_URL: - return OriginURL; - case GPGME_KEYORG_FILE: - return OriginFile; - case GPGME_KEYORG_SELF: - return OriginSelf; - case GPGME_KEYORG_OTHER: - return OriginOther; - case GPGME_KEYORG_UNKNOWN: - default: - return OriginUnknown; - } + return gpgme_origin_to_pp_origin(key->origin); } time_t Key::lastUpdate() const diff --git a/lang/cpp/src/key.h b/lang/cpp/src/key.h index 07ddc256..76a0d4f4 100644 --- a/lang/cpp/src/key.h +++ b/lang/cpp/src/key.h @@ -392,6 +392,16 @@ public: * * @returns an error on error.*/ Error revoke(); + + /*! Get the origin of the key. + * + * @returns the Origin. */ + Key::Origin origin() const; + + /*! Get the last update time. + * + * @returns the last update time. */ + time_t lastUpdate() const; private: shared_gpgme_key_t key; gpgme_user_id_t uid; -- cgit v1.2.3