> Source: https://docs.cyberelements.io/saas/el/Security/GatewayCertificates/

# Edge Gateway certificate and private key

When **CyberElements Edge Gateway** servers are installed, a `p12` file is put in place for each instance: it holds a certificate and its private key, used to establish the SSL/VPN tunnel towards the Mediation Controller.

> **Information**
>
> These files are sensitive in the same way as the other cryptographic material already covered by this guide (SSH host keys, see [SSH](https://docs.cyberelements.io/saas/el/Security/Ssh/)). Compromising them would allow an attacker to **impersonate the legitimate gateway** towards the Mediation Controller. The principle applied here is the one set out by ANSSI-BP-028 (R50, R51) in the system hardening chapter: restrict access to sensitive files to the one service account that needs it, **from installation onwards**.

## Summary

| # | Recommendation | Edge Gateway |
|---|---|---|
| [**R48**](#r48) | Protection of p12 files and their associated configuration | ✅ |
| [**R49**](#r49) | Continuity of protection after a certificate update or renewal | ✅ |

## R48. Protection of p12 files and their associated configuration

**Applies to**: Edge Gateway ✅

Make sure that **only the dedicated service account** needs access to the `p12` file of a given instance.

The password protecting that `p12` file is itself stored in the **XML configuration file** of the corresponding instance: this second file must be given permissions just as restrictive as the `p12` itself. Restricting one without the other provides only **illusory protection**, since reading the XML file is enough to obtain the password that opens the `p12`.

| Instance | Files concerned | Service account |
|---|---|---|
| Edge Gateway (`gateway`) | `/etc/ipdiva/gateway/ssl/gateway.p12` `/etc/ipdiva/gateway/gateway.xml` | `ipdivagateway` (group `carerecord`) |
| Edge Gateway (`html5gateway`) | `/etc/ipdiva/html5gateway/ssl/gateway.p12` `/etc/ipdiva/html5gateway/html5gateway.xml` | `ipdivahtml5gateway` |
| Recording service (`careserver`) | `/etc/ipdiva/careserver/careserver.xml` certificate associated with the `careserver` service | `ipdivacarerecord` (group `carerecord`) |

Commands that set the appropriate rights:

```
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
```

Perform the same operation (owner `ipdivacarerecord`, group `carerecord` with read access) for the certificate of the `careserver` service, then restart the recording service:

```
1
```

**Specific to CyberElements**: the `carerecord` group must be able to read the certificate and the configuration file of the gateway (hence the `carerecord` owning group on the `gateway` files above) as well as those of the `careserver` service, the recording service running under the dedicated service account `ipdivacarerecord`.

> **Warning!**
>
> The file name `gateway.p12` is the one encountered **by default**; it must be adapted to the name actually present on the server. These commands must also be adapted where **several instances** of `gateway` or HTML5 coexist on the same server, each instance having its own set of files.

Checking the effective permissions:

```
1
2
3
```

## R49. Continuity of protection after a certificate update or renewal

**Applies to**: Edge Gateway ✅

Renewing a certificate (whether managed by the product or resulting from the manual import of a new `p12` file supplied by the integrator) may **recreate the files concerned with default permissions**, more permissive than those set in [R48](#r48). The same applies after a major update of CyberElements or a restore from backup.

> **Warning!**
>
> This behaviour is similar to the one already reported for the `sudo` binary (see [R9](https://docs.cyberelements.io/saas/el/Security/SystemHardening/SystemAccounts/#r9)): **a maintenance operation can silently undo hardening that was applied manually**. The permissions of `p12` files and of their associated configuration files must therefore be checked **systematically** after every certificate renewal, product update or restore, not once, at initial installation.

> **Information**
>
> Where generating or importing the certificate is the integrator's responsibility rather than being handled natively by the product, the key size requirements already set for SSH keys ([R32](https://docs.cyberelements.io/saas/el/Security/Ssh/#r32): RSA 4096 bits or ECDSA secp384r1) are a consistent reference to apply here as well, to be validated against the capabilities of the certification authority used.
