Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add HTTP request connection with authorization #33

Merged
merged 12 commits into from
Oct 18, 2020

Conversation

cspiel1
Copy link
Collaborator

@cspiel1 cspiel1 commented Oct 11, 2020

Adds client side basic and digest authorization and HTTP request code (request.c) that combines these with http_cli (client.c) in order to provide a higher level interface for performing HTTP request. Supports:

  • GET, POST, PUT, ... requests (HTTP method can be specified.)
  • basic, digest and bearer authentication
  • TLS

This new high level API should be usable from:

Tested with:

This PR is related to PR baresip/baresip#1099.

Function httpauth_digest_make_response takes a struct httpauth_digest_chall and
creates an httpauth_digest_resp. Especially, it computes the response field
due to RFC-2617.

Function httpauth_digest_response_encode serializes the struct
httpauth_digest_resp. The result is the Authorization header ready to send in
a http request.
This commit adds functions httpauth_basic_decode, httpauth_basic_make_response
and httpauth_basic_encode in order to generate a Basic Authorization header for
the HTTP client.
The function http_request has a parsing problem with ipv6 uris. This patch
adds function http_uri_decode to re_http.h that separates scheme, host, port
and path for http uris, which works also for IPv6 addresses.
This function is useful if a trusted CA is already given as PEM string.
@cspiel1 cspiel1 force-pushed the add_http_request branch 3 times, most recently from cf346f9 to dfe6ec2 Compare October 15, 2020 14:16
Adds functions that sets the client certificate and private key for HTTPS. The
certificate and key can be specified as:
- file with http_client_set_cert(), http_client_set_key() or
- directly as PEM string with http_client_set_certpem(),
  http_client_set_keypem().
The function http_client_set_cert() and http_client_set_certpem() accept PEM
file/data where certificate and private key are combined or only certificate
is contained. If the key is not contained then also http_client_set_key() or
http_client_set_keypem() has to be used.
- Wrong pointer notation in first parameter (char * instead of char **). But
  the function can be removed for simplicity.
- Renames also http_cli.tls_hostname to http_cli.tlshn which might be more
  libre conform naming style.
Adds a HTTP connection on top of client.c (struct http_cli) to handle the
authorization process by answering 401/403 responses. Supports basic, digest
and bearer authentication. Provides a high level interface for:
- setting HTTP method (GET, POST, PUT),
- setting content type and TLS host name,
- setting user, password and bearer,
- adding custom headers.
@sreimers sreimers merged commit a2f00f3 into baresip:master Oct 18, 2020
@cspiel1
Copy link
Collaborator Author

cspiel1 commented Oct 19, 2020

Thank you Sebastian! :-)

@cspiel1 cspiel1 deleted the add_http_request branch October 21, 2020 05:55
@sreimers sreimers added this to the v2.0.0 milestone Apr 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants