Skip to content

Commit 5214cac

Browse files
authored
Merge pull request #3692 from reubenmiller/docs-download-root-cert
docs: add tip on how to download only the root certificate using openssl and awk
2 parents f976ca3 + 3e460b8 commit 5214cac

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

docs/src/operate/security/cloud-authentication.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@ tags: [Operate, Security]
44
description: Configuring certificates for your cloud connection
55
---
66

7+
import UserContext from '@site/src/components/UserContext';
8+
import UserContextForm from '@site/src/components/UserContextForm';
9+
10+
:::tip
11+
#### User Context {#user-context}
12+
13+
You can customize the documentation and commands shown on this page by providing relevant settings which will be reflected in the instructions. It makes it even easier to explore and use %%te%%.
14+
15+
<UserContextForm settings="DEVICE_ID,C8Y_URL,C8Y_USER" />
16+
17+
The user context will be persisted in your web browser's local storage.
18+
:::
19+
720
When %%te%% connects a cloud, the cloud endpoint is authenticated using X.509 certificates.
821
For that to work, the signing certificate of the cloud certificate must be trusted by the device.
922
Usually, these certificates are stored in `/etc/ssl/certs` and nothing specific has to done on the device.
@@ -66,10 +79,29 @@ Copy your root certificate (in `PEM` format with `.crt` extension) to the create
6679
sudo cp <full_path_to_the_certificate> /usr/local/share/ca-certificates/
6780
```
6881

82+
:::tip
83+
84+
If you have openssl and awk available on your device, then you can download the root certificate (e.g. the last certificate in the chain) from a given server using the following command:
85+
86+
<UserContext>
87+
88+
```sh
89+
openssl s_client -connect $C8Y_URL:443 -showcerts 2>/dev/null </dev/null \
90+
| awk '/-*BEGIN CERTIFICATE-*/{m=1; last_cert=""} m{last_cert=last_cert"\n"$0} m{if( /-*END CERTIFICATE-*/ ) m=0} END{ sub(/^\n/, "", last_cert); print last_cert}' \
91+
| sudo tee /usr/local/share/ca-certificates/$C8Y_URL.crt
92+
```
93+
94+
</UserContext>
95+
96+
:::
97+
6998
Install the certificates:
7099

71100
```sh
72101
sudo update-ca-certificates
102+
103+
# If you need to reprocess all certificates (not just the certs that were added/removed) then use:
104+
sudo update-ca-certificates -f
73105
```
74106

75107
```text title="Output"

docs/src/start/connect-c8y.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ This is the certificate chain of the server and not the device's certificate kep
113113
:::
114114

115115
If the Cumulocity server's certificate chain file isn't available locally, it can be downloaded using a web browser or using some other
116-
third-party tools like openssl command as follows:
116+
third-party tools like openssl command to download the root certificate for a given instance:
117117

118118
<UserContext>
119119

120120
```sh
121-
openssl s_client -connect $C8Y_URL:443 < /dev/null 2>/dev/null \
122-
| sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'
121+
openssl s_client -connect $C8Y_URL:443 -showcerts 2>/dev/null </dev/null \
122+
| awk '/-*BEGIN CERTIFICATE-*/{m=1; last_cert=""} m{last_cert=last_cert"\n"$0} m{if( /-*END CERTIFICATE-*/ ) m=0} END{ sub(/^\n/, "", last_cert); print last_cert}'
123123
```
124124

125125
</UserContext>

0 commit comments

Comments
 (0)