| 1 |  |
| 2 | |
| 3 | # Certstream Server Go |
| 4 | |
| 5 | [](https://github.com/d-Rickyy-b/certstream-server-go/actions/workflows/release_build.yml) |
| 6 | [](https://hub.docker.com/repository/docker/0rickyy0/certstream-server-go) |
| 7 | [](https://pkg.go.dev/github.com/d-Rickyy-b/certstream-server-go) |
| 8 | |
| 9 | This project aims to be a drop-in replacement for the [certstream server](https://github.com/CaliDog/certstream-server/) by Calidog. This tool aggregates, parses, and streams certificate data from multiple [certificate transparency logs](https://www.certificate-transparency.org/what-is-ct) via websocket connections to the clients. |
| 10 | |
| 11 | Everyone can use this project to analyze newly created TLS certificates as they are issued. |
| 12 | |
| 13 | ## Motivation |
| 14 | |
| 15 | From the moment I first found out about the certificate transparency logs, I was absolutely amazed by the great software of [Calidog](https://github.com/CaliDog/), which made the transparency log easier accessible for everyone. |
| 16 | Their software "Certstream" parses the log and provides it in an easy-to-use format: JSON. |
| 17 | |
| 18 | After creating my first application that utilized the certstream server, I found that the hosted (demo) version of the server wasn't as reliable as I thought it would be. |
| 19 | I got disconnects and sometimes other errors. Eventually, the provided server was still only thought to be **a demo**. |
| 20 | |
| 21 | I quickly thought about running my own instance of certstream. But I didn't want to install Elixir/Erlang on my server. Sure, I could have used Docker, but on second thought, I was really into the idea of creating an alternative server written in Go. |
| 22 | |
| 23 | "Why Go?", you might ask. Because it is a great language that compiles to native binaries on all major architectures and OSes. All the cool kids are using it right now. |
| 24 | |
| 25 | ## Getting started |
| 26 | |
| 27 | Setting up an instance of the certstream server is straightforward. You can either download and compile the code yourself, or use one of the [precompiled binaries](https://github.com/d-Rickyy-b/certstream-server-go/releases). |
| 28 | |
| 29 | By default, certstream-server-go will monitor all logs listed in the [Google Log list](https://www.gstatic.com/ct/log_list/v3/log_list.json), which are also included in the Chrome browser. There are more CT logs available than the ones listed there. Google provides [another list with all known CT logs](https://www.gstatic.com/ct/log_list/v3/all_logs_list.json). But not all of them might be relevant to you. Or maybe you are running your own CT log and want to monitor that as well? |
| 30 | |
| 31 | You can define additional logs in the config file. Check out the [sample config file](https://github.com/d-Rickyy-b/certstream-server-go/blob/master/config.sample.yaml) |
| 32 | |
| 33 | ### Docker |
| 34 | |
| 35 | There's also a prebuilt [Docker image](https://hub.docker.com/repository/docker/0rickyy0/certstream-server-go) available. |
| 36 | You can use it by running this command: |
| 37 | |
| 38 | `docker run -d -v /path/to/config.yaml:/app/config.yaml -p 8080:8080 0rickyy0/certstream-server-go` |
| 39 | |
| 40 | > [!WARNING] |
| 41 | > If you don't mount your own config file, the default config (config.sample.yaml) will be used. For more details, check out the [wiki](https://github.com/d-Rickyy-b/certstream-server-go/wiki/Configuration). |
| 42 | |
| 43 | ## Connecting |
| 44 | |
| 45 | certstream-server-go offers multiple endpoints to connect to. |
| 46 | |
| 47 | | Config | Default | Function | |
| 48 | |--------------------|-----------------|-------------------------------------------------------------------------------------------| |
| 49 | | `full_url` | `/full-stream` | Constant stream of new certificates with all details available | |
| 50 | | `lite_url` | `/` | Constant stream of new certificates with reduced details (no `as_der` and `chain` fields) | |
| 51 | | `domains_only_url` | `/domains-only` | Constant stream of domains found in new certificates | |
| 52 | |
| 53 | You can connect to the certstream-server by opening a **websocket connection** to any of the aforementioned endpoints. |
| 54 | After you're connected, certificate information will be streamed to your websocket. |
| 55 | |
| 56 | The server requires you to send a **ping message** at least every 60 seconds (it's recommended to use an interval of 30s for pings). |
| 57 | If the server does not receive a ping message for more than this time, it will disconnect you. |
| 58 | The server will **not** send out ping messages to your client. |
| 59 | |
| 60 | Read more about ping/pong WebSocket messages in the [Mozilla Developer Docs](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#pings_and_pongs_the_heartbeat_of_websockets). |
| 61 | |
| 62 | ### Performance |
| 63 | |
| 64 | At idle (no clients connected), the server uses about **40 MB** of RAM, **14.5 Mbit/s** and **4–10% CPU** (Oracle Free Tier) on average while processing around **250–300 certificates per second**. |
| 65 | |
| 66 | ### Network considerations |
| 67 | |
| 68 | This tool requires outgoing access to the public internet to connect to the [Google Log list](https://www.gstatic.com/ct/log_list/v3/log_list.json) and the CT logs themselves. |
| 69 | So if you happen to this tool in a corporate environment (e.g., behind a proxy/firewall), make sure to allow outgoing connections to gstatic.com and the CT logs you want to connect to. |
| 70 | |
| 71 | If you plan to connect clients to the server from outside your local network, make sure to allow incoming connections to the port you configured in the config file (webserver.listen_port). |
| 72 | |
| 73 | ### Monitoring |
| 74 | |
| 75 | **certstream-server-go** also offers a Prometheus metrics endpoint at `/metrics`. You can use this to monitor the server with Prometheus and Grafana. |
| 76 | For an in-depth guide on how to do this, please refer to the [wiki](https://github.com/d-Rickyy-b/certstream-server-go/wiki/Collecting-and-Visualizing-Metrics). |
| 77 | |
| 78 |  |
| 79 | |
| 80 | ### Example |
| 81 | |
| 82 | To receive a live example for any of the endpoints, send an HTTP GET request to the endpoints with `/example.json` appended to the endpoint. |
| 83 | For example: `/full-stream/example.json`. This shows the lite format of a certificate update. |
| 84 | |
| 85 | ```json |
| 86 | { |
| 87 | "data": { |
| 88 | "cert_index": 712420366, |
| 89 | "cert_link": "https://yeti2022-2.ct.digicert.com/log/ct/v1/get-entries?start=712420366&end=712420366", |
| 90 | "leaf_cert": { |
| 91 | "all_domains": [ |
| 92 | "cmslieferhit.e06.k-k.de" |
| 93 | ], |
| 94 | "extensions": { |
| 95 | "authorityInfoAccess": "URI:http://r3.i.lencr.org/, URI:http://r3.o.lencr.org", |
| 96 | "authorityKeyIdentifier": "keyid:14:2e:b3:17:b7:58:56:cb:ae:50:09:40:e6:1f:af:9d:8b:14:c2:c6", |
| 97 | "basicConstraints": "CA:FALSE", |
| 98 | "keyUsage": "Digital Signature, Key Encipherment", |
| 99 | "subjectAltName": "DNS:cmslieferhit.e06.k-k.de", |
| 100 | "subjectKeyIdentifier": "keyid:4e:cb:ae:47:84:a8:92:f7:e7:de:78:d1:00:9e:d9:cc:80:ac:0b:ce" |
| 101 | }, |
| 102 | "fingerprint": "27:58:3D:01:3D:71:B8:D3:A6:6E:2C:7A:86:3A:E9:1F:DB:F0:1B:5D", |
| 103 | "sha1": "27:58:3D:01:3D:71:B8:D3:A6:6E:2C:7A:86:3A:E9:1F:DB:F0:1B:5D", |
| 104 | "sha256": "57:61:38:C0:3C:03:A3:34:6A:0B:32:89:11:1B:74:AB:8A:DF:A5:02:9F:06:43:E6:F3:0E:69:F3:0E:4E:4E:FC", |
| 105 | "not_after": 1667028404, |
| 106 | "not_before": 1659252405, |
| 107 | "serial_number": "0498BDF812FAF923FEBD5EF7B374899FC61A", |
| 108 | "signature_algorithm": "sha256, rsa", |
| 109 | "subject": { |
| 110 | "C": null, |
| 111 | "CN": "cmslieferhit.e06.k-k.de", |
| 112 | "L": null, |
| 113 | "O": null, |
| 114 | "OU": null, |
| 115 | "ST": null, |
| 116 | "aggregated": "/CN=cmslieferhit.e06.k-k.de", |
| 117 | "email_address": null |
| 118 | }, |
| 119 | "issuer": { |
| 120 | "C": "US", |
| 121 | "CN": "R3", |
| 122 | "L": null, |
| 123 | "O": "Let's Encrypt", |
| 124 | "OU": null, |
| 125 | "ST": null, |
| 126 | "aggregated": "/C=US/CN=R3/O=Let's Encrypt", |
| 127 | "email_address": null |
| 128 | }, |
| 129 | "is_ca": false |
| 130 | }, |
| 131 | "seen": 1659301203.904, |
| 132 | "source": { |
| 133 | "name": "DigiCert Yeti2022-2 Log", |
| 134 | "url": "https://yeti2022-2.ct.digicert.com/log" |
| 135 | }, |
| 136 | "update_type": "PrecertLogEntry" |
| 137 | }, |
| 138 | "message_type": "certificate_update" |
| 139 | } |
| 140 | ``` |