Skip to content

openssl: Fix compilation on Windows when ngtcp2 is enabled#5606

Closed
jblazquez wants to merge 1 commit intocurl:masterfrom
jblazquez:patch-1
Closed

openssl: Fix compilation on Windows when ngtcp2 is enabled#5606
jblazquez wants to merge 1 commit intocurl:masterfrom
jblazquez:patch-1

Conversation

@jblazquez
Copy link
Copy Markdown
Contributor

The wincrypt.h Windows header defines a number of preprocessor macros that conflict with identically named OpenSSL types. For example, it defines the following macros:

#define X509_NAME                           ((LPCSTR) 7)
#define OCSP_REQUEST                        ((LPCSTR) 66)
#define OCSP_RESPONSE                       ((LPCSTR) 67)

Which conflict with these OpenSSL types and cause compile errors:

typedef struct X509_name_st X509_NAME;
typedef struct ocsp_request_st OCSP_REQUEST;
typedef struct ocsp_response_st OCSP_RESPONSE;

OpenSSL headers already try to avoid these conflicts by undefining these Windows macros. However, that requires that wincrypt.h is included before any OpenSSL header.

In curl's vtls/openssl.c file, there is at least one configuration where an OpenSSL header is included before wincrypt.h. If ngtcp2 is enabled, for example, then the urldata.h include ends up including OpenSSL headers transitively like this:

Note: including file: urldata.h
Note: including file:  quic.h
Note: including file:   vquic/ngtcp2.h
Note: including file:    openssl/ssl.h

That include happens here.

In order to solve these conflicts and fix the compile issues when ngtcp2 is enabled, we need to move the wincrypt.h include as early as possible.

The `wincrypt.h` Windows header defines a number of preprocessor macros that conflict with identically named OpenSSL types. For example, it defines the following macros:

```
#define X509_NAME                           ((LPCSTR) 7)
#define OCSP_REQUEST                        ((LPCSTR) 66)
#define OCSP_RESPONSE                       ((LPCSTR) 67)
```

Which conflict with these OpenSSL types and cause compile errors:

```
typedef struct X509_name_st X509_NAME;
typedef struct ocsp_request_st OCSP_REQUEST;
typedef struct ocsp_response_st OCSP_RESPONSE;
```

OpenSSL headers already try to avoid these conflicts by [undefining these Windows macros](https://github.com/openssl/openssl/blob/15dfa0/include/openssl/types.h#L71-L78). However, that requires that `wincrypt.h` is included _before_ any OpenSSL header.

In curl's `vtls/openssl.c` file, there is at least one configuration where an OpenSSL header is included before `wincrypt.h`. If `ngtcp2` is enabled, for example, then the `urldata.h` include ends up including OpenSSL headers transitively like this:

```
Note: including file: urldata.h
Note: including file:  quic.h
Note: including file:   vquic/ngtcp2.h
Note: including file:    openssl/ssl.h
```

That include happens [here](https://github.com/curl/curl/blob/14c17a/lib/vquic/ngtcp2.h#L32).

In order to solve these conflicts and fix the compile issues when `ngtcp2` is enabled, we need to move the `wincrypt.h` include as early as possible.
@jay jay added build TLS Windows Windows-specific labels Jun 25, 2020
@jay jay closed this in ae3d1e0 Jun 25, 2020
@jay
Copy link
Copy Markdown
Member

jay commented Jun 25, 2020

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build TLS Windows Windows-specific

Development

Successfully merging this pull request may close these issues.

2 participants