curl_sasl.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #ifndef HEADER_CURL_SASL_H
  2. #define HEADER_CURL_SASL_H
  3. /***************************************************************************
  4. * _ _ ____ _
  5. * Project ___| | | | _ \| |
  6. * / __| | | | |_) | |
  7. * | (__| |_| | _ <| |___
  8. * \___|\___/|_| \_\_____|
  9. *
  10. * Copyright (C) 2012 - 2013, 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 "pingpong.h"
  25. /* Authentication mechanism values */
  26. #define SASL_AUTH_NONE 0
  27. #define SASL_AUTH_ANY ~0U
  28. /* Authentication mechanism flags */
  29. #define SASL_MECH_LOGIN (1 << 0)
  30. #define SASL_MECH_PLAIN (1 << 1)
  31. #define SASL_MECH_CRAM_MD5 (1 << 2)
  32. #define SASL_MECH_DIGEST_MD5 (1 << 3)
  33. #define SASL_MECH_GSSAPI (1 << 4)
  34. #define SASL_MECH_EXTERNAL (1 << 5)
  35. #define SASL_MECH_NTLM (1 << 6)
  36. #define SASL_MECH_XOAUTH2 (1 << 7)
  37. /* Authentication mechanism strings */
  38. #define SASL_MECH_STRING_LOGIN "LOGIN"
  39. #define SASL_MECH_STRING_PLAIN "PLAIN"
  40. #define SASL_MECH_STRING_CRAM_MD5 "CRAM-MD5"
  41. #define SASL_MECH_STRING_DIGEST_MD5 "DIGEST-MD5"
  42. #define SASL_MECH_STRING_GSSAPI "GSSAPI"
  43. #define SASL_MECH_STRING_EXTERNAL "EXTERNAL"
  44. #define SASL_MECH_STRING_NTLM "NTLM"
  45. #define SASL_MECH_STRING_XOAUTH2 "XOAUTH2"
  46. /* This is used to test whether the line starts with the given mechanism */
  47. #define sasl_mech_equal(line, wordlen, mech) \
  48. (wordlen == (sizeof(mech) - 1) / sizeof(char) && \
  49. !memcmp(line, mech, wordlen))
  50. /* This is used to generate a base64 encoded PLAIN authentication message */
  51. CURLcode Curl_sasl_create_plain_message(struct SessionHandle *data,
  52. const char *userp,
  53. const char *passwdp,
  54. char **outptr, size_t *outlen);
  55. /* This is used to generate a base64 encoded LOGIN authentication message
  56. containing either the user name or password details */
  57. CURLcode Curl_sasl_create_login_message(struct SessionHandle *data,
  58. const char *valuep, char **outptr,
  59. size_t *outlen);
  60. #ifndef CURL_DISABLE_CRYPTO_AUTH
  61. /* This is used to decode a base64 encoded CRAM-MD5 challange message */
  62. CURLcode Curl_sasl_decode_cram_md5_message(const char *chlg64, char **outptr,
  63. size_t *outlen);
  64. /* This is used to generate a base64 encoded CRAM-MD5 response message */
  65. CURLcode Curl_sasl_create_cram_md5_message(struct SessionHandle *data,
  66. const char *chlg,
  67. const char *user,
  68. const char *passwdp,
  69. char **outptr, size_t *outlen);
  70. /* This is used to decode a base64 encoded DIGEST-MD5 challange message */
  71. CURLcode Curl_sasl_decode_digest_md5_message(const char *chlg64,
  72. char *nonce, size_t nlen,
  73. char *realm, size_t rlen,
  74. char *alg, size_t alen);
  75. /* This is used to generate a base64 encoded DIGEST-MD5 response message */
  76. CURLcode Curl_sasl_create_digest_md5_message(struct SessionHandle *data,
  77. const char *nonce,
  78. const char *realm,
  79. const char *user,
  80. const char *passwdp,
  81. const char *service,
  82. char **outptr, size_t *outlen);
  83. #endif
  84. #ifdef USE_NTLM
  85. /* This is used to generate a base64 encoded NTLM type-1 message */
  86. CURLcode Curl_sasl_create_ntlm_type1_message(const char *userp,
  87. const char *passwdp,
  88. struct ntlmdata *ntlm,
  89. char **outptr,
  90. size_t *outlen);
  91. /* This is used to decode a base64 encoded NTLM type-2 message */
  92. CURLcode Curl_sasl_decode_ntlm_type2_message(struct SessionHandle *data,
  93. const char *type2msg,
  94. struct ntlmdata *ntlm);
  95. /* This is used to generate a base64 encoded NTLM type-3 message */
  96. CURLcode Curl_sasl_create_ntlm_type3_message(struct SessionHandle *data,
  97. const char *userp,
  98. const char *passwdp,
  99. struct ntlmdata *ntlm,
  100. char **outptr, size_t *outlen);
  101. #endif /* USE_NTLM */
  102. /* This is used to generate a base64 encoded XOAUTH2 authentication message
  103. containing the user name and bearer token */
  104. CURLcode Curl_sasl_create_xoauth2_message(struct SessionHandle *data,
  105. const char *user,
  106. const char *bearer,
  107. char **outptr, size_t *outlen);
  108. /* This is used to cleanup any libraries or curl modules used by the sasl
  109. functions */
  110. void Curl_sasl_cleanup(struct connectdata *conn, unsigned int authused);
  111. #endif /* HEADER_CURL_SASL_H */