schannel_int.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #define HAS_MANUAL_VERIFY_API
  31. #endif
  32. #if defined(CryptStringToBinary) && defined(CRYPT_STRING_HEX) \
  33. && !defined(DISABLE_SCHANNEL_CLIENT_CERT)
  34. #define HAS_CLIENT_CERT_PATH
  35. #endif
  36. #ifndef CRYPT_DECODE_NOCOPY_FLAG
  37. #define CRYPT_DECODE_NOCOPY_FLAG 0x1
  38. #endif
  39. #ifndef CRYPT_DECODE_ALLOC_FLAG
  40. #define CRYPT_DECODE_ALLOC_FLAG 0x8000
  41. #endif
  42. #ifndef CERT_ALT_NAME_DNS_NAME
  43. #define CERT_ALT_NAME_DNS_NAME 3
  44. #endif
  45. #ifndef CERT_ALT_NAME_IP_ADDRESS
  46. #define CERT_ALT_NAME_IP_ADDRESS 8
  47. #endif
  48. #if defined(_MSC_VER) && (_MSC_VER <= 1600)
  49. /* Workaround for warning:
  50. 'type cast' : conversion from 'int' to 'LPCSTR' of greater size */
  51. #undef CERT_STORE_PROV_MEMORY
  52. #undef CERT_STORE_PROV_SYSTEM_A
  53. #undef CERT_STORE_PROV_SYSTEM_W
  54. #define CERT_STORE_PROV_MEMORY ((LPCSTR)(size_t)2)
  55. #define CERT_STORE_PROV_SYSTEM_A ((LPCSTR)(size_t)9)
  56. #define CERT_STORE_PROV_SYSTEM_W ((LPCSTR)(size_t)10)
  57. #endif
  58. #ifndef SCH_CREDENTIALS_VERSION
  59. #define SCH_CREDENTIALS_VERSION 0x00000005
  60. typedef enum _eTlsAlgorithmUsage
  61. {
  62. TlsParametersCngAlgUsageKeyExchange,
  63. TlsParametersCngAlgUsageSignature,
  64. TlsParametersCngAlgUsageCipher,
  65. TlsParametersCngAlgUsageDigest,
  66. TlsParametersCngAlgUsageCertSig
  67. } eTlsAlgorithmUsage;
  68. typedef struct _CRYPTO_SETTINGS
  69. {
  70. eTlsAlgorithmUsage eAlgorithmUsage;
  71. UNICODE_STRING strCngAlgId;
  72. DWORD cChainingModes;
  73. PUNICODE_STRING rgstrChainingModes;
  74. DWORD dwMinBitLength;
  75. DWORD dwMaxBitLength;
  76. } CRYPTO_SETTINGS, * PCRYPTO_SETTINGS;
  77. typedef struct _TLS_PARAMETERS
  78. {
  79. DWORD cAlpnIds;
  80. PUNICODE_STRING rgstrAlpnIds;
  81. DWORD grbitDisabledProtocols;
  82. DWORD cDisabledCrypto;
  83. PCRYPTO_SETTINGS pDisabledCrypto;
  84. DWORD dwFlags;
  85. } TLS_PARAMETERS, * PTLS_PARAMETERS;
  86. typedef struct _SCH_CREDENTIALS
  87. {
  88. DWORD dwVersion;
  89. DWORD dwCredFormat;
  90. DWORD cCreds;
  91. PCCERT_CONTEXT* paCred;
  92. HCERTSTORE hRootStore;
  93. DWORD cMappers;
  94. struct _HMAPPER **aphMappers;
  95. DWORD dwSessionLifespan;
  96. DWORD dwFlags;
  97. DWORD cTlsParameters;
  98. PTLS_PARAMETERS pTlsParameters;
  99. } SCH_CREDENTIALS, * PSCH_CREDENTIALS;
  100. #define SCH_CRED_MAX_SUPPORTED_PARAMETERS 16
  101. #define SCH_CRED_MAX_SUPPORTED_ALPN_IDS 16
  102. #define SCH_CRED_MAX_SUPPORTED_CRYPTO_SETTINGS 16
  103. #define SCH_CRED_MAX_SUPPORTED_CHAINING_MODES 16
  104. #endif /* SCH_CREDENTIALS_VERSION */
  105. struct Curl_schannel_cred {
  106. CredHandle cred_handle;
  107. TimeStamp time_stamp;
  108. TCHAR *sni_hostname;
  109. #ifdef HAS_CLIENT_CERT_PATH
  110. HCERTSTORE client_cert_store;
  111. #endif
  112. int refcount;
  113. };
  114. struct Curl_schannel_ctxt {
  115. CtxtHandle ctxt_handle;
  116. TimeStamp time_stamp;
  117. };
  118. struct schannel_ssl_backend_data {
  119. struct Curl_schannel_cred *cred;
  120. struct Curl_schannel_ctxt *ctxt;
  121. SecPkgContext_StreamSizes stream_sizes;
  122. size_t encdata_length, decdata_length;
  123. size_t encdata_offset, decdata_offset;
  124. unsigned char *encdata_buffer, *decdata_buffer;
  125. /* encdata_is_incomplete: if encdata contains only a partial record that
  126. can't be decrypted without another recv() (that is, status is
  127. SEC_E_INCOMPLETE_MESSAGE) then set this true. after an recv() adds
  128. more bytes into encdata then set this back to false. */
  129. bool encdata_is_incomplete;
  130. unsigned long req_flags, ret_flags;
  131. CURLcode recv_unrecoverable_err; /* schannel_recv had an unrecoverable err */
  132. bool recv_sspi_close_notify; /* true if connection closed by close_notify */
  133. bool recv_connection_closed; /* true if connection closed, regardless how */
  134. bool recv_renegotiating; /* true if recv is doing renegotiation */
  135. bool use_alpn; /* true if ALPN is used for this connection */
  136. #ifdef HAS_MANUAL_VERIFY_API
  137. bool use_manual_cred_validation; /* true if manual cred validation is used */
  138. #endif
  139. };
  140. struct schannel_multi_ssl_backend_data {
  141. unsigned char *CAinfo_blob_digest; /* CA info blob digest */
  142. size_t CAinfo_blob_size; /* CA info blob size */
  143. char *CAfile; /* CAfile path used to generate
  144. certificate store */
  145. HCERTSTORE cert_store; /* cached certificate store or
  146. NULL if none */
  147. struct curltime time; /* when the cached store was created */
  148. };
  149. HCERTSTORE Curl_schannel_get_cached_cert_store(struct Curl_cfilter *cf,
  150. const struct Curl_easy *data);
  151. bool Curl_schannel_set_cached_cert_store(struct Curl_cfilter *cf,
  152. const struct Curl_easy *data,
  153. HCERTSTORE cert_store);
  154. #endif /* USE_SCHANNEL */
  155. #endif /* HEADER_CURL_SCHANNEL_INT_H */