curl_sasl.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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, <daniel@haxx.se>, 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. struct ntlmdata;
  28. #if defined(USE_KRB5)
  29. struct kerberos5data;
  30. #endif
  31. /* Authentication mechanism values */
  32. #define SASL_AUTH_NONE 0
  33. #define SASL_AUTH_ANY ~0U
  34. /* Authentication mechanism flags */
  35. #define SASL_MECH_LOGIN (1 << 0)
  36. #define SASL_MECH_PLAIN (1 << 1)
  37. #define SASL_MECH_CRAM_MD5 (1 << 2)
  38. #define SASL_MECH_DIGEST_MD5 (1 << 3)
  39. #define SASL_MECH_GSSAPI (1 << 4)
  40. #define SASL_MECH_EXTERNAL (1 << 5)
  41. #define SASL_MECH_NTLM (1 << 6)
  42. #define SASL_MECH_XOAUTH2 (1 << 7)
  43. /* Authentication mechanism strings */
  44. #define SASL_MECH_STRING_LOGIN "LOGIN"
  45. #define SASL_MECH_STRING_PLAIN "PLAIN"
  46. #define SASL_MECH_STRING_CRAM_MD5 "CRAM-MD5"
  47. #define SASL_MECH_STRING_DIGEST_MD5 "DIGEST-MD5"
  48. #define SASL_MECH_STRING_GSSAPI "GSSAPI"
  49. #define SASL_MECH_STRING_EXTERNAL "EXTERNAL"
  50. #define SASL_MECH_STRING_NTLM "NTLM"
  51. #define SASL_MECH_STRING_XOAUTH2 "XOAUTH2"
  52. /* This is used to test whether the line starts with the given mechanism */
  53. #define sasl_mech_equal(line, wordlen, mech) \
  54. (wordlen == (sizeof(mech) - 1) / sizeof(char) && \
  55. !memcmp(line, mech, wordlen))
  56. /* This is used to build a SPN string */
  57. #if !defined(USE_WINDOWS_SSPI)
  58. char *Curl_sasl_build_spn(const char *service, const char *instance);
  59. #else
  60. TCHAR *Curl_sasl_build_spn(const char *service, const char *instance);
  61. #endif
  62. /* This is used to generate a base64 encoded PLAIN authentication message */
  63. CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data,
  64. const char *userp,
  65. const char *passwdp,
  66. char **outptr, size_t *outlen);
  67. /* This is used to generate a base64 encoded LOGIN authentication message
  68. containing either the user name or password details */
  69. CURLcode Curl_sasl_create_login_message(struct SessionHandle *data,
  70. const char *valuep, char **outptr,
  71. size_t *outlen);
  72. #ifndef CURL_DISABLE_CRYPTO_AUTH
  73. /* This is used to decode a base64 encoded CRAM-MD5 challange message */
  74. CURLcode Curl_sasl_decode_cram_md5_message(const char *chlg64, char **outptr,
  75. size_t *outlen);
  76. /* This is used to generate a base64 encoded CRAM-MD5 response message */
  77. CURLcode Curl_sasl_create_cram_md5_message(struct SessionHandle *data,
  78. const char *chlg,
  79. const char *user,
  80. const char *passwdp,
  81. char **outptr, size_t *outlen);
  82. /* This is used to generate a base64 encoded DIGEST-MD5 response message */
  83. CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
  84. const char *chlg64,
  85. const char *userp,
  86. const char *passwdp,
  87. const char *service,
  88. char **outptr, size_t *outlen);
  89. #endif
  90. #ifdef USE_NTLM
  91. /* This is used to generate a base64 encoded NTLM type-1 message */
  92. CURLcode Curl_sasl_create_ntlm_type1_message(const char *userp,
  93. const char *passwdp,
  94. struct ntlmdata *ntlm,
  95. char **outptr,
  96. size_t *outlen);
  97. /* This is used to decode a base64 encoded NTLM type-2 message */
  98. CURLcode Curl_sasl_decode_ntlm_type2_message(struct SessionHandle *data,
  99. const char *type2msg,
  100. struct ntlmdata *ntlm);
  101. /* This is used to generate a base64 encoded NTLM type-3 message */
  102. CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
  103. const char *userp,
  104. const char *passwdp,
  105. struct ntlmdata *ntlm,
  106. char **outptr, size_t *outlen);
  107. #endif /* USE_NTLM */
  108. #if defined(USE_KRB5)
  109. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) user token
  110. message */
  111. CURLcode Curl_sasl_create_gssapi_user_message(struct SessionHandle *data,
  112. const char *userp,
  113. const char *passwdp,
  114. const char *service,
  115. const bool mutual,
  116. const char *chlg64,
  117. struct kerberos5data *krb5,
  118. char **outptr, size_t *outlen);
  119. /* This is used to generate a base64 encoded GSSAPI (Kerberos V5) security
  120. token message */
  121. CURLcode Curl_sasl_create_gssapi_security_message(struct SessionHandle *data,
  122. const char *input,
  123. struct kerberos5data *krb5,
  124. char **outptr,
  125. size_t *outlen);
  126. #endif /* USE_KRB5 */
  127. /* This is used to generate a base64 encoded XOAUTH2 authentication message
  128. containing the user name and bearer token */
  129. CURLcode Curl_sasl_create_xoauth2_message(struct SessionHandle *data,
  130. const char *user,
  131. const char *bearer,
  132. char **outptr, size_t *outlen);
  133. /* This is used to cleanup any libraries or curl modules used by the sasl
  134. functions */
  135. void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
  136. #endif /* HEADER_CURL_SASL_H */