]> git.kaiwu.me - haproxy.git/commitdiff
BUG/MINOR: jwe: check that the EC point is on the curve
authorGihyeon Ryu <rlgusryu@gmail.com>
Thu, 26 Nov 2026 14:38:58 +0000 (15:38 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 26 Nov 2026 14:55:47 +0000 (15:55 +0100)
EC_POINT_set_affine_coordinates() returns 0 when the point is not on the
curve, but curve_param_to_pubkey() only treats a negative value as an
error, as do the two tests of the OpenSSL 1.1.1 branch. An off-curve
ECDH-ES "epk" is then rejected later by OpenSSL itself in the tested
version (3.0), so no impact was found, but the check should not rely on
it. The three tests now require a return value of 1.

This may be backported up to 3.4.

src/jwe.c

index 59cd2515ffb6e76ca6c18d9021b390bf415380a6..f5155a0c55da49de720dea5a6e427f4b8dca6c46 100644 (file)
--- a/src/jwe.c
+++ b/src/jwe.c
@@ -1572,7 +1572,8 @@ static inline int curve_param_to_pubkey(int nid, BIGNUM *x, BIGNUM *y, struct bu
        if (!ec_point)
                goto end;
 
-       if (EC_POINT_set_affine_coordinates(group, ec_point, x, y, bnctx) < 0)
+       /* returns 0, not a negative value, for a point which is not on the curve */
+       if (EC_POINT_set_affine_coordinates(group, ec_point, x, y, bnctx) != 1)
                goto end;
 
        out->data = EC_POINT_point2oct(group, ec_point, POINT_CONVERSION_UNCOMPRESSED,
@@ -1666,10 +1667,10 @@ end:
        if (!ec_key)
                goto end;
 
-       if (nums[EC_BIGNUM_D] && EC_KEY_set_private_key(ec_key, nums[EC_BIGNUM_D]) < 0)
+       if (nums[EC_BIGNUM_D] && EC_KEY_set_private_key(ec_key, nums[EC_BIGNUM_D]) != 1)
                goto end;
 
-       if (EC_KEY_set_public_key_affine_coordinates(ec_key, nums[EC_BIGNUM_X], nums[EC_BIGNUM_Y]) < 0)
+       if (EC_KEY_set_public_key_affine_coordinates(ec_key, nums[EC_BIGNUM_X], nums[EC_BIGNUM_Y]) != 1)
                goto end;
 
        if (EC_KEY_check_key(ec_key) == 0)