Artifactspublic-v0

curl

master
ply4 git calls55 ms289 KiB3 cachedprotocol v2
130 lines5.2 KiBRaw

curl peers

A peer in curl internals is represented by a struct Curl_peer. It has the following members:

  • scheme: a struct Curl_scheme of the URL schemes known to curl
  • user_hostname: the hostname as supplied by the user/application
  • hostname: a normalized version of user_hostname
  • port: the network port
  • ipv6: if hostname is an IPv6 address
  • unix_socket: if hostname is a path to a unix domain socket
  • user_ipv6zone: user supplied IPv6 zone name or NULL
  • ipv6scope_id: IPv6 address scope or 0
  • abstract: (if unix_socket) if the socket is abstract

A peer, in short, is a communication endpoint.

peers and transfers

The peer a transfer, e.g. easy handle, works against is determined at the start of each request. It is kept in data->state.origin. For the first request done in a curl_easy_perform() or equivalent, this origin is linked to data->state.initial_origin. This allows checks if properties of data->set.* should apply to a request or not.

data->state.origin is relevant for cookie processing, signing requests and other request/response based processing.

peers and connections

A network connection always goes somewhere. That somewhere is called the origin of the connection (e.g. the source of responses/downloads). It is kept in conn->origin and is always present in a connection.

The origin is logical endpoint a connection talks to. In most configurations it is the same as data->state.origin (see proxies below).

For most connections, the origin is connected to directly. It can be directed to another peer, however.

connect-to

With the command line option --connect-to or the libcurl option CURLOPT_CONNECT_TO, a connection can be told to make the network connection to another endpoint while keeping the origin unchanged.

This other endpoint is also a peer and is available as conn->via_peer. This may be a peer for a different hostname and port or it may be a unix domain socket.

proxies

When a connection uses a proxy, the endpoint for contacting the proxy server is also represented as a peer and is kept at conn->socks_proxy.peer and/or conn->http_proxy.peer. SOCKS proxies always come first, so a connection might connect as:

1. curl -------------------------------------------> conn->origin
2. curl -------------------------------------------> conn->via_peer (acting as conn->origin)
3. curl --> socks_proxy.peer ----------------------> conn->via_peer/origin
4. curl -----------------------> http_proxy.peer --> conn->via_peer/origin
5. curl --> socks_proxy.peer --> http_proxy.peer --> conn->via_peer/origin

A conn->(socks|http)_proxy.peer is only ever present when the proxy is in use and NULL otherwise.

SOCKS proxies are always used for tunneling, either to the origin or the HTTP proxy. They operate in a connection filter.

HTTP proxies can operate in two modes: tunneling or forwarding. When tunneling, they also operate in a connection filter. In forwarding mode however, they become the origin the connection talks to.

Therefore, connections that talk to a forwarding HTTP proxy have conn->origin set to conn->http_proxy.peer and conn->bits.origin_is_proxy is set.

The connection filter SETUP, that assembles the filters for a connection, figures out which peer to pass to which filter in order to make it all work. The individual filters get passed a specific peer and do not need be concerned with the whole chain.

For example, IP connection goes to origin(1), via_peer(2), socks_proxy.peer(3+5), http_proxy.peer(4) and that is the peer that gets passed to the DNS and HAPPY-EYEBALLS filters.

TLS

TLS filters' task is to verify the peer they talk to (unless that is switched off). They either talk to the conn->origin or the conn->http_proxy.peer (SOCKS does not have TLS). The conn->via_peer is irrelevant. A via_peer endpoint needs to present a certificate matching conn->origin or the connect must fail.

unix domain sockets

Peers that represent a unix domain socket may be used in two places:

  1. via_peer: curl can connect to an origin server via unix domain sockets. This disables any proxy settings a transfer might carry.
  2. socks_proxy.peer: a SOCKS proxy may be contacted over a unix domain socket.

It is not supported to contact an http proxy over unix domain sockets.

peers and credentials

There have been several vulnerabilities by leaking credentials in requests where they should not appear. In future work we plan to tie credentials to peers and use them only when their peer still matches the current connection use.

peers internals

A struct Curl_peer is allocated with space of the user_hostname. Only when the user supplied value needs conversions (removing [] or IDN encoding) is hostname an extra allocation. This keeps the number of allocations the same as before.

