# Getting and installing certificates

A certificate proves to browsers and FTP clients that your server is the one they asked for. A new server uses a certificate that is built into every copy of CrushMFT: it encrypts, and proves nothing, and every browser warns about it. Replace it before the server goes online.

This page is the way from "no certificate" to "the padlock is closed". It is all done in Preferences › [Certificates](Prefs-Certificates.md), which describes each button.

## Which way?

| You have | Do |
|---|---|
| nothing yet, and port 80 or 443 of the name reaches the server from the internet | **Free certificate**: [From Let's Encrypt](#from-lets-encrypt), below. It renews itself. |
| nothing yet, and a name the internet cannot reach, or a wildcard | **Free certificate**, **Through DNS**: [Let's Encrypt by DNS](ACME-DNS.md) |
| nothing yet, and you buy certificates from a certificate company | [A new certificate from a company](#a-new-certificate-from-a-company), below |
| a `.pfx` or `.p12` file, for example exported from a Windows server (IIS) | drop it on the box under the list: [Bringing in a certificate you have](#bringing-in-a-certificate-you-have) |
| a key file and certificate files, as other web servers keep them, or the zip a company sent | drop them all on the box, the same way |
| a certificate that is about to end | **Renewal** tab of the certificate: [Renewing](#renewing) |
| a file that certbot or your IT team keeps up to date | **Key store files**, **Open a key store file**: [Key store files](Certificates-Key-Store-Files.md) |
| a server that ran before, with a certificate file in its settings | nothing: CrushMFT finds it and it is in the list |

Then [choose where it is used](#using-it).

## From Let's Encrypt

1. Point each name at your server (its DNS A record), and forward port 80 of your public address to an HTTP port of CrushMFT. The port inside may have any number: [Port 80 on the internet, any port on CrushMFT](ACME-Ports-And-Forwarding.md).
2. **Free certificate**: the names (filled in from **The addresses people use**), **Through port 80**, and **Use it on**: **The server's certificate**.
3. **Test, then get it**. The whole exchange runs first with Let's Encrypt's test service, so a mistake does not use up your allowance of real certificates ([Testing first](ACME-Testing-And-Limits.md)); then the real certificate is ordered and put in use. Each step shows as it happens. Press **Keep** when the page loads again.

It renews by itself from then on: [Let's Encrypt](ACME-Lets-Encrypt.md).

## A new certificate from a company

A certificate company wants a request (CSR), made from a private key that stays on your server.

1. **Request from a company**: the names. CrushMFT makes a new private key and its request; the list shows the certificate with **Request out**.
2. **Copy** or **Download** the request and give it to the company, where they ask for a CSR.
3. When they send the certificate, drop the file on the box under the list: it is matched to the waiting key, and **Finish the request of NAME** keeps it.

Or ask the company for the certificate and its key as a `.pfx` file, or make the key and the request with OpenSSL ([Converting keys and certificates](Security-TLS-Converting-Keys.md)), and [bring in what they send](#bringing-in-a-certificate-you-have).

Once a certificate is in the list, every later renewal starts from its Renewal tab: [Renewing](#renewing).

## Bringing in a certificate you have

Drop every file you have on the box at once (**Add a certificate: drop its files here, or choose them**): the `.pfx`, or the certificate, its key and the company's chain or bundle file, or their zip. CrushMFT works out what each file is, asks for a password only for a file that has one, matches the key to its certificate, completes the chain, and shows what it found with its checks before anything is saved.

Read the checks, then **Save as a new certificate** (or **Replace NAME** for a certificate it renews).

| A check says | Do |
|---|---|
| a middle (intermediate) certificate is missing | add the company's bundle or chain file to the drop; or later, on the certificate's Chain tab, **Fetch missing** ([Chains](Certificates-Chains.md)) |
| it does not cover a name | it is for other names than the ones people type: check **The addresses people use**, or get a certificate with all the names |
| no private key here | add the key file. A certificate alone is of no use to a server. |
| it comes from an authority browsers do not trust on their own | a certificate of your own company's authority. Fine for partners who trust it; browsers warn. |

The private key is the part you must never lose and never give away. CrushMFT keeps it in a file of its own under `keystores/` in the CrushMFT folder, with a password it makes: [How CrushMFT keeps certificates](Certificates-How-CrushMFT-Keeps-Them.md).

## Using it

On the certificate, **Use it on…**, **The server's certificate**: every port without a certificate of its own then serves it. Or a port of its own, for a port reached under another name; or a port that serves it **as well**, to the clients that ask for its names.

The server checks the certificate, starts those ports again in place, reads what each serves, and loads the page again. Press **Keep** within two minutes, or everything goes back as it was. So a wrong choice cannot lock you out.

To see it first without changing any port: **Try it first** on its Overview.

Several names on one port, each with its own certificate: [Several names on one port](Certificates-Several-Names.md).

## Renewing

On the certificate's **Renewal** tab, **Request from my certificate company** makes a new private key of the same kind and a request with the same names. Send the request to the company ("renew" or "reissue" on their website). When they send the certificate, drop it on the box: it is matched to the waiting key, and **Finish the request of NAME** puts it in place. The ports take it within a minute, without a restart. Until then nothing changes.

Start two weeks before the end date. The list turns amber 30 days before, **Needs you** lists it, and the [TLS Certificate alert](Prefs-Certificates.md#alerts) can mail you at 30, 14, 7 and 1 days.

A certificate from Let's Encrypt renews itself. **Renew now** on its Renewal tab renews it at once.

## Proving the name is yours

A certificate company must be sure that you control the name. It offers one or more of:

| Method | You do |
|---|---|
| a mail to an address of the domain | click the link in it |
| a record in DNS | add the record they name |
| a file on the web server, at `http://files.example.com/.well-known/pki-validation/…` | see below |

### The file on the server

1. On the server's disk, make a folder `well-known` with a folder `pki-validation` in it, and put the company's file there.
2. Make a user named `anonymous` if there is none, and give it that `well-known` folder: drag it into the user's folders in [the VFS editor](Users-Setup-VFS-Editor.md), and rename the item to `.well-known`, with the dot. Download and view are enough.
3. In [WebInterface](Prefs-WebInterface.md#anonymous-access) of the Preferences, make sure **Ignore web anonymous** is off, so that requests without a login reach that user.
4. Open the address from another machine and check that the file is shown.
5. When the certificate is issued, undo it: remove the folder from the user, or the user, and turn **Ignore web anonymous** back on if it was on.

Let's Encrypt does its own proof without any of this: [Let's Encrypt](ACME-Lets-Encrypt.md).

## Checking

- In Certificates: each certificate's checks on its Overview and Chain, and in **Where used** what each port serves, read by the server itself.
- In a browser: the padlock, and in its details the names, the end date, and the chain up to a known authority.
- From a command line:

  ```
  openssl s_client -connect files.example.com:443 -servername files.example.com </dev/null | openssl x509 -noout -subject -issuer -dates
  ```

- A test from outside your network, with one of the public TLS checkers, shows what strangers see: the chain, the TLS versions and the ciphers. See [Ciphers](Prefs-Encryption-Ciphers.md).

## When browsers still warn

| The browser says | Usually |
|---|---|
| the name does not match | the name typed is not among the certificate's names: its Names tab says it is not covered when the name is under **The addresses people use** |
| the issuer is unknown, on some devices only | the middle certificate is missing: **Fix chain** on its Chain tab ([Chains](Certificates-Chains.md)) |
| the certificate has expired | renew; and check the clock of the server |
| it still shows the built-in certificate | the port has a certificate of its own, or the server's certificate is the built-in one: see **Where used**. A red notice at the top of Certificates means a file did not open at the last start. |
| an old certificate, after a renewal | the port serves a kept copy because the new file does not open: the notice at the top of Certificates says why |
