charlesreid1.com blog

July 2021 TILs

Posted in TIL

permalink

This year we've been keeping track of some of the surprising things that we have learned. For December, we're compiling a list of some of the things we've learned this year.

Here are the "Today I Learned", or TILs, from July 2021.

July 2, 2021:

  • TIL Ted Kaczynski, the Unabomber, who went to Harvard to study mathematics when he was 16, was recruited in his sophomore year to participate in a "purposely brutalizing psychological experiment" where students would share their deepest-held beliefs, views, and goals, which were then used to belittle and verbally abuse the students. The study was a part of the CIA's MK-Ultra program studying methods of mind control. (Link)

July 8, 2021:

  • TIL Nunavut is a territory of Canada that was formed in 1999 and provided to the Inuit people for independent governance. (Link)

July 9, 2021:

  • TIL people 55 and older own 72% of the wealth in the US; they make up 28.5% of the population. (Source: USA FACTS, via PBS News Hour)

  • TIL that throughout most of the 2010s, the population of millennials was soaring, but number of households headed by people under 35 was declining. But since 2016, household formation rates among millennials have been rising, with the pandemic having only a short term negative impact on that trend. (Source: Harvard report, "The State of the Nation's Housing")

July 10, 2021:

  • TIL how modifying the number of suits and number of cards per suit in a deck of cards can affect the relative probability of the most rare outcomes (straight, flush, and full house).
    • For example, for regular deck of cards, 13 cards per suit, 4 suits, the ranking is straights lose to flushes lose to full houses.
    • But if you use a modified deck with 13 cards per suit and 8 suits (clubs/spades/diamonds/hearts/tridents/roses/hatchets/doves), straights are easier, as are full houses, so the ranking becomes straights lose to full houses lose to flushes.
    • Related: https://charlesreid1.com/wiki/Cards

July 11, 2021:

  • TIL about apscheduler (advanced Python scheduler), which allows you to run Python code at specified dates, intervals, or schedules. (Link)

July 15, 2021:

  • TIL that giant brushes make cows very happy. (Link)

July 16, 2021:

  • TIL about the gamer motivation model. There is a survey by the inventors to see what kind of a gamer you are. I am a bounty hunter. (Link)

July 17, 2021:

  • TIL that China was formerly referred to as the Celestial Empire. It was common in 19th century US, Canada, and Australia. The name originates from how the Chinese characters for "China" are translated (basically, celestial/heavenly dynasty)