A Curl_peer is not expected to be modified after it has been created. However, each Curl_peer has a reference counter. Code needs to use Curl_peer_link() and Curl_peer_unlink() to keep/release references. This makes it safe and cheap to keep references to peers in connections and filters.

1<!--
2Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
4SPDX-License-Identifier: curl
5-->
7# curl peers
9A `peer` in curl internals is represented by a `struct Curl_peer`. It has the following members:
11* `scheme`: a `struct Curl_scheme` of the URL schemes known to curl
12* `user_hostname`: the hostname as supplied by the user/application
13* `hostname`: a *normalized* version of `user_hostname`
14* `port`: the network port
15* `ipv6`: if `hostname` is an IPv6 address
16* `unix_socket`: if `hostname` is a path to a `unix domain socket`
17* `user_ipv6zone`: user supplied IPv6 zone name or `NULL`
18* `ipv6scope_id`: IPv6 address scope or 0
19* `abstract`: (if `unix_socket`) if the socket is abstract
21A peer, in short, is a communication endpoint.
23## peers and transfers
25The peer a transfer, e.g. easy handle, works against is determined at the
26start of each request. It is kept in `data->state.origin`. For the first
27request done in a `curl_easy_perform()` or equivalent, this origin is
28linked to `data->state.initial_origin`. This allows checks if properties
29of `data->set.*` should apply to a request or not.
31`data->state.origin` is relevant for cookie processing, signing requests
32and other request/response based processing.
34## peers and connections
36A network connection always goes *somewhere*. That *somewhere* is called
37the `origin` of the connection (e.g. the source of responses/downloads).
38It is kept in `conn->origin` and is always present in a connection.
40The `origin` is *logical* endpoint a connection talks to. In most
41configurations it is the same as `data->state.origin` (see proxies below).
43For most connections, the `origin` is connected to *directly*. It
44can be directed to another peer, however.
46### `connect-to`
48With the command line option `--connect-to` or the `libcurl` option
49`CURLOPT_CONNECT_TO`, a connection can be told to make the network connection
50to another endpoint *while keeping the `origin` unchanged*.
52This other endpoint is also a peer and is available as `conn->via_peer`.
53This may be a peer for a different hostname and port or it may be a
54`unix domain socket`.
56### proxies
58When a connection uses a proxy, the endpoint for contacting the proxy server
59is also represented as a peer and is kept at `conn->socks_proxy.peer` and/or
60`conn->http_proxy.peer`. `SOCKS` proxies always come first, so a connection
61might connect as:
63```
641. curl -------------------------------------------> conn->origin
652. curl -------------------------------------------> conn->via_peer (acting as conn->origin)
663. curl --> socks_proxy.peer ----------------------> conn->via_peer/origin
674. curl -----------------------> http_proxy.peer --> conn->via_peer/origin
685. curl --> socks_proxy.peer --> http_proxy.peer --> conn->via_peer/origin
69```
71A `conn->(socks|http)_proxy.peer` is only ever present when the proxy
72is in use and `NULL` otherwise.
74SOCKS proxies are always used for tunneling, either to the origin or
75the HTTP proxy. They operate in a connection filter.
77HTTP proxies can operate in two modes: tunneling or forwarding. When tunneling,
78they also operate in a connection filter. In forwarding mode however, they
79become the `origin` the connection talks to.
81Therefore, connections that talk to a forwarding HTTP proxy have `conn->origin`
82set to `conn->http_proxy.peer` and `conn->bits.origin_is_proxy` is set.
84The connection filter `SETUP`, that assembles the filters for a connection,
85figures out which peer to pass to which filter in order to make it all work.
86The individual filters get passed a specific peer and do not need be concerned
87with the whole chain.
89For example, IP connection goes to `origin`(1), `via_peer`(2),
90`socks_proxy.peer`(3+5), `http_proxy.peer`(4) and that is the peer that gets
91passed to the `DNS` and `HAPPY-EYEBALLS` filters.
93### TLS
95TLS filters' task is to verify the peer they talk to (unless that is
96switched off). They either talk to the `conn->origin` or the
97`conn->http_proxy.peer` (`SOCKS` does not have TLS). The `conn->via_peer` is
98irrelevant. A `via_peer` endpoint needs to present a certificate matching
99`conn->origin` or the connect must fail.
101### `unix domain socket`s
103Peers that represent a `unix domain socket` may be used in two places:
1051. `via_peer`: curl can connect to an `origin` server via `unix domain socket`s.
106 This disables any proxy settings a transfer might carry.
1072. `socks_proxy.peer`: a `SOCKS` proxy may be contacted over a `unix domain
108 socket`.
110It is not supported to contact an http proxy over `unix domain socket`s.
112## peers and credentials
114There have been several vulnerabilities by leaking credentials in requests
115where they should not appear. In future work we plan to tie credentials to
116`peers` and use them only when their `peer` still matches the current
117connection use.
119## peers internals
121A `struct Curl_peer` is allocated with space of the `user_hostname`.
122Only when the user supplied value needs conversions (removing `[]` or
123IDN encoding) is `hostname` an extra allocation. This keeps the number
124of allocations the same as before.
126A `Curl_peer` is not expected to be modified after it has been created.
127However, each `Curl_peer` has a reference counter. Code needs to use
128`Curl_peer_link()` and `Curl_peer_unlink()` to keep/release references.
129This makes it safe and cheap to keep references to peers in connections
130and filters.
Diagnostics4 git calls · 55 ms
CallStatusSizeTime055 ms
discover200152 B2 ms
git.upload-pack discover
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=152
git.server.agent=gitty/1.0
git.server.object_format=sha1
git.server.caps=agent ls-refs fetch object-format
git.server.fetch=shallow filter sideband-all
git.protocol.version=2
git.pkt.frames=8
git.pkt.data=6
git.pkt.flush=2
git.pkt.delim=0
git.pkt.bytes=152
git.pkt.payload.max=34
ls-refs200149 B · hit2 ms
git.upload-pack ls-refs
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=ls-refs
git.upstream.dur_ms=2
git.response.bytes=149
git.response.cache=HIT
git.response.duration_ms=2
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=149
git.pkt.payload.max=78
git.ls_refs.count=2
git.ls_refs.head=refs/heads/master
fetchblob:none · deepen 10200287 KiB · hit27 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=3
git.response.bytes=293470
git.response.cache=HIT
git.response.duration_ms=27
git.fetch.filter=blob:none
git.fetch.filter.requested=tree:0
git.fetch.filter.fallback=blob:none
git.fetch.filter.learned=false
git.fetch.wants=31c911efe5652725e930f4d2e60c9060e5f6646d
git.fetch.haves.count=0
git.fetch.deepen=10
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=10
git.pkt.data=8
git.pkt.flush=1
git.pkt.delim=1
git.pkt.bytes=293470
git.pkt.payload.max=65516
git.sideband.band1.bytes=293354
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0
git.pack.objects=87
git.pack.bytes=293354
git.pack.ofs_delta=0
git.pack.ref_delta=1
git.pack.chain.max=1
git.pack.trailer=6a646bcda6740bab42e321b51998b52ea15146c0
git.pack.full=86
Open pack map
fetch2002.3 KiB · hit26 ms
git.upload-pack fetch
http.response.status_code=200
git.upstream.cf_ray=-
git.upstream.phase=fetch
git.upstream.dur_ms=26
git.response.bytes=2338
git.response.cache=HIT
git.response.duration_ms=26
git.fetch.wants=28d002a92685fd4c099f9909e85ebbba60898d15
git.fetch.haves.count=0
git.fetch.deepen=0
git.fetch.thin_pack=false
git.fetch.ofs_delta=true
git.protocol.version=2
git.pkt.frames=3
git.pkt.data=2
git.pkt.flush=1
git.pkt.delim=0
git.pkt.bytes=2338
git.pkt.payload.max=2317
git.sideband.band1.bytes=2316
git.sideband.band2.bytes=0
git.sideband.band3.bytes=0

Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.

Remote
https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/curl.git
Ref
refs/heads/master
Commit
31c911efe5652725e930f4d2e60c9060e5f6646d
cf-ray
a5e316f4bcedcf5b
Request
6c8d0204…
Protocol
v2 · sha1
Agent
gitty/1.0
Filter
advertised
Fetch
shallow filter sideband-all
Capabilities
agent ls-refs fetch object-format