json: Add information about revocation keys to key list result

* 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
This commit is contained in:
Ingo Klöcker 2024-05-15 10:39:26 +02:00
parent adadfac997
commit f2575b6313
No known key found for this signature in database
GPG Key ID: F5A5D1692277A1E9
6 changed files with 155 additions and 1 deletions

View File

@ -1024,6 +1024,24 @@ subkey_to_json (gpgme_subkey_t sub)
return result;
}
/* Create a revocation key json object */
static cjson_t
revocation_key_to_json (gpgme_revocation_key_t revkey)
{
cjson_t result = xjson_CreateObject ();
xjson_AddBoolToObject (result, "sensitive", revkey->sensitive);
xjson_AddStringToObject0 (result, "fingerprint", revkey->fpr);
xjson_AddStringToObject0 (result, "pubkey_algo_name",
gpgme_pubkey_algo_name (revkey->pubkey_algo));
xjson_AddNumberToObject (result, "pubkey_algo", revkey->pubkey_algo);
xjson_AddNumberToObject (result, "key_class", revkey->key_class);
return result;
}
/* Create a key json object */
static cjson_t
key_to_json (gpgme_key_t key)
@ -1075,6 +1093,16 @@ key_to_json (gpgme_key_t key)
xjson_AddItemToObject (result, "userids", uid_array);
}
/* Revocation keys */
if (key->revocation_keys)
{
gpgme_revocation_key_t revkey;
cjson_t array = xjson_CreateArray ();
for (revkey = key->revocation_keys; revkey; revkey = revkey->next)
cJSON_AddItemToArray (array, revocation_key_to_json (revkey));
xjson_AddItemToObject (result, "revocation_keys", array);
}
return result;
}

View File

@ -88,9 +88,13 @@ gpg-sample.stamp: $(private_keys)
done
echo x > ./gpg-sample.stamp
pubring-stamp: $(top_srcdir)/tests/gpg/pubdemo.asc gpg-sample.stamp
pubring-stamp: $(top_srcdir)/tests/gpg/pubdemo.asc \
$(top_srcdir)/tests/json/key-with-revokers.asc \
gpg-sample.stamp
$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(top_srcdir)/tests/gpg/pubdemo.asc
$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(top_srcdir)/tests/json/key-with-revokers.asc
-$(TESTS_ENVIRONMENT) $(GPG) --batch --no-permission-warning \
--import $(top_srcdir)/tests/gpg/secdemo.asc
-$(TESTS_ENVIRONMENT) gpgconf --kill all

View File

@ -0,0 +1,19 @@
-----BEGIN PGP PUBLIC KEY BLOCK-----
mDMEZkTFQxYJKwYBBAHaRw8BAQdATFay6x2u19PsF5P7YDj2WW9KproKIqAMAqHR
cnkiebiIkAQfFgoAOBYhBMlchkt3X3HQL1LO9r0HuCiy91BxBQJmRMVDFwzAEaD/
RZC7YSLt7248VC1yfMdoaXc0AgcAAAoJEL0HuCiy91BxhCMBAKtymj/0Q/XDKO3c
9mlz5ycll8MfT/a6H2WFWGV6L9SEAPwN3/n4qR9bBiReT9Xo3q58e2efoXoFXz86
BXv1rCYJAYiQBB8WCgA4FiEEyVyGS3dfcdAvUs72vQe4KLL3UHEFAmZExUMXDIAR
I/00ekGUKbrM1ecta8R3gFSs0kYCBwAACgkQvQe4KLL3UHFlBwEA1JL4yE/sWOKr
BfbHbUI4ffS6s+oh7sQxHEQy0pJN7LoA/RSKUIThOl5apOVhd/dYOPj+4aGZ9ZP1
ARqeXIWYxpwCtB1rZXktd2l0aC1yZXZva2Vyc0BleGFtcGxlLm5ldIiZBBMWCgBB
FiEEyVyGS3dfcdAvUs72vQe4KLL3UHEFAmZExUMCGwMFCQWjmoAFCwkIBwICIgIG
FQoJCAsCBBYCAwECHgcCF4AACgkQvQe4KLL3UHFcjwD/ZpSNHKpGV99sKlxbzABg
msIGKLgcuFLUsT1QCV3yE4cA/iS4NW9Y508uUqoJfFH0lBpJ4+US6VQevVpRNe6N
KqYEuDgEZkTFQxIKKwYBBAGXVQEFAQEHQFDZXf9Y1Y6A00CDcYw8RO73idcn/d7B
ifTuBfYpXVJjAwEIB4h4BBgWCgAgFiEEyVyGS3dfcdAvUs72vQe4KLL3UHEFAmZE
xUMCGwwACgkQvQe4KLL3UHEZrQD/SWYkwCFtqaxbYQUcSJ+v2+wA28RUm7KrgJ+A
PsdiNJsBAIjUUsYlf+J/d4Ia0tccfzPBqVpyeWZ52bBD0pH/Eu8N
=JTll
-----END PGP PUBLIC KEY BLOCK-----

View File

@ -41,6 +41,7 @@ static const char*tests[] = { "t-config", "t-version",
"t-encrypt", "t-encrypt-sign", "t-sign", "t-verify",
"t-decrypt-verify", "t-export", "t-createkey",
"t-export-secret-info", "t-chunking", "t-sig-notations",
"t-keylist-revokers",
/* For these two the order is important
* as t-import imports the deleted key from t-delete */
"t-delete", "t-import",

View File

@ -0,0 +1,5 @@
{
"op": "keylist",
"keys": [ "key-with-revokers@example.net" ],
"with-secret": false
}

View File

@ -0,0 +1,97 @@
{
"keys": [
{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": true,
"can_certify": true,
"can_authenticate": false,
"secret": false,
"is_qualified": false,
"protocol": "OpenPGP",
"fingerprint": "C95C864B775F71D02F52CEF6BD07B828B2F75071",
"owner_trust": "unknown",
"origin": 0,
"last_update": 0,
"subkeys": [
{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": false,
"can_sign": true,
"can_certify": true,
"can_authenticate": false,
"secret": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "EdDSA",
"pubkey_algo_string": "ed25519",
"keyid": "BD07B828B2F75071",
"curve": "ed25519",
"pubkey_algo": 303,
"length": 255,
"timestamp": 1715782979,
"expires": 1810390979
},
{
"revoked": false,
"expired": false,
"disabled": false,
"invalid": false,
"can_encrypt": true,
"can_sign": false,
"can_certify": false,
"can_authenticate": false,
"secret": false,
"is_qualified": false,
"is_cardkey": false,
"is_de_vs": false,
"pubkey_algo_name": "ECDH",
"pubkey_algo_string": "cv25519",
"keyid": "94C2E4C722CADAF9",
"curve": "cv25519",
"pubkey_algo": 302,
"length": 255,
"timestamp": 1715782979,
"expires": 0
}
],
"userids": [
{
"revoked": false,
"invalid": false,
"validity": "unknown",
"uid": "key-with-revokers@example.net",
"name": "",
"email": "key-with-revokers@example.net",
"comment": "",
"address": "key-with-revokers@example.net",
"origin": 0,
"last_update": 0
}
],
"revocation_keys": [
{
"sensitive": true,
"fingerprint": "A0FF4590BB6122EDEF6E3C542D727CC768697734",
"pubkey_algo_name": "DSA",
"pubkey_algo": 17,
"key_class": 192
},
{
"sensitive": false,
"fingerprint": "23FD347A419429BACCD5E72D6BC4778054ACD246",
"pubkey_algo_name": "DSA",
"pubkey_algo": 17,
"key_class": 128
}
]
}
]
}