OpenSSL 3 HTTP client C++ example?

Benedikt Hallinger beni at hallinger.org
Wed Jun 22 08:08:04 UTC 2022


Thanks for the answer - Ii found out that it has todo with the -static 
flag.
My rationale was that I wanted to have openSSL statically compiled into 
my code, so its to be used easier in the transition period where 
OpenSSL3 is not yet rolled out in major distributions.

With dynamic linkage, it works like expected.
Thank you!



Am 2022-06-22 9:41, schrieb David von Oheimb:
> Hi again Beni,
> 
> On Wed, 2022-06-22 at 08:29 +0200, Benedikt Hallinger wrote:
> 
>> Hi David and thank you for your advice and example.
> 
> my pleasure.
> I was about to send a slightly improved version of my example code
> regarding the use of proxies and the expected content type - see
> attached
> and an extended sample invocation (of course, adapt "myproxy" as
> needed):
> 
> https_proxy=myproxy ./http_client https://example.com && echo ok
> 
>> I tried to compile it, run onto errors tough.
>> 
>> I just put the file into my openssl source tree, which is on commit:
>> 
>> commit 9e86b3815719d29f7bde2294403f97c42ce82a16 (HEAD,
>> 
>> origin/openssl-3.0)
> 
> I've just tried myself using that commit (and default configuration)
> and as expected everything works fine.
> 
>> $ gcc http_client.c -Iinclude -L. -lcrypto -lssl -o http_client
>> 
>> /usr/bin/ld: ./libssl.a(libssl-lib-ssl_cert.o): in function
>> 
>> `add_uris_recursive':
>> 
>> ssl_cert.c:(.text+0x116): undefined reference to `OSSL_STORE_open'
>> 
>> /usr/bin/ld: ssl_cert.c:(.text+0x134): undefined reference to
>> 
>> `OSSL_STORE_eof'
>> 
>> [...]
> 
> This issue is pretty surely unrelated to the example code itself
> but most likely due to some general build issue you have, such as some
> inconsistency with pre-installed OpenSSL versions.
> Sorry that I do not have the time to provide further aid on such
> general build issues.
> 
>  David
> 
>> Am 2022-06-21 22:52, schrieb David von Oheimb:
>> 
>> Hallo Beni,
>> 
>> good that you ask.
>> 
>> Using the new HTTP client API with TLS (possibly via a proxy) indeed
>> 
>> is not easy so far.
>> 
>> I'm going to improve this by adding some high-level helper functions
>> 
>> and extending the docs.
>> 
>> A good starting point when looking for examples is, as usual, the
>> 
>> application code in apps/.
>> 
>> In this case, there is some pretty useful code in apps/lib/apps.c,
>> 
>> but it turns out that the adaptation of app_http_get_asn1() and
>> 
>> app_http_tls_cb()
>> 
>> for receiving plain text (rather than ASN.1 encoded data) from the
>> 
>> server
>> 
>> is not straightforward because OSSL_HTTP_get() may close the SSL
>> read
>> 
>> BIO prematurely.
>> 
>> Also the behavior of non-blocking BIOs makes things a little more
>> 
>> tricky than expected.
>> 
>> Meanwhile I got it working - see the example attached.
>> 
>> Example build and usage:
>> 
>> gcc http_client.c -Iinclude -L. -lcrypto -lssl -o http_client
>> 
>> ./http_client https://httpbin.org/ && echo ok
>> 
>> Regards,
>> 
>> David
>> 
>> On 20.06.22 10:54, Benedikt Hallinger wrote:
>> 
>> Hi there,
>> 
>> I currently try to get my hands dirty with C++ and  the new HTTPs
>> 
>> client
>> 
>> introduced with OpenSSL 3.
>> 
>> However I struggle to get started. My goal is to open a https
>> 
>> secured
>> 
>> website and download its contents into a std::string for further
>> 
>> parsing.
>> 
>> Does someone on the list know of a small basic example?
>> 
>> I imagine that I'm not the first person implementing a HTTPs website
>> 
>> connector with OpenSSL 3.
>> 
>> Thank you for your support,
>> 
>> Beni


More information about the openssl-users mailing list