diff options
author | Werner Koch <wk@gnupg.org> | 2009-07-01 20:30:33 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2009-07-01 20:30:33 +0200 |
commit | 1925cb37f9cad721ff7ca228dab3ba214a14f767 (patch) | |
tree | c7885e9f57ecbeeae49e3c4b45581c5db5e9024e /common | |
parent | Add comment about Cherry. (diff) | |
download | gnupg2-1925cb37f9cad721ff7ca228dab3ba214a14f767.tar.xz gnupg2-1925cb37f9cad721ff7ca228dab3ba214a14f767.zip |
Alow batch ode for gpgsm --gen-key.
Allow CSR generation using an existing key with gpgsm.
Diffstat (limited to 'common')
-rw-r--r-- | common/ChangeLog | 4 | ||||
-rw-r--r-- | common/sexputil.c | 54 | ||||
-rw-r--r-- | common/util.h | 3 |
3 files changed, 53 insertions, 8 deletions
diff --git a/common/ChangeLog b/common/ChangeLog index bd4be4faf..40faa541e 100644 --- a/common/ChangeLog +++ b/common/ChangeLog @@ -1,3 +1,7 @@ +2009-07-01 Werner Koch <wk@g10code.com> + + * sexputil.c (get_pk_algo_from_canon_sexp): New. + 2009-06-29 Werner Koch <wk@g10code.com> * estream.c (BUFFER_ROUND_TO_BLOCK): Remove unused macro. diff --git a/common/sexputil.c b/common/sexputil.c index 73608816d..1e5918723 100644 --- a/common/sexputil.c +++ b/common/sexputil.c @@ -292,14 +292,8 @@ make_canon_sexp_from_rsa_pk (const void *m_arg, size_t mlen, } -/* Return the so called "keygrip" which is the SHA-1 hash of the - public key parameters expressed in a way depended on the algorithm. - - KEY is expected to be an canonical encoded S-expression with a - public or private key. KEYLEN is the length of that buffer. - - GRIP must be at least 20 bytes long. On success 0 is returned, on - error an error code. */ +/* Return the so parameters of a public RSA key expressed as an + canonical encoded S-expression. */ gpg_error_t get_rsa_pk_from_canon_sexp (const unsigned char *keydata, size_t keydatalen, unsigned char const **r_n, size_t *r_nlen, @@ -389,3 +383,47 @@ get_rsa_pk_from_canon_sexp (const unsigned char *keydata, size_t keydatalen, *r_elen = rsa_e_len; return 0; } + + +/* Return the algo of a public RSA expressed as an canonical encoded + S-expression. On error the algo is set to 0. */ +gpg_error_t +get_pk_algo_from_canon_sexp (const unsigned char *keydata, size_t keydatalen, + int *r_algo) +{ + gpg_error_t err; + const unsigned char *buf, *tok; + size_t buflen, toklen; + int depth; + + *r_algo = 0; + + buf = keydata; + buflen = keydatalen; + depth = 0; + if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) + return err; + if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) + return err; + if (!tok || toklen != 10 || memcmp ("public-key", tok, toklen)) + return gpg_error (GPG_ERR_BAD_PUBKEY); + if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) + return err; + if ((err = parse_sexp (&buf, &buflen, &depth, &tok, &toklen))) + return err; + if (!tok) + return gpg_error (GPG_ERR_BAD_PUBKEY); + + if (toklen == 3 && !memcmp ("rsa", tok, toklen)) + *r_algo = GCRY_PK_RSA; + else if (toklen == 3 && !memcmp ("dsa", tok, toklen)) + *r_algo = GCRY_PK_DSA; + else if (toklen == 3 && !memcmp ("elg", tok, toklen)) + *r_algo = GCRY_PK_ELG; + else if (toklen == 5 && !memcmp ("ecdsa", tok, toklen)) + *r_algo = GCRY_PK_ECDSA; + else + return gpg_error (GPG_ERR_PUBKEY_ALGO); + + return 0; +} diff --git a/common/util.h b/common/util.h index 816afff0b..61b26f1de 100644 --- a/common/util.h +++ b/common/util.h @@ -201,6 +201,9 @@ gpg_error_t get_rsa_pk_from_canon_sexp (const unsigned char *keydata, size_t *r_nlen, unsigned char const **r_e, size_t *r_elen); +gpg_error_t get_pk_algo_from_canon_sexp (const unsigned char *keydata, + size_t keydatalen, + int *r_algo); /*-- convert.c --*/ int hex2bin (const char *string, void *buffer, size_t length); |