aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpgme-json.c (unfollow)
Commit message (Collapse)AuthorFilesLines
2025-05-23Refactor gpgme-json for future re-use.Werner Koch1-3402/+25
* src/gpgme-json.c: Factor large chunks of code out to ... * src/json-core.c: new file and ... * src/json-util.c: new file and ... * src/json-common.h: new file. * src/Makefile.am (gpgme_json_SOURCES): Add new files.
2024-05-21json: Add information about revocation keys to key list resultIngo Klöcker1-0/+28
* src/gpgme-json.c (revocation_key_to_json): New. (key_to_json): Add list of revocation keys. * tests/json/Makefile.am (pubring-stamp): Import new pub key. * tests/json/key-with-revokers.asc: New. * tests/json/t-json.c (tests): Add "t-keylist-revokers". * tests/json/t-keylist-revokers.in.json, tests/json/t-keylist-revokers.in.json: New. -- GnuPG-bug-id: 7118
2023-01-31json: New operation "identify" and convenience option --identify.Werner Koch1-1/+126
* src/gpgme-json.c (data_type_to_string): New. (op_identify): New. (process_request): Add to command list. (cmd_identify): New. (main): Add option --identify. --
2022-04-27core: Support --locate-external-keys command of gpgIngo Klöcker1-0/+5
* src/gpgme.h.in (GPGME_KEYLIST_MODE_FORCE_EXTERN): New. (GPGME_KEYLIST_MODE_LOCATE_EXTERNAL): New. * src/gpgme.c (gpgme_set_keylist_mode): Check for invalid mode. * src/engine-gpg.c (gpg_keylist_build_options): Use "--locate-external-keys" instead of "--locate-keys" if flag is set. * src/gpgme-json.c (op_keylist): New flag "force-extern". * src/gpgme-tool.c (gt_get_keylist_mode, cmd_keylist_mode): Handle new mode. -- GnuPG-bug-id: 5951
2020-11-09Require at least libgpg-error 1.36Werner Koch1-24/+0
* configure.ac (NEED_GPG_ERROR_VERSION): Require 1.36. * src/cJSON.c: Remove code for older version. * src/engine.c (gpgme_get_engine_info): Ditto. * src/gpgme-json.c: Ditto. * src/op-support.c: Ditto. * src/util.h: Ditto. -- Libgpg-error 1.36 has been released more than 18 months ago so it is time to avoid hacks and require this verion. This will for example help Kleopatra to support PIV cards and improves the gpgme-json. Signed-off-by: Werner Koch <[email protected]>
2020-07-15core: New keylist mode GPGME_KEYLIST_MODE_WITH_KEYGRIP.Werner Koch1-0/+6
* src/gpgme.h.in (GPGME_KEYLIST_MODE_WITH_KEYGRIP): New. * src/gpgme-json.c (op_keylist): New flag "keygrip". * src/engine-gpg.c (gpg_keylist_build_options): Pass the options. * lang/cpp/src/global.h (WithKeygrip): New. * lang/cpp/src/context.cpp: Add check. * lang/cpp/src/key.cpp (Key::update): Handle WithKeygrip. * lang/cpp/src/verificationresult.cpp: Ditto. * lang/cpp/src/util.h (add_to_gpgme_keylist_mode_t): Ditto. -- GnuPG-bug-id: 4939 Signed-off-by: Werner Koch <[email protected]>
2019-02-28json: Fix cosmetic error in the repl.Werner Koch1-1/+1
* src/gpgme-json.c (native_messaging_repl): Use correct var with sizeof. -- Signed-off-by: Werner Koch <[email protected]>
2019-01-25json: Better use gpgme_freeWerner Koch1-1/+1
* src/gpgme-json.c (subkey_to_json): here -- Avoid Windows ugliness of allowing different CRTs in the same process. Fixes-commit: 7f2423371964263784252cf839269023b6573bd2 Signed-off-by: Werner Koch <[email protected]>
2019-01-25json: Fix minor memory leaks.Werner Koch1-6/+14
* src/gpgme-json.c (interactive_repl): Fix memleak. (subkey_to_json): Ditto (op_config): Delay init of j_comps to avoid a leak on error. -- GnuPG-bug-id: 4341, 4342, 4343 Signed-off-by: Werner Koch <[email protected]>
2018-12-17core: Silence newer compiler warnings.Werner Koch1-1/+1
* configure.ac: Add -Wno-format-truncation and -Wno-sizeof-pointer-div. * src/b64dec.c (_gpgme_b64dec_proc): Add fallthrough annotation. * src/cJSON.c (parse_string): Ditto. * src/gpgme-json.c (main): Ditto. -- gcc 8 enables a couple of new warnings. Some of them are useless for us. In particular: util.h:42:26: warning: division 'sizeof (char *) / sizeof (char)' does not compute the number of array elements [-Wsizeof-pointer-div] #define DIM(v) (sizeof(v)/sizeof((v)[0])) ^ trustlist.c:101:22: note: in expansion of macro 'DIM' if (strlen (p) == DIM(item->keyid) - 1) Which is a real standard way to use DIM, here the right hand side is equivalent to sizeof but nevertheless it is correct. Yes sir, we know C. The format string warnings I have seen were assuming that the time structure returns valued out of scope - but if the system is that broken, the s_n_printf catches this. Signed-off-by: Werner Koch <[email protected]>
2018-11-16Add SPDX identifiers to most source filesWerner Koch1-3/+3
-- Signed-off-by: Werner Koch <[email protected]>
2018-11-08spelling: fix misspellingsDaniel Kahn Gillmor1-6/+6
Signed-off-by: Daniel Kahn Gillmor <[email protected]>
2018-10-18doc: use https:// for www.gnu.orgDaniel Kahn Gillmor1-1/+1
-- Signed-off-by: Daniel Kahn Gillmor <[email protected]>
2018-09-19json: Remove subkey-algo from createkey command.Werner Koch1-82/+7
* src/gpgme-json.c (op_createkey): Remove subkey-algo param. (GPG_AGENT_ALLOWS_KEYGEN_TRHOUGH_BROWSER): Fix typo. * lang/js/src/Keyring.js: Remove subkey-algo support. * lang/js/src/permittedOperations.js: Ditto. -- We do not want to expose details of the protocol's key generation and thus the subkey-algo does not make sense. Right now we support only the default and future-default algorithms. A user can configure them anyway using new-default-key-algo in gpg.conf. Eventually we may officially support a more flexible way of creating special structured OpenPGP keys but right now that is not part of the API. Signed-off-by: Werner Koch <[email protected]>
2018-08-29json: Fix detached verifyAndre Heinecke1-20/+23
* src/gpgme-json.c (op_verify): Only create output and use it for clearsigned and opaque signed. -- Just passing output to gpgme_op_verify changes the behavior to no longer do a verify of the signature.
2018-08-28json: Delete primary key if subkey gen failsAndre Heinecke1-2/+22
* src/gpgme-json.c (op_delete): Delete primary key on subkey gen error. -- This can happen for example if the user cancels the pinentry to unlock the primary key when adding the subkey. To avoid an artifact of a pimary key without an encryption capable subkey we delete the created key and treat the whole operation as failed.
2018-08-28json: Allow NULL request in encode and chunkAndre Heinecke1-2/+1
* src/gpgme-json.c (encode_and_chunk): Don't error on NULL request. -- This fixes the error that is passed when parthing the json object failed and request would be NULL. Instead of the JSON parser error it would otherwise report that encode and chunk failed.
2018-08-27json: Do not put FILE_NAME into the verify result.Werner Koch1-2/+1
* src/gpgme-json.c (verify_result_to_json): Remove "file_name". -- Having the file name in the verify result may lead developers to assume that the file name is covered by the signature. This is not the case and can easily be checked by hex-editing a signed message. We better don't output it at all. The same is true for the is_mime flag but that is anyway only an advisory and I can't see damage from a faulty one. Note that we keep file_name in gpgme's output for ABI stability and because some tools want to display meta information even if they are subject to tampering. This is similar to the non-encrypted subject in mails. Signed-off-by: Werner Koch <[email protected]>
2018-08-23json: Add sender and file name to encryptAndre Heinecke1-0/+21
* src/gpgme-json.c (hlp_encrypt, op_encrypt): Support sender and file_name.
2018-08-21json: Add proper decrypt_result_t handlingAndre Heinecke1-7/+80
* src/gpgme-json.c (recipient_to_json, decrypt_result_to_json): New. (op_decrypt, hlp_decrypt): Update. -- The op_decrypt as one of the first operations did not yet match the current 1 <> 1 mapping of gpgme types to json dictonaries. info and dec_info are bad names but used for compatibility reasons.
2018-08-20json: Add subkey_algo and defaults to createkeyAndre Heinecke1-4/+62
* src/gpgme-json.c (op_createkey, hlp_createkey): Add subkey_algo handling. (hlp_createkey): Fix documentation of expiry. -- Due to the funny quick-gen-key interface generating a key with an explicit algo would result in bad defaults (only an SC key), without a subkey. This adds handling that should probably be in GnuPG proper to fix the semantics of createkey by adding default subkey_algo handling.
2018-08-08json: Only use calloc instead of mallocAndre Heinecke1-6/+15
* src/cJSON.c, src/gpgme-json.c (CALLOC_ONLY): New define to change xmalloc / xtrymalloc to use calloc. -- Some people consider malloc dangerous as it might allow an information leak.
2018-08-08json: Don't error out if chunksize is omittedAndre Heinecke1-4/+1
* src/gpgme-json.c (encode_and_chunk): Don't error out if no chunksize is provided. -- This fixes 82e4b900a96c837392259469a9a5821a95e7a707 which caused every call without chunksize to error out.
2018-07-19json: Don't use strdup but the xtrystrdup wrapper.Werner Koch1-5/+8
* src/gpgme-json.c (create_keylist_patterns): Use CNT as first arg for xcalloc. (process_request): s/strdup/xtrystrdup/. -- calloc takes two arguments so to be able to detect integer overflow. Thus if we switch from malloc to calloc we should utilize that. Signed-off-by: Werner Koch <[email protected]>
2018-07-18json: Fix memleak in native msging replAndre Heinecke1-0/+4
* src/gpgme-json.c (native_messaging_repl): Free request and response after each loop. -- If we only accept once request we should not loop. If we loop we should do it properly.
2018-07-18json: Ensure that native msging request is stringAndre Heinecke1-1/+2
* src/gpgme-json.c (native_messaging_repl): Ensure that the request is NULL terminated. -- This avoids potential memory leaks and access to unmapped memory in case the request was not terminated. Other request functions use es_read_line which gurantees NULL termination.
2018-07-18json: Fix crash by ensuring response is never NULLAndre Heinecke1-7/+43
* src/gpgme-json.c (encode_and_chunk): Try to always return at least an error. (process_request): Double check that it does not return NULL. -- If process_request returns NULL the following strlen on it would crash.
2018-07-18json: Fix memory errors in create_keylist_patternsAndre Heinecke1-5/+4
* src/gpgme-json.c (create_keylist_patterns): Reserve two pointers more then linefeeds. (create_keylist_patterns): Fix loop to count linebreaks. (create_keylist_patterns): Use calloc for good measure. -- This fixes crashes and memory corruption as cnt did not match i.
2018-07-16json: Fix crash on invalid jsonAndre Heinecke1-2/+2
* src/gpgme-json.c (process_request): Init res. Check for json object before encode and chunk. -- If json is invalid we can't read chunksize and would crash in encode and chunk.
2018-07-16json: Fix uninitialized key unref in op_deleteAndre Heinecke1-1/+1
* src/gpgme-json.c (op_delete): Init key.
2018-07-11json: Add with-sec-fprs param to exportAndre Heinecke1-5/+68
* src/gpgme-json.c (add_secret_fprs): New helper. (op_export, hlp_export): Extend for with-sec fprs. -- This is a request from Mailvelope, to import an export they need the information for which keys from the export a secret key is also available. For simplicity it is much preferred to get this information in a single call without the need to do and parse a keylisting additionally in a second native-messaging call. So we make it optional to include that info in the export.
2018-07-09json: Add with-secret without secret onlyAndre Heinecke1-4/+11
* src/gpgme-json.c (op_keylist, hlp_keylist): Add "with-secret" as a flag to do a public keylist with secret information.
2018-07-04json: Add keylist mode locateAndre Heinecke1-0/+6
* src/gpgme-json.c (op_keylist, hlp_keylist): Add locate. -- The same rationale for the KEYLIST_MODE_LOCATE in GPGME also applies here. It makes the API a little less magic.
2018-06-20json: Add file handling for debug outputAndre Heinecke1-2/+16
* src/gpgme-json.c (main): Add possibilty to set log file. -- This is similar to how GPGME_DEBUG works. It takes ; on Windows as seperator and : on linux. Followed by a file name. For Linux it might make sense to use a different seperator to allow setting a socket explicitly. But this is better in line with the current GPGME_DEBUG behavior. The change helps on Windows where we don't have a log socket.
2018-06-08json: Return fingerprint as createkey resultAndre Heinecke1-2/+10
* src/gpgme-json.c (op_createkey): Return fingerprint of new key.
2018-06-08json: Add op_createkeyAndre Heinecke1-0/+86
* src/gpgme-json.c (hlp_createkey, op_createkey): New. (process_request, hlp_help): Add it. -- This uses an unrestricted context for now until GnuPG-Bug-Id: T4010 is implemented in GnuPG.
2018-06-08json: Generalize chunking and getmoreAndre Heinecke1-125/+141
* src/gpgme-json.c (MIN_REPLY_CHUNK_SIZE): Lower value to new real minimum. (DEF_REPLY_CHUNK_SIZE): Don't chunk by default. (pending_data): Remove type and base64. (make_data_object): Remove chunksize handling as this is now generic. (encode_and_chunk): Setup the pending_data buffer for chunking if required. (op_getmore): Changed to generically work on a response. (hlp_getmore): Update accordingly. (hlp_help): Document chunksize as generic parameter for all commands. (process_request): Use encode_and_chunk on the response. (hlp_encrypt, op_encrypt, hlp_decrypt, op_decrypt), (hlp_verify, op_verify, hlp_sign, op_sign), (op_keylist, hlp_keylist, hlp_export, op_export): Update accordingly. -- To include handling for json properties e.g. in a keylist in the chunk mechanism the mechanism is now more general. If the chunksize property is provided the response will always look exactly like a "getmore" response. E.g. e.g.: { "op": "keylist", "chunksize": 64 } Results in: { "more": true, "base64": true, "response": "ewoJImtleXMiOglbewoJCQkicmV2b2tlZCI6" } For simplicity this is even true if the chunksize is larger then the response. The client has to combine all "response" chunks and base64 decode them to get valid json. The complete response (including json) is never larger then the chunksize but might be smaller. Except for interactive use due to additional format characters.
2018-06-07json: Rework verify_result_to_jsonAndre Heinecke1-39/+159
* src/gpgme-json.c (sigsum_to_json): Add bool repr. (signature_to_json, verify_result_to_json): Extend and follow better pattern. (hlp_decrypt, hlp_verify): Expand doc. -- This should make it more clear which values are mapped as the naming is more direct and clear and help to use the gpgme documentation to understand the verify_result values.
2018-06-07json: Add direct way to query a config optionAndre Heinecke1-12/+109
* src/gpgme-json.c (op_config_opt, hlp_config_opt): New operation. (process_request, hlp_help): Add it. -- This is more conveniant API for most query operations where a single option is required. An example would be: { "op": "config_opt", "component": "gpg", "option": "default-key" } Which results in: { "option": { "name": "default-key", "description": "use NAME as default secret key", "argname": "NAME", "flags": 0, "level": 0, "type": 1, "alt_type": 1, "value": [{ "string": "F462B6B1", "is_none": false }] } }
2018-06-07json: Add op_config to query gpgconfAndre Heinecke1-1/+207
* src/gpgme-json.c (op_config, hlp_config): New. (hlp_help, process_request): Add config. (conf_arg_to_json, conf_opt_to_json, conf_comp_to_json): New helpers.
2018-05-28json: Fix compiler warning.Werner Koch1-0/+4
* src/gpgme-json.c (op_version): Mark request as unused. Signed-off-by: Werner Koch <[email protected]>
2018-05-28json: Do not allow to export or delete secret keys.Werner Koch1-7/+11
* src/gpgme-json.c (op_export, op_delete): Return GPG_ERR_FORBIDDEN if "secret" is used. -- This should not be possible from a browser and we need to make this fully clear. Actually gpg-agent won't allow that anyway but having this explicitly is better. If that is ever needed a dedicated command line option may enable this, for example when used by regular programs and not by the browser. But that requires other changes as well. Signed-off-by: Werner Koch <[email protected]>
2018-05-28json: Fix use of get_context.Werner Koch1-11/+48
* src/gpgme-json.c (create_onetime_context): New. (release_onetime_context): New. (op_sign): Use the new fucntions to create a separate context. (op_encrypt): Use a separate context for key listings. (create_keylist_patterns): Remove unneeded cast. -- get_context retruns a static per-process context and can thus not be used as a separate context. Use dedicated fucntions for this. Signed-off-by: Werner Koch <[email protected]>
2018-05-25json: Implement encrypt-signAndre Heinecke1-14/+60
* src/gpgme-json.c (op_encrypt): Add optional signing_keys param. (get_keys, create_keylist_patterns): Add param for json object name. -- If the optional parameter signing_keys is provided to encrypt it becomes an encrypt-sign operation.
2018-05-25json: Implement delete commandAndre Heinecke1-0/+72
* src/gpgme-json.c (op_delete): New. (hlp_help, process_request): Add it. -- As with import / export delete also does not work for the browser origin.
2018-05-25json: Implement op_exportAndre Heinecke1-1/+111
* src/gpgme-json.c (op_export): New. (hlp_getmore, process_request): Add it. -- Secret key export does not work with request-origin browser.
2018-05-25json: Fix double ctx allocAndre Heinecke1-3/+0
* src/gpgme-json.c (op_keylist): Only get one ctx.
2018-05-25json: Add guard in create_keylist_patternsAndre Heinecke1-1/+1
* src/gpgme-json.c (create_keylist_patterns): Guard against a string ending with a linbreak.
2018-05-25json: Implement import operationAndre Heinecke1-1/+126
* src/gpgme-json.c (op_import): New. (import_status_to_json, import_result_to_json): New. (hlp_help, process_request): Add import.
2018-05-25json: Improve keylist helpAndre Heinecke1-2/+3
* src/gpgme-json.c (hlp_keylist): Clarify doc about keys parameter.