Commit bd482e23d0 for openssl.org
commit bd482e23d0001805ae7c6a9a7f65cc0aa0fb6ced
Author: Mounir IDRASSI <mounir.idrassi@idrix.fr>
Date: Fri Aug 7 18:34:11 2026 +0900
Add regression tests for BIT STRING X509 attributes
Test that X509_ATTRIBUTE_create_by_NID() accepts a BIT STRING value
supplied as raw bytes with an explicit length, as done for the keyUsage
attribute by openssl pkcs12 -export -keyex and -keysig via
PKCS8_add_keyusage(). Both KEY_EX (0x10) and KEY_SIG (0x80) are exercised
at this common boundary, and the resulting attribute is checked for the
expected type, value, length, and zero unused bits.
Also pass -keyex to an existing PKCS12 export test so the reported CLI
path is covered end to end.
Regression test for https://github.com/openssl/openssl/issues/32234
Assisted-by: Codex:gpt-5.6-sol
Reviewed-by: Richard Levitte <levitte@openssl.org>
Reviewed-by: Bob Beck <beck@openssl.org>
Merge-date: Wed Aug 19 15:44:50 2026
Merged-from: https://github.com/openssl/openssl/pull/32238
diff --git a/test/recipes/80-test_pkcs12.t b/test/recipes/80-test_pkcs12.t
index 37a86e77f3..c82b07a1bf 100644
--- a/test/recipes/80-test_pkcs12.t
+++ b/test/recipes/80-test_pkcs12.t
@@ -180,7 +180,7 @@ ok(grep(/Trusted key usage (Oracle)/, @pkcs12info) == 0,
# keyBag (created with -keypbe NONE) rather than a shrouded keyBag.
{
my $keybag = "keybag.p12";
- ok(run(app(["openssl", "pkcs12", "-export", "-keypbe", "NONE",
+ ok(run(app(["openssl", "pkcs12", "-export", "-keyex", "-keypbe", "NONE",
"-certpbe", "NONE", "-nomac",
"-inkey", srctop_file(@path, "cert-key-cert.pem"),
"-in", srctop_file(@path, "cert-key-cert.pem"),
diff --git a/test/x509_internal_test.c b/test/x509_internal_test.c
index d2d118dd17..c68e44d118 100644
--- a/test/x509_internal_test.c
+++ b/test/x509_internal_test.c
@@ -957,6 +957,35 @@ err:
return test;
}
+/*
+ * X509_ATTRIBUTE_create_by_NID() must accept a BIT STRING value supplied as
+ * raw bytes plus an explicit length, as PKCS8_add_keyusage() does for
+ * 'openssl pkcs12 -export -keyex' (0x10) and '-keysig' (0x80).
+ * Regression test for https://github.com/openssl/openssl/issues/32234
+ */
+static int test_x509_attribute_bit_string(int idx)
+{
+ unsigned char usage = idx == 0 ? 0x10 : 0x80;
+ X509_ATTRIBUTE *attr = NULL;
+ const ASN1_BIT_STRING *bs;
+ size_t length = 0;
+ int unused_bits = -1, ret = 0;
+
+ if (!TEST_ptr(attr = X509_ATTRIBUTE_create_by_NID(NULL, NID_key_usage,
+ V_ASN1_BIT_STRING, &usage, 1))
+ || !TEST_ptr(bs = X509_ATTRIBUTE_get0_data(attr, 0, V_ASN1_BIT_STRING,
+ NULL))
+ || !TEST_true(ASN1_BIT_STRING_get_length(bs, &length, &unused_bits))
+ || !TEST_size_t_eq(length, 1)
+ || !TEST_int_eq(unused_bits, 0)
+ || !TEST_mem_eq(ASN1_STRING_get0_data(bs), 1, &usage, 1))
+ goto err;
+ ret = 1;
+err:
+ X509_ATTRIBUTE_free(attr);
+ return ret;
+}
+
int setup_tests(void)
{
ADD_TEST(test_standard_exts);
@@ -970,6 +999,7 @@ int setup_tests(void)
ADD_TEST(tests_x509_check_ext_duplicity);
ADD_TEST(tests_x509_check_ext_duplicity_nid_undef);
ADD_TEST(tests_x509_check_ext_duplicity_nid_dynamic);
+ ADD_ALL_TESTS(test_x509_attribute_bit_string, 2);
return 1;
}