curl_sasl.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #ifndef HEADER_CURL_SASL_H
  2. #define HEADER_CURL_SASL_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2012 - 2014, Daniel Stenberg, <[email protected]>, et al.
  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 http://curl.haxx.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. ***************************************************************************/
  24. #include <curl/curl.h>
  25. struct SessionHandle;
  26. struct connectdata;
  27. #if !defined(CURL_DISABLE_CRYPTO_AUTH)
  28. struct digestdata;
  29. #endif
  30. #if defined(USE_NTLM)
  31. struct ntlmdata;
  32. #endif
  33. #if defined(USE_KERBEROS5)
  34. struct kerberos5data;
  35. #endif
  36. /* Authentication mechanism values */
  37. #define SASL_AUTH_NONE 0
  38. #define SASL_AUTH_ANY ~0U
  39. /* Authentication mechanism flags */
  40. #define SASL_MECH_LOGIN (1 << 0)
  41. #define SASL_MECH_PLAIN (1 << 1)
  42. #define SASL_MECH_CRAM_MD5 (1 << 2)
  43. #define SASL_MECH_DIGEST_MD5 (1 << 3)
  44. #define SASL_MECH_GSSAPI (1 << 4)
  45. #define SASL_MECH_EXTERNAL (1 << 5)
  46. #define SASL_MECH_NTLM (1 << 6)
  47. #define SASL_MECH_XOAUTH2 (1 << 7)
  48. /* Authentication mechanism strings */
  49. #define SASL_MECH_STRING_LOGIN "LOGIN"
  50. #define SASL_MECH_STRING_PLAIN "PLAIN"
  51. #define SASL_MECH_STRING_CRAM_MD5 "CRAM-MD5"
  52. #define SASL_MECH_STRING_DIGEST_MD5 "DIGEST-MD5"
  53. #define SASL_MECH_STRING_GSSAPI "GSSAPI"
  54. #define SASL_MECH_STRING_EXTERNAL "EXTERNAL"
  55. #define SASL_MECH_STRING_NTLM "NTLM"
  56. #define SASL_MECH_STRING_XOAUTH2 "XOAUTH2"
  57. enum {
  58. CURLDIGESTALGO_MD5,
  59. CURLDIGESTALGO_MD5SESS
  60. };
  61. /* This is used to test whether the line starts with the given mechanism */
  62. #define sasl_mech_equal(line, wordlen, mech) \
  63. (wordlen == (sizeof(mech) - 1) / sizeof(char) && \
  64. !memcmp(line, mech, wordlen))
  65. /* This is used to build a SPN string */
  66. #if !defined(USE_WINDOWS_SSPI)
  67. char *Curl_sasl_build_spn(const char *service, const char *instance);
  68. #else
  69. TCHAR *Curl_sasl_build_spn(const char *service, const char *instance);
  70. #endif
  71. /* This is used to generate a base64 encoded PLAIN authentication message */
  72. CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data,
  73. const char *userp,
  74. const char *passwdp,
  75. char **outptr, size_t *outlen);
  76. /* This is used to generate a base64 encoded LOGIN authentication message
  77. containing either the user name or password details */
  78. CURLcode Curl_sasl_create_login_message(struct SessionHandle *data,
  79. const char *valuep, char **outptr,
  80. size_t *outlen);
  81. #ifndef CURL_DISABLE_CRYPTO_AUTH
  82. /* This is used to decode a base64 encoded CRAM-MD5 challange message */
  83. CURLcode Curl_sasl_decode_cram_md5_message(const char *chlg64, char **outptr,
  84. size_t *outlen);
  85. /* This is used to generate a base64 encoded CRAM-MD5 response message */
  86. CURLcode Curl_sasl_create_cram_md5_message(struct SessionHandle *data,
  87. const char *chlg,
  88. const char *user,
  89. const char *passwdp,
  90. char **outptr, size_t *outlen);
  91. /* This is used to generate a base64 encoded DIGEST-MD5 response message */
  92. CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
  93. const char *chlg64,
  94. const char *userp,
  95. const char *passwdp,
  96. const char *service,
  97. char **outptr, size_t *outlen);
  98. /* This is used to decode a HTTP DIGEST challenge message */
  99. CURLcode Curl_sasl_decode_digest_http_message(const char *chlg,
  100. struct digestdata *digest);
  101. /* This is used to generate a HTTP DIGEST response message */
  102. CURLcode Curl_sasl_create_digest_http_message(struct SessionHandle *data,
  103. const char *userp,
  104. const char *passwdp,
  105. const unsigned char *request,
  106. const unsigned char *uri,
  107. struct digestdata *digest,
  108. char **outptr, size_t *outlen);
  109. /* This is used to clean up the digest specific data */
  110. void Curl_sasl_digest_cleanup(struct digestdata *digest);
  111. #endif
  112. #ifdef USE_NTLM
  113. /* This is used to generate a base64 encoded NTLM type-1 message */
  114. CURLcode Curl_sasl_create_ntlm_type1_message(const char *userp,
  115. const char *passwdp,
  116. struct ntlmdata *ntlm,
  117. char **outptr,
  118. size_t *outlen);
  119. /* This is used to decode a base64 encoded NTLM type-2 message */
  120. CURLcode Curl_sasl_decode_ntlm_type2_message(struct SessionHandle *data,
  121. const char *type2msg,
  122. struct ntlmdata *ntlm);
  123. /* This is used to generate a base64 encoded NTLM type-3 message */
  124. CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
  125. const char *userp,
  126. const char *passwdp,
  127. struct ntlmdata *ntlm,
  128. char **outptr, size_t *outlen);
  129. /* This is used to clean up the ntlm specific data */
  130. void Curl_sasl_ntlm_cleanup(struct ntlmdata *ntlm);
  131. #endif /* USE_NTLM */
  132. #if defined(USE_KERBEROS5)
  133. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
  134. message */
  135. CURLcode Curl_sasl_create_gssapi_user_message(struct SessionHandle *data,
  136. const char *userp,
  137. const char *passwdp,
  138. const char *service,
  139. const bool mutual,
  140. const char *chlg64,
  141. struct kerberos5data *krb5,
  142. char **outptr, size_t *outlen);
  143. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
  144. token message */
  145. CURLcode Curl_sasl_create_gssapi_security_message(struct SessionHandle *data,
  146. const char *input,
  147. struct kerberos5data *krb5,
  148. char **outptr,
  149. size_t *outlen);
  150. /* This is used to clean up the gssapi specific data */
  151. void Curl_sasl_gssapi_cleanup(struct kerberos5data *krb5);
  152. #endif /* USE_KERBEROS5 */
  153. /* This is used to generate a base64 encoded XOAUTH2 authentication message
  154. containing the user name and bearer token */
  155. CURLcode Curl_sasl_create_xoauth2_message(struct SessionHandle *data,
  156. const char *user,
  157. const char *bearer,
  158. char **outptr, size_t *outlen);
  159. /* This is used to cleanup any libraries or curl modules used by the sasl
  160. functions */
  161. void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
  162. #endif /* HEADER_CURL_SASL_H */