vauth.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #ifndef HEADER_CURL_VAUTH_H
  2. #define HEADER_CURL_VAUTH_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) Steve Holme, <[email protected]>.
  11. *
  12. * This software is licensed as described in the file COPYING, which
  13. * you should have received as part of this distribution. The terms
  14. * are also available at https://curl.se/docs/copyright.html.
  15. *
  16. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  17. * copies of the Software, and permit persons to whom the Software is
  18. * furnished to do so, under the terms of the COPYING file.
  19. *
  20. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  21. * KIND, either express or implied.
  22. *
  23. * SPDX-License-Identifier: curl
  24. *
  25. ***************************************************************************/
  26. #include <curl/curl.h>
  27. #include "../bufref.h"
  28. #include "../curlx/dynbuf.h"
  29. struct Curl_easy;
  30. struct connectdata;
  31. #ifndef CURL_DISABLE_DIGEST_AUTH
  32. struct digestdata;
  33. #endif
  34. #ifdef USE_NTLM
  35. struct ntlmdata;
  36. #endif
  37. #if (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) && defined(USE_SPNEGO)
  38. struct negotiatedata;
  39. #endif
  40. #ifdef USE_GSASL
  41. struct gsasldata;
  42. #endif
  43. #ifdef USE_WINDOWS_SSPI
  44. #include "../curl_sspi.h"
  45. #define GSS_ERROR(status) ((status) & 0x80000000)
  46. #endif
  47. /*
  48. * Curl_auth_allowed_to_host() tells if authentication, cookies or other
  49. * "sensitive data" can (still) be sent to this host.
  50. */
  51. bool Curl_auth_allowed_to_host(struct Curl_easy *data);
  52. /* This is used to build an SPN string */
  53. #ifndef USE_WINDOWS_SSPI
  54. char *Curl_auth_build_spn(const char *service, const char *host,
  55. const char *realm);
  56. #else
  57. TCHAR *Curl_auth_build_spn(const char *service, const char *host,
  58. const char *realm);
  59. #endif
  60. /* This is used to test if the user contains a Windows domain name */
  61. bool Curl_auth_user_contains_domain(const char *user);
  62. /* This is used to generate a PLAIN cleartext message */
  63. CURLcode Curl_auth_create_plain_message(const char *authzid,
  64. const char *authcid,
  65. const char *passwd,
  66. struct bufref *out);
  67. /* This is used to generate a LOGIN cleartext message */
  68. void Curl_auth_create_login_message(const char *value, struct bufref *out);
  69. /* This is used to generate an EXTERNAL cleartext message */
  70. void Curl_auth_create_external_message(const char *user, struct bufref *out);
  71. #ifndef CURL_DISABLE_DIGEST_AUTH
  72. /* This is used to generate a CRAM-MD5 response message */
  73. CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
  74. const char *userp,
  75. const char *passwdp,
  76. struct bufref *out);
  77. /* This is used to evaluate if DIGEST is supported */
  78. bool Curl_auth_is_digest_supported(void);
  79. /* This is used to generate a base64 encoded DIGEST-MD5 response message */
  80. CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
  81. const struct bufref *chlg,
  82. const char *userp,
  83. const char *passwdp,
  84. const char *service,
  85. struct bufref *out);
  86. /* This is used to decode an HTTP DIGEST challenge message */
  87. CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
  88. struct digestdata *digest);
  89. /* This is used to generate an HTTP DIGEST response message */
  90. CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
  91. const char *userp,
  92. const char *passwdp,
  93. const unsigned char *request,
  94. const unsigned char *uri,
  95. struct digestdata *digest,
  96. char **outptr, size_t *outlen);
  97. /* This is used to clean up the digest specific data */
  98. void Curl_auth_digest_cleanup(struct digestdata *digest);
  99. #else
  100. #define Curl_auth_is_digest_supported() FALSE
  101. #endif /* !CURL_DISABLE_DIGEST_AUTH */
  102. #ifdef USE_GSASL
  103. /* meta key for storing GSASL meta at connection */
  104. #define CURL_META_GSASL_CONN "meta:auth:gsasl:conn"
  105. #include <gsasl.h>
  106. struct gsasldata {
  107. Gsasl *ctx;
  108. Gsasl_session *client;
  109. };
  110. struct gsasldata *Curl_auth_gsasl_get(struct connectdata *conn);
  111. /* This is used to evaluate if MECH is supported by gsasl */
  112. bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
  113. const char *mech,
  114. struct gsasldata *gsasl);
  115. /* This is used to start a gsasl method */
  116. CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
  117. const char *userp,
  118. const char *passwdp,
  119. struct gsasldata *gsasl);
  120. /* This is used to process and generate a new SASL token */
  121. CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
  122. const struct bufref *chlg,
  123. struct gsasldata *gsasl,
  124. struct bufref *out);
  125. /* This is used to clean up the gsasl specific data */
  126. void Curl_auth_gsasl_cleanup(struct gsasldata *digest);
  127. #endif
  128. #ifdef USE_NTLM
  129. /* meta key for storing NTML meta at connection */
  130. #define CURL_META_NTLM_CONN "meta:auth:ntml:conn"
  131. /* meta key for storing NTML-PROXY meta at connection */
  132. #define CURL_META_NTLM_PROXY_CONN "meta:auth:ntml-proxy:conn"
  133. struct ntlmdata {
  134. #ifdef USE_WINDOWS_SSPI
  135. /* The sslContext is used for the Schannel bindings. The
  136. * api is available on the Windows 7 SDK and later.
  137. */
  138. #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
  139. CtxtHandle *sslContext;
  140. #endif
  141. CredHandle *credentials;
  142. CtxtHandle *context;
  143. SEC_WINNT_AUTH_IDENTITY identity;
  144. SEC_WINNT_AUTH_IDENTITY *p_identity;
  145. size_t token_max;
  146. BYTE *output_token;
  147. BYTE *input_token;
  148. size_t input_token_len;
  149. TCHAR *spn;
  150. #else
  151. unsigned int flags;
  152. unsigned char nonce[8];
  153. unsigned int target_info_len;
  154. void *target_info; /* TargetInfo received in the NTLM type-2 message */
  155. #endif
  156. };
  157. /* This is used to evaluate if NTLM is supported */
  158. bool Curl_auth_is_ntlm_supported(void);
  159. struct ntlmdata *Curl_auth_ntlm_get(struct connectdata *conn, bool proxy);
  160. void Curl_auth_ntlm_remove(struct connectdata *conn, bool proxy);
  161. /* This is used to clean up the NTLM specific data */
  162. void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm);
  163. /* This is used to generate a base64 encoded NTLM type-1 message */
  164. CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
  165. const char *userp,
  166. const char *passwdp,
  167. const char *service,
  168. const char *host,
  169. struct ntlmdata *ntlm,
  170. struct bufref *out);
  171. /* This is used to decode a base64 encoded NTLM type-2 message */
  172. CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
  173. const struct bufref *type2,
  174. struct ntlmdata *ntlm);
  175. /* This is used to generate a base64 encoded NTLM type-3 message */
  176. CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
  177. const char *userp,
  178. const char *passwdp,
  179. struct ntlmdata *ntlm,
  180. struct bufref *out);
  181. #else
  182. #define Curl_auth_is_ntlm_supported() FALSE
  183. #endif /* USE_NTLM */
  184. /* This is used to generate a base64 encoded OAuth 2.0 message */
  185. CURLcode Curl_auth_create_oauth_bearer_message(const char *user,
  186. const char *host,
  187. const long port,
  188. const char *bearer,
  189. struct bufref *out);
  190. /* This is used to generate a base64 encoded XOAuth 2.0 message */
  191. CURLcode Curl_auth_create_xoauth_bearer_message(const char *user,
  192. const char *bearer,
  193. struct bufref *out);
  194. #ifdef USE_KERBEROS5
  195. #ifdef HAVE_GSSAPI
  196. # ifdef HAVE_GSSGNU
  197. # include <gss.h>
  198. # else
  199. # include <gssapi/gssapi.h>
  200. # endif
  201. #endif
  202. /* meta key for storing KRB5 meta at connection */
  203. #define CURL_META_KRB5_CONN "meta:auth:krb5:conn"
  204. struct kerberos5data {
  205. #ifdef USE_WINDOWS_SSPI
  206. CredHandle *credentials;
  207. CtxtHandle *context;
  208. TCHAR *spn;
  209. SEC_WINNT_AUTH_IDENTITY identity;
  210. SEC_WINNT_AUTH_IDENTITY *p_identity;
  211. size_t token_max;
  212. BYTE *output_token;
  213. #else
  214. gss_ctx_id_t context;
  215. gss_name_t spn;
  216. #endif
  217. };
  218. struct kerberos5data *Curl_auth_krb5_get(struct connectdata *conn);
  219. /* This is used to evaluate if GSSAPI (Kerberos V5) is supported */
  220. bool Curl_auth_is_gssapi_supported(void);
  221. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
  222. message */
  223. CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
  224. const char *userp,
  225. const char *passwdp,
  226. const char *service,
  227. const char *host,
  228. const bool mutual,
  229. const struct bufref *chlg,
  230. struct kerberos5data *krb5,
  231. struct bufref *out);
  232. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
  233. token message */
  234. CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
  235. const char *authzid,
  236. const struct bufref *chlg,
  237. struct kerberos5data *krb5,
  238. struct bufref *out);
  239. /* This is used to clean up the GSSAPI specific data */
  240. void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5);
  241. #else
  242. #define Curl_auth_is_gssapi_supported() FALSE
  243. #endif /* USE_KERBEROS5 */
  244. #ifdef USE_SPNEGO
  245. bool Curl_auth_is_spnego_supported(void);
  246. /* meta key for storing NEGO meta at connection */
  247. #define CURL_META_NEGO_CONN "meta:auth:nego:conn"
  248. /* meta key for storing NEGO PROXY meta at connection */
  249. #define CURL_META_NEGO_PROXY_CONN "meta:auth:nego-proxy:conn"
  250. /* Struct used for Negotiate (SPNEGO) authentication */
  251. struct negotiatedata {
  252. #ifdef HAVE_GSSAPI
  253. OM_uint32 status;
  254. gss_ctx_id_t context;
  255. gss_name_t spn;
  256. gss_buffer_desc output_token;
  257. #ifdef CURL_GSSAPI_HAS_CHANNEL_BINDING
  258. struct dynbuf channel_binding_data;
  259. #endif
  260. #else
  261. #ifdef USE_WINDOWS_SSPI
  262. #ifdef SECPKG_ATTR_ENDPOINT_BINDINGS
  263. CtxtHandle *sslContext;
  264. #endif
  265. SECURITY_STATUS status;
  266. CredHandle *credentials;
  267. CtxtHandle *context;
  268. SEC_WINNT_AUTH_IDENTITY identity;
  269. SEC_WINNT_AUTH_IDENTITY *p_identity;
  270. TCHAR *spn;
  271. size_t token_max;
  272. BYTE *output_token;
  273. size_t output_token_length;
  274. #endif
  275. #endif
  276. BIT(noauthpersist);
  277. BIT(havenoauthpersist);
  278. BIT(havenegdata);
  279. BIT(havemultiplerequests);
  280. };
  281. struct negotiatedata *
  282. Curl_auth_nego_get(struct connectdata *conn, bool proxy);
  283. /* This is used to decode a base64 encoded SPNEGO (Negotiate) challenge
  284. message */
  285. CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
  286. const char *user,
  287. const char *password,
  288. const char *service,
  289. const char *host,
  290. const char *chlg64,
  291. struct negotiatedata *nego);
  292. /* This is used to generate a base64 encoded SPNEGO (Negotiate) response
  293. message */
  294. CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
  295. char **outptr, size_t *outlen);
  296. /* This is used to clean up the SPNEGO specific data */
  297. void Curl_auth_cleanup_spnego(struct negotiatedata *nego);
  298. #endif /* USE_SPNEGO */
  299. #endif /* HEADER_CURL_VAUTH_H */