Debian Codegraph @

tlsdemo/README.md

raw symbols SCIP
1 ## Libtrust TLS Config Demo
2
3 This program generates key pairs and trust files for a TLS client and server.
4
5 To generate the keys, run:
6
7 ```
8 $ go run genkeys.go
9 ```
10
11 The generated files are:
12
13 ```
14 $ ls -l client_data/ server_data/
15 client_data/:
16 total 24
17 -rw------- 1 jlhawn staff 281 Aug 8 16:21 private_key.json
18 -rw-r--r-- 1 jlhawn staff 225 Aug 8 16:21 public_key.json
19 -rw-r--r-- 1 jlhawn staff 275 Aug 8 16:21 trusted_hosts.json
20
21 server_data/:
22 total 24
23 -rw-r--r-- 1 jlhawn staff 348 Aug 8 16:21 trusted_clients.json
24 -rw------- 1 jlhawn staff 281 Aug 8 16:21 private_key.json
25 -rw-r--r-- 1 jlhawn staff 225 Aug 8 16:21 public_key.json
26 ```
27
28 The private key and public key for the client and server are stored in `private_key.json` and `public_key.json`, respectively, and in their respective directories. They are represented as JSON Web Keys: JSON objects which represent either an ECDSA or RSA private key. The host keys trusted by the client are stored in `trusted_hosts.json` and contain a mapping of an internet address, `<HOSTNAME_OR_IP>:<PORT>`, to a JSON Web Key which is a JSON object representing either an ECDSA or RSA public key of the trusted server. The client keys trusted by the server are stored in `trusted_clients.json` and contain an array of JSON objects which contain a comment field which can be used describe the key and a JSON Web Key which is a JSON object representing either an ECDSA or RSA public key of the trusted client.
29
30 To start the server, run:
31
32 ```
33 $ go run server.go
34 ```
35
36 This starts an HTTPS server which listens on `localhost:8888`. The server configures itself with a certificate which is valid for both `localhost` and `127.0.0.1` and uses the key from `server_data/private_key.json`. It accepts connections from clients which present a certificate for a key that it is configured to trust from the `trusted_clients.json` file and returns a simple 'hello' message.
37
38 To make a request using the client, run:
39
40 ```
41 $ go run client.go
42 ```
43
44 This command creates an HTTPS client which makes a GET request to `https://localhost:8888`. The client configures itself with a certificate using the key from `client_data/private_key.json`. It only connects to a server which presents a certificate signed by the key specified for the `localhost:8888` address from `client_data/trusted_hosts.json` and made to be used for the `localhost` hostname. If the connection succeeds, it prints the response from the server.
45
46 The file `gencert.go` can be used to generate PEM encoded version of the client key and certificate. If you save them to `key.pem` and `cert.pem` respectively, you can use them with `curl` to test out the server (if it is still running).
47
48 ```
49 curl --cert cert.pem --key key.pem -k https://localhost:8888
50 ```