Skip straight to the CLI commands to manually verify the identity of a server using its x.509 certificate.


A few months ago, my buddy Marty and I started a little side project for which we needed a few private repos on GitHub. In order to save money on the $25/month GitHub organizational plan, we recently moved these repos from GitHub to Marty's personal server running an instance of gitlab. For security, Marty deployed a self-signed x.509 certificate to encrypt the connection to the server over SSL/TLS.

Every time I tried to connect to the server, my browser would pop up a warning telling me the identity of the server was unknown. The popup was annoying, but the annoyance wasn't a dealbreaker. The real issue was: how do I know that the server to which I'm connecting is actually Marty's server? Trying to address this issue led me to the more general question of: is there a framework outside the traditional certificate authority (CA) model in which this process is more automated and less error prone? Ultimately, I think the most important issue raised by this exercise was: how is semi-anonymity facilitated while enjoying the encryption and verification benefits of the SSL/TLS protocol?

Background: How do I know my information is going to who I think its going to on the interweb?

Before going into the details of how I verified Marty's server, I want to give a little background on internet security. Note that I am not an internet security expert, so take everything here with a grain of salt. Imagine you open your web browser and type in a URL like "". You press the Return key and in a few milliseconds, your Facebook page pops up. Your computer sent some bits out over the network connection to the internet, and some bits representing your Facebook page came back.

  1. Who sent those bits?
  2. Are you sure it was Facebook's server?
  3. When you send a very private message to your spouse/significant other/child/best friend over this connection to this "Facebook", how do you know that some nefarious person isn't reading your very private messages by spoofing your Facebook page?
  4. Even if a nefarious person is not spoofing your Facebook page, how do you know that a nefarious person cannot intercept your very private message and read it as it makes its way to Facebook's server?

The short answer is cryptography via two protocols called SSL/TLS, and x.509.

A good implementation of the SSL/TLS protocol takes care of #4 in the above list because traffic over an SSL/TLS connection is encrypted using a special file on the server called a certificate, or cert for short. Thus, a man-in-the-middle listening to data from your computer to the server sees what appears to be random nonsense.

Issues 1-3 in the above list are different manifestations of the same issue: who is on the other end of the connection? It is entirely possible that someone is spoofing the server to which you are trying to connect and is implementing SSL/TLS. In this case, your data is encrypted as it travels to the spoofer; men-in-the-middle can't read your data, but the spoofer still can.

The solution to this problem requires broader coordination; you need some kind of assurance that the server to which you are connecting is the server you think it is. This assurance can either come from the operator of the server itself, or from some trusted third party. In the case of Marty and I, I had to get that assurance directly from Marty. In the case of Facebook, Twitter, Google, GitHub, etc. that assurance comes from a trusted third party.

The bottom line is the SSL/TLS protocol and careful security engineering on Facebook's part ensures that your browser can positively identify that the data coming from "" indeed comes from Facebook the company and not someone spoofing their server. This system works because your browser ships with so-called "root certificates" issued by trusted third parties like VeriSign. Organizations like VeriSign are called Certificate Authorities, or CAs for short. These root certificates, along with audits by VeriSign and similar companies, are used to verify the authenticity of the certificates Facebook (for example) uses to create the secure SSL/TLS connection. These built-in root certs represent the broader coordination mentioned above: the CAs use the private component of their root cert to "sign" Facebook's SSL/TLS cert. In addition, the public component of the CAs root certs come packaged with your browser. Your browser can therefore use the public component of the root certs it has to verify that a server is sending a cert that was signed by one of the root certs.

Self-signed certs and the little guy

There is nothing special about the x.509 cert that Facebook holds other than VeriSign, etc. helped issue it. You could generate your own x.509 certificate and the end-to-end encryption of traffic over SSL/TLS protocol would work just as well. This practice is known as creating a self-signed certificate, and is common. There are a number of legitimate reasons why someone would want to issue a self-signed certificate. First, leaving the server identity issue aside, SSL/TLS ensures an encrypted connection; it is a good practice to encrypt all data across the internet. In fact, nowadays all major internet companies encrypt their data by default via SSL/TLS; doing so is considered a best practice and you should be skeptical of any service that doesn't. Second, acquiring a signed certificate from a CA is expensive. There's no sense in spending money if all you want is to set up a little hobby server with a secure connection. Third, getting a cert from a CA requires the CA to perform some kind of background check. In this case, you would have to divulge a lot of personal data to the CA which raises some privacy issues. For example, what happens if the CA itself doesn't have good internal security practices and your personal data is leaked (a la Target, Home Depot, Ashley Madison, etc.)?


The most important issue that is not well addressed in the CA framework of SSL/TLS is semi-anonymity. Let's say you have an associate you know as Mr. X. You don't know X's identity, but there's some amount of trust you have in his work. Mr. X finds it unacceptable to divulge his identity to a corporate CA, but he needs to set up a website that employs both the encryption and identity features of SSL/TLS. Encryption is relatively easy: X sets up a self-signed x.509 cert. Identity is much more tedious because it looks like the steps listed below. In my opinion, this issue of semi-anonymity is the edge case that needs a better solution. I may not know exactly who X is, but I automatically want to be sure that my browser is connecting to his server.

The problem: it isn't straightforward to verify a self-signed cert

