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:
parent
d1af7b781c
commit
e249f51c64
@ -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);
|
gcry_sexp_t *r_curve, gcry_sexp_t *r_flags);
|
||||||
|
|
||||||
/*-- sexp-secret.c --*/
|
/*-- 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,
|
gpg_error_t sexp_sscan_private_key (gcry_sexp_t *result, size_t *r_erroff,
|
||||||
unsigned char *buf);
|
unsigned char *buf);
|
||||||
|
|
||||||
|
@ -968,7 +968,7 @@ agent_key_from_file (ctrl_t ctrl, const char *cache_nonce,
|
|||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
unsigned char *buf;
|
unsigned char *buf;
|
||||||
size_t len, buflen, erroff;
|
size_t len, erroff;
|
||||||
gcry_sexp_t s_skey;
|
gcry_sexp_t s_skey;
|
||||||
nvc_t keymeta = NULL;
|
nvc_t keymeta = NULL;
|
||||||
char *desc_text_buffer = NULL; /* Used in case we extend DESC_TEXT. */
|
char *desc_text_buffer = NULL; /* Used in case we extend DESC_TEXT. */
|
||||||
|
@ -372,7 +372,7 @@ read_and_protect (const char *fname)
|
|||||||
static void
|
static void
|
||||||
read_and_unprotect (ctrl_t ctrl, const char *fname)
|
read_and_unprotect (ctrl_t ctrl, const char *fname)
|
||||||
{
|
{
|
||||||
int rc;
|
gpg_error_t err;
|
||||||
unsigned char *key;
|
unsigned char *key;
|
||||||
unsigned char *result;
|
unsigned char *result;
|
||||||
size_t resultlen;
|
size_t resultlen;
|
||||||
@ -383,15 +383,15 @@ read_and_unprotect (ctrl_t ctrl, const char *fname)
|
|||||||
if (!key)
|
if (!key)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rc = agent_unprotect (ctrl, key, (pw=get_passphrase (1)),
|
err = agent_unprotect (ctrl, key, (pw=get_passphrase (1)),
|
||||||
protected_at, &result, &resultlen);
|
protected_at, &result, &resultlen);
|
||||||
release_passphrase (pw);
|
release_passphrase (pw);
|
||||||
xfree (key);
|
xfree (key);
|
||||||
if (rc)
|
if (err)
|
||||||
{
|
{
|
||||||
if (opt_status_msg)
|
if (opt_status_msg)
|
||||||
log_info ("[PROTECT-TOOL:] bad-passphrase\n");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (opt.verbose)
|
if (opt.verbose)
|
||||||
@ -404,7 +404,12 @@ read_and_unprotect (ctrl_t ctrl, const char *fname)
|
|||||||
log_info ("key protection done at [unknown]\n");
|
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)
|
if (opt_armor)
|
||||||
{
|
{
|
||||||
char *p = make_advanced (result, resultlen);
|
char *p = make_advanced (result, resultlen);
|
||||||
|
@ -22,13 +22,15 @@
|
|||||||
#include "../common/sexp-parse.h"
|
#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
|
gpg_error_t
|
||||||
fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
|
fixup_when_ecc_private_key (unsigned char *buf, size_t *buflen_p)
|
||||||
{
|
{
|
||||||
const unsigned char *s;
|
const unsigned char *s;
|
||||||
size_t n;
|
size_t n;
|
||||||
|
size_t buflen = *buflen_p;
|
||||||
|
|
||||||
s = buf;
|
s = buf;
|
||||||
if (*s != '(')
|
if (*s != '(')
|
||||||
@ -44,7 +46,7 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
|
|||||||
s++;
|
s++;
|
||||||
n = snext (&s);
|
n = snext (&s);
|
||||||
if (!smatch (&s, n, "ecc"))
|
if (!smatch (&s, n, "ecc"))
|
||||||
return buflen;
|
return 0;
|
||||||
|
|
||||||
/* It's ECC */
|
/* It's ECC */
|
||||||
while (*s == '(')
|
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);
|
memset (s0+numsize+buflen - (s - buf), 0, (n0 - numsize) + 1);
|
||||||
buflen -= (n0 - numsize);
|
buflen -= (n0 - numsize);
|
||||||
s = s0+numsize+n;
|
s = s0+numsize+n;
|
||||||
|
*buflen_p = buflen;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
s += n;
|
s += n;
|
||||||
@ -99,7 +102,7 @@ fixup_when_ecc_private_key (unsigned char *buf, size_t buflen)
|
|||||||
return gpg_error (GPG_ERR_INV_SEXP);
|
return gpg_error (GPG_ERR_INV_SEXP);
|
||||||
s++;
|
s++;
|
||||||
|
|
||||||
return buflen;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gpg_error_t
|
gpg_error_t
|
||||||
@ -107,12 +110,13 @@ sexp_sscan_private_key (gcry_sexp_t *result, size_t *r_erroff,
|
|||||||
unsigned char *buf)
|
unsigned char *buf)
|
||||||
{
|
{
|
||||||
gpg_error_t err;
|
gpg_error_t err;
|
||||||
size_t buflen, buflen1;
|
size_t buflen, buflen0;
|
||||||
|
|
||||||
buflen = gcry_sexp_canon_len (buf, 0, NULL, NULL);
|
buflen = buflen0 = gcry_sexp_canon_len (buf, 0, NULL, NULL);
|
||||||
buflen1 = fixup_when_ecc_private_key (buf, buflen);
|
err = fixup_when_ecc_private_key (buf, &buflen);
|
||||||
err = gcry_sexp_sscan (result, r_erroff, (char*)buf, buflen1);
|
if (!err)
|
||||||
wipememory (buf, buflen);
|
err = gcry_sexp_sscan (result, r_erroff, (char*)buf, buflen0);
|
||||||
|
wipememory (buf, buflen0);
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user