libekmfweb: Check length of JWK EC public key coordinates

RFC 7517 requires that the x and y coordinates of a ECC JSON Web Key
(JWK) are specified in its full size of a coordinate for the curve used.

Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Signed-off-by: Jan Höppner <hoeppner@linux.ibm.com>
This commit is contained in:
Ingo Franzki
2021-01-29 10:17:09 +01:00
committed by Jan Höppner
parent faf26220a7
commit bf5ca4367d
2 changed files with 22 additions and 0 deletions

View File

@@ -1061,6 +1061,12 @@ int cca_import_key_from_json_web_key(const struct ekmf_cca_lib *cca_lib,
pr_verbose(verbose, "Failed to get and decode x");
goto out;
}
if (len != prime_len) {
/* RFC 7517: Must be full size of a coordinate */
pr_verbose(verbose, "x coordinate length is wrong");
rc = -EINVAL;
goto out;
}
len = prime_len;
rc = json_object_get_base64url(jwk, "y", &q[1 + prime_len],
@@ -1069,6 +1075,12 @@ int cca_import_key_from_json_web_key(const struct ekmf_cca_lib *cca_lib,
pr_verbose(verbose, "Failed to get and decode y");
goto out;
}
if (len != prime_len) {
/* RFC 7517: Must be full size of a coordinate */
pr_verbose(verbose, "y coordinate length is wrong");
rc = -EINVAL;
goto out;
}
rule_array_count = 1;
memcpy(rule_array, "ECC-PUBL", CCA_KEYWORD_SIZE);