1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

ecc-sos, agent: More fixes for fixup of ECC private key.

Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
NIIBE Yutaka 2020-06-04 10:48:39 +09:00
parent d1af7b781c
commit e249f51c64
4 changed files with 27 additions and 19 deletions

View File

@ -640,8 +640,7 @@ extract_private_key (gcry_sexp_t s_key, int req_private_key_data,
gcry_sexp_t *r_curve, gcry_sexp_t *r_flags);
/*-- sexp-secret.c --*/
size_t fixup_when_ecc_private_key (unsigned char *buf, size_t buflen);
gpg_error_t fixup_when_ecc_private_key (unsigned char *buf, size_t *buflen_p);
gpg_error_t sexp_sscan_private_key (gcry_sexp_t *result, size_t *r_erroff,
unsigned char *buf);

View File

@ -968,7 +968,7 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
{
gpg_error_t err;
unsigned char *buf;
size_t len, buflen, erroff;
size_t len, erroff;
gcry_sexp_t s_skey;
nvc_t keymeta = NULL;
char *desc_text_buffer = NULL; /* Used in case we extend DESC_TEXT. */

View File

@ -372,7 +372,7 @@ read_and_protect (const char *fname)
static void
read_and_unprotect (ctrl_t ctrl, const char *fname)
{
int rc;
gpg_error_t err;
unsigned char *key;
unsigned char *result;
size_t resultlen;
@ -383,15 +383,15 @@ read_and_unprotect (ctrl_t ctrl, const char *fname)
if (!key)
return;
rc = agent_unprotect (ctrl, key, (pw=get_passphrase (1)),
protected_at, &result, &resultlen);
err = agent_unprotect (ctrl, key, (pw=get_passphrase (1)),
protected_at, &result, &resultlen);
release_passphrase (pw);
xfree (key);
if (rc)
if (err)
{
if (opt_status_msg)
log_info ("[PROTECT-TOOL:] bad-passphrase\n");
log_error ("unprotecting the key failed: %s\n", gpg_strerror (rc));
log_error ("unprotecting the key failed: %s\n", gpg_strerror (err));
return;
}
if (opt.verbose)
@ -404,7 +404,12 @@ read_and_unprotect (ctrl_t ctrl, const char *fname)
log_info ("key protection done at [unknown]\n");
}
resultlen = fixup_when_ecc_private_key (result, resultlen);
err = fixup_when_ecc_private_key (result, &resultlen);
if (err)
{
log_error ("malformed key: %s\n", gpg_strerror (err));
return;
}
if (opt_armor)
{
char *p = make_advanced (result, resultlen);

View File

@ -22,13 +22,15 @@
#include "../common/sexp-parse.h"
/*
* Fixup private key part in the cannonical SEXP.
* When it's for ECC, fixup private key part in the cannonical SEXP
* representation in BUF.
*/
size_t
fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
gpg_error_t
fixup_when_ecc_private_key (unsigned char *buf, size_t *buflen_p)
{
const unsigned char *s;
size_t n;
size_t buflen = *buflen_p;
s = buf;
if (*s != '(')
@ -44,7 +46,7 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
s++;
n = snext (&s);
if (!smatch (&s, n, "ecc"))
return buflen;
return 0;
/* It's ECC */
while (*s == '(')
@ -79,6 +81,7 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
memset (s0+numsize+buflen - (s - buf), 0, (n0 - numsize) + 1);
buflen -= (n0 - numsize);
s = s0+numsize+n;
*buflen_p = buflen;
}
else
s += n;
@ -99,7 +102,7 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
return gpg_error (GPG_ERR_INV_SEXP);
s++;
return buflen;
return 0;
}
gpg_error_t
@ -107,12 +110,13 @@ sexp_sscan_private_key (gcry_sexp_t *result, size_t *r_erroff,
unsigned char *buf)
{
gpg_error_t err;
size_t buflen, buflen1;
size_t buflen, buflen0;
buflen = gcry_sexp_canon_len (buf, 0, NULL, NULL);
buflen1 = fixup_when_ecc_private_key (buf, buflen);
err = gcry_sexp_sscan (result, r_erroff, (char*)buf, buflen1);
wipememory (buf, buflen);
buflen = buflen0 = gcry_sexp_canon_len (buf, 0, NULL, NULL);
err = fixup_when_ecc_private_key (buf, &buflen);
if (!err)
err = gcry_sexp_sscan (result, r_erroff, (char*)buf, buflen0);
wipememory (buf, buflen0);
return err;
}