From 56112cc01f8be29578d52c1c2af6f481c3d77bd2 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 15 Dec 2023 18:28:54 -0500 Subject: [PATCH 1/4] Skip emitting empty
 blocks in documentation

We sometimes have decl-less comments interspersed in headers. Avoid the
empty patch of blue when they get rendered.

Change-Id: I6668946d07349febd6d28bbe7d4fd8d2426adca9
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64927
Auto-Submit: David Benjamin 
Commit-Queue: David Benjamin 
Reviewed-by: Bob Beck 
Commit-Queue: Bob Beck 
---
 util/doc.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/util/doc.go b/util/doc.go
index 4fb73ca0d..ae5c45df8 100644
--- a/util/doc.go
+++ b/util/doc.go
@@ -649,7 +649,7 @@ func generate(outPath string, config *Config) (map[string]string, error) {
           {{range .Comment}}
             

{{. | markupPipeWords | newlinesToBR | markupFirstWord | markupRFC}}

{{end}} -
{{.Decl}}
+ {{if .Decl}}
{{.Decl}}
{{end}} {{end}} From 9c821af02f2c38ac9ba58708164ccb6c4d7654bc Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Fri, 15 Dec 2023 18:23:43 -0500 Subject: [PATCH 2/4] Add conf.h to the documentation output We don't want anyone using it, but we probably should render all our documented headers. I've grouped it with the rest of the legacy X.509 stack. Change-Id: If01dfd19c71598f47a40cd334b0fd7ef3e00685d Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64928 Reviewed-by: Bob Beck Commit-Queue: David Benjamin --- include/openssl/conf.h | 5 ++++- util/doc.config | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/openssl/conf.h b/include/openssl/conf.h index c9027c1db..1e613261b 100644 --- a/include/openssl/conf.h +++ b/include/openssl/conf.h @@ -67,7 +67,9 @@ extern "C" { #endif -// Config files look like: +// Config files. +// +// This library handles OpenSSL's config files, which look like: // // # Comment // @@ -82,6 +84,7 @@ extern "C" { // untrusted input as a config file risks string injection and denial of service // vulnerabilities. + struct conf_value_st { char *section; char *name; diff --git a/util/doc.config b/util/doc.config index d6ae92585..49b0ec668 100644 --- a/util/doc.config +++ b/util/doc.config @@ -56,6 +56,7 @@ "Name": "Legacy ASN.1 and X.509 implementation (documentation in progress)", "Headers": [ "include/openssl/asn1.h", + "include/openssl/conf.h", "include/openssl/time.h" ] },{ From faac623b09d6b14fbb06fe5150016de78b359eea Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 16 Dec 2023 21:07:46 -0500 Subject: [PATCH 3/4] Restore the X509 ASN1_ITEM https://boringssl-review.googlesource.com/c/boringssl/+/63946 removed it, but sadly wpa_supplicant depends on it. Change-Id: Ib3aca5269d740457ba83ca529b797bfb4a089763 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64907 Reviewed-by: Bob Beck Auto-Submit: David Benjamin Commit-Queue: Bob Beck --- crypto/asn1/asn1_test.cc | 57 ++++++++++++++++++++++++++++++++++++++++ crypto/x509/x_x509.c | 48 +++++++++++++++++++++++++++++++++ include/openssl/x509.h | 4 +++ 3 files changed, 109 insertions(+) diff --git a/crypto/asn1/asn1_test.cc b/crypto/asn1/asn1_test.cc index efeb72816..196d7b7e5 100644 --- a/crypto/asn1/asn1_test.cc +++ b/crypto/asn1/asn1_test.cc @@ -2834,6 +2834,12 @@ struct EMBED_X509_NAME { STACK_OF(X509_NAME) *seq; }; +struct EMBED_X509 { + X509 *simple; + X509 *opt; + STACK_OF(X509) *seq; +}; + DECLARE_ASN1_FUNCTIONS(EMBED_X509_ALGOR) ASN1_SEQUENCE(EMBED_X509_ALGOR) = { ASN1_SIMPLE(EMBED_X509_ALGOR, simple, X509_ALGOR), @@ -2850,6 +2856,14 @@ ASN1_SEQUENCE(EMBED_X509_NAME) = { } ASN1_SEQUENCE_END(EMBED_X509_NAME) IMPLEMENT_ASN1_FUNCTIONS(EMBED_X509_NAME) +DECLARE_ASN1_FUNCTIONS(EMBED_X509) +ASN1_SEQUENCE(EMBED_X509) = { + ASN1_SIMPLE(EMBED_X509, simple, X509), + ASN1_EXP_OPT(EMBED_X509, opt, X509, 0), + ASN1_IMP_SEQUENCE_OF_OPT(EMBED_X509, seq, X509, 1), +} ASN1_SEQUENCE_END(EMBED_X509) +IMPLEMENT_ASN1_FUNCTIONS(EMBED_X509) + template void TestEmbedType(bssl::Span inp, int (*i2d)(MaybeConstT *, uint8_t **), @@ -2925,6 +2939,49 @@ TEST(ASN1Test, EmbedTypes) { TestEmbedType(kTestName, i2d_X509_NAME, EMBED_X509_NAME_new, EMBED_X509_NAME_free, d2i_EMBED_X509_NAME, i2d_EMBED_X509_NAME, sk_X509_NAME_num, sk_X509_NAME_value); + + static const uint8_t kTestCert[] = { + 0x30, 0x82, 0x01, 0xcf, 0x30, 0x82, 0x01, 0x76, 0xa0, 0x03, 0x02, 0x01, + 0x02, 0x02, 0x09, 0x00, 0xd9, 0x4c, 0x04, 0xda, 0x49, 0x7d, 0xbf, 0xeb, + 0x30, 0x09, 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x01, 0x30, + 0x45, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, + 0x41, 0x55, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, + 0x0a, 0x53, 0x6f, 0x6d, 0x65, 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, + 0x21, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, 0x6e, + 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, + 0x74, 0x73, 0x20, 0x50, 0x74, 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, 0x1e, + 0x17, 0x0d, 0x31, 0x34, 0x30, 0x34, 0x32, 0x33, 0x32, 0x33, 0x32, 0x31, + 0x35, 0x37, 0x5a, 0x17, 0x0d, 0x31, 0x34, 0x30, 0x35, 0x32, 0x33, 0x32, + 0x33, 0x32, 0x31, 0x35, 0x37, 0x5a, 0x30, 0x45, 0x31, 0x0b, 0x30, 0x09, + 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x41, 0x55, 0x31, 0x13, 0x30, + 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x53, 0x6f, 0x6d, 0x65, + 0x2d, 0x53, 0x74, 0x61, 0x74, 0x65, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x03, + 0x55, 0x04, 0x0a, 0x0c, 0x18, 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, + 0x74, 0x20, 0x57, 0x69, 0x64, 0x67, 0x69, 0x74, 0x73, 0x20, 0x50, 0x74, + 0x79, 0x20, 0x4c, 0x74, 0x64, 0x30, 0x59, 0x30, 0x13, 0x06, 0x07, 0x2a, + 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, + 0x3d, 0x03, 0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xe6, 0x2b, 0x69, 0xe2, + 0xbf, 0x65, 0x9f, 0x97, 0xbe, 0x2f, 0x1e, 0x0d, 0x94, 0x8a, 0x4c, 0xd5, + 0x97, 0x6b, 0xb7, 0xa9, 0x1e, 0x0d, 0x46, 0xfb, 0xdd, 0xa9, 0xa9, 0x1e, + 0x9d, 0xdc, 0xba, 0x5a, 0x01, 0xe7, 0xd6, 0x97, 0xa8, 0x0a, 0x18, 0xf9, + 0xc3, 0xc4, 0xa3, 0x1e, 0x56, 0xe2, 0x7c, 0x83, 0x48, 0xdb, 0x16, 0x1a, + 0x1c, 0xf5, 0x1d, 0x7e, 0xf1, 0x94, 0x2d, 0x4b, 0xcf, 0x72, 0x22, 0xc1, + 0xa3, 0x50, 0x30, 0x4e, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, + 0x16, 0x04, 0x14, 0xab, 0x84, 0xd2, 0xac, 0xab, 0x95, 0xf0, 0x82, 0x4e, + 0x16, 0x78, 0x07, 0x55, 0x57, 0x5f, 0xe4, 0x26, 0x8d, 0x82, 0xd1, 0x30, + 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30, 0x16, 0x80, 0x14, + 0xab, 0x84, 0xd2, 0xac, 0xab, 0x95, 0xf0, 0x82, 0x4e, 0x16, 0x78, 0x07, + 0x55, 0x57, 0x5f, 0xe4, 0x26, 0x8d, 0x82, 0xd1, 0x30, 0x0c, 0x06, 0x03, + 0x55, 0x1d, 0x13, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x09, + 0x06, 0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x04, 0x01, 0x03, 0x48, 0x00, + 0x30, 0x45, 0x02, 0x21, 0x00, 0xf2, 0xa0, 0x35, 0x5e, 0x51, 0x3a, 0x36, + 0xc3, 0x82, 0x79, 0x9b, 0xee, 0x27, 0x50, 0x85, 0x8e, 0x70, 0x06, 0x74, + 0x95, 0x57, 0xd2, 0x29, 0x74, 0x00, 0xf4, 0xbe, 0x15, 0x87, 0x5d, 0xc4, + 0x07, 0x02, 0x20, 0x7c, 0x1e, 0x79, 0x14, 0x6a, 0x21, 0x83, 0xf0, 0x7a, + 0x74, 0x68, 0x79, 0x5f, 0x14, 0x99, 0x9a, 0x68, 0xb4, 0xf1, 0xcb, 0x9e, + 0x15, 0x5e, 0xe6, 0x1f, 0x32, 0x52, 0x61, 0x5e, 0x75, 0xc9, 0x14}; + TestEmbedType(kTestCert, i2d_X509, EMBED_X509_new, EMBED_X509_free, + d2i_EMBED_X509, i2d_EMBED_X509, sk_X509_num, sk_X509_value); } #endif // !WINDOWS || !SHARED_LIBRARY diff --git a/crypto/x509/x_x509.c b/crypto/x509/x_x509.c index d5b9d4d1e..1d3ebf645 100644 --- a/crypto/x509/x_x509.c +++ b/crypto/x509/x_x509.c @@ -299,6 +299,54 @@ err: return -1; } +static int x509_new_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { + *pval = (ASN1_VALUE *)X509_new(); + return *pval != NULL; +} + +static void x509_free_cb(ASN1_VALUE **pval, const ASN1_ITEM *it) { + X509_free((X509 *)*pval); + *pval = NULL; +} + +static int x509_d2i_cb(ASN1_VALUE **pval, const unsigned char **in, long len, + const ASN1_ITEM *it, int opt, ASN1_TLC *ctx) { + if (len < 0) { + OPENSSL_PUT_ERROR(ASN1, ASN1_R_BUFFER_TOO_SMALL); + return 0; + } + + CBS cbs; + CBS_init(&cbs, *in, len); + if (opt && !CBS_peek_asn1_tag(&cbs, CBS_ASN1_SEQUENCE)) { + return -1; + } + + X509 *ret = x509_parse(&cbs, NULL); + if (ret == NULL) { + return 0; + } + + *in = CBS_data(&cbs); + X509_free((X509 *)*pval); + *pval = (ASN1_VALUE *)ret; + return 1; +} + +static int x509_i2d_cb(ASN1_VALUE **pval, unsigned char **out, + const ASN1_ITEM *it) { + return i2d_X509((X509 *)*pval, out); +} + +static const ASN1_EXTERN_FUNCS x509_extern_funcs = { + x509_new_cb, + x509_free_cb, + x509_d2i_cb, + x509_i2d_cb, +}; + +IMPLEMENT_EXTERN_ASN1(X509, V_ASN1_SEQUENCE, x509_extern_funcs) + X509 *X509_dup(X509 *x509) { uint8_t *der = NULL; int len = i2d_X509(x509, &der); diff --git a/include/openssl/x509.h b/include/openssl/x509.h index b27c97d33..6fb07aa62 100644 --- a/include/openssl/x509.h +++ b/include/openssl/x509.h @@ -123,6 +123,10 @@ extern "C" { DEFINE_STACK_OF(X509) +// X509 is an |ASN1_ITEM| whose ASN.1 type is X.509 Certificate (RFC 5280) and C +// type is |X509*|. +DECLARE_ASN1_ITEM(X509) + // X509_up_ref adds one to the reference count of |x509| and returns one. OPENSSL_EXPORT int X509_up_ref(X509 *x509); From 3d5a848d2fc081872123ba3d6e2b0f653281aa13 Mon Sep 17 00:00:00 2001 From: David Benjamin Date: Sat, 16 Dec 2023 02:43:26 -0500 Subject: [PATCH 4/4] Give time.h a title and move to low-level infra group Change-Id: I4cb50bda726fcc0f22fcb53dca92cf297aeea169 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/64929 Commit-Queue: David Benjamin Reviewed-by: Bob Beck --- include/openssl/time.h | 4 ++++ util/doc.config | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/openssl/time.h b/include/openssl/time.h index 723ce10a0..50db22d32 100644 --- a/include/openssl/time.h +++ b/include/openssl/time.h @@ -23,6 +23,10 @@ extern "C" { #endif + +// Time functions. + + // OPENSSL_posix_to_tm converts a int64_t POSIX time value in |time|, which must // be in the range of year 0000 to 9999, to a broken out time value in |tm|. It // returns one on success and zero on error. diff --git a/util/doc.config b/util/doc.config index 49b0ec668..29bba6701 100644 --- a/util/doc.config +++ b/util/doc.config @@ -15,7 +15,8 @@ "include/openssl/obj.h", "include/openssl/pool.h", "include/openssl/rand.h", - "include/openssl/stack.h" + "include/openssl/stack.h", + "include/openssl/time.h" ] },{ "Name": "Low-level crypto primitives", @@ -56,8 +57,7 @@ "Name": "Legacy ASN.1 and X.509 implementation (documentation in progress)", "Headers": [ "include/openssl/asn1.h", - "include/openssl/conf.h", - "include/openssl/time.h" + "include/openssl/conf.h" ] },{ "Name": "SSL implementation",