Skip to content

Commit edbe3a3

Browse files
Read certificates from localdata and preserve them during upgrades (#187)
1 parent d7a2fdb commit edbe3a3

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,26 +117,26 @@ achieve this, for example by using `scp` to copy the files from a remote machine
117117
This can be done by running the following command on the remote machine:
118118

119119
```sh
120-
scp ca.pem server-cert.pem server-key.pem root@<device ip>:/usr/local/packages/dockerdwrapper/
120+
scp ca.pem server-cert.pem server-key.pem root@<device ip>:/usr/local/packages/dockerdwrapper/localdata/
121121
```
122122

123123
#### The Certificate Authority (CA) certificate
124124

125125
This certificate needs to be present in the dockerdwrapper package folder on the
126126
Axis device and be named `ca.pem`. The full path of the file should be
127-
`/usr/local/packages/dockerdwrapper/ca.pem`.
127+
`/usr/local/packages/dockerdwrapper/localdata/ca.pem`.
128128

129129
#### The server certificate
130130

131131
This certificate needs to be present in the dockerdwrapper package folder on the
132132
Axis device and be named `server-cert.pem`. The full path of the file should be
133-
`/usr/local/packages/dockerdwrapper/server-cert.pem`.
133+
`/usr/local/packages/dockerdwrapper/localdata/server-cert.pem`.
134134

135135
#### The private server key
136136

137137
This key needs to be present in the dockerdwrapper package folder on the Axis device
138138
and be named `server-key.pem`. The full path of the file should be
139-
`/usr/local/packages/dockerdwrapper/server-key.pem`.
139+
`/usr/local/packages/dockerdwrapper/localdata/server-key.pem`.
140140

141141
#### Client key and certificate
142142

app/dockerdwrapper.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static const char* ax_parameters[] = {PARAM_APPLICATION_LOG_LEVEL,
9595
PARAM_TCP_SOCKET,
9696
PARAM_USE_TLS};
9797

98-
static const char* tls_cert_path = APP_DIRECTORY;
98+
#define TLS_CERT_PATH APP_LOCALDATA
9999

100100
static const char* tls_certs[] = {"ca.pem", "server-cert.pem", "server-key.pem"};
101101

@@ -410,9 +410,9 @@ static gboolean get_and_verify_tls_selection(AXParameter* param_handle, bool* us
410410
const bool use_tls = is_parameter_yes(param_handle, PARAM_USE_TLS);
411411
{
412412
if (use_tls) {
413-
char* ca_path = g_strdup_printf("%s/%s", tls_cert_path, tls_certs[0]);
414-
char* cert_path = g_strdup_printf("%s/%s", tls_cert_path, tls_certs[1]);
415-
char* key_path = g_strdup_printf("%s/%s", tls_cert_path, tls_certs[2]);
413+
char* ca_path = g_strdup_printf("%s/%s", TLS_CERT_PATH, tls_certs[0]);
414+
char* cert_path = g_strdup_printf("%s/%s", TLS_CERT_PATH, tls_certs[1]);
415+
char* key_path = g_strdup_printf("%s/%s", TLS_CERT_PATH, tls_certs[2]);
416416

417417
bool ca_exists = access(ca_path, F_OK) == 0;
418418
bool cert_exists = access(cert_path, F_OK) == 0;
@@ -530,19 +530,15 @@ static bool start_dockerd(const struct settings* settings, struct app_state* app
530530
args_offset +=
531531
g_snprintf(args + args_offset, args_len - args_offset, " -H tcp://0.0.0.0:%d", port);
532532
if (use_tls) {
533-
const char* ca_path = APP_DIRECTORY "/ca.pem";
534-
const char* cert_path = APP_DIRECTORY "/server-cert.pem";
535-
const char* key_path = APP_DIRECTORY "/server-key.pem";
536533
args_offset += g_snprintf(args + args_offset,
537534
args_len - args_offset,
538-
" %s %s %s %s %s %s %s",
539-
"--tlsverify",
540-
"--tlscacert",
541-
ca_path,
542-
"--tlscert",
543-
cert_path,
544-
"--tlskey",
545-
key_path);
535+
" --tlsverify"
536+
" --tlscacert %s/ca.pem"
537+
" --tlscert %s/server-cert.pem"
538+
" --tlskey %s/server-key.pem",
539+
TLS_CERT_PATH,
540+
TLS_CERT_PATH,
541+
TLS_CERT_PATH);
546542
g_strlcat(msg, " in TLS mode", msg_len);
547543
} else {
548544
args_offset += g_snprintf(args + args_offset, args_len - args_offset, " --tls=false");

0 commit comments

Comments
 (0)