vauth.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. #ifndef HEADER_CURL_VAUTH_H
  2. #define HEADER_CURL_VAUTH_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2014 - 2022, Steve Holme, <steve_holme@hotmail.com>.
  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. struct Curl_easy;
  29. #if !defined(CURL_DISABLE_CRYPTO_AUTH)
  30. struct digestdata;
  31. #endif
  32. #if defined(USE_NTLM)
  33. struct ntlmdata;
  34. #endif
  35. #if defined(USE_KERBEROS5)
  36. struct kerberos5data;
  37. #endif
  38. #if (defined(HAVE_GSSAPI) || defined(USE_WINDOWS_SSPI)) && defined(USE_SPNEGO)
  39. struct negotiatedata;
  40. #endif
  41. #if defined(USE_GSASL)
  42. struct gsasldata;
  43. #endif
  44. #if defined(USE_WINDOWS_SSPI)
  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 a SPN string */
  53. #if !defined(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. CURLcode Curl_auth_create_login_message(const char *value,
  69. struct bufref *out);
  70. /* This is used to generate an EXTERNAL cleartext message */
  71. CURLcode Curl_auth_create_external_message(const char *user,
  72. struct bufref *out);
  73. #if !defined(CURL_DISABLE_CRYPTO_AUTH)
  74. /* This is used to generate a CRAM-MD5 response message */
  75. CURLcode Curl_auth_create_cram_md5_message(const struct bufref *chlg,
  76. const char *userp,
  77. const char *passwdp,
  78. struct bufref *out);
  79. /* This is used to evaluate if DIGEST is supported */
  80. bool Curl_auth_is_digest_supported(void);
  81. /* This is used to generate a base64 encoded DIGEST-MD5 response message */
  82. CURLcode Curl_auth_create_digest_md5_message(struct Curl_easy *data,
  83. const struct bufref *chlg,
  84. const char *userp,
  85. const char *passwdp,
  86. const char *service,
  87. struct bufref *out);
  88. /* This is used to decode an HTTP DIGEST challenge message */
  89. CURLcode Curl_auth_decode_digest_http_message(const char *chlg,
  90. struct digestdata *digest);
  91. /* This is used to generate an HTTP DIGEST response message */
  92. CURLcode Curl_auth_create_digest_http_message(struct Curl_easy *data,
  93. const char *userp,
  94. const char *passwdp,
  95. const unsigned char *request,
  96. const unsigned char *uri,
  97. struct digestdata *digest,
  98. char **outptr, size_t *outlen);
  99. /* This is used to clean up the digest specific data */
  100. void Curl_auth_digest_cleanup(struct digestdata *digest);
  101. #endif /* !CURL_DISABLE_CRYPTO_AUTH */
  102. #ifdef USE_GSASL
  103. /* This is used to evaluate if MECH is supported by gsasl */
  104. bool Curl_auth_gsasl_is_supported(struct Curl_easy *data,
  105. const char *mech,
  106. struct gsasldata *gsasl);
  107. /* This is used to start a gsasl method */
  108. CURLcode Curl_auth_gsasl_start(struct Curl_easy *data,
  109. const char *userp,
  110. const char *passwdp,
  111. struct gsasldata *gsasl);
  112. /* This is used to process and generate a new SASL token */
  113. CURLcode Curl_auth_gsasl_token(struct Curl_easy *data,
  114. const struct bufref *chlg,
  115. struct gsasldata *gsasl,
  116. struct bufref *out);
  117. /* This is used to clean up the gsasl specific data */
  118. void Curl_auth_gsasl_cleanup(struct gsasldata *digest);
  119. #endif
  120. #if defined(USE_NTLM)
  121. /* This is used to evaluate if NTLM is supported */
  122. bool Curl_auth_is_ntlm_supported(void);
  123. /* This is used to generate a base64 encoded NTLM type-1 message */
  124. CURLcode Curl_auth_create_ntlm_type1_message(struct Curl_easy *data,
  125. const char *userp,
  126. const char *passwdp,
  127. const char *service,
  128. const char *host,
  129. struct ntlmdata *ntlm,
  130. struct bufref *out);
  131. /* This is used to decode a base64 encoded NTLM type-2 message */
  132. CURLcode Curl_auth_decode_ntlm_type2_message(struct Curl_easy *data,
  133. const struct bufref *type2,
  134. struct ntlmdata *ntlm);
  135. /* This is used to generate a base64 encoded NTLM type-3 message */
  136. CURLcode Curl_auth_create_ntlm_type3_message(struct Curl_easy *data,
  137. const char *userp,
  138. const char *passwdp,
  139. struct ntlmdata *ntlm,
  140. struct bufref *out);
  141. /* This is used to clean up the NTLM specific data */
  142. void Curl_auth_cleanup_ntlm(struct ntlmdata *ntlm);
  143. #endif /* USE_NTLM */
  144. /* This is used to generate a base64 encoded OAuth 2.0 message */
  145. CURLcode Curl_auth_create_oauth_bearer_message(const char *user,
  146. const char *host,
  147. const long port,
  148. const char *bearer,
  149. struct bufref *out);
  150. /* This is used to generate a base64 encoded XOAuth 2.0 message */
  151. CURLcode Curl_auth_create_xoauth_bearer_message(const char *user,
  152. const char *bearer,
  153. struct bufref *out);
  154. #if defined(USE_KERBEROS5)
  155. /* This is used to evaluate if GSSAPI (Kerberos V5) is supported */
  156. bool Curl_auth_is_gssapi_supported(void);
  157. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
  158. message */
  159. CURLcode Curl_auth_create_gssapi_user_message(struct Curl_easy *data,
  160. const char *userp,
  161. const char *passwdp,
  162. const char *service,
  163. const char *host,
  164. const bool mutual,
  165. const struct bufref *chlg,
  166. struct kerberos5data *krb5,
  167. struct bufref *out);
  168. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
  169. token message */
  170. CURLcode Curl_auth_create_gssapi_security_message(struct Curl_easy *data,
  171. const char *authzid,
  172. const struct bufref *chlg,
  173. struct kerberos5data *krb5,
  174. struct bufref *out);
  175. /* This is used to clean up the GSSAPI specific data */
  176. void Curl_auth_cleanup_gssapi(struct kerberos5data *krb5);
  177. #endif /* USE_KERBEROS5 */
  178. #if defined(USE_SPNEGO)
  179. /* This is used to evaluate if SPNEGO (Negotiate) is supported */
  180. bool Curl_auth_is_spnego_supported(void);
  181. /* This is used to decode a base64 encoded SPNEGO (Negotiate) challenge
  182. message */
  183. CURLcode Curl_auth_decode_spnego_message(struct Curl_easy *data,
  184. const char *user,
  185. const char *passwood,
  186. const char *service,
  187. const char *host,
  188. const char *chlg64,
  189. struct negotiatedata *nego);
  190. /* This is used to generate a base64 encoded SPNEGO (Negotiate) response
  191. message */
  192. CURLcode Curl_auth_create_spnego_message(struct negotiatedata *nego,
  193. char **outptr, size_t *outlen);
  194. /* This is used to clean up the SPNEGO specific data */
  195. void Curl_auth_cleanup_spnego(struct negotiatedata *nego);
  196. #endif /* USE_SPNEGO */
  197. #endif /* HEADER_CURL_VAUTH_H */