OpenSSL 3 HTTP client C++ example?
Benedikt Hallinger
beni at hallinger.org
Wed Jun 22 06:29:12 UTC 2022
Hi David and thank you for your advice and example.
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)
Author: Randall S. Becker <randall.becker at nexbridge.ca>
Date: Tue Jun 14 06:10:53 2022 -0400
I built OpenSSL with:
./Configure -static no-pinshared no-weak-ssl-ciphers no-ssl3 no-idea
no-dtls1 && make clean && make -j4
This is what i get (gcc version 11.3.0 (Debian 11.3.0-3) ):
$ 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'
/usr/bin/ld: ssl_cert.c:(.text+0x140): undefined reference to
`OSSL_STORE_error'
/usr/bin/ld: ssl_cert.c:(.text+0x14c): undefined reference to
`OSSL_STORE_load'
/usr/bin/ld: ssl_cert.c:(.text+0x15c): undefined reference to
`OSSL_STORE_INFO_get_type'
/usr/bin/ld: ssl_cert.c:(.text+0x16e): undefined reference to
`OSSL_STORE_INFO_free'
/usr/bin/ld: ssl_cert.c:(.text+0x176): undefined reference to
`OSSL_STORE_eof'
/usr/bin/ld: ssl_cert.c:(.text+0x187): undefined reference to
`OSSL_STORE_close'
/usr/bin/ld: ssl_cert.c:(.text+0x1a8): undefined reference to
`OSSL_STORE_INFO_get0_NAME'
/usr/bin/ld: ssl_cert.c:(.text+0x1c4): undefined reference to
`OSSL_STORE_INFO_get0_CERT'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_cert.o): in function
`SSL_load_client_CA_file_ex':
ssl_cert.c:(.text+0x1b2b): undefined reference to `PEM_read_bio_X509'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_cert.o): in function
`SSL_add_file_cert_subjects_to_stack':
ssl_cert.c:(.text+0x1d73): undefined reference to `PEM_read_bio_X509'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_ciph.o): in function
`do_load_builtin_compressions_ossl_':
ssl_ciph.c:(.text+0x386): undefined reference to `COMP_get_type'
/usr/bin/ld: ssl_ciph.c:(.text+0x3c4): undefined reference to
`COMP_get_name'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_ciph.o): in function
`SSL_COMP_add_compression_method':
ssl_ciph.c:(.text+0x34dd): undefined reference to `COMP_get_type'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_ciph.o): in function
`SSL_COMP_get_name':
ssl_ciph.c:(.text+0x3696): undefined reference to `COMP_get_name'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_free.part.0':
ssl_lib.c:(.text+0xd13): undefined reference to `COMP_CTX_free'
/usr/bin/ld: ssl_lib.c:(.text+0xd2a): undefined reference to
`COMP_CTX_free'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function `SSL_clear':
ssl_lib.c:(.text+0x1e3b): undefined reference to `COMP_CTX_free'
/usr/bin/ld: ssl_lib.c:(.text+0x1e52): undefined reference to
`COMP_CTX_free'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function `SSL_accept':
ssl_lib.c:(.text+0x6d77): undefined reference to `COMP_CTX_free'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o):ssl_lib.c:(.text+0x6d8e):
more undefined references to `COMP_CTX_free' follow
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_set_default_verify_dir':
ssl_lib.c:(.text+0x8285): undefined reference to `X509_LOOKUP_hash_dir'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_set_default_verify_file':
ssl_lib.c:(.text+0x82da): undefined reference to `X509_LOOKUP_file'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_set_default_verify_store':
ssl_lib.c:(.text+0x833a): undefined reference to `X509_LOOKUP_store'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_load_verify_locations':
ssl_lib.c:(.text+0x8408): undefined reference to
`X509_STORE_load_file_ex'
/usr/bin/ld: ssl_lib.c:(.text+0x8422): undefined reference to
`X509_STORE_load_path'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_get0_peer_scts':
ssl_lib.c:(.text+0x90bf): undefined reference to
`OCSP_response_get1_basic'
/usr/bin/ld: ssl_lib.c:(.text+0x90e7): undefined reference to
`OCSP_resp_count'
/usr/bin/ld: ssl_lib.c:(.text+0x90f9): undefined reference to
`OCSP_resp_get0'
/usr/bin/ld: ssl_lib.c:(.text+0x910f): undefined reference to
`OCSP_SINGLERESP_get1_ext_d2i'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`ssl_validate_ct':
ssl_lib.c:(.text+0x9354): undefined reference to
`CT_POLICY_EVAL_CTX_new_ex'
/usr/bin/ld: ssl_lib.c:(.text+0x937f): undefined reference to
`CT_POLICY_EVAL_CTX_set1_cert'
/usr/bin/ld: ssl_lib.c:(.text+0x938a): undefined reference to
`CT_POLICY_EVAL_CTX_set1_issuer'
/usr/bin/ld: ssl_lib.c:(.text+0x93a0): undefined reference to
`CT_POLICY_EVAL_CTX_set_shared_CTLOG_STORE'
/usr/bin/ld: ssl_lib.c:(.text+0x93bf): undefined reference to
`CT_POLICY_EVAL_CTX_set_time'
/usr/bin/ld: ssl_lib.c:(.text+0x942f): undefined reference to
`CT_POLICY_EVAL_CTX_free'
/usr/bin/ld: ssl_lib.c:(.text+0x9478): undefined reference to
`CT_POLICY_EVAL_CTX_free'
/usr/bin/ld: ssl_lib.c:(.text+0x94be): undefined reference to
`CT_POLICY_EVAL_CTX_free'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_stateless':
ssl_lib.c:(.text+0xacd2): undefined reference to `COMP_CTX_free'
/usr/bin/ld: ssl_lib.c:(.text+0xace9): undefined reference to
`COMP_CTX_free'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_get_current_compression':
ssl_lib.c:(.text+0x7f2d): undefined reference to `COMP_CTX_get_method'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_get_current_expansion':
ssl_lib.c:(.text+0x7f4d): undefined reference to `COMP_CTX_get_method'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_set_default_verify_paths':
ssl_lib.c:(.text+0x8272): undefined reference to
`X509_STORE_set_default_paths_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_load_verify_file':
ssl_lib.c:(.text+0x83a2): undefined reference to
`X509_STORE_load_file_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_load_verify_dir':
ssl_lib.c:(.text+0x83b5): undefined reference to `X509_STORE_load_path'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_lib.o): in function
`SSL_CTX_load_verify_store':
ssl_lib.c:(.text+0x83d2): undefined reference to
`X509_STORE_load_store_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-t1_lib.o): in function
`ssl_get_auto_dh':
t1_lib.c:(.text+0x4d59): undefined reference to
`BN_get_rfc3526_prime_2048'
/usr/bin/ld: t1_lib.c:(.text+0x4d91): undefined reference to
`BN_get_rfc3526_prime_8192'
/usr/bin/ld: t1_lib.c:(.text+0x4e11): undefined reference to
`BN_get_rfc3526_prime_4096'
/usr/bin/ld: t1_lib.c:(.text+0x4e31): undefined reference to
`BN_get_rfc2409_prime_1024'
/usr/bin/ld: t1_lib.c:(.text+0x4eb9): undefined reference to
`BN_get_rfc3526_prime_3072'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`ssl_srp_server_param_with_username_intern':
tls_srp.c:(.text+0x778): undefined reference to `SRP_Calc_B_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`SSL_srp_server_param_with_username':
tls_srp.c:(.text+0x898): undefined reference to `SRP_Calc_B_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`SSL_set_srp_server_param_pw':
tls_srp.c:(.text+0x8e7): undefined reference to `SRP_get_default_gN'
/usr/bin/ld: tls_srp.c:(.text+0x971): undefined reference to
`SRP_create_verifier_BN_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`srp_generate_server_master_secret':
tls_srp.c:(.text+0xbd0): undefined reference to `SRP_Verify_A_mod_N'
/usr/bin/ld: tls_srp.c:(.text+0xc2f): undefined reference to
`SRP_Calc_u_ex'
/usr/bin/ld: tls_srp.c:(.text+0xc5e): undefined reference to
`SRP_Calc_server_key'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`srp_generate_client_master_secret':
tls_srp.c:(.text+0xd30): undefined reference to `SRP_Verify_B_mod_N'
/usr/bin/ld: tls_srp.c:(.text+0xd63): undefined reference to
`SRP_Calc_u_ex'
/usr/bin/ld: tls_srp.c:(.text+0xdbe): undefined reference to
`SRP_Calc_x_ex'
/usr/bin/ld: tls_srp.c:(.text+0xe00): undefined reference to
`SRP_Calc_client_key_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`srp_verify_server_param':
tls_srp.c:(.text+0x10ef): undefined reference to
`SRP_check_known_gN_param'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`ssl_srp_calc_a_param_intern':
tls_srp.c:(.text+0x11bd): undefined reference to `SRP_Calc_A'
/usr/bin/ld: ./libssl.a(libssl-lib-tls_srp.o): in function
`SRP_Calc_A_param':
tls_srp.c:(.text+0x124d): undefined reference to `SRP_Calc_A'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl3_record.o): in function
`ssl3_get_record':
ssl3_record.c:(.text+0x7dd): undefined reference to `COMP_expand_block'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl3_record.o): in function
`ssl3_do_uncompress':
ssl3_record.c:(.text+0x144a): undefined reference to `COMP_expand_block'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl3_record.o): in function
`ssl3_do_compress':
ssl3_record.c:(.text+0x14bf): undefined reference to
`COMP_compress_block'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl3_record.o): in function
`dtls1_process_record':
ssl3_record.c:(.text+0x3284): undefined reference to `COMP_expand_block'
/usr/bin/ld: ./libssl.a(libssl-lib-s3_enc.o): in function
`ssl3_change_cipher_state':
s3_enc.c:(.text+0x8a): undefined reference to `COMP_CTX_free'
/usr/bin/ld: s3_enc.c:(.text+0xa2): undefined reference to
`COMP_CTX_new'
/usr/bin/ld: s3_enc.c:(.text+0x208): undefined reference to
`COMP_CTX_free'
/usr/bin/ld: s3_enc.c:(.text+0x220): undefined reference to
`COMP_CTX_new'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_conf.o): in function
`cmd_ChainCAPath':
ssl_conf.c:(.text+0xf07): undefined reference to `X509_STORE_load_path'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_conf.o): in function
`cmd_VerifyCAFile':
ssl_conf.c:(.text+0xfab): undefined reference to
`X509_STORE_load_file_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_conf.o): in function
`cmd_VerifyCAPath':
ssl_conf.c:(.text+0x1067): undefined reference to `X509_STORE_load_path'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_conf.o): in function
`cmd_VerifyCAStore':
ssl_conf.c:(.text+0x110b): undefined reference to
`X509_STORE_load_store_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_conf.o): in function
`cmd_ChainCAStore':
ssl_conf.c:(.text+0x11db): undefined reference to
`X509_STORE_load_store_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_conf.o): in function
`cmd_ChainCAFile':
ssl_conf.c:(.text+0x12ab): undefined reference to
`X509_STORE_load_file_ex'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_rsa.o): in function
`SSL_use_certificate_file':
ssl_rsa.c:(.text+0xe1a): undefined reference to `PEM_read_bio_X509'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_rsa.o): in function
`SSL_CTX_use_certificate_file':
ssl_rsa.c:(.text+0x15a4): undefined reference to `PEM_read_bio_X509'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_rsa.o): in function
`SSL_CTX_use_certificate_chain_file':
ssl_rsa.c:(.text+0x1c7f): undefined reference to `PEM_read_bio_X509_AUX'
/usr/bin/ld: ssl_rsa.c:(.text+0x1d75): undefined reference to
`PEM_read_bio_X509'
/usr/bin/ld: ./libssl.a(libssl-lib-ssl_rsa.o): in function
`SSL_use_certificate_chain_file':
ssl_rsa.c:(.text+0x1f78): undefined reference to `PEM_read_bio_X509_AUX'
/usr/bin/ld: ssl_rsa.c:(.text+0x207e): undefined reference to
`PEM_read_bio_X509'
/usr/bin/ld: ./libssl.a(libssl-lib-t1_enc.o): in function
`tls1_change_cipher_state':
t1_enc.c:(.text+0x624): undefined reference to `COMP_CTX_free'
/usr/bin/ld: t1_enc.c:(.text+0x63d): undefined reference to
`COMP_CTX_new'
/usr/bin/ld: t1_enc.c:(.text+0x964): undefined reference to
`COMP_CTX_free'
/usr/bin/ld: t1_enc.c:(.text+0x97d): undefined reference to
`COMP_CTX_new'
collect2: error: ld returned 1 exit status
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