|
| 1 | +From 61b76bf4a6ee2a1b47aea2d47baa22cfe8e43568 Mon Sep 17 00:00:00 2001 |
| 2 | +From: David Benjamin < [email protected]> |
| 3 | +Date: Mon, 13 Jun 2022 12:22:05 -0400 |
| 4 | +Subject: [PATCH 3/3] Remove a host of incorrect OPENSSL_IS_BORINGSSL ifdefs |
| 5 | + |
| 6 | +The <openssl/buf.h> include is neccessary in both OpenSSL and BoringSSL |
| 7 | +because the file uses BUF_MEM (IWYU). It's just that OpenSSL spells it |
| 8 | +<openssl/buffer.h>, not matching the type, so use the compatible |
| 9 | +spelling. |
| 10 | + |
| 11 | +Additionally all the CHECKED_CAST and manual STACK_OF(T) definitions are |
| 12 | +calling into BoringSSL internals that we were only keeping around for |
| 13 | +compatible with wpa_supplicant's incorrect use of the APIs. The correct |
| 14 | +APIs are simply to just use the same code as OpenSSL and call the |
| 15 | +DEFINE_STACK_OF macros. |
| 16 | + |
| 17 | +(tls_openssl_ocsp.c needs to be rewritten entirely later, as the use of |
| 18 | +<openssl/asn1t.h> is also quite dangerous, but I've left that alone for |
| 19 | +now.) |
| 20 | + |
| 21 | +Test: treehugger |
| 22 | +Change-Id: Id923db6513f9e2833854322994aa3a113ee1579d |
| 23 | +--- |
| 24 | + hs20/client/est.c | 28 +++------------------------- |
| 25 | + src/crypto/tls_openssl_ocsp.c | 8 +------- |
| 26 | + src/utils/http_curl.c | 23 ----------------------- |
| 27 | + 3 files changed, 4 insertions(+), 55 deletions(-) |
| 28 | + |
| 29 | +diff --git a/hs20/client/est.c b/hs20/client/est.c |
| 30 | +index 97f91321..c3f27e1e 100644 |
| 31 | +--- a/hs20/client/est.c |
| 32 | ++++ b/hs20/client/est.c |
| 33 | +@@ -17,9 +17,7 @@ |
| 34 | + #include <openssl/x509.h> |
| 35 | + #include <openssl/x509v3.h> |
| 36 | + #include <openssl/opensslv.h> |
| 37 | +-#ifdef OPENSSL_IS_BORINGSSL |
| 38 | +-#include <openssl/buf.h> |
| 39 | +-#endif /* OPENSSL_IS_BORINGSSL */ |
| 40 | ++#include <openssl/buffer.h> |
| 41 | + |
| 42 | + #include "common.h" |
| 43 | + #include "utils/base64.h" |
| 44 | +@@ -220,9 +218,7 @@ typedef struct { |
| 45 | + } d; |
| 46 | + } AttrOrOID; |
| 47 | + |
| 48 | +-#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(OPENSSL_IS_BORINGSSL) |
| 49 | + DEFINE_STACK_OF(AttrOrOID) |
| 50 | +-#endif |
| 51 | + |
| 52 | + typedef struct { |
| 53 | + int type; |
| 54 | +@@ -340,30 +336,13 @@ static void add_csrattrs(struct hs20_osu_client *ctx, CsrAttrs *csrattrs, |
| 55 | + if (!csrattrs || ! csrattrs->attrs) |
| 56 | + return; |
| 57 | + |
| 58 | +-#ifdef OPENSSL_IS_BORINGSSL |
| 59 | +- num = sk_num(CHECKED_CAST(_STACK *, STACK_OF(AttrOrOID) *, |
| 60 | +- csrattrs->attrs)); |
| 61 | +- for (i = 0; i < num; i++) { |
| 62 | +- AttrOrOID *ao = sk_value( |
| 63 | +- CHECKED_CAST(_STACK *, const STACK_OF(AttrOrOID) *, |
| 64 | +- csrattrs->attrs), i); |
| 65 | +- switch (ao->type) { |
| 66 | +- case 0: |
| 67 | +- add_csrattrs_oid(ctx, ao->d.oid, exts); |
| 68 | +- break; |
| 69 | +- case 1: |
| 70 | +- add_csrattrs_attr(ctx, ao->d.attribute, exts); |
| 71 | +- break; |
| 72 | +- } |
| 73 | +- } |
| 74 | +-#else /* OPENSSL_IS_BORINGSSL */ |
| 75 | +-#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(OPENSSL_IS_BORINGSSL) |
| 76 | ++#if OPENSSL_VERSION_NUMBER >= 0x10100000L |
| 77 | + num = sk_AttrOrOID_num(csrattrs->attrs); |
| 78 | + #else |
| 79 | + num = SKM_sk_num(AttrOrOID, csrattrs->attrs); |
| 80 | + #endif |
| 81 | + for (i = 0; i < num; i++) { |
| 82 | +-#if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(OPENSSL_IS_BORINGSSL) |
| 83 | ++#if OPENSSL_VERSION_NUMBER >= 0x10100000L |
| 84 | + AttrOrOID *ao = sk_AttrOrOID_value(csrattrs->attrs, i); |
| 85 | + #else |
| 86 | + AttrOrOID *ao = SKM_sk_value(AttrOrOID, csrattrs->attrs, i); |
| 87 | +@@ -377,7 +356,6 @@ static void add_csrattrs(struct hs20_osu_client *ctx, CsrAttrs *csrattrs, |
| 88 | + break; |
| 89 | + } |
| 90 | + } |
| 91 | +-#endif /* OPENSSL_IS_BORINGSSL */ |
| 92 | + } |
| 93 | + |
| 94 | + |
| 95 | +diff --git a/src/crypto/tls_openssl_ocsp.c b/src/crypto/tls_openssl_ocsp.c |
| 96 | +index b570bea0..a74e6f3d 100644 |
| 97 | +--- a/src/crypto/tls_openssl_ocsp.c |
| 98 | ++++ b/src/crypto/tls_openssl_ocsp.c |
| 99 | +@@ -216,13 +216,7 @@ ASN1_SEQUENCE(BasicOCSPResponse) = { |
| 100 | + |
| 101 | + IMPLEMENT_ASN1_FUNCTIONS(BasicOCSPResponse); |
| 102 | + |
| 103 | +-#define sk_SingleResponse_num(sk) \ |
| 104 | +-sk_num(CHECKED_CAST(_STACK *, STACK_OF(SingleResponse) *, sk)) |
| 105 | +- |
| 106 | +-#define sk_SingleResponse_value(sk, i) \ |
| 107 | +- ((SingleResponse *) \ |
| 108 | +- sk_value(CHECKED_CAST(_STACK *, STACK_OF(SingleResponse) *, sk), (i))) |
| 109 | +- |
| 110 | ++DEFINE_STACK_OF(SingleResponse) |
| 111 | + |
| 112 | + static char * mem_bio_to_str(BIO *out) |
| 113 | + { |
| 114 | +diff --git a/src/utils/http_curl.c b/src/utils/http_curl.c |
| 115 | +index 30b07f23..77d5b357 100644 |
| 116 | +--- a/src/utils/http_curl.c |
| 117 | ++++ b/src/utils/http_curl.c |
| 118 | +@@ -433,28 +433,6 @@ ASN1_SEQUENCE(LogotypeExtn) = { |
| 119 | + |
| 120 | + IMPLEMENT_ASN1_FUNCTIONS(LogotypeExtn); |
| 121 | + |
| 122 | +-#ifdef OPENSSL_IS_BORINGSSL |
| 123 | +-#define sk_LogotypeInfo_num(st) \ |
| 124 | +-sk_num(CHECKED_CAST(_STACK *, STACK_OF(LogotypeInfo) *, (st))) |
| 125 | +-#define sk_LogotypeInfo_value(st, i) (LogotypeInfo *) \ |
| 126 | +-sk_value(CHECKED_CAST(_STACK *, const STACK_OF(LogotypeInfo) *, (st)), (i)) |
| 127 | +-#define sk_LogotypeImage_num(st) \ |
| 128 | +-sk_num(CHECKED_CAST(_STACK *, STACK_OF(LogotypeImage) *, (st))) |
| 129 | +-#define sk_LogotypeImage_value(st, i) (LogotypeImage *) \ |
| 130 | +-sk_value(CHECKED_CAST(_STACK *, const STACK_OF(LogotypeImage) *, (st)), (i)) |
| 131 | +-#define sk_LogotypeAudio_num(st) \ |
| 132 | +-sk_num(CHECKED_CAST(_STACK *, STACK_OF(LogotypeAudio) *, (st))) |
| 133 | +-#define sk_LogotypeAudio_value(st, i) (LogotypeAudio *) \ |
| 134 | +-sk_value(CHECK_CAST(_STACK *, const STACK_OF(LogotypeAudio) *, (st)), (i)) |
| 135 | +-#define sk_HashAlgAndValue_num(st) \ |
| 136 | +-sk_num(CHECKED_CAST(_STACK *, STACK_OF(HashAlgAndValue) *, (st))) |
| 137 | +-#define sk_HashAlgAndValue_value(st, i) (HashAlgAndValue *) \ |
| 138 | +-sk_value(CHECKED_CAST(_STACK *, const STACK_OF(HashAlgAndValue) *, (st)), (i)) |
| 139 | +-#define sk_ASN1_IA5STRING_num(st) \ |
| 140 | +-sk_num(CHECKED_CAST(_STACK *, STACK_OF(ASN1_IA5STRING) *, (st))) |
| 141 | +-#define sk_ASN1_IA5STRING_value(st, i) (ASN1_IA5STRING *) \ |
| 142 | +-sk_value(CHECKED_CAST(_STACK *, const STACK_OF(ASN1_IA5STRING) *, (st)), (i)) |
| 143 | +-#else /* OPENSSL_IS_BORINGSSL */ |
| 144 | + #if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 145 | + #define sk_LogotypeInfo_num(st) SKM_sk_num(LogotypeInfo, (st)) |
| 146 | + #define sk_LogotypeInfo_value(st, i) SKM_sk_value(LogotypeInfo, (st), (i)) |
| 147 | +@@ -473,7 +451,6 @@ DEFINE_STACK_OF(LogotypeAudio) |
| 148 | + DEFINE_STACK_OF(HashAlgAndValue) |
| 149 | + DEFINE_STACK_OF(ASN1_IA5STRING) |
| 150 | + #endif |
| 151 | +-#endif /* OPENSSL_IS_BORINGSSL */ |
| 152 | + |
| 153 | + |
| 154 | + static void add_logo(struct http_ctx *ctx, struct http_cert *hcert, |
| 155 | +-- |
| 156 | +2.39.2 |
| 157 | + |
0 commit comments