1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//! Define the configuration of the host device.
//!
//! The constants in this module define the maximum sizes of the various buffers used during
//! communication in `kdeconnect-proto`. Each of these constants have a default value but can be
//! set using the correct environment variable.
use crateDeviceType;
use ;
pub const MIN_TCP_PORT: u16 = 1716;
pub const MAX_TCP_PORT: u16 = 1764;
pub const UDP_PORT: u16 = 1716;
pub const KDECONNECT_PROTOCOL_VERSION: u16 = 8;
/// The maximum size of the buffer used by UDP connections (this setting also applies for
/// MDNS buffers, although they are not shared with UDP-only connections).
///
/// Default value: 2500 bytes
/// Environment variable to set: KDECONNECT_UDP_BUFFER_SIZE
pub const UDP_BUFFER_SIZE: usize = const ;
/// The maximum size of the buffer used by TCP connections.
///
/// Default value: 2500 bytes
/// Environment variable to set: KDECONNECT_TCP_BUFFER_SIZE
pub const TCP_BUFFER_SIZE: usize = const ;
/// The maximum size of the buffer used by TLS connections.
///
/// Default value: 2500 bytes
/// Environment variable to set: KDECONNECT_TLS_BUFFER_SIZE
pub const TLS_BUFFER_SIZE: usize = const ;
/// The maximum size of the buffer used by TLS connections of the main application.
///
/// Default value: 3000 bytes
/// Environment variable to set: KDECONNECT_TLS_APP_BUFFER_SIZE
pub const TLS_APP_BUFFER_SIZE: usize = const ;
/// The configuration of the host device.
///
/// You must generate a self-signed certificate with the device ID as CommonName in order to start
/// a device and connect to other peers.
///
/// You can either use `openssl` to generate a certificate using:
///
/// ```bash
/// openssl req -x509 \
/// -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -keyout private_key.pem \
/// -addext basicConstraints=critical,CA:FALSE \
/// -days 3650 -nodes -subj "/O=KDE/OU=KDE Connect/CN=<your host device ID>" -out cert.pem
/// ```
///
/// Or use the `rcgen` crate:
///
/// ```ignore
/// use std::fs;
/// use rcgen::{CertificateParams, DistinguishedName, DnType, IsCa, KeyPair};
///
/// pub fn gen_certificate(uuid: &str) {
/// let mut params = CertificateParams::default();
/// params.is_ca = IsCa::ExplicitNoCa;
///
/// let mut dn = DistinguishedName::new();
/// dn.push(DnType::CommonName, uuid);
/// dn.push(DnType::OrganizationName, "KDE");
/// dn.push(DnType::OrganizationalUnitName, "KDE Connect");
/// params.distinguished_name = dn;
///
/// let key_pair = KeyPair::generate().unwrap();
/// let cert = params.self_signed(&key_pair).unwrap();
///
/// fs::write("private_key.pem", key_pair.serialize_pem()).unwrap();
/// fs::write("cert.pem", cert.pem()).unwrap();
/// }
/// ```
///
/// You can then make a [`DeviceConfig`] using the content of the files `cert.pem` and
/// `private_key.pem`, respectively in the [`DeviceConfig::cert`] and [`DeviceConfig::private_key`]
/// fields.