README.md
1# libcfnet - CFEngine Network protocol
2
3Generally, details about the protocol are explained in comments / code.
4However, some explanations don't naturally fit in one part / file of the codebase.
5So, they are provided here.
6
7
8## Network protocol versioning
9
10
11### Protocol versions
12
13Names of protocol versions:
14
151. `"classic"` - Legacy, pre-TLS, protocol. Not enabled or allowed by default.
162. `"tls"` - TLS Protocol using OpenSSL. Encrypted and 2-way authentication.
173. `"cookie"` - TLS Protocol with cookie command for duplicate host detection.
18
19Wanted protocol version can be specified from policy:
20
21```
22body copy_from protocol_latest
23{
24 protocol_version => "latest";
25}
26```
27
28Additionally, numbers can also be used:
29
30```
31body copy_from protocol_three
32{
33 protocol_version => "3";
34}
35```
36
37
38### Version negotiation
39
40Client side (`cf-agent`, `cf-hub`, `cf-runagent`, `cf-net`) uses `ServerConnection()` function to connect to a server.
41Server side (`cf-serverd`, `cf-testd`) uses `ServerTLSPeek()` to check if the connection is TLS or not, distinguishing version 1 and 2.
42Protocol version 1 is not allowed by default, but can be allowed using `allowlegacyconnects`.
43Version negotiation then happens inside `ServerIdentificationDialog()` (server side) and `ServerConnection()` (client side).
44Client requests a wanted version, by sending a version string, for example:
45
46```
47CFE_v3
48```
49
50The version requested is usually the latest supported, unless specified in policy (`body copy_from`).
51Then, the server responds with the highest supported version (but not higher than the requested version).
52For a 3.12 server, this would be:
53
54```
55CFE_v2
56```
57
58Both server and client will then set `conn_info->protocol` to `2`, and use protocol version 2.
59There is currently no way to require a specific version number (only allow / disallow version 1).
60This is because version 2 and 3 are practically identical.
61Downgrade from version 3 to 2 happens seamlessly, but crucially, it doesn't downgrade to version 1 inside the TLS code.
62