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