Create key and assign group before starting to parse.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@24694 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2009-02-14 20:12:23 +00:00
parent 5585a2b58b
commit adba9c066a

View File

@@ -1321,20 +1321,33 @@ pk_rd_pa_reply_dh(krb5_context context,
} else { } else {
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
const EC_GROUP *group; const EC_GROUP *group;
EC_KEY *public; EC_KEY *public = NULL;
public = o2i_ECPublicKey(NULL, &p, size); group = EC_KEY_get0_group(ctx->u.eckey);
public = EC_KEY_new();
if (public == NULL) { if (public == NULL) {
ret = ENOMEM;
goto out;
}
if (EC_KEY_set_group(public, group) != 1) {
EC_KEY_free(public);
ret = ENOMEM;
goto out;
}
if (o2i_ECPublicKey(&public, &p, size) == NULL) {
EC_KEY_free(public);
ret = KRB5KRB_ERR_GENERIC; ret = KRB5KRB_ERR_GENERIC;
krb5_set_error_message(context, ret, krb5_set_error_message(context, ret,
N_("PKINIT: Can't parse ECDH public key", "")); N_("PKINIT: Can't parse ECDH public key", ""));
goto out; goto out;
} }
group = EC_KEY_get0_group(ctx->u.eckey);
size = (EC_GROUP_get_degree(group) + 7) / 8; size = (EC_GROUP_get_degree(group) + 7) / 8;
dh_gen_key = malloc(size); dh_gen_key = malloc(size);
if (dh_gen_key == NULL) { if (dh_gen_key == NULL) {
EC_KEY_free(public);
ret = ENOMEM; ret = ENOMEM;
krb5_set_error_message(context, ret, krb5_set_error_message(context, ret,
N_("malloc: out of memory", "")); N_("malloc: out of memory", ""));
@@ -1342,13 +1355,13 @@ pk_rd_pa_reply_dh(krb5_context context,
} }
dh_gen_keylen = ECDH_compute_key(dh_gen_key, size, dh_gen_keylen = ECDH_compute_key(dh_gen_key, size,
EC_KEY_get0_public_key(public), ctx->u.eckey, NULL); EC_KEY_get0_public_key(public), ctx->u.eckey, NULL);
EC_KEY_free(public);
if (dh_gen_keylen == -1) { if (dh_gen_keylen == -1) {
ret = KRB5KRB_ERR_GENERIC; ret = KRB5KRB_ERR_GENERIC;
krb5_set_error_message(context, ret, krb5_set_error_message(context, ret,
N_("PKINIT: Can't compute ECDH public key", "")); N_("PKINIT: Can't compute ECDH public key", ""));
goto out; goto out;
} }
#else #else
ret = EINVAL; ret = EINVAL;
#endif #endif