schannel_int.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. #ifndef HEADER_CURL_SCHANNEL_INT_H
  2. #define HEADER_CURL_SCHANNEL_INT_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Marc Hoersken, <info@marc-hoersken.de>, et al.
  11. * Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
  12. *
  13. * This software is licensed as described in the file COPYING, which
  14. * you should have received as part of this distribution. The terms
  15. * are also available at https://curl.se/docs/copyright.html.
  16. *
  17. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  18. * copies of the Software, and permit persons to whom the Software is
  19. * furnished to do so, under the terms of the COPYING file.
  20. *
  21. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  22. * KIND, either express or implied.
  23. *
  24. * SPDX-License-Identifier: curl
  25. *
  26. ***************************************************************************/
  27. #include "curl_setup.h"
  28. #ifdef USE_SCHANNEL
  29. #if (defined(__MINGW32__) || defined(CERT_CHAIN_REVOCATION_CHECK_CHAIN)) \
  30. && !defined(CURL_WINDOWS_APP)
  31. #define HAS_MANUAL_VERIFY_API
  32. #endif
  33. #if defined(CryptStringToBinary) && defined(CRYPT_STRING_HEX) \
  34. && !defined(DISABLE_SCHANNEL_CLIENT_CERT)
  35. #define HAS_CLIENT_CERT_PATH
  36. #endif
  37. #ifndef CRYPT_DECODE_NOCOPY_FLAG
  38. #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  39. #endif
  40. #ifndef CRYPT_DECODE_ALLOC_FLAG
  41. #define CRYPT_DECODE_ALLOC_FLAG 0x8000
  42. #endif
  43. #ifndef CERT_ALT_NAME_DNS_NAME
  44. #define CERT_ALT_NAME_DNS_NAME 3
  45. #endif
  46. #ifndef CERT_ALT_NAME_IP_ADDRESS
  47. #define CERT_ALT_NAME_IP_ADDRESS 8
  48. #endif
  49. #if defined(_MSC_VER) && (_MSC_VER <= 1600)
  50. /* Workaround for warning:
  51. 'type cast' : conversion from 'int' to 'LPCSTR' of greater size */
  52. #undef CERT_STORE_PROV_MEMORY
  53. #undef CERT_STORE_PROV_SYSTEM_A
  54. #undef CERT_STORE_PROV_SYSTEM_W
  55. #define CERT_STORE_PROV_MEMORY ((LPCSTR)(size_t)2)
  56. #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR)(size_t)9)
  57. #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR)(size_t)10)
  58. #endif
  59. #ifndef SCH_CREDENTIALS_VERSION
  60. #define SCH_CREDENTIALS_VERSION 0x00000005
  61. typedef enum _eTlsAlgorithmUsage
  62. {
  63. TlsParametersCngAlgUsageKeyExchange,
  64. TlsParametersCngAlgUsageSignature,
  65. TlsParametersCngAlgUsageCipher,
  66. TlsParametersCngAlgUsageDigest,
  67. TlsParametersCngAlgUsageCertSig
  68. } eTlsAlgorithmUsage;
  69. typedef struct _CRYPTO_SETTINGS
  70. {
  71. eTlsAlgorithmUsage eAlgorithmUsage;
  72. UNICODE_STRING strCngAlgId;
  73. DWORD cChainingModes;
  74. PUNICODE_STRING rgstrChainingModes;
  75. DWORD dwMinBitLength;
  76. DWORD dwMaxBitLength;
  77. } CRYPTO_SETTINGS, * PCRYPTO_SETTINGS;
  78. typedef struct _TLS_PARAMETERS
  79. {
  80. DWORD cAlpnIds;
  81. PUNICODE_STRING rgstrAlpnIds;
  82. DWORD grbitDisabledProtocols;
  83. DWORD cDisabledCrypto;
  84. PCRYPTO_SETTINGS pDisabledCrypto;
  85. DWORD dwFlags;
  86. } TLS_PARAMETERS, * PTLS_PARAMETERS;
  87. typedef struct _SCH_CREDENTIALS
  88. {
  89. DWORD dwVersion;
  90. DWORD dwCredFormat;
  91. DWORD cCreds;
  92. PCCERT_CONTEXT* paCred;
  93. HCERTSTORE hRootStore;
  94. DWORD cMappers;
  95. struct _HMAPPER **aphMappers;
  96. DWORD dwSessionLifespan;
  97. DWORD dwFlags;
  98. DWORD cTlsParameters;
  99. PTLS_PARAMETERS pTlsParameters;
  100. } SCH_CREDENTIALS, * PSCH_CREDENTIALS;
  101. #define SCH_CRED_MAX_SUPPORTED_PARAMETERS 16
  102. #define SCH_CRED_MAX_SUPPORTED_ALPN_IDS 16
  103. #define SCH_CRED_MAX_SUPPORTED_CRYPTO_SETTINGS 16
  104. #define SCH_CRED_MAX_SUPPORTED_CHAINING_MODES 16
  105. #endif /* SCH_CREDENTIALS_VERSION */
  106. struct Curl_schannel_cred {
  107. CredHandle cred_handle;
  108. TimeStamp time_stamp;
  109. TCHAR *sni_hostname;
  110. #ifdef HAS_CLIENT_CERT_PATH
  111. HCERTSTORE client_cert_store;
  112. #endif
  113. int refcount;
  114. };
  115. struct Curl_schannel_ctxt {
  116. CtxtHandle ctxt_handle;
  117. TimeStamp time_stamp;
  118. };
  119. struct schannel_ssl_backend_data {
  120. struct Curl_schannel_cred *cred;
  121. struct Curl_schannel_ctxt *ctxt;
  122. SecPkgContext_StreamSizes stream_sizes;
  123. size_t encdata_length, decdata_length;
  124. size_t encdata_offset, decdata_offset;
  125. unsigned char *encdata_buffer, *decdata_buffer;
  126. /* encdata_is_incomplete: if encdata contains only a partial record that
  127. cannot be decrypted without another recv() (that is, status is
  128. SEC_E_INCOMPLETE_MESSAGE) then set this true. after an recv() adds
  129. more bytes into encdata then set this back to false. */
  130. bool encdata_is_incomplete;
  131. unsigned long req_flags, ret_flags;
  132. CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
  133. bool recv_sspi_close_notify; /* true if connection closed by close_notify */
  134. bool recv_connection_closed; /* true if connection closed, regardless how */
  135. bool recv_renegotiating; /* true if recv is doing renegotiation */
  136. bool use_alpn; /* true if ALPN is used for this connection */
  137. #ifdef HAS_MANUAL_VERIFY_API
  138. bool use_manual_cred_validation; /* true if manual cred validation is used */
  139. #endif
  140. BIT(sent_shutdown);
  141. };
  142. /* key to use at `multi->proto_hash` */
  143. #define MPROTO_SCHANNEL_CERT_SHARE_KEY "tls:schannel:cert:share"
  144. struct schannel_cert_share {
  145. unsigned char *CAinfo_blob_digest; /* CA info blob digest */
  146. size_t CAinfo_blob_size; /* CA info blob size */
  147. char *CAfile; /* CAfile path used to generate
  148. certificate store */
  149. HCERTSTORE cert_store; /* cached certificate store or
  150. NULL if none */
  151. struct curltime time; /* when the cached store was created */
  152. };
  153. HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf,
  154. const struct Curl_easy *data);
  155. bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf,
  156. const struct Curl_easy *data,
  157. HCERTSTORE cert_store);
  158. #endif /* USE_SCHANNEL */
  159. #endif /* HEADER_CURL_SCHANNEL_INT_H */