Tobias Frauenschläger
63dc0dc827
Reset stale key metadata when d2i reuses an EVP_PKEY
...
d2i_make_pkey() replaces the key data, size and type of a caller-supplied
WOLFSSL_EVP_PKEY, but left pkcs8HeaderSz, mldsaOID, pkey_curve and
save_type describing the key the object held before.
A stale pkcs8HeaderSz is the damaging one. pkcs8_encode() and
wolfssl_i_evp_pkey_get_der() both encode from pkey.ptr + pkcs8HeaderSz,
so after
d2i_PrivateKey(EVP_PKEY_RSA, NULL, &p, pkcs8RsaDer);
d2i_PrivateKey_EVP(&pkey, &q, traditionalEccDer);
PEM_write_bio_PKCS8PrivateKey() reports success while wrapping the ECC
key with its first 26 bytes cut off, and the resulting PEM cannot be
read back.
Only the d2i_PUBKEY and d2i_PrivateKey_EVP routes are affected;
d2i_PrivateKey and d2i_AutoPrivateKey go through d2i_evp_pkey(), which
allocates a fresh object and recomputes the header size.
The same branch also drops the data and the key object of the previous
key without releasing either. pkey.ptr is overwritten with a fresh
allocation, and wolfSSL_EVP_PKEY_free() only disposes of the object
matching the type currently set, so the object of a key whose type has
since changed is never freed. The sequence above leaks the 1219 byte RSA
encoding together with the WOLFSSL_RSA and its bignums, 13 allocations
in all. The data is released after the new encoding has been copied in,
since the caller may be decoding out of it.
Clear the metadata and dispose of the previous key on the reuse branch,
so a reused object decodes to the same state as a new one, and add a
regression test comparing the PKCS#8 output of a reused key against a
freshly decoded one.
2026-08-06 22:19:42 +02:00
..
2026-02-18 09:52:21 -07:00
2026-07-07 02:35:51 -05:00
2026-07-10 18:56:51 +02:00
2026-07-31 12:56:52 +02:00
2026-08-05 13:53:47 -05:00
2026-07-09 10:02:21 +02:00
2026-06-10 11:36:29 +02:00
2026-06-10 11:36:29 +02:00
2026-02-18 09:52:21 -07:00
2026-07-31 13:16:41 +02:00
2026-07-31 12:56:51 +02:00
2026-08-06 08:50:30 +02:00
2026-08-06 08:50:30 +02:00
2026-07-31 12:56:51 +02:00
2026-07-31 12:56:51 +02:00
2026-07-31 12:56:51 +02:00
2026-07-02 11:36:01 +02:00
2026-07-24 14:34:17 -04:00
2026-07-24 14:34:17 -04:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-08-01 13:11:52 +02:00
2026-08-01 13:11:52 +02:00
2026-08-05 13:53:46 -05:00
2026-07-13 11:19:23 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-08-03 16:30:31 -07:00
2026-08-03 16:30:31 -07:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:51 +02:00
2026-08-01 13:13:00 +02:00
2026-08-01 13:13:00 +02:00
2026-02-18 09:52:21 -07:00
2026-07-13 11:19:24 +02:00
2026-07-13 11:19:23 +02:00
2026-08-01 12:04:57 +02:00
2026-08-01 11:54:40 +02:00
2026-08-03 10:11:25 -07:00
2026-08-01 12:04:57 +02:00
2026-08-01 13:13:00 +02:00
2026-08-01 13:13:00 +02:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:51 +02:00
2026-08-04 10:29:42 -07:00
2026-08-04 10:29:42 -07:00
2026-07-29 23:20:44 +02:00
2026-07-29 23:20:44 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-06-04 17:26:48 -05:00
2026-03-05 08:51:52 -06:00
2026-05-06 15:25:06 -06:00
2026-02-18 09:52:21 -07:00
2026-08-06 22:19:42 +02:00
2026-08-06 22:19:42 +02:00
2026-07-07 16:41:15 -07:00
2026-02-18 09:52:21 -07:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:52 +02:00
2026-08-05 13:55:14 -05:00
2026-07-17 22:38:55 +10:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-08-04 10:43:24 -07:00
2026-08-04 10:43:24 -07:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:51 +02:00
2026-08-05 13:53:45 -05:00
2026-07-17 08:56:03 +02:00
2026-08-05 22:23:43 +02:00
2026-08-05 22:23:43 +02:00
2026-05-13 11:36:36 -06:00
2026-02-18 09:52:21 -07:00
2026-05-13 11:36:36 -06:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-06-04 18:29:24 +10:00
2026-08-05 13:53:46 -05:00
2026-07-17 08:56:03 +02:00
2026-07-29 14:59:47 +10:00
2026-07-17 08:56:03 +02:00
2026-07-10 11:51:52 -07:00
2026-07-31 22:02:42 +02:00
2026-07-31 22:02:42 +02:00
2026-07-07 17:41:49 -07:00
2026-02-18 09:52:21 -07:00
2026-07-02 11:36:01 +02:00
2026-07-02 11:36:01 +02:00
2026-04-13 15:50:26 +02:00
2026-02-18 09:52:21 -07:00
2026-06-10 11:36:29 +02:00
2026-05-07 02:33:58 +00:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-04-06 00:53:57 -05:00
2026-02-18 09:52:21 -07:00
2026-05-27 15:38:30 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-08-01 11:54:40 +02:00
2026-08-01 11:54:40 +02:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-06-26 14:44:16 -06:00
2026-06-16 20:19:22 +02:00
2026-06-25 14:44:03 -06:00
2026-05-22 19:24:53 +03:00
2026-05-14 16:59:12 +00:00
2026-05-14 16:59:12 +00:00
2026-07-07 00:19:47 -05:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-07-08 09:33:47 +10:00
2026-07-08 09:33:47 +10:00
2026-07-22 13:07:55 +02:00
2026-02-18 09:52:21 -07:00
2026-07-13 11:56:57 -06:00
2026-07-13 11:56:57 -06:00
2026-07-09 10:02:22 +02:00
2026-07-09 10:02:21 +02:00
2026-06-26 14:44:16 -06:00
2026-02-18 09:52:21 -07:00
2026-06-04 10:38:37 -07:00
2026-06-04 10:38:37 -07:00
2026-04-28 10:06:47 +00:00
2026-04-28 10:06:47 +00:00
2026-06-26 14:44:16 -06:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-07-22 13:31:03 +02:00
2026-07-22 13:31:03 +02:00
2026-07-21 09:50:17 -06:00
2026-02-18 09:52:21 -07:00
2026-08-01 11:54:40 +02:00
2026-08-01 11:54:40 +02:00
2026-08-04 10:33:15 -07:00
2026-08-04 10:33:15 -07:00
2026-07-09 10:02:22 +02:00
2026-07-09 10:02:21 +02:00
2026-07-13 11:19:23 +02:00
2026-04-10 15:43:21 +10:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-02 11:36:01 +02:00
2026-07-02 11:36:01 +02:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-07-13 14:13:46 +02:00
2026-07-09 10:02:21 +02:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:51 +02:00
2026-05-28 19:34:09 +10:00
2026-05-28 19:34:09 +10:00
2026-07-24 16:39:54 -05:00
2026-07-13 17:48:56 +10:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-07-13 11:19:24 +02:00
2026-06-04 20:21:50 +02:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-04-15 18:03:39 -06:00
2026-04-15 11:28:03 -06:00
2026-08-02 20:56:01 +09:00
2026-07-17 08:56:03 +02:00
2026-07-31 12:56:51 +02:00
2026-07-31 12:56:51 +02:00
2026-08-04 22:23:03 +02:00
2026-08-04 22:23:03 +02:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-02-18 09:52:21 -07:00
2026-04-14 13:25:15 +10:00
2026-04-14 13:25:15 +10:00
2026-07-31 12:56:51 +02:00
2026-07-31 12:56:51 +02:00
2026-06-10 12:05:00 -05:00
2026-06-10 09:11:59 +10:00
2026-07-20 14:19:37 -05:00
2026-07-20 14:19:37 -05:00
2026-08-04 22:23:03 +02:00
2026-06-10 09:11:59 +10:00
2026-07-31 22:02:42 +02:00
2026-07-23 07:42:20 +09:00
2026-08-04 15:54:59 -07:00
2026-08-04 15:54:59 -07:00
2026-08-05 20:39:57 +02:00
2026-08-05 08:34:09 +02:00
2026-07-08 09:33:47 +10:00
2026-07-08 09:33:47 +10:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-17 08:56:03 +02:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:52 +02:00
2026-07-31 12:56:52 +02:00
2026-07-17 08:56:03 +02:00
2026-07-31 17:46:16 -06:00
2026-07-31 17:46:16 -06:00