diff options
author | Werner Koch <[email protected]> | 2011-03-02 14:35:10 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2011-03-02 14:35:10 +0000 |
commit | 1c09def22d97de3738a2bec4970504bfc155680b (patch) | |
tree | 44fbc5d154ca96be68fb8e43c6695c8dba9580d5 /g10/call-agent.c | |
parent | Add comment to last patch. (diff) | |
download | gnupg-1c09def22d97de3738a2bec4970504bfc155680b.tar.gz gnupg-1c09def22d97de3738a2bec4970504bfc155680b.zip |
Fix usage of SHA-2 algorithm with OpenPGP cards.
This was a regression in 2.1 introduced due to having the agent do the
signing in contrast to the old "SCD PKSIGN" command which accesses the
scdaemon directly and passed the hash algorithm. The hash algorithm
is used by app-openpgp.c only for a sanity check.
Diffstat (limited to 'g10/call-agent.c')
-rw-r--r-- | g10/call-agent.c | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/g10/call-agent.c b/g10/call-agent.c index 6333586fb..03ea1685f 100644 --- a/g10/call-agent.c +++ b/g10/call-agent.c @@ -914,144 +914,6 @@ membuf_data_cb (void *opaque, const void *buffer, size_t length) } -/* Helper returning a command option to describe the used hash - algorithm. See scd/command.c:cmd_pksign. */ -static const char * -hash_algo_option (int algo) -{ - switch (algo) - { - case GCRY_MD_RMD160: return "--hash=rmd160"; - case GCRY_MD_SHA1 : return "--hash=sha1"; - case GCRY_MD_SHA224: return "--hash=sha224"; - case GCRY_MD_SHA256: return "--hash=sha256"; - case GCRY_MD_SHA384: return "--hash=sha384"; - case GCRY_MD_SHA512: return "--hash=sha512"; - case GCRY_MD_MD5 : return "--hash=md5"; - default: return ""; - } -} - - -/* Send a sign command to the scdaemon via gpg-agent's pass thru - mechanism. */ -int -agent_scd_pksign (const char *serialno, int hashalgo, - const unsigned char *indata, size_t indatalen, - unsigned char **r_buf, size_t *r_buflen) -{ - int rc; - char line[ASSUAN_LINELENGTH]; - membuf_t data; - size_t len; - - /* Note, hashalgo is not yet used but hardwired to SHA1 in SCdaemon. */ - - *r_buf = NULL; - *r_buflen = 0; - - rc = start_agent (NULL, 1); - if (gpg_err_code (rc) == GPG_ERR_CARD_NOT_PRESENT - || gpg_err_code (rc) == GPG_ERR_NOT_SUPPORTED) - rc = 0; /* We check later. */ - if (rc) - return rc; - - if (indatalen*2 + 50 > DIM(line)) - return gpg_error (GPG_ERR_GENERAL); - - rc = select_openpgp (serialno); - if (rc) - return rc; - - strcpy (line, "SCD SETDATA "); - bin2hex (indata, indatalen, line + strlen (line)); - - rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); - if (rc) - return rc; - - init_membuf (&data, 1024); - /* if (!hashalgo) /\* Temporary test hack. *\/ */ - /* snprintf (line, DIM(line)-1, "SCD PKAUTH %s", serialno); */ - /* else */ - snprintf (line, DIM(line)-1, "SCD PKSIGN %s %s", - hash_algo_option (hashalgo), serialno); - line[DIM(line)-1] = 0; - rc = assuan_transact (agent_ctx, line, membuf_data_cb, &data, - default_inq_cb, NULL, NULL, NULL); - if (rc) - { - xfree (get_membuf (&data, &len)); - } - else - *r_buf = get_membuf (&data, r_buflen); - - status_sc_op_failure (rc); - return rc; -} - - -/* Decrypt INDATA of length INDATALEN using the card identified by - SERIALNO. Return the plaintext in a nwly allocated buffer stored - at the address of R_BUF. - - Note, we currently support only RSA or more exactly algorithms - taking one input data element. */ -int -agent_scd_pkdecrypt (const char *serialno, - const unsigned char *indata, size_t indatalen, - unsigned char **r_buf, size_t *r_buflen) -{ - int rc; - char line[ASSUAN_LINELENGTH]; - membuf_t data; - size_t len; - - *r_buf = NULL; - rc = start_agent (NULL, 1); - if (gpg_err_code (rc) == GPG_ERR_CARD_NOT_PRESENT - || gpg_err_code (rc) == GPG_ERR_NOT_SUPPORTED) - rc = 0; /* We check later. */ - if (rc) - return rc; - - /* FIXME: use secure memory where appropriate */ - if (indatalen*2 + 50 > DIM(line)) - return gpg_error (GPG_ERR_GENERAL); - - rc = select_openpgp (serialno); - if (rc) - return rc; - - strcpy (line, "SCD SETDATA "); - bin2hex (indata, indatalen, line + strlen (line)); - - rc = assuan_transact (agent_ctx, line, NULL, NULL, NULL, NULL, NULL, NULL); - if (rc) - return rc; - - init_membuf (&data, 1024); - snprintf (line, DIM(line)-1, "SCD PKDECRYPT %s", serialno); - line[DIM(line)-1] = 0; - rc = assuan_transact (agent_ctx, line, - membuf_data_cb, &data, - default_inq_cb, NULL, NULL, NULL); - if (rc) - { - xfree (get_membuf (&data, &len)); - } - else - { - *r_buf = get_membuf (&data, r_buflen); - if (!*r_buf) - rc = gpg_error (GPG_ERR_ENOMEM); - } - - status_sc_op_failure (rc); - return rc; -} - /* Send a READCERT command to the SCdaemon. */ |