Skip to content

Commit 9fe4f50

Browse files
committed
use cumulocity certificate-authority for device registration to avoid self-signed certificates
Signed-off-by: reubenmiller <reuben.d.miller@gmail.com>
1 parent 45f8d25 commit 9fe4f50

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

tests/RobotFramework/tests/pkcs11/private_key_storage.robot

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ Select Private key using a request URI
7373
Should Contain ${stderr} item=cryptoki: socket (key: pkcs11:token=token123)
7474

7575
Execute Command cmd=tedge config unset device.key_uri
76-
Execute Command cmd=tedge config set c8y.device.key_uri pkcs11:token=token123
76+
Execute Command cmd=tedge config set device.key_uri pkcs11:token=token123
7777
${stderr}= Tedge Reconnect Should Fail With Failed to find a signing key
7878
Should Contain ${stderr} item=cryptoki: socket (key: pkcs11:token=token123)
7979

80-
Execute Command cmd=tedge config set c8y.device.key_uri "pkcs11:token=tedge;object=tedge"
80+
Execute Command cmd=tedge config set device.key_uri "pkcs11:token=tedge;object=tedge"
8181
${stderr}= Tedge Reconnect Should Succeed
8282
Should Contain ${stderr} item=cryptoki: socket (key: pkcs11:token=tedge;object=tedge)
8383

@@ -181,24 +181,20 @@ Connect to C8y using new keypair
181181
ELSE
182182
Fail Wrong key type provided.
183183
END
184-
VAR ${cert_path}= /etc/tedge/device-certs/${object_name}.pem
184+
${csr_path}= Execute Command cmd=tedge config get device.csr_path strip=${True}
185185

186186
Execute Command
187187
... cmd=p11tool --set-pin=123456 --login --generate-privkey ${type} ${p11tool_args} --label ${object_name} "pkcs11:token=tedge"
188-
# we should probably generate certs signed by CA instead of uploading them
189188
Execute Command
190-
... cmd=GNUTLS_PIN=123456 certtool --generate-self-signed --template ${CERT_TEMPLATE} --outfile ${cert_path} --load-privkey "pkcs11:token=tedge;object=${object_name}"
189+
... cmd=GNUTLS_PIN=123456 certtool --generate-request --template "${CERT_TEMPLATE}" --outfile "${csr_path}" --load-privkey "pkcs11:token=tedge;object=${object_name}"
191190

192-
Execute Command tedge config set c8y.device.cert_path ${cert_path}
193-
Execute Command cmd=tedge config set c8y.device.key_uri "pkcs11:token=tedge;object=${object_name}"
191+
Execute Command cmd=tedge config set device.key_uri "pkcs11:token=tedge;object=${object_name}"
194192

195-
# upload (THIS STAYS ON C8Y AND ISN'T DELETED)
196-
Upload Currently Used Certificates To Cumulocity
193+
Register Device With Cumulocity CA ${csr_path}
197194

198195
Tedge Reconnect Should Succeed
199196

200-
Execute Command tedge config unset c8y.device.cert_path
201-
Execute Command tedge config unset c8y.device.key_uri
197+
Execute Command tedge config unset device.key_uri
202198

203199
Custom Setup
204200
${DEVICE_SN}= Setup skip_bootstrap=${True}
@@ -208,18 +204,19 @@ Custom Setup
208204
Execute Command sudo usermod -a -G softhsm tedge
209205
Transfer To Device ${CURDIR}/data/init_softhsm.sh /usr/bin/
210206

211-
# initialize the soft hsm and create a self-signed certificate
207+
# initialize the soft hsm and create a certificate signing request
212208
Execute Command tedge config set device.cryptoki.pin 123456
213209
Execute Command tedge config set device.cryptoki.module_path /usr/lib/softhsm/libsofthsm2.so
214-
Execute Command sudo -u tedge /usr/bin/init_softhsm.sh --self-signed --device-id "${DEVICE_SN}" --pin 123456
210+
Execute Command sudo -u tedge /usr/bin/init_softhsm.sh --device-id "${DEVICE_SN}" --pin 123456
215211

216212
# configure tedge
217213
${domain}= Cumulocity.Get Domain
218214
Execute Command tedge config set c8y.url "${domain}"
219215
Execute Command tedge config set mqtt.bridge.built_in true
220216
Execute Command tedge config set device.cryptoki.mode socket
221217

222-
Upload Currently Used Certificates To Cumulocity
218+
${csr_path}= Execute Command cmd=tedge config get device.csr_path strip=${True}
219+
Register Device With Cumulocity CA ${csr_path}
223220

224221
Set tedge-p11-server Uri value=
225222

@@ -238,7 +235,8 @@ Tedge Reconnect Should Fail With
238235
Should Contain ${stderr} ${error}
239236
RETURN ${stderr}
240237

241-
Upload Currently Used Certificates To Cumulocity
238+
Register Device With Cumulocity CA
239+
[Arguments] ${csr_path}
240+
${credentials}= Cumulocity.Bulk Register Device With Cumulocity CA external_id=${DEVICE_SN}
242241
Execute Command
243-
... cmd=sudo env C8Y_USER="${C8Y_CONFIG.username}" C8Y_PASSWORD="${C8Y_CONFIG.password}" tedge cert upload c8y
244-
Register Certificate For Cleanup
242+
... cmd=tedge cert download c8y --csr-path "${csr_path}" --device-id "${DEVICE_SN}" --one-time-password '${credentials.one_time_password}' --retry-every 5s --max-timeout 60s

0 commit comments

Comments
 (0)