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