Process SSL header expansions. If this is not an SSL connection, then we need to delete the SSL headers so that malicious clients cannot inject bogus information. Otherwise, we populate the header with the expanded value. If the value expands to something empty, we nuke the header.
| 172 | // so that malicious clients cannot inject bogus information. Otherwise, we populate the header with the |
| 173 | // expanded value. If the value expands to something empty, we nuke the header. |
| 174 | static void |
| 175 | SslHdrExpand(SSL *ssl, const SslHdrInstance::expansion_list &expansions, TSMBuffer mbuf, TSMLoc mhdr) |
| 176 | { |
| 177 | if (ssl == nullptr) { |
| 178 | for (const auto &expansion : expansions) { |
| 179 | SslHdrRemoveHeader(mbuf, mhdr, expansion.name); |
| 180 | } |
| 181 | } else { |
| 182 | WrapX509<true> clientX509(ssl); |
| 183 | WrapX509<false> serverX509(ssl); |
| 184 | X509 *x509; |
| 185 | |
| 186 | BIO *exp = BIO_new(BIO_s_mem()); |
| 187 | |
| 188 | for (const auto &expansion : expansions) { |
| 189 | switch (expansion.scope) { |
| 190 | case SSL_HEADERS_SCOPE_CLIENT: |
| 191 | x509 = clientX509.get(); |
| 192 | if (x509 == nullptr) { |
| 193 | SslHdrRemoveHeader(mbuf, mhdr, expansion.name); |
| 194 | continue; |
| 195 | } |
| 196 | break; |
| 197 | case SSL_HEADERS_SCOPE_SERVER: |
| 198 | x509 = serverX509.get(); |
| 199 | if (x509 == nullptr) { |
| 200 | continue; |
| 201 | } |
| 202 | break; |
| 203 | default: |
| 204 | continue; |
| 205 | } |
| 206 | |
| 207 | SslHdrExpandX509Field(exp, x509, expansion.field); |
| 208 | if (BIO_pending(exp)) { |
| 209 | SslHdrSetHeader(mbuf, mhdr, expansion.name, exp); |
| 210 | } else { |
| 211 | SslHdrRemoveHeader(mbuf, mhdr, expansion.name); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | BIO_free(exp); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | static SslHdrInstance * |
| 220 | SslHdrParseOptions(int argc, const char **argv) |
no test coverage detected