Skip to content

Instantly share code, notes, and snippets.

@vedangj044
Last active September 10, 2021 11:40
Show Gist options
  • Save vedangj044/831ecdec5197b6b76a095bca6c11eb5a to your computer and use it in GitHub Desktop.
Save vedangj044/831ecdec5197b6b76a095bca6c11eb5a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Assuming you already have `drg login ..`
rm z*
openssl req -x509 -nodes -newkey rsa:4096 -keyout zapp-key.pem -out zapp-cert.pem -days 365 -subj "/O=Drogue IoT/OU=Cloud/CN=app1"
openssl req -nodes -newkey rsa:4096 -keyout zdevice-private.pem -days 365 -subj "/O=Drogue IoT/OU=app1/CN=d7" > zdevice-cert.req
cat zdevice-cert.req | openssl x509 -req -extfile ca.cnf -extensions "san_ext" -out zdevice.crt -days 3650 -CA zapp-cert.pem -CAkey zapp-key.pem -set_serial 2
CERT=$(base64 -w0 < "zapp-cert.pem")
APP=cert1
DEVICE="O=Drogue IoT, OU=app1, CN=d7"
drg delete app $APP || true
drg create app $APP --spec "{\"trustAnchors\": {\"anchors\": [ {\"certificate\": \"$CERT\"} ]}}"
drg create device --app $APP "$DEVICE" --spec '{"credentials": {}}'
mqtt pub -v -h mqtt.sandbox.drogue.cloud -p 443 --cert zdevice.crt --key zdevice-private.pem -s -t temp -m '{\"temp\":42}'
@vedangj044
Copy link
Author

ca.cnf

[san_ext]

extendedKeyUsage = serverAuth, clientAuth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment