First working TLS-KDH system! (Still with possible memleaks)
[tlspool] / INSTALL
1 INSTALLING TLSPOOL
2 ==================
3
4 This explains how to install the TLS pool daemon, and how to play with the
5 test/demo programs for the client and server side.
6
7
8 Dependencies
9 ------------
10
11 Runtime dependencies are:
12
13  * libgnutls >= 3.4.4 for TLS handling (that implies libnettle-2.7)
14  * p11-kit >= 0.22.1 for PKCS #11 URI handling
15  * libdb >= 4.0 for key->value lookup with BerkeleyDB transactions/replication
16  * libtasn1 for parsing of BER and DER data structures
17  * NOT-YET: libldns for DNS lookups
18  * NOT-YET: libldap for LDAP lookups
19  * NOT-YET: libmemcached for caching of intermediate results
20  * NOT-YET: libradius to do additional authn / authz [/acct]
21  * the PKCS #11 implementation of your choice (for easy entrance: softhsm)
22
23 Include the development variants if your aim is to build your own TLS Pool.
24
25 TODO: We should probably consider build variations to avoid requiring all
26 these dependencies when only a bit is kwown to be required.  That's the
27 sort of maturity that this project has not reached yet.
28
29
30 First-time build
31 ----------------
32
33 Create a user and group "tlspool" if you wish to drop privileges to a
34 separate account.
35
36 Use the common building approach:
37
38         ./configure
39         make
40         make install
41
42 When your purpose is to test, you will also need a PKCS #11 store for your
43 private keys.  Then you can fill PKCS #11 and the databases.
44
45
46 Build details
47 -------------
48
49 There are three sub-targets with their own Makefiles:
50
51  * src/* hosts the daemon, which is an executable named "tlspool"
52  * lib/* hosts the stub library for applications, and provides:
53     - "libstarttls.a" and "libstarttls.so" to append to applications
54     - "tlspool.py" is similar, but used with Python
55  * tool/* hosts a few demonstration applications, and provides:
56     - "testcli" and "testsrv" test/demo apps, for line-based chat
57     - "tlstunnel" as a plaintext-to-TLS or TLS-to-plaintext passthrough
58     - "webclientdemo.py" and "webserverdemo.py" are Python demonstrations
59     - "lidsel" and "pinentry" plug into the TLS Pool's localid and PIN services
60     - "https_proxy.py" demonstrates an intervening HTTPS proxy
61
62 The main directory "make" will also make all these subdirectory projects.
63
64
65 Testing
66 -------
67
68 The source package includes a "testdata" directory that can be filled
69 with databases that you can use for a quick and dirty test.  You will
70 need to setup a PKCS #11 repository; we suggest to use SoftHSMv2 from the
71 OpenDNSSEC project to get started, you can always try hardware-based
72 tokens later on.  The idea of PKCS #11 is that such choices are pluggable.
73
74 To create a SoftHSM token, you can use the following command::
75
76         softhsm2-util --init-token --free --label 'TLS_Pool_dev_data'
77
78 This label is configured in the default configuration for the TLS Pool.
79 The default configuration works with a PIN 1234; you can choose any
80 SO-PIN you like.
81
82 You can now build the private keys and from that, certificates that go
83 into the databases::
84
85         cd testdata
86         make
87
88 (If it fails, please run it again.)
89 The databases may also be rebuilt using the Makefile in the directory,
90 there are rebuild- clean- and fill- targets for -pkcs11, -cert, -pgp and
91 -db that will do this for you.  Note that rebuilding PKCS #11 is heavy,
92 it wipes your private key and possibly even the store.
93
94 The PKCS #11 data may not be available to your TLS Pool if it runs under
95 another user, such as the default setup for daemon user "tlspool".  If
96 that is the case, you may need to locate your PKCS #11 store and run
97 the command; this is for SoftHSMv2::
98
99         useradd tlspool
100         chown -R tlspool:tlspool testdata
101
102         chown -R tlspool:tlspool /var/lib/softhsm/tokens/XXX
103
104 To setup Kerberos authentication, you need to install the basic package,
105 usually named `krb5-user` or `krb5-client`, depending on your distro.
106 In `/etc/krb5.conf`, be sure to have this entry to guide the test
107 domain names to our KDC::
108
109         [domain_realm]
110                 # ...other entries...
111                 tlspool.arpa2.lab = ARPA2.NET
112
113 The following test demonstrates proper working of the TLS Pool based on
114 the testdata and under the warnings above:
115
116         # terminal 1
117         cd src
118         ./tlspool -kc ../etc/tlspool.conf
119
120         # terminal 2
121         cd src
122         ../tool/testsrv
123
124         # termainl 3
125         cd src
126         ../tool/testcli
127
128 This will setup a TLS connection over localhost:12345 and provide a simple
129 line-by-line chat session between terminals 2 and 3, while showing debugging
130 output from the TLS Pool in terminal 1.  The test client and server are
131 written to test more functionality as well, and they show some of it too,
132 namely key agreement based on the master key, which show as matching
133 "PRNG bytes" in terminals 2 and 3.
134
135 A somewhat more complicated test is to actually wrap an existing service
136 with tunnels:
137
138         cd src
139         ./tlspool -kc ../etc/tlspool.conf
140         ../tool/tlstunnel -s -l [::1]:22335 -L testsrv@tlspool.arpa2.lab -r [2001:db8::1234]:80
141         ../tool/tlstunnel -c -l [::1]:22334 -L testcli@tlspool.arpa2.lab -r [::1]:22335 -R testsrv@tlspool.arpa2.lab
142         nc ::1 22334
143
144 The `tlspool` binary is the TLS Pool itself.
145
146 The `tlstunnel -s` is a server-side TLS unwrapper.  It receives TLS traffic
147 on `[::1]:22335`, uses the TLS Pool to unwrap it, and forwards the traffic
148 to `[2001:db8::1234]:80`, which is a non-existent address but could be replaced
149 by something like a web server.  You should provide your own
150 IPv6 server address of choice.  Note that backward compatibility with IPv4
151 is available.  The identity of the server is `testsrv@tlspool.arpa2.lab`
152 and that is all that the tunnel needs to know; it will ask the TLS Pool to
153 fill in the credentials belonging to this identity.
154
155 The `tlstunnel -c` is a client-side TLS wrapper.  It receives plaintext
156 traffic on `[::1]:22334`, uses the TLS Pool to wrap it in TLS, and forwards
157 the traffic to `[::1]:22335`, which was not quite coincidentally configured
158 before as a TLS-unwrapping server.  The client needs to know both its local
159 identity, `testcli@tlspool.arpa2.lab`, as the server's.  The local identity
160 is used to access the client credentials, as was done on the server, and the
161 remote identity is used to determine if the client identity may be disclosed
162 to this server; furthermore, the identity is used for TLS' Server Name
163 Indication, which helps with virtual hosting of TLS-secured websites.  (And
164 only websites, really, as all other protocols have embraced a `STARTTLS`
165 method -- it is mostly everyone's popular protocol in the World that has become
166 unable to evolve.)
167
168 It is admittedly silly to run the client and server on the same machine, but
169 it serves as a quick test, and isolates any networking trouble that might
170 creep up in a distributed test.
171
172 The identities shown here are in fact a bit silly for a website, which does
173 not normally use a `user@` part --another thing in which the web is lagging
174 behind other protocols-- but the applications don't mind that because they
175 are not aware if the application used is a web server.  It is assumed that
176 the application would not supply silly identifiers in a real setup.
177
178 Finally, and perhaps smashingly, this simple demonstration already shows a
179 power of the TLS Pool: both client and server are capable of using credentials
180 in the X.509 and OpenPGP formats.  WireShark should show you that the client
181 offers both `cert_type` values in an extension, and the server selects one
182 that it likes.  If the server prefers to use OpenPGP then your luck with
183 WireShark may change; at the time of this writing, even the newest versions
184 are unable to decode the OpenPGP certificate type.  As a result, a perfectly
185 good exchange will cry for attention in WireShark, assuming packet formatting
186 errors.
187
188
189 Running
190 -------
191
192 The tlspool daemon can be run against a configfile of choice, which must
193 be explicitly configured.  My suggestion is to standardise on
194 /etc/tlspool.conf so the normal script would implement actions with:
195
196  * "start" through "tlspool -c /etc/tlspool.conf"
197  * "stop" through "killall `cat /var/run/tlspool.pid`"
198  * "restart" through "tlspool -kc /etc/tlspool.conf"
199
200 The -k option indicates that any older TLS pool daemon should be kicked
201 out, if it exists.  This will remove its locks on the PID file and sockets.
202 At present, this will also break off any existing connections.  This also
203 assumes that the PID file is set to /var/run/tlspool.pid and although not
204 visible here, the socket's default location is /var/run/tlspool.sock
205
206 When running the TLS pool as a user without root privileges, a few things
207 need to be different than in the default configuration:
208
209  * "daemon_pidfile" should be in the user's area of control
210  * "socket_user" and "socket_group" should probably not be set
211  * "daemon_chroot" cannot be used
212  * "daemon_user" and "daemon_group" should probably not be set
213  * "socket_path" and "daemon_pidfile" should be in the user's area
214  * "memcache_host" should normally not be used
215  * "pkcs11_path" may be setup for a personally held token device
216  * "radius_XXX" should normally not be used
217
218 We could support a setup with defaults like ~/.tlspool/tlspool.conf for
219 the configuration, ~/.tlspool/tlspool.pid for the PID file and
220 ~/.tlspool/tlspool.sock for the socket.  Note that it can make a lot of
221 sense to run your own TLS pool within your user account, to avoid
222 sharing access to your PKCS #11 credentials with others.  But doing so
223 will not automatically incorporate it in system-wide key management
224 strategies.
225
226
227 Online identities
228 -----------------
229
230 TODO
231
232
233 Testing
234 -------
235
236 Assuming that the TLS pool daemon started successfully, the only thing
237 that clients and servers need to do is to connect to it and ask it to
238 STARTTLS over a given file descriptor or socket, and return another one
239 to replace it.  This is implemented in the stub library, for which the
240 testcli and testsrv programs form a test client and test server,
241 respectively.
242
243 The test programs are best started in their own terminals, so their
244 input and output does not confuse you.  The server starts as any
245 normal server, creating a listening socket and waiting for input.
246 We have hardcoded address ::1 or localhost and port 12345 into the
247 test software.  When the client connects, each immediately calls
248 the STARTTLS operation from their perspective; one starts a TLS client
249 connection and the other a TLS server connection.  Then, typed lines
250 are passed from one to the other, going through the TLS pool which
251 takes care of the TLS encryption on the sending side, and the TLS
252 decryption on the other end.
253
254 The TLS pool takes care of authentication, authorization and, if so
255 desired, even accounting.  The basic mode of authentication comes down
256 to validating certificates as proper online identitites, using such
257 technologies as LDAP, DANE and DNSSEC.  External RADIUS tools can be
258 added to expand on this, and flag bits may also prove helpful to
259 modify the TLS pool behaviour in predetermined manners.
260
261 The TLS pool also handles teardown in all its forms with grace; that
262 is, it will detect it immediately and notify the other side.
263