2006-08-11 13:04:38 +02:00
|
|
|
/* http.h - HTTP protocol handler
|
2010-07-16 15:19:45 +02:00
|
|
|
* Copyright (C) 1999, 2000, 2001, 2003, 2006,
|
|
|
|
* 2010 Free Software Foundation, Inc.
|
2015-03-19 09:59:20 +01:00
|
|
|
* Copyright (C) 2015 g10 Code GmbH
|
2011-02-04 12:57:53 +01:00
|
|
|
*
|
2006-08-11 13:04:38 +02:00
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* This file is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of either
|
2006-08-11 13:04:38 +02:00
|
|
|
*
|
Change license for some files in common to LGPLv3+/GPLv2+.
Having the LGPL on the common GnuPG code helps to share code
between GnuPG and related projects (like GPGME and Libassuan). This
is good for interoperability and to reduces bugs.
* common/asshelp.c, common/asshelp.h, common/asshelp2.c, common/b64dec.c
* common/b64enc.c, common/convert.c, common/dns-cert.c
* common/dns-cert.h common/exechelp-posix.c, common/exechelp-w32.c
* common/exechelp-w32ce.c, common/exechelp.h, common/get-passphrase.c
* common/get-passphrase.h, common/gettime.c, common/gpgrlhelp.c
* common/helpfile.c, common/homedir.c, common/http.c, common/http.h
* common/i18n.c, common/init.c, common/init.h, common/iobuf.c
* common/iobuf.h, common/localename.c, common/membuf.c, common/membuf.h
* common/miscellaneous.c, common/openpgp-oid.c, common/openpgpdefs.h
* common/percent.c, common/pka.c, common/pka.h, common/session-env.c
* common/session-env.h, common/sexp-parse.h, common/sexputil.c
* common/signal.c, common/srv.c, common/srv.h, common/ssh-utils.c
* common/ssh-utils.h, common/sysutils.c, common/sysutils.h
* common/tlv.c, common/tlv.h, common/ttyio.c, common/ttyio.h
* common/userids.c, common/userids.h, common/xasprintf.c: Change
license to LGPLv3+/GPLv2+/
2012-04-20 15:43:06 +02:00
|
|
|
* - the GNU Lesser General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 3 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or
|
|
|
|
*
|
|
|
|
* - the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation; either version 2 of the License, or (at
|
|
|
|
* your option) any later version.
|
|
|
|
*
|
|
|
|
* or both in parallel, as here.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful,
|
2006-08-11 13:04:38 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2016-11-05 12:02:19 +01:00
|
|
|
* along with this program; if not, see <https://www.gnu.org/licenses/>.
|
2006-08-11 13:04:38 +02:00
|
|
|
*/
|
|
|
|
#ifndef GNUPG_COMMON_HTTP_H
|
2011-02-04 12:57:53 +01:00
|
|
|
#define GNUPG_COMMON_HTTP_H
|
2006-08-11 13:04:38 +02:00
|
|
|
|
|
|
|
#include <gpg-error.h>
|
2019-11-18 17:22:45 +01:00
|
|
|
#include "../common/fwddecl.h"
|
2006-08-11 13:04:38 +02:00
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
struct uri_tuple_s
|
2011-01-10 14:30:17 +01:00
|
|
|
{
|
2006-08-11 13:04:38 +02:00
|
|
|
struct uri_tuple_s *next;
|
|
|
|
const char *name; /* A pointer into name. */
|
|
|
|
char *value; /* A pointer to value (a Nul is always appended). */
|
|
|
|
size_t valuelen; /* The real length of the value; we need it
|
|
|
|
because the value may contain embedded Nuls. */
|
|
|
|
int no_value; /* True if no value has been given in the URL. */
|
|
|
|
};
|
|
|
|
typedef struct uri_tuple_s *uri_tuple_t;
|
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
struct parsed_uri_s
|
2006-08-11 13:04:38 +02:00
|
|
|
{
|
|
|
|
/* All these pointers point into BUFFER; most stuff is not escaped. */
|
2017-07-18 12:53:55 +02:00
|
|
|
char *original; /* Unmodified copy of the parsed URI. */
|
2011-01-10 14:30:17 +01:00
|
|
|
char *scheme; /* Pointer to the scheme string (always lowercase). */
|
|
|
|
unsigned int is_http:1; /* This is a HTTP style URI. */
|
2019-11-26 13:09:35 +01:00
|
|
|
unsigned int is_ldap:1; /* This is a LDAP style URI. */
|
2011-01-10 14:30:17 +01:00
|
|
|
unsigned int use_tls:1; /* Whether TLS should be used. */
|
2019-11-26 13:09:35 +01:00
|
|
|
unsigned int opaque:1; /* Unknown scheme; PATH has the rest. */
|
|
|
|
unsigned int v6lit:1; /* Host was given as a literal v6 address. */
|
|
|
|
unsigned int onion:1; /* .onion address given. */
|
2017-01-09 10:11:20 +01:00
|
|
|
unsigned int explicit_port :1; /* The port was explicitly specified. */
|
2020-12-17 16:09:31 +01:00
|
|
|
unsigned int ad_current:1; /* Use Active Directory's current user. */
|
2011-02-08 21:11:19 +01:00
|
|
|
char *auth; /* username/password for basic auth. */
|
2006-08-11 13:04:38 +02:00
|
|
|
char *host; /* Host (converted to lowercase). */
|
|
|
|
unsigned short port; /* Port (always set if the host is set). */
|
2018-11-22 22:27:56 +01:00
|
|
|
unsigned short off_host; /* Offset to the HOST respective PATH parts */
|
|
|
|
unsigned short off_path; /* in the original URI buffer. */
|
2006-08-11 13:04:38 +02:00
|
|
|
char *path; /* Path. */
|
|
|
|
uri_tuple_t params; /* ";xxxxx" */
|
|
|
|
uri_tuple_t query; /* "?xxx=yyy" */
|
|
|
|
char buffer[1]; /* Buffer which holds a (modified) copy of the URI. */
|
|
|
|
};
|
|
|
|
typedef struct parsed_uri_s *parsed_uri_t;
|
|
|
|
|
2015-03-31 12:00:58 +02:00
|
|
|
struct uri_tuple_s *uri_query_lookup (parsed_uri_t uri, const char *key);
|
2021-05-25 16:08:56 +02:00
|
|
|
const char *uri_query_value (parsed_uri_t url, const char *key);
|
2015-03-19 09:59:20 +01:00
|
|
|
|
2011-02-04 12:57:53 +01:00
|
|
|
typedef enum
|
2006-08-11 13:04:38 +02:00
|
|
|
{
|
|
|
|
HTTP_REQ_GET = 1,
|
|
|
|
HTTP_REQ_HEAD = 2,
|
2011-02-08 21:11:19 +01:00
|
|
|
HTTP_REQ_POST = 3,
|
|
|
|
HTTP_REQ_OPAQUE = 4 /* Internal use. */
|
2011-02-04 12:57:53 +01:00
|
|
|
}
|
2006-08-11 13:04:38 +02:00
|
|
|
http_req_t;
|
|
|
|
|
|
|
|
/* We put the flag values into an enum, so that gdb can display them. */
|
|
|
|
enum
|
2011-02-04 12:57:53 +01:00
|
|
|
{
|
2014-03-14 17:00:10 +01:00
|
|
|
HTTP_FLAG_TRY_PROXY = 1, /* Try to use a proxy. */
|
|
|
|
HTTP_FLAG_SHUTDOWN = 2, /* Close sending end after the request. */
|
2015-09-18 15:58:26 +02:00
|
|
|
HTTP_FLAG_FORCE_TOR = 4, /* Force a TOR connection. */
|
2016-04-26 21:57:56 +02:00
|
|
|
HTTP_FLAG_LOG_RESP = 8, /* Log the server response. */
|
2015-09-18 15:58:26 +02:00
|
|
|
HTTP_FLAG_FORCE_TLS = 16, /* Force the use of TLS. */
|
2014-03-14 17:00:10 +01:00
|
|
|
HTTP_FLAG_IGNORE_CL = 32, /* Ignore content-length. */
|
|
|
|
HTTP_FLAG_IGNORE_IPv4 = 64, /* Do not use IPv4. */
|
2016-04-26 21:57:56 +02:00
|
|
|
HTTP_FLAG_IGNORE_IPv6 = 128, /* Do not use IPv6. */
|
2017-02-21 14:55:04 +01:00
|
|
|
HTTP_FLAG_TRUST_DEF = 256, /* Use the CAs configured for HKP. */
|
2018-04-25 09:43:18 +02:00
|
|
|
HTTP_FLAG_TRUST_SYS = 512, /* Also use the system defined CAs. */
|
|
|
|
HTTP_FLAG_TRUST_CFG = 1024, /* Also use configured CAs. */
|
|
|
|
HTTP_FLAG_NO_CRL = 2048 /* Do not consult CRLs for https. */
|
2006-08-11 13:04:38 +02:00
|
|
|
};
|
|
|
|
|
2014-05-02 10:33:19 +02:00
|
|
|
|
|
|
|
struct http_session_s;
|
|
|
|
typedef struct http_session_s *http_session_t;
|
|
|
|
|
2006-08-14 16:40:07 +02:00
|
|
|
struct http_context_s;
|
2006-08-11 13:04:38 +02:00
|
|
|
typedef struct http_context_s *http_t;
|
|
|
|
|
2018-11-22 22:27:56 +01:00
|
|
|
/* An object used to track redirection infos. */
|
|
|
|
struct http_redir_info_s
|
|
|
|
{
|
|
|
|
unsigned int redirects_left; /* Number of still possible redirects. */
|
2019-11-18 17:22:45 +01:00
|
|
|
ctrl_t ctrl; /* The usual connection info or NULL. */
|
2018-11-22 22:27:56 +01:00
|
|
|
const char *orig_url; /* The original requested URL. */
|
|
|
|
unsigned int orig_onion:1; /* Original request was an onion address. */
|
|
|
|
unsigned int orig_https:1; /* Original request was a http address. */
|
|
|
|
unsigned int silent:1; /* No diagnostics. */
|
|
|
|
unsigned int allow_downgrade:1;/* Allow a downgrade from https to http. */
|
|
|
|
unsigned int trust_location:1; /* Trust the received Location header. */
|
|
|
|
};
|
|
|
|
typedef struct http_redir_info_s http_redir_info_t;
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-18 16:09:16 +01:00
|
|
|
/* A TLS verify callback function. */
|
|
|
|
typedef gpg_error_t (*http_verify_cb_t) (void *opaque,
|
|
|
|
http_t http,
|
|
|
|
http_session_t session,
|
|
|
|
unsigned int flags,
|
|
|
|
void *tls_context);
|
|
|
|
|
2017-01-11 10:34:49 +01:00
|
|
|
void http_set_verbose (int verbose, int debug);
|
|
|
|
|
2014-05-02 10:33:19 +02:00
|
|
|
void http_register_tls_callback (gpg_error_t (*cb)(http_t,http_session_t,int));
|
|
|
|
void http_register_tls_ca (const char *fname);
|
2018-04-25 09:43:18 +02:00
|
|
|
void http_register_cfg_ca (const char *fname);
|
2016-11-11 17:30:23 +01:00
|
|
|
void http_register_netactivity_cb (void (*cb)(void));
|
|
|
|
|
2014-05-02 10:33:19 +02:00
|
|
|
|
|
|
|
gpg_error_t http_session_new (http_session_t *r_session,
|
2016-04-26 21:57:56 +02:00
|
|
|
const char *intended_hostname,
|
2017-02-18 16:09:16 +01:00
|
|
|
unsigned int flags,
|
|
|
|
http_verify_cb_t cb,
|
|
|
|
void *cb_value);
|
2014-05-05 16:06:42 +02:00
|
|
|
http_session_t http_session_ref (http_session_t sess);
|
2014-05-02 10:33:19 +02:00
|
|
|
void http_session_release (http_session_t sess);
|
|
|
|
|
2014-05-19 09:47:18 +02:00
|
|
|
void http_session_set_log_cb (http_session_t sess,
|
|
|
|
void (*cb)(http_session_t, gpg_error_t,
|
|
|
|
const char *,
|
|
|
|
const void **, size_t *));
|
2017-06-08 08:23:06 +02:00
|
|
|
void http_session_set_timeout (http_session_t sess, unsigned int timeout);
|
2014-05-19 09:47:18 +02:00
|
|
|
|
2006-08-11 13:04:38 +02:00
|
|
|
|
2021-05-25 16:08:56 +02:00
|
|
|
#define HTTP_PARSE_NO_SCHEME_CHECK 1
|
2012-02-07 10:15:57 +01:00
|
|
|
gpg_error_t http_parse_uri (parsed_uri_t *ret_uri, const char *uri,
|
2021-05-25 16:08:56 +02:00
|
|
|
unsigned int flags);
|
2006-08-11 13:04:38 +02:00
|
|
|
|
|
|
|
void http_release_parsed_uri (parsed_uri_t uri);
|
|
|
|
|
2018-07-25 14:35:04 +02:00
|
|
|
gpg_error_t http_raw_connect (ctrl_t ctrl, http_t *r_hd,
|
2012-02-07 10:15:57 +01:00
|
|
|
const char *server, unsigned short port,
|
2017-06-08 08:23:06 +02:00
|
|
|
unsigned int flags, const char *srvtag,
|
|
|
|
unsigned int timeout);
|
2012-02-07 10:15:57 +01:00
|
|
|
|
2018-07-25 14:35:04 +02:00
|
|
|
gpg_error_t http_open (ctrl_t ctrl, http_t *r_hd, http_req_t reqtype,
|
2012-02-07 10:15:57 +01:00
|
|
|
const char *url,
|
2014-05-16 20:58:58 +02:00
|
|
|
const char *httphost,
|
2012-02-07 10:15:57 +01:00
|
|
|
const char *auth,
|
|
|
|
unsigned int flags,
|
|
|
|
const char *proxy,
|
2014-05-02 10:33:19 +02:00
|
|
|
http_session_t session,
|
2012-02-07 10:15:57 +01:00
|
|
|
const char *srvtag,
|
|
|
|
strlist_t headers);
|
2006-08-11 13:04:38 +02:00
|
|
|
|
|
|
|
void http_start_data (http_t hd);
|
|
|
|
|
2012-02-07 10:15:57 +01:00
|
|
|
gpg_error_t http_wait_response (http_t hd);
|
2006-08-11 13:04:38 +02:00
|
|
|
|
|
|
|
void http_close (http_t hd, int keep_read_stream);
|
|
|
|
|
2018-07-25 14:35:04 +02:00
|
|
|
gpg_error_t http_open_document (ctrl_t ctrl, http_t *r_hd,
|
2012-02-07 10:15:57 +01:00
|
|
|
const char *document,
|
|
|
|
const char *auth,
|
|
|
|
unsigned int flags,
|
|
|
|
const char *proxy,
|
2014-05-02 10:33:19 +02:00
|
|
|
http_session_t session,
|
2012-02-07 10:15:57 +01:00
|
|
|
const char *srvtag,
|
|
|
|
strlist_t headers);
|
2006-08-11 13:04:38 +02:00
|
|
|
|
2006-08-14 16:40:07 +02:00
|
|
|
estream_t http_get_read_ptr (http_t hd);
|
|
|
|
estream_t http_get_write_ptr (http_t hd);
|
|
|
|
unsigned int http_get_status_code (http_t hd);
|
2014-05-02 15:37:02 +02:00
|
|
|
const char *http_get_tls_info (http_t hd, const char *what);
|
2006-09-04 13:00:52 +02:00
|
|
|
const char *http_get_header (http_t hd, const char *name);
|
2014-05-02 10:33:19 +02:00
|
|
|
const char **http_get_header_names (http_t hd);
|
|
|
|
gpg_error_t http_verify_server_credentials (http_session_t sess);
|
2006-08-14 16:40:07 +02:00
|
|
|
|
|
|
|
char *http_escape_string (const char *string, const char *specials);
|
2011-01-20 14:12:53 +01:00
|
|
|
char *http_escape_data (const void *data, size_t datalen, const char *specials);
|
2006-08-14 16:40:07 +02:00
|
|
|
|
2018-11-22 22:27:56 +01:00
|
|
|
gpg_error_t http_prepare_redirect (http_redir_info_t *info,
|
|
|
|
unsigned int status_code,
|
|
|
|
const char *location, char **r_url);
|
|
|
|
|
2018-12-11 13:24:21 +01:00
|
|
|
const char *http_status2string (unsigned int status);
|
|
|
|
|
2006-08-14 16:40:07 +02:00
|
|
|
|
2006-08-11 13:04:38 +02:00
|
|
|
#endif /*GNUPG_COMMON_HTTP_H*/
|