47 Commits

Author SHA1 Message Date
Dmitry Ilyin
10ed1f1c28 Change code for samples 2022-10-04 17:57:01 +03:00
Azat Khuzhin
1bc62ce171 https-client: fix strndup() for mingw build
Right now it still reports [1]:

    2022-07-09T10:53:05.4152800Z ../sample/https-client.c:558:43: warning: implicit declaration of function 'strndup' [-Wimplicit-function-declaration]
    2022-07-09T10:53:05.4153300Z   558 |                         char *host_ipv6 = strndup(&host[1], strlen(&host[1]) - 1);
    2022-07-09T10:53:05.4153651Z       |                                           ^~~~~~~
    2022-07-09T10:53:05.4154095Z ../sample/https-client.c:558:43: warning: incompatible implicit declaration of built-in function 'strndup' [-Wbuiltin-declaration-

  [1]: https://github.com/libevent/libevent/runs/7263194178?check_suite_focus=true
2022-07-09 14:39:32 +03:00
William Marlow
e43376df2a Add missing strndup function on Windows to fix build on MSVC 2022
v2: Only define strndup on non-Mingw32 Windows
2022-07-09 13:16:00 +03:00
Azat Khuzhin
41239c9dac https-client: fix connect to ipv6 address with square brackets
getaddrinfo() cannot process addresses like "[::1]", only "::1"

Fixes: #1275
2022-05-12 07:37:19 +03:00
Azat Khuzhin
6135248a0c https-client: add newline into error messages 2020-10-27 01:19:40 +03:00
Azat Khuzhin
f51ec25306 https-client: add -4/-6 switches 2020-10-27 01:18:52 +03:00
okhowang(王沛文)
b45a02efab sample: add https-client-mbedtls 2020-09-16 11:57:52 +08:00
yuangongji
572a565130 https-client: load certificates from the system cert store on Windows 2019-09-17 20:57:01 +08:00
wenyg
891dd1880f
https-client: correction error checking
When connecting to a non-existent HTTPS service, the "req" is not null
but the "evhttp_request_get_response_code(req)" is zero.

Closes: #822 (cherry-picked)
2019-06-01 00:41:25 +03:00
Azat Khuzhin
428f36e5dd
https-client: do not try to free not initialized base
Otherwise:
  $ https-client --help
  Syntax:
     https-client -url <https-url> [-data data-file.bin] [-ignore-cert] [-retries num] [-timeout sec] [-crt crt]
  Example:
     https-client -url https://ip.appspot.com/
  [warn] event_base_free_: no base to free
2019-04-03 23:24:17 +03:00
Bernard Spil
28b8075400 Fix build with LibreSSL 2.7
LibreSSL 2.7 implements OpenSSL 1.1 API except for BIO_get_init()

See also: https://bugs.freebsd.org/226900
Signed-off-by: Bernard Spil <brnrd@FreeBSD.org>
Closes: #617 (cherry-pick)
2018-04-02 23:13:28 +03:00
Pierce Lopez
05318f1314 sample/https-client: use ERR_remove_*state() when we have them
ERR_remove_thread_state:
- openssl 0.9.8         does not have
- openssl 1.0/libressl  has
- openssl 1.1           deprecates
2017-03-06 02:44:58 +03:00
Pierce Lopez
5d18d87916 Do not check for ERR_remove_thread_state() (do not link ssl into every library)
This reverts commit c4e9d9bd662de7f575f2172c160795d452ebe709
("sample/https-client: check for ERR_remove_thread_state() existence").

Calling AC_SEARCH_LIBS() modifies LIBS - -lcrypto incorrectly
ends up in LIBS, and thus linked to by libevent_core.so.

Checking for ERR_remove_thread_state should no longer be needed
because it was introduced in openssl 1.0.0, and the previous line
0.9.8 had support discontinued at the end of 2015.

Fixes: #473
2017-03-06 01:39:29 +03:00
David Disseldorp
e139cbac0a sample/https-client: use host SSL certificate store by default
Currently a static (Debian) certificate path is used by default, which
can be overridden using the -crt parameter. This commit changes the
default behaviour such that the openssl default certificate store is
used, unless overridden by -crt.

Signed-off-by: David Disseldorp <ddiss@suse.de>
2017-02-28 00:39:50 +03:00
Jan Beich
d057c45e8f Unbreak build with LibreSSL after openssl 1.1 support added
Fixes: 3e9e0a0d46e4 ("Make it build using OpenSSL 1.1.0")
Fixes: #445
2017-01-30 00:25:26 +03:00
Azat Khuzhin
13a4acdae3 https-cilent: fix compilation warnings about unused vars/functions on win32 2016-12-06 13:27:02 +03:00
Kurt Roeckx
3e9e0a0d46 Make it build using OpenSSL 1.1.0
Rebased (azat):
- tabs instead of whitespaces
- make openssl-compat.h safe for complex expressions
- do not call sk_SSL_COMP_free() in 1.1 (fixes double free)

TODO:
- clean methods_bufferevent

Closes: #397 (cherry-picked)
2016-10-16 19:05:24 +03:00
Azat Khuzhin
fdf713a08b sample/https-client: allow to change path to ca-certificates
And default to one that linux have, for freebsd you will need:
$ https-client -url https://google.com -crt /usr/local/share/certs/ca-root-nss.crt
2015-11-24 01:37:06 +03:00
Azat Khuzhin
c4e9d9bd66 sample/https-client: check for ERR_remove_thread_state() existence
Fixes: freebsd 9.2 build
2015-11-24 01:19:25 +03:00
Azat Khuzhin
77ad68a658 sample/https-client: replace ERR_remove_state() by ERR_remove_thread_state()
Since ERR_remove_state() is deprecated:
  $ git log --grep ERR_remove_thread_state
  commit 2ecd2ededece66bf090fefc93ef3ddb672d9e71a
  Author: Bodo Möller <bodo@openssl.org>
  Date:   Wed Aug 13 19:30:01 2008 +0000

      Mention ERR_remove_state() deprecation, and ERR_remove_thread_state(NULL).

Link: https://www.openssl.org/docs/manmaster/crypto/ERR_remove_state.html
2015-11-18 15:39:08 +03:00
Azat Khuzhin
4637aa8841 sample/https-client: add -timeout option 2015-09-02 19:34:52 +03:00
Azat Khuzhin
f3d7ff5da2 sample/https-client: don't try to free uninitialized SSL
sample/https-client.c:459:3: warning: ‘ssl’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   SSL_free(ssl);
2015-08-19 13:23:20 +03:00
Azat Khuzhin
24a1f25ab6 sample/https-client: graceful exit with freeing memory (to make valgrind happy) 2015-08-19 13:19:41 +03:00
Andrey Skriabin
29a04825d0 https-client: correctly handle URLs with no path (like "https://host:port")
path == NULL check removed

Fixes: #233
Fixes: #234
2015-08-19 12:28:03 +03:00
Nick Mathewson
2e2d18bcd3 Merge pull request #170 from azat/https-client-retries
https-client: add -retries argument, for connection retries
2014-10-09 11:29:17 -04:00
Joakim Soderberg
5c7282f7a5 Fix compilation for older OpenSSL versions.
For instance OpenSSL 0.9.7 does not have SSL_set_tlsext_host_name.

Also add the missing EVENT__DISABLE_SAMPLES CMake option.
2014-09-24 13:46:09 +02:00
Azat Khuzhin
d9da844369 https-client: add -retries argument, for connection retries
Using evhttp_connection_set_retries() API.
2014-09-21 23:48:07 +04:00
Nick Mathewson
462e6b609b add a cast to https-client.c 2014-03-12 12:45:41 -04:00
Joakim Soderberg
d7be788780 Fix https-client compilation on Windows.
ssize_t is not defined. But using ssize_t for s in this context makes no
sense, since fread returns size_t.
2014-01-22 11:15:17 +01:00
Nick Mathewson
4cb44fdf56 Merge remote-tracking branch 'joakimsoderberg/new_cmake'
Conflicts:
	sample/https-client.c
2014-01-21 14:26:01 -05:00
Joakim Söderberg
4e1439588f Change all uses of WIN32 to _WIN32 2014-01-21 11:30:27 +01:00
Nick Mathewson
88ecda3bbb Fix a couple of "#ifdef WIN32" instances 2013-12-24 14:37:30 -05:00
Nick Mathewson
d1976f8ec4 Sample HTTPS Client: Set hostname for SNI extension (by f69m)
Patch from f69m on SourceForge
2013-12-24 14:05:44 -05:00
Nick Mathewson
90786eb073 Small tweaks to https-client.c 2013-12-24 12:59:36 -05:00
Joakim Soderberg
0ef1d04e44 Get rid of unknown pragma warnings. 2013-12-17 14:32:07 +01:00
Joakim Söderberg
69c3516be6 Get rid of deprecation warnings for OpenSSL on OSX 10.7+ 2013-12-17 13:28:23 +01:00
Joakim Soderberg
19222e5247 Added some GCC specific options.
- Added sample applications.
- Fixed the https-client to work on Windows kind of (No cert validation).
2013-12-13 16:27:10 +00:00
Alexey Ozeritsky
29af65ebfc https-client: code cleanup 2013-04-14 15:41:44 +04:00
Alexey Ozeritsky
902bf21e58 Merge branch 'master' of https://github.com/libevent/libevent into https 2013-04-14 15:12:22 +04:00
Nick Mathewson
95acdaa353 Another tweak to https-client.c 2013-04-10 17:56:54 -04:00
Nick Mathewson
8a90a850fc Remove http_struct.h usage in sample/https-client.c 2013-04-10 13:53:44 -04:00
Alexey Ozeritsky
c5887f73b7 POST supported, args supported 2013-03-11 18:31:19 +04:00
Patrick Pelletier
64d9f161fe use iSECPartners code to validate hostname in certificate
The problem is that if you go to a website whose certificate does not
match its hostname, it should fail.  Try this in a web browser for
https://www.kegel.com/ for example.  Your web browser will say the
certificate is for *.pair.com, not for www.kegel.com, and won't let
you visit it without clicking through a bunch of scary warnings.

However, prior to this commit, https-client was happy to fetch
https://www.kegel.com/ without complaining.  That is bad.  Now, with
this commit, it will properly complain, which is good:

pelletier@chives:~/src/libevent/sample$ ./https-client https://www.kegel.com/
Got 'MatchNotFound' for hostname 'www.kegel.com' and certificate:
/C=US/postalCode=15203/ST=Pennsylvania/L=Pittsburgh/street=Suite 210/street=2403 Sidney Street/O=pair Networks, Inc./OU=Provided by pair Networks, Inc./OU=PairWildcardSSL $250,000/CN=*.pair.com
some request failed - no idea which one though!
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
ppelletier@chives:~/src/libevent/sample$

It will still succeed for sites with an exactly-matching certificate,
such as https://github.com/ and that is also good!

However, the problem is that the iSECPartners code doesn't handle
wildcards, which means we reject https://ip.appspot.com/ even though
it is perfectly legitimate, because we don't understand the wildcard:

ppelletier@chives:~/src/libevent/sample$ ./https-client https://ip.appspot.com/
Got 'MatchNotFound' for hostname 'ip.appspot.com' and certificate:
/C=US/ST=California/L=Mountain View/O=Google Inc/CN=*.appspot.com
some request failed - no idea which one though!
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
ppelletier@chives:~/src/libevent/sample$

So, we need to fix this.  In other words, "to be continued..."
2013-02-27 21:22:03 -08:00
Patrick Pelletier
aacd674c94 use Debian's default root certificate location
as suggested here:
http://archives.seul.org/libevent/users/Feb-2013/msg00034.html

although curl's acinclude.m4 reveals many other possibilities:

dnl /etc/ssl/certs/ca-certificates.crt Debian systems
dnl /etc/pki/tls/certs/ca-bundle.crt Redhat and Mandriva
dnl /usr/share/ssl/certs/ca-bundle.crt old(er) Redhat
dnl /usr/local/share/certs/ca-root.crt FreeBSD
dnl /etc/ssl/cert.pem OpenBSD
dnl /etc/ssl/certs/ (ca path) SUSE

And none of these cover Windows :(
2013-02-27 21:22:03 -08:00
Patrick Pelletier
5754d96a6e better handling of OpenSSL errors 2013-02-27 21:22:03 -08:00
Patrick Pelletier
42d7441ac4 https-client was putting newlines at 256-byte boundaries
presumably this was meant to put a ">" before every line, but that
isn't what it does, since evbuffer_remove is simply returning
fixed-size chunks.  So, when retrieving a document of more than 256
bytes (e. g. any nontrivial document), we got "> " and newlines thrown
in at very arbitrary places.
2013-02-27 21:22:03 -08:00
Catalin Patulea
be46c99b89 Add sample/https-client.c, an example of stacking evhttp as a client on top of bufferevent_ssl.
Signed-off-by: Catalin Patulea <catalinp@google.com>
2013-02-27 16:06:56 -08:00