How to generate certs for missing ad domains?
Download
EasyRSA-3.0.0.0. Unzip to a Linux PC or Asus Router. The benefit of putting on router is total automation (later on) of the steps we're about to go through.
If decided to put on the router, it's better to have Entware installed. We can extract EasyRSA 3 to "/opt/local". EasyRSA 3 requires
mktemp (available from Entware). PC Linux most likely comes with mktemp pre-installed.
The next few steps are pretty much a recap of
EasyRSA 3 QuickStart. We initialise this copy of EasyRSA with
If I remember right, the above steps essentially created the "pki" sub-directory and a few text files such as
serial,
index..etc. Now we're ready to create the most important cert, Root CA.
Enter data as prompt. Mostly I go with defaults except for "Common Name" which I enter "Pixelserv CA" for easy identification. At the end of this step, we get in "pki" sub-dir three important files
- ca.crt - which is a public cert of our Root CA enterprise...
- ca.key - under "pki/private" sub-dir. This is the private key to the Root CA
- ca.key.passphrase - under "pki/private" sub-dir. It's the password we entered earlier to protect the private key.
Now there are tonnes of advice on how to secure the second and last files but let's not too paranoid for our adblock enterprise. ca.crt need to be installed on clients e.g. Android/iOS/OS X/Windows. It's only cert we need to install on clients.
We'll be using this Root CA to sign all other certs that we're going to generate for our ad domains.
If you've been running pixelserv version V35.HZ12.Kc, you find in syslog.log (or your log file) lines similar to the below one:
Oct 7 00:18:14 RT-AC56U pixelserv[13904]: settings.crashlytics.com _.crashlytics.com missing
This tells us that in your Dnsmasq you've blocked the ad domain "settings.crashlytics.com" by redirecting to pixelserv. A little while back, your client browser tried to https to this ad domain. Pixelserv got the request but failed to load the cert (named _.crashlytics.com) since this is new and no cert has been created for it yet.
Now let's generate a wildcard cert for "*.crashlytics.com" which covers well "settings.crashlytics.com". Go back to your EasyRSA directory, then
- ./easyrsa gen-req _.crashlytics.com
Follow screen prompts, I simply go by default except for "Common Name" which is essential here. We have to type in "*.crashlytics.com". Now you have generate a so called CSR (Certificate Signing Request) and an associated private key to this CSR. CSR need to be signed by Root CA to turn into a cert. Let's do that,
- ./easyrsa sign-req server _.crashlytics.com
Our ad server (living inside pixelserv) is.... a server. Hence the first argument "server" The second argument is simply the same name we initially give to this cert. Screen will prompt us for a few things. Just go with the follow. Then it'll ask you to type in passphrase which is in "ca.key.passphrase" mentioned above.
Congrats! Our first CSR is signed and now turned into a cert...and it's a wildcard cert!
To prepare the cert for use in Pixelserv, we need to concate the public key and private key of this cert into a single file. Input files:
- _.crashlytics.com.crt (in "pki/issued")
- _.crashlytics.com.key (in "pki/private")
Output file:
- _.crashlytics.com (under anywhere you like...)
Copy the lines between "--BEGIN xxxxx --" and "--END xxxx --" from the two input files and store them in the output file.
We're done. Now copy
_.crashlytics.com to /opt/var/cache/pixelserv on the router. Or another directory of your choice (you just then have to let pixelserv know the dir through -z command line option).
For any missing ad domains, we repeat the last three steps: gen-req, sign-req and prepare the final file for pixelserv.