summaryrefslogtreecommitdiffstats
path: root/crypto/http/http_lib.c
diff options
context:
space:
mode:
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-02-19 18:00:26 +0100
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>2020-04-02 18:17:00 +0200
commitafe554c2d244b4e7fc8c1b14acef806a2a581a8d (patch)
tree0af31aa1a20a0106423ee23522e35504e6013e1a /crypto/http/http_lib.c
parent98278b963171ece10a42d18594045b875103115b (diff)
Chunk 10 of CMP contribution to OpenSSL: CMP http client and related tests
Also improve the generic HTTP client w.r.t. proxy and no_proxy options. Certificate Management Protocol (CMP, RFC 4210) extension to OpenSSL Also includes CRMF (RFC 4211) and HTTP transfer (RFC 6712). Adds the CMP and CRMF API to libcrypto and the "cmp" app to the CLI. Adds extensive documentation and tests. Reviewed-by: Matt Caswell <matt@openssl.org> Reviewed-by: David von Oheimb <david.von.oheimb@siemens.com> (Merged from https://github.com/openssl/openssl/pull/11404)
Diffstat (limited to 'crypto/http/http_lib.c')
-rw-r--r--crypto/http/http_lib.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/crypto/http/http_lib.c b/crypto/http/http_lib.c
index 1d7ad0422a..41749f00e8 100644
--- a/crypto/http/http_lib.c
+++ b/crypto/http/http_lib.c
@@ -12,6 +12,8 @@
#include <openssl/err.h>
#include <string.h>
+#include "http_local.h"
+
/*
* Parse a URL and split it up into host, port and path components and
* whether it indicates SSL/TLS. Return 1 on success, 0 on error.
@@ -114,3 +116,39 @@ int OSSL_HTTP_parse_url(const char *url, char **phost, char **pport,
OPENSSL_free(buf);
return 0;
}
+
+int http_use_proxy(const char *no_proxy, const char *server)
+{
+ size_t sl = strlen(server);
+ const char *found = NULL;
+
+ if (no_proxy == NULL)
+ no_proxy = getenv("no_proxy");
+ if (no_proxy == NULL)
+ no_proxy = getenv("NO_PROXY");
+ if (no_proxy != NULL)
+ found = strstr(no_proxy, server);
+ while (found != NULL
+ && ((found != no_proxy && found[-1] != ' ' && found[-1] != ',')
+ || (found[sl] != '\0' && found[sl] != ' ' && found[sl] != ',')))
+ found = strstr(found + 1, server);
+ return found == NULL;
+}
+
+const char *http_adapt_proxy(const char *proxy, const char *no_proxy,
+ const char *server, int use_ssl)
+{
+ int prefix_len = strlen(HTTP_URL_PREFIX);
+
+ if (proxy == NULL)
+ proxy = getenv(use_ssl ? "https_proxy" : "http_proxy");
+ if (proxy == NULL)
+ proxy = getenv(use_ssl ? "HTTPS_PROXY" : "HTTP_PROXY");
+ if (proxy != NULL && strncmp(proxy, HTTP_URL_PREFIX, prefix_len) == 0)
+ proxy += prefix_len; /* skip any leading "http://" */
+ if (proxy != NULL && *proxy == '\0')
+ proxy = NULL;
+ if (proxy != NULL && !http_use_proxy(no_proxy, server))
+ proxy = NULL;
+ return proxy;
+}