diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2016-08-08 11:46:44 +0200 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2016-08-08 11:55:53 +0200 |
commit | 591a8373a5d9567db9b1a1a48205e8a206c7b669 (patch) | |
tree | 92a30bd5c7ee410c6a146935343a70974217182f /common/sexputil.c | |
parent | tests: Add openpgp/gpgv-forged-keyring.scm. (diff) | |
download | gnupg2-591a8373a5d9567db9b1a1a48205e8a206c7b669.tar.xz gnupg2-591a8373a5d9567db9b1a1a48205e8a206c7b669.zip |
agent: More clean up of SSH support.
* common/util.h (get_pk_algo_from_key): New.
* common/sexputil.c (get_pk_algo_from_key): The implementation.
* agent/gpg-agent.c: Remove include of openpgpdefs.h.
* agent/command-ssh.c (struct ssh_key_type_spec): Use integer ALGO.
(ssh_key_types): Update with GCRY_PK_*.
(make_cstring, sexp_extract_identifier): Remove.
(sexp_key_construct): Use gcry_pk_algo_name to get ALGO string.
(ssh_key_to_blob): Use cadr to get value list.
(ssh_key_type_lookup): Lookup with integer ALGO.
(ssh_receive_key): Follow the change of ssh_key_type_lookup.
(ssh_send_key_public): Likewise. Use get_pk_algo_from_key to get ALGO.
--
This fixes the regresson introduced by the commit
894789c3299dc47a8c1ccaaa7070382f0fae0262.
Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'common/sexputil.c')
-rw-r--r-- | common/sexputil.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/common/sexputil.c b/common/sexputil.c index a63fc20ce..50635462e 100644 --- a/common/sexputil.c +++ b/common/sexputil.c @@ -45,6 +45,7 @@ #include "util.h" #include "tlv.h" #include "sexp-parse.h" +#include "openpgpdefs.h" /* for pubkey_algo_t */ /* Return a malloced string with the S-expression CANON in advanced @@ -556,3 +557,52 @@ get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen, return 0; } + + +/* Return the algo of a public KEY of SEXP. */ +int +get_pk_algo_from_key (gcry_sexp_t key) +{ + gcry_sexp_t list; + const char *s; + size_t n; + char algoname[6]; + int algo = 0; + + list = gcry_sexp_nth (key, 1); + if (!list) + goto out; + s = gcry_sexp_nth_data (list, 0, &n); + if (!s) + goto out; + if (n >= sizeof (algoname)) + goto out; + memcpy (algoname, s, n); + algoname[n] = 0; + + algo = gcry_pk_map_name (algoname); + if (algo == GCRY_PK_ECC) + { + gcry_sexp_t l1 = gcry_sexp_find_token (list, "flags", 0); + int i; + + for (i = l1 ? gcry_sexp_length (l1)-1 : 0; i > 0; i--) + { + s = gcry_sexp_nth_data (l1, i, &n); + if (!s) + continue; /* Not a data element. */ + + if (n == 5 && !memcmp (s, "eddsa", 5)) + { + algo = GCRY_PK_EDDSA; + break; + } + } + gcry_sexp_release (l1); + } + + out: + gcry_sexp_release (list); + + return algo; +} |