Commit Graph

647 Commits

Author SHA1 Message Date
Ben McGinnes
8a6a73b9c4 Python bindings constants: PEP8 compliance (almost)
* PEP8 compliance for all constants except the globals in
  src/constants/__init__.py depending on whether the import sequence
  affects the globals themselves.
2018-08-18 15:36:23 +10:00
Ben McGinnes
7962cde13c Python bindings src: PEP8 compliance
* import namespace clearance for src/*.py.
* Fixed a handful of is/is not None checks as well.
2018-08-18 15:05:34 +10:00
Ben McGinnes
279cac0ffb Symmetric example
* lang/python/examples/howto/symcrypt-file.py: *sigh*; passphrase was
  right the first time, just the error check that wasn't.
* I really should stop second guessing myself one of these days ...

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-08-14 02:55:56 +10:00
Ben McGinnes
a256d84882 Symmetric encryption example
* lang/python/examples/howto/symcrypt-file.py: Fixed the error code
  and the passphrase key word arg.
2018-08-14 02:48:38 +10:00
Ben McGinnes
ed5ef8293c Symmetric encryption example.
* lang/python/examples/howto/symcrypt-file.py: A variation on standard
  key based encryption.
2018-08-14 02:22:36 +10:00
Ben McGinnes
94bf13e78e PEP8 compliance and other code fixes
* Ran all the .py files in src/ and below through Yapf.
* Included some manual edits of core.py, this time successfully making
  two notorious sections a bit more pythonic than scheming.
* Left the module imports as is.
* This will be committed if it passes the most essential test:
  compiling, installing and running it.

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-08-10 11:25:01 +10:00
Ben McGinnes
b6d2a66b41 Link fixes
* lang/python/README: Fixed links in both versions of the README.
2018-08-10 03:42:15 +10:00
Andre Heinecke
3b78244360
cpp: Fix use after free in gencardkeyinteractor
* lang/cpp/src/gpggencardkeyinteractor.cpp
(GpgGenCardKeyInteractor::Private::keysize): Change to string.

--
The value is only required as string so we can save it this
way to avoid the need to convert it for the action command.

GnuPG-Bug-Id: T4094
2018-08-08 09:22:46 +02:00
Andre Heinecke
d09d19fa9f
Make GNUPGHOME for tests overridable
* lang/python/tests/Makefile.am,
lang/qt/tests/Makefile.am,
tests/Makefile.am,
tests/gpg/Makefile.am,
tests/gpgsm/Makefile.am,
tests/opassuan/Makefile.am (GNUPGHOME): Make variable explict.

--
If the build directory has too long path, gpgme could fail.
This is similar to

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=847206

In order to fix that, this patch extracts the GNUPGHOME variable
to be presented directly in the Makefile and thus overridable by
command line option.

A build system can then create a symlink to the GNUPGHOME directory
in /tmp and use that symlink as the GNUPGHOME directory
thus making the path very short.

GnuPG-Bug-Id: T4091

Patch provided by vlmarek
2018-08-06 09:30:47 +02:00
Andre Heinecke
a6e5c8bf18
cpp: Add safety checks for key update
* lang/cpp/src/key.cpp (Key::update): Check that the key is
not NULL.
* lang/cpp/src/verificationresult.cpp (GpgME::Signature::key):
Check for fingerprint.
2018-07-24 08:40:28 +02:00
Ben McGinnes
4d1642b11e docs: python bindings howto
* Fixed and tested the changes necessary for org-mode to correctly
  parse pythonic (Python 3) indentation.
* Updated the source blocks to recommended upper case for BEGIN_SRC
  and END_SRC.
* Tested and confirmed XHTML output matches correct examples.
* Tested against pseudo-control output via exporting from org-mode to
  org-mode and then exporting that to XHTML.  Remaining differences
  appear to be discarding the custom tags used to provide X[HT]ML id
  elements to each section which does not appear to offer any benefit.
* Exporting directly to XHTML or other HTML output should no longer
  cause problems, but if there are any then the first step should be
  exporting from org-to-org and then exporting that to XHTML.

Tested-by: Ben McGinnes <ben@adversary.org>
Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-07-23 01:35:12 +10:00
Ben McGinnes
d7c5366d58 doc: python bindings howto
* Another retrofitting of the HOWTO Python example code, this time
  following adjustments to python-mode configuration and having
  trawled through the org-mode mailing lists for clues.
2018-07-23 01:35:12 +10:00
Ben McGinnes
b47e1bb98a doc: python bindings howto
* Added org-mode byline.
2018-07-23 01:35:12 +10:00
Andre Heinecke
8168dfbeb1
cpp: Print origin and last update for key/uid
* lang/cpp/src/key.cpp: Print origin and last update in
iostream operators.
2018-07-19 12:58:49 +02:00
Andre Heinecke
16462c54b3
qt: Handle encoding for diagnostics
* lang/qt/src/threadedjobmixin.cpp (fromEncoding)
(stringFromGpgOutput): New helpers.
(markupDiagnostics): Use it.

--
The Problem is that on my western windows system GnuPG
gets CP 437 as GetConsoleOutputCP and prints in that codepage.
In a W32 GUI Application we get 0 as GetConsoleOutputCP and 1252
with GetACP.

The only thing that seemed to somehow match was GetOEMCP but
that might just be luck and it might still be broken in
other windows languages.

This code is also used in Kleopatra so it might make sense
to make it public once it is demonstrated that it works on
most systems.
2018-07-18 11:27:46 +02:00
Ben McGinnes
1bb3f8409d python bindings: example scripts
* Fixed incorrect mention of output prompt referencing secret keys
  when the scripts are only for exporting public keys in whole or
  minimised forms.
2018-07-13 20:36:27 +10:00
Ben McGinnes
0e760e396f example scripts: python work-arounds
* fixed three typos which were guaranteed to break said script.
2018-07-10 13:40:18 +10:00
Ben McGinnes
1eceacaff4 docs: python bindings howto
* Complete typographic overhaul.
* Removed all section level indentation since it does not affect
  output formatting, but might affect source code examples.
* In text-mode stripped out all tabs which had crept in and replaced
  them with four spaces.
* Updated all code examples (again) to conform with Python-mode.
* Bumped version number in preparation for next release of GPG 2.2.9
  and corresponding GPGME release.
2018-07-09 21:30:20 +10:00
Ben McGinnes
cacca62d06 python bindings: howto examples
* Made sure all example scripts meet PEP8 compliance.
* Required fixing approx. a dozen of them in minor ways.
2018-07-08 03:40:35 +10:00
Andre Heinecke
66c2a99422
qt: Handle OpenPGP Diagnostic log
* lang/qt/src/threadedjobmixin.cpp (_detail::audit_log_as_html):
Handle OpenPGP audit log differently.
2018-07-05 11:29:36 +02:00
Andre Heinecke
629afebe50
cpp: Add enum mapping for GPGME_AUDIT_LOG_DIAG
* src/context.cpp (to_auditlog_flags): Map DIAG value.
* src/context.h (AuditLogFlags): Add it.
2018-07-05 11:29:36 +02:00
Andre Heinecke
7d65dc2a5c
cpp: Fix memory of DecryptionResult::symkeyAlgo
* lang/cpp/src/decryptionresult.cpp (Private, ~Private): strdup
the symkey algo.
2018-07-04 12:17:43 +02:00
Ben McGinnes
5bca499750 python bindings: scheming serpents
* Apparently I am wrong and Scheme is the new Python after all.
* Non-import related PEP8 compliance must wait for another day, though
  the other PEP8 fixes remain.
2018-07-02 05:05:09 +10:00
Ben McGinnes
789ea1b019 python bindings: gpg.core
* Changed id/else statements to a more pythonic form from scheme
  masquerading as python - sorry Justus, it had to go ;).
* With the added bonus of enabling PEP8 compliance in those sections.
* Fixed remaining PEP8 compliance issues with the exception of the
  imports at the beginning of the file (changing those will break the
  entire module, so we'll cope with it as it is).
2018-07-02 03:55:19 +10:00
Ben McGinnes
43a2b57545 python bindings: python 3.7
* Bindings confirmed to work with the newly released 3.7.0.
* Updated M4 file to reflect this change and correct the Python binary
  search order (3.7 is not yet given priority, but will still be found
  first via the more generic python3 executable).
* Updated setup.py.in, bindings documentation and README to reflect this.
2018-06-29 14:26:30 +10:00
Ben McGinnes
48174b2bcc whitespace police:
* There's always one or, in this case, two.
2018-06-28 18:51:47 +10:00
Ben McGinnes
6aec7d6e4a docs: python bindings howto
* Updated official doc (the org-mode file) with the instructions on
  importing and exporting both public and secret keys.
2018-06-28 18:51:47 +10:00
Ben McGinnes
a7ccdc51ef python bindings examples
* Added a secret key export variant which saves output as both GPG
  binary and ASCII armoured, plus saves in $GNUPGHOME and uses
  multiple methods of determining what that location is.
2018-06-28 18:51:47 +10:00
Ben McGinnes
7fc7e80e54 python bindings examples
* Added a key import variant which accesses the SKS keyservers in a
  RESTful fashion and then imports or attempts to import the response.
2018-06-28 18:51:47 +10:00
Ben McGinnes
0d163a7d12 python bindings examples: three export scripts
* Example of default exporting keys.
* Example of exporting minimised keys.
* Example of exporting secret keys to a file with correct permissions.

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-06-28 18:51:47 +10:00
Ben McGinnes
4251cae34d python bindings: import example
* Added an example script for importing a key from a file (either
  ASCII armoured or not).
2018-06-28 18:51:47 +10:00
Ben McGinnes
a5b91b21f5 python bindings: export secret keys
* The holy grail: a function to export secret keys.
* GPGME will still invoke pinentry and gpg-agent as usual to authorise
  the export.
* Mostly similar to the two previous export functions for public keys
  except that it will return None if the result had a length of zero
  bytes.  Meaning that the difference between the specified pattern
  (if any) not matching available keys and an incorrect passphrase is
  not able to be determined from this function (or the underlying one
  for that matter).

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-06-28 18:51:47 +10:00
Ben McGinnes
7faef33d13 python bindings: export public keys
* Updated key_export and key_export_minimal to return None where a
  pattern matched no keys in a manner simnilar to the possible result
  of key_export_secret.
2018-06-28 18:51:47 +10:00
Ben McGinnes
89c548efdf python bindings: export public keys
* Added functions for exporting public keys to gpg.core in both
  complete form and in minimised form.
* Rather than letting people need to worry about the export modes we
  are simply separating the functions as people would be more familiar
  with from the command line usage anyway.
* Functions added for Context are: ctx.key_export_minimal and
  ctx.key_export as the default or full export.

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-06-28 18:48:05 +10:00
Ben McGinnes
19c5267f86 python bindings: core import statements
* Fixed the bit I broke while fixing the PEP8 compliance issues.
2018-06-17 22:42:43 +10:00
Ben McGinnes
a5b24ae46c python bindings: core — PEP8 compliance
* Fixed most of the PEP8 errors in core.py
* Those remaining may need more than little edits and are a bit
  strange (too clearly the result of a programmer who has spent far
  too much time dealing with Lisp so that for Python it looks
  ... strange).
2018-06-17 15:58:44 +10:00
Ben McGinnes
5a80e75500 python bindings: core - key import
* Wrapped the key import function in the try/exception statements
  needed to catch at least the most likely unsuccessful import attempt
  errors.
* Mostly draws on the file error and no data import statuses for
  errors, with a couple of exceptions.

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-06-17 14:35:20 +10:00
Ben McGinnes
0e762608ef python bindings: core key import
* The foundation of a pythonic key import function authored by Jacob
  Adams.
* A unit testing script for the same function originally authored by
  Tobias Mueller
* Added DCO reference for Jacob Adams to the GPGME AUTHORS file.
* Additional details regarding this patch are available here:
  https://dev.gnupg.org/T4001

Signed-off-by: Ben McGinnes <ben@adversary.org>
2018-06-17 09:28:30 +10:00
Ben McGinnes
92cd060f5e script: groups.py
* Added check for if it is run on a Windows system so that the correct
  binary filename is invoked.
2018-06-11 01:03:58 +10:00
Andre Heinecke
8dff414e17
cpp: Add proper gpgme_op_createkey
* lang/cpp/src/context.cpp, lang/cpp/src/context.h
(Context::createKeyEx): New.

--
The createKeyEx function follows the usual pattern that the
synchronous call returns a result directly while for the
async an extra call is neccessary.
2018-06-08 16:19:47 +02:00
Ben McGinnes
a3a08584d6 examples: python howto
* Uses the groups module to prepare a list of recipients and encrypt
  to those.
* The main version (encrypt-to-group.py) tries to check for invalid
  recipients, but still falls back to always trust for the second
  encryption attempt.
* The gullible version doesn't try pruning the recipient list at all,
  it just tries to encrypt and if it fails, switches straight to
  always trust.
* The trustno1 version doesn't use the always trust model at all and
  only attempts pruning the list of invalid recipients.
2018-06-07 15:06:20 +10:00
Ben McGinnes
897423422b docs: python bindings howto
* Another attempt at fixing the org-mode version.
* A proof reader ascertained there were tabs in it instead of whitespace.
* Stripped the lot out and replaced with standard 4 spaces, fixed
  every incorrect example ... and it still breaks upon save and/or export.
* Added the reference to the mutt-groups.py script to demonstrate the
  groups.py module/code.
2018-06-03 00:46:46 +10:00
Andre Heinecke
00b027af86
cpp: Add gpgme_(get)set_ctx_flag
* NEWS: Mention API extensions.
* lang/cpp/src/context.cpp, lang/cpp/src/context.h
(Context::setFlag, Context::getFlag): New.
2018-06-01 11:10:45 +02:00
Andre Heinecke
d46768c960
cpp: Add legacy_cipher_nomdc
* lang/cpp/src/decryptionresult.cpp, lang/cpp/src/decryptionresult.h
(DecryptionResult::isLegacyCipherNoMDC): New.

--
2018-06-01 10:58:24 +02:00
Andre Heinecke
618aa7f08d
cpp: Add gpgme_data_rewind to cpp API
* lang/cpp/src/data.h, lang/cpp/src/data.cpp (Data::rewind): New.
* lang/qt/tests/t-various.cpp (testDataRewind): Test it.

--
The advantage of this convieniance function in GPGME is that
it avoids the messiness that are declarations with off_t.

GnuPG-Bug-Id: T3996
2018-05-29 09:19:50 +02:00
Ben McGinnes
321005c12f examples: mutt crypt-hooks generator
* Added a script which demonstrates how the groups module works.
* Script generates Mutt/Neomutt crypt-hooks for every group entry in
  gpg.conf, including those entries for multiple keys (Mutt handles
  that differently).
2018-05-25 07:12:52 +10:00
Ben McGinnes
48e946a96d docs: python bindings howto
* Fixed the groups.py script so it really does what is described (the
  old code had the same result for groups, group_lines and
  group_lists).
* Updated the corresponding example in the doc to match.
2018-05-25 05:50:11 +10:00
Ben McGinnes
9038d30017 doc: python bindings howto
* Fixed org-mode python source indenting.
** Note: nested indented blocks do not indent correctly when exported
   to [X]HTML.
2018-05-25 05:50:11 +10:00
Ben McGinnes
3a9e6a8e08 docs and examples: python howto
* Updated the decryption example code in the HOWTO and the
  corresponding decrypt-file.py script to gracefully handle a
  decryption failure.  This error will always be triggered when GPGME
  is used to try to decrypt an old, MDC-less encrypted message or
  file.
2018-05-23 14:43:06 +10:00
Andre Heinecke
28e3778ce2
cpp: Expose sessionKey and symkeyAlgo
* lang/cpp/decryptionresult.cpp, lang/cpp/decryptionresult.h
(DecryptionResult::symkeyAlgo, DecryptionResult::sessionKey): New.
2018-05-22 12:08:01 +02:00