July 18, 2021:

  • TIL you can calculate the perimeter of a Möbius strip, all you have to do is integrate a complex parametric curve from 0 to 4π (also fun fact, it can't be done analytically). (Link)

July 30, 2021:

  • TIL: Monrovia, the capital of Liberia, is named after US President James Monroe. (It's the second capital city named after a US president, the other being Washington DC.) It was called that because in 1816 a group of emancipated slaves arrived there under the American Colonization Society, with support from the US government. They named the city after James Monroe because of his support of the colony as a place for emancipated slaves to go, if they preferred that to life as an emancipated slave in the US.

July 31, 2021:

  • TIL there's a branch of mathematics called braid theory, that is a kind of intersection of topology and linear algebra, and has some really interesting applications (and visualizations). (Link)

Tags:    til   

June 2021 TILs

Posted in TIL

permalink

This year, we've been keeping track of some of the surprising things that we have learned.

We call these "Today I Learned", or TILs. We have a private Slack channel set up to keep track of these, and occasionally we scrape the channel and collect the new TILs into a list.

Once you have a list, it makes it easy to review the things you've learned, and share it with other people!

Here are the "Today I Learned", or TILs, from June 2021.

June 27, 2021:

  • TIL "headship" is a word.

June 29, 2021:

  • TIL Superfund sites name a Potentially Responsible Party (PRP) who is held responsible (through legal and administrative actions) for cleaning up the site. (Link)

  • TIL that Operation Valuable/Fiend, an early CIA operation to overthrow the leftist government of Albania. It was sabotaged by Kim Philby, a Cambridge-educated double agent working as a Soviet mole inside MI6 (British Intelligence Service). (Link)

  • TIL about the Philby Tape. In a secret videotape from 1981, discovered by the BBC in the Stasi (East German Secret Police) archives in 2016, Philby describes his experience being recruited as a Soviet spy, his role in sabotaging various operations, and why he believes that his sabotage of Operation Valuable/Fiend prevented World War 3. (Link)

June 30, 2021:

  • TIL ginger, cardamom, and tumeric are all in the same plant family. (Link)

  • TIL the world produced 2.8 million tons of ginger in 2018. (I have no idea how to put that into perspective.) (Link)

Tags:    til   

Copying LetsEncrypt Certs Between Machines

Posted in Security

permalink

A quick post that details a useful operation: copying LetsEncrypt certificates from one machine to another.

(We also cover our use case: setting up certificates for private VPN networks that use public DNS entries.)

HTTPS, SSL Certificates, and LetsEncrypt

As a bit of background, the whole reason this is necessary, the whole reason we are dealing with the hassle of setting up SSL certificates, is to enable end-to-end encrypted connections to a server.

For example, we might have a web application that we want to make available over a VPN network. The web application would have a private IP address on the VPN network, say 10.0.0.101.

Now, what we want is for clients connected to the VPN to be able to visit a domain, say foobar.limo, and be able to make encrypted connections to the web service at 10.0.0.101.

We can do this (assuming we control the foobar.limo domain) by creating a public DNS entry for foobar.limo to point to 10.0.0.101. Then when visitors type foobar.limo into their browser, if they are connected to the VPN they will reach the web service at 10.0.0.101.

To make connections encrypted, however, so that users can type https://foobar.limo and make an encrypted connection to the server at 10.0.0.101, the server must have an SSL certificate for the foobar.limo domain.

Assuming the web service at 10.0.0.101 cannot be reached from the outside world, it becomes necessary to perform several extra steps to enable SSL on the 10.0.0.101 server:

  • First, the DNS entry for foobar.limo must be temporarily updated to point to a server that:

    • has a publicly-accessible IP address,
    • has LetsEncrypt and certbot installed,
    • is connected to or can connect to the VPN or private 10.0.0.101 server,
    • has no services running on port 80
  • Second, the certbot utility must be run on the publicly-accessible server to request a new or renewed certificate foobar.limo. This will put the new or renewed foobar.limo cert files into /etc/letsencrypt/live.

  • Third, the LetsEncrypt certificates are owned by the root user, they must be owned by the root user on the remote machine they are copied to, and SSH/SCP via the root user is (or should be!) prohibited, the certificate files must be compressed using tar, so they can be copied as a non-root user; and on the remote machine, they must be uncompressed to the appropriate location.

(Yes, there is always a relevant XKCD.)

In this post, we cover how this works, and why you might want to do this.

Create Certificates

The first time you create a private VPN certificate on a machine:

  • Log into the DNS provider
  • Create a DNS record - type A, pointing to the IP address of the public server.
  • Run the certbot command to create a certificate on the public server (see below).
  • Copy the certificates to the private VPN node using scp (see below).
  • Update the DNS record - type A, to point to the private VPN IP address of the private server.

Certbot Command

Command to create a certbot certificate (must be run as sudo):

#!/bin/bash
if [ "$(id -u)" != "0" ]; then
    echo ""
    echo ""
    echo "This script should be run as root."
    echo ""
    echo ""
    exit 1;
fi

set -x

DOM="foobar.limo"

certbot certonly \
    --standalone \
    --non-interactive \
    --agree-tos \
    --email test@example.com \
    -d ${DOM}

This command requires port 80 be available (the --standalone flag starts a standalone web server that binds to port 80). If port 80 is being used this command will fail to run and the cert will not be created.

Tar Compress Certs Command

Archive on the public server:

DOM="foobar.limo"
sudo tar -chvzf foobar_certs.tar.gz \
    /etc/letsencrypt/archive/${DOM} \
    /etc/letsencrypt/renewal/${DOM}.conf \
    /etc/letsencrypt/live/${DOM}

Secure Copy Certs Command

Use scp to copy certs to private remote machine:

scp foobar_certs.tar.gz user@10.0.0.101:~/

Untar Certs Command

On the private remote machine, untar the certs file copied over:

cd /
sudo tar -xvf ~/foobar_certs.tar.gz

Last, fix permissions for cert directories:

sudo chmod 700 /etc/letsencrypt/archive
sudo chmod -R 755 /etc/letsencrypt/archive/*
sudo chmod 700 /etc/letsencrypt/live
sudo chmod -R 755 /etc/letsencrypt/live/*
sudo chmod 700 /etc/letsencrypt/archive

Renew Certificates

When you renew a private VPN certificate on a machine:

  • Log into the DNS provider
  • Update the DNS record to a type A, pointing to the IP adress of the public server.
  • Run the certbot command to renew a certificate on the public server (see above).
  • Copy the certificates to the private VPN node (see above).
  • Untar the certificates into place on the private VPN node (see above).
  • Restore the DNS record - type A, to point to the private VPN IP address of private server again.

Tags:    letsencrypt    ssl    https    certificates   

November 2026

Baby Mac Crypto

March 2022

How to Read Ulysses

July 2020

Applied Gitflow

September 2019

Mocking AWS in Unit Tests

November 2017

A Hard(y) Math Problem