At this point you should be convinced that it isn't technically too difficult to set up a self-signed cert on your webserver, SSL/TLS traffic is secure end-to-end, and there are legitimate reasons for deploying a self-signed certificate. The big problem is: how do I know the server holding a self-signed cert and to which I'm sending data is actually Marty's server?

It turns out that verifying the identity of Marty's server was more involved than I would have liked. I had to actually type more than one command into the command line, send an email to Marty, he had to log into his server and type several commands into the command line, and then respond with another email. There were an unacceptably large number of manual steps in this scenario. When this many manual steps are required, security will end up suffering because nobody is going to take the time to do them all.

Specifics: How did I verify the identity of Marty's server?

This process was implemented over the following steps. The upshot is that I had an excuse to use the openssl command in the terminal; this exercise demystified a lot of the SSL/TLS framework for me.

  1. Acquire Marty's cert and associated metadata

    $ openssl s_client -showcerts -connect | openssl x509 -text -fingerprint

    In this command, I am calling the openssl program twice, piping the output of one command into another. The first time I am invoking the s_client option to show the certificate (-showcerts) after connecting to Marty's server (-connect command) on the TLS port 443. The second openssl command is to manage the x509 cert, returning it as -text and calculating its -fingerprint.

    The above command yielded the following data:

            Version: 1 (0x0)
            Serial Number: 13286215849167086773 (0xb8621eebe2c4e4b5)
        Signature Algorithm: sha256WithRSAEncryption
            Issuer: C=US, ST=Maryland, L=Baltimore, O=SCHMARTY DOT NET, CN=SCHMARTY DOT NET
                Not Before: Oct 15 15:57:00 2014 GMT
                Not After : Oct 14 15:57:00 2019 GMT
            Subject: C=US, ST=Maryland, L=Baltimore, O=SCHMARTY DOT NET, CN=*
            Subject Public Key Info:
                Public Key Algorithm: rsaEncryption
                    Public-Key: (2048 bit)
                    Exponent: 65537 (0x10001)
        Signature Algorithm: sha256WithRSAEncryption
    SHA1 Fingerprint=C6:E2:AF:00:12:E6:F4:53:96:3F:F5:00:2D:4D:7D:C1:26:D9:F2:C8
    -----END CERTIFICATE-----

    This data (e.g. the SHA1 fingerprint) matched what I saw when I connected to the server with Safari and examined the certificate.

  2. I copied the above data (especially the part between the "BEGIN CERTIFICATE" and "END CERTIFICATE") and pasted it into a textfile with an email message to Marty. I then signed this message with my gpg key (200C61F9) because it seemed like the crypto thing to do. Also I wanted to indicate that I wanted Marty to sign whatever response he sent back because I wanted to be sure that I wasn't experiencing a sophisticated spoofing attack (super low probability, but no sense in half-assing this security exercise).

  3. Marty executed some commands on his hardware to verify the cert:

    marty@dogeland:~$ openssl x509 -noout -modulus -in saved_certificate.txt | openssl sha256
    (stdin)= ef835bdf6080bfe6e73c8c81545e8088bf2169970a0a70ac3305a54267431a52
    marty@dogeland:~$ openssl rsa -noout -modulus -in /path/to/gitlab/server.key | openssl sha256
    (stdin)= ef835bdf6080bfe6e73c8c81545e8088bf2169970a0a70ac3305a54267431a52

    Note that saved_certificate.txt contained the stuff between "BEGIN CERTIFICATE" and "END CERTIFICATE".

For fun, he also compared this with the server certificate file used by his web server:

marty@dogeland:~$ openssl x509 -noout -modulus -in /path/to/gitlab/server.crt | openssl sha256
(stdin)= ef835bdf6080bfe6e73c8c81545e8088bf2169970a0a70ac3305a54267431a52

We were both happy that the above results verified his server.

Reiteration: these steps are a pain in the ass

Again, there are too many steps here. Normal people won't take the time to figure out how to do them, even if they are willing to take the time to set up a self-signed x.509 cert for their server. Pretty much the only reason I did them was out of boredom while waiting for my phone to get fixed at the Apple store.

95% Solution: Let's Encrypt

The key problem that needs to be solved is identity: was the self-signed x.509 cert issued by someone with a key I already trust? Related, can the holder of that cert revoke it?

Fortunately, it looks like some of these issues will be resolved when the Let's Encrypt project is out of beta. It looks like Let's Encrypt will run a service that issues free certs that are signed by a root cert that most browsers already trust. Let's Encrypt has a clever way to guarantee the owner of the domain is the operator of the server to which the domain resolves; I invite you to read their description if you want to know the technical details.

The issue of facilitating semi-anonymity still exists in this scenario because Marty/Mr. X and I still have to exchange communication (via cryptographically signed messages) for me to know his server can be reached at a particular domain. I think this problem could be solved by integrating Let's Encrypt and

  1. A user could first verify their domain.
  2. Next, they would request a cert from Let's Encrypt.
  3. Let's Encrypt would note that the domain was verified on and embed that information into the cert it issues.

I'm not an expert at this kind of infrastructure, so a better implementation likely exists.

At this point, there should be enough information in the cert held by Marty's server that I can cryptographically convince myself that:

  1. The connection is end-to-end secure.
  2. The identity of the server at the other end is what it should be (avoiding man-in-the-middle).
  3. This server actually belongs to Marty because his gpg signature appears in the cert.

The third item could be implemented in the keybase command line client and also appear on a user's profile page.