1

I've created a self-signed sertificate

$ openssl genrsa -out key.pem 1024
$ openssl req -new -key key.pem -out request.csr
$ openssl x509 -req -in request.csr -signkey key.pem -out cert.pem

and created an HTTPS server:

var server = https.createServer({
    key: fs.readFileSync(__dirname + "/key.pem"),
    cert: fs.readFileSync(__dirname + "/cert.pem")
}

Then I requested the page. The expected result is that a browser complained that a connection is not secure. My question how does a browser know that? Is it server job to verify the certificate and notify browser about that or it's a browser job?

Max Koretskyi
  • 101,079
  • 60
  • 333
  • 488
  • 2
    http://security.stackexchange.com/questions/20803/how-does-ssl-tls-work – DavidDomain Dec 23 '16 at 09:23
  • 2
    [SSL Certificate framework 101: How does the browser actually verify the validity of a given server certificate?](http://security.stackexchange.com/questions/56389/ssl-certificate-framework-101-how-does-the-browser-actually-verify-the-validity) – Steffen Ullrich Dec 23 '16 at 09:56

3 Answers3

6

SSL Certificates are verified by the client.

The server typically will verify the certificate is not broken or corrupt on start-up, but most servers don't actually validate the legitimacy of their certificate.

Why verify the certificate?

Verification of the server certificate is important because otherwise the client can't really know who it is communicating with. MITM (Man In the Middle) attacks can take place where a third party is intercepting both sides of the communication and they can provide their data to you instead of the data from the server which you thought you were receiving.

A little bit about certificate types

Most certificates are signed by CAs, there are also self-signed certificates, and pinned certificates. I advise using a certificate signed by a CA whenever possible. The Second best option (which generally can only be used within an organization) would using your own internal CA and then self-signing your server cert with your CA cert, this is known as a self-signed certificate and it won't be trusted automatically by any clients or browsers which receive it.

In the self-signed option you must import your CA public key into your CA key store for your server certificate to be trusted. Finally there is simply a pinned certificate, this is where you simply tell your browser to trust an otherwise untrusted certificate (do not do this).

Warning - You should avoid pinning certificates because they are almost impossible to replace during a compromise, and certificates should be schedule to expire within a reasonable period, and be regularly rotated. Pinning makes that very difficult if almost impossible in some situations.

Types of certificates

  • CA Signed (Needed to operate a secure site on the WWW)
  • Self Signed (Good for internal organization usage, internal company wikis for example)
  • Pinned (Avoid)

What kind of verification happens?

So you have a certificate, first you configure your server to use that certificate.

Now when a client comes along and requests a secure connection to your site (as indicated by connecting to port 443 in in the case of HTTPS). Your server sends it's public (not private) certificate and begins a secure handshake. One such handshake is called a Diffie–Hellman key exchange. The handshake itself is beyond the scope of this question.

Before participating in the key exchange, the browser will first examine the certificate which the server provided. For it to be valid several checks must be successful.

There are some of the checks performed.

  • Does this certificate contain the hostname which matches the hostname we connected to?

    • If NO, does the certificate include a wildcard CN (Common Name)?
      • If YES, does that CN have a valid "wildcard" that matches the host name we're connected to? YES/NO
  • Does the certificate include a CRL (Certificate Revocation List)? If so, does that CRL indicate that this certificate is still valid? YES/NO

  • Is this certificate signed by a known certificate authority (CA)? YES/NO

    • Only if NO, does this client (browser) have a public certificate (which matches the certificate offered by this server), which has been marked as Trusted? YES/NO *This is also known as a pinned certificate, as you are not relying on a CA to verify it's authenticity.

For the browser to trust the certificate, and by proxy the server. Then we must check each of the Yes boxes above

Other security stuff that makes the world safer

Now there are other things not "specific" to the certificate which are also verified.

For example, both the client and server must agree on the handshake method, the ciphers used, the hashing algorithm used, and other things.

The server may also pass special HTTPS security flags instructing the browser not to trust other certificates for this service for a period of time (this is known as certificate pinning). Certificate pinning like that used in "Strict Transport Security" (not to be confused with pinning a certificate as mentioned above) can help prevent MITM (man in the middle) attacks. This is one of the many extra security features that HTTPS Strict Transport Security offers.

Once all of the security checks have been certified the browser sends any request it had to the server and the server responds appropriately.

Joshua Briefman
  • 3,783
  • 2
  • 22
  • 33
  • The question is currently missing the information why the client must check the certificate and why it is not enough that the client simply trusts that the server has already checked the certificate as the OP offered as one option for verification. – Steffen Ullrich Dec 23 '16 at 09:50
  • I think you mean answer. First, those questions were not asked by the requestor, the requestor asked "How the certificate is verified". But I will answer these two questions for you in my post. – Joshua Briefman Dec 23 '16 at 09:53
2

When you visit a secured website (with https), the server also sends a certificate signed by an authority to prove its identity (so that you know you're not getting man in the middled).

Then, your browser needs to know if the certificate is genuine or not, because the man in the middle could send a certificate too. Luckily for you, your browser has a list of authorities to trust. If the certificate's authority signature matches one of the trusted authorities, then everything is fine and no alert is raised.

But if no authorities matches, then the browser kindly asks you if we can trust this authority. In the case of a self-signed certificate, you can trust it (but not before verifying the fingerprint, because, again, a man in the middle could send a different certificate to trick you into believing they're the real deal).

If you trust it, then the browser imports it and adds it to the certificates to trust, never raising an alarm again (until your certificates expires or change (like in a man in the middle situation)).

Trucy
  • 146
  • 2
  • 14
  • thanks, can you define the process how it's done or provide a link to resource that describes the process? I'd like to know the steps starting with `a browser sends Upgrade-Insecure-Requests:1 header...` – Max Koretskyi Dec 23 '16 at 08:57
  • It depends on your OS, but a quick search returned this: [for Windows](http://www.omnisecu.com/security/public-key-infrastructure/how-import-root-ca-certificate-trusted-root-certification-authorities.php), [for Firefox on Linux](https://www.cyberciti.biz/faq/firefox-adding-trusted-ca/) – Trucy Dec 23 '16 at 09:03
  • thanks, your answer is more like a comment. Can you elaborate it a bit with a process description? The link you provided didn't help much. It's says that I have to import something, although I never import anything when vising different http websites – Max Koretskyi Dec 23 '16 at 09:13
  • I edited it but I don't know if you want to know how it works or how to import a certificate, as your question is just about "is it server side or browser side". – Trucy Dec 23 '16 at 09:28
  • 1
    Is it possible for a `Man in the Middle` to issue a certificate as well? In my opinion, if a `Man in the Middle` can issue a certificate, there is no use since however the connection will be encrypted once the certificate is validated. Since the client-server connection is encrypted through SSL, the `Man in the Middle` cannot read the data transmitted along the connection. If I'm wrong of what I've just said, you could provide valid explanation. – Wolverine Jan 11 '17 at 20:12
2

Is it server job to verify the certificate and notify browser about that or it's a browser job?

The main role of the server certificate is to make sure that the client is communicating with the expected server. If the client (browser) would just trust the server that the certificate is valid some man in the middle attacker could simply claim to be the real server and claim that the certificate is valid. And after this the client would establish the encrypted connection to the attacker instead of the real server which means that the attacker gets access to the sensitive data. Therefore the servers certificate must always be properly checked by the client.

My question how does a browser know that?

In short: by checking that the certificate is trusted by checking the signature of the issuer and following the trust chain up to a locally trusted root certificate, also checking that the hostname of the URL matches the subject of the certificate and that the certificates are still valid, i.e. not expired and not revoked. For more details see SSL Certificate framework 101: How does the browser actually verify the validity of a given server certificate?.

Community
  • 1
  • 1
Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • This answer does not appropriately answer the requestor's question. – Joshua Briefman Dec 23 '16 at 09:28
  • @JoshuaBriefman: better now? If not please explain instead of complain only. – Steffen Ullrich Dec 23 '16 at 09:39
  • Answers which are mainly a "Link to an answer" are discouraged as the content may or may not be there in the future. Your answer should contain your full answer. You may reference outside links as references/citations however. Please take a look at my response for an example. – Joshua Briefman Dec 23 '16 at 09:46