forked from faucetsdn/udmi
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into configclean
- Loading branch information
Showing
44 changed files
with
639 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,52 @@ | ||
#!/bin/bash -e | ||
|
||
if [ $# != 3 ]; then | ||
echo $0 site_path project_id device_id | ||
if [ $# != 2 ]; then | ||
echo $0 site_path project_spec | ||
false | ||
fi | ||
|
||
ROOT_DIR=$(dirname $0)/.. | ||
UDMI_ROOT=$(realpath $(dirname $0)/..) | ||
source $UDMI_ROOT/etc/shell_common.sh | ||
|
||
site_path=$(realpath $1) | ||
project=$2 | ||
device=$3 | ||
shift 3 | ||
project_spec=$2 | ||
registry_id=$3 | ||
shift 2 | ||
|
||
config_file=$site_path/cloud_iot_config.json | ||
device_dir=$site_path/devices/$device | ||
|
||
if [ ! -d $site_path/devices/$device ]; then | ||
echo Device directory $device_dir not found. | ||
false | ||
registry_id=$(jq -r .registry_id $config_file) | ||
key_file=$site_path/reflector/rsa_private.pkcs8 | ||
|
||
partial=${project_spec#//} | ||
project_id=${partial#*/} | ||
project_id=${project_id%/*} | ||
protocol=${partial%%/*} | ||
namespace=${project_spec##*/} | ||
REFLECT_REGISTRY=UDMI-REFLECT | ||
REGISTRY_REGION=us-central1 | ||
|
||
[[ -n $namespace ]] && namespace_prefix=${namespace}~ | ||
use_registry=$namespace_prefix$registry_id | ||
|
||
echo Provisioning reflector protocol $protocol project $project_id registry $use_registry | ||
|
||
if [[ $protocol == mqtt ]]; then | ||
echo Adding registry $use_registry | ||
ETCD="$UDMI_ROOT/udmis/bin/etcdctl --endpoints localhost:2379" | ||
registries=$($ETCD get --print-value-only /registries) | ||
updated=${registries},$use_registry | ||
updated=${updated#,} | ||
$ETCD put /registries "$updated" | ||
echo Updated registries to $updated | ||
|
||
PASSWORD_FILE=/etc/mosquitto/test_mosquitto.passwd | ||
USERNAME=$project_id/$namespace_prefix$REFLECT_REGISTRY/$use_registry | ||
hash=$(sha256sum $key_file) | ||
PASSWORD=${hash:0:8} | ||
echo Provisioning hash-key $USERNAME $PASSWORD | ||
sudo mosquitto_passwd -b ${PASSWORD_FILE} ${USERNAME} ${PASSWORD} | ||
sudo systemctl restart mosquitto | ||
echo Device password provisioned | ||
else | ||
fail Unable to provision protocol $protocol | ||
fi | ||
|
||
device=AHU-1 | ||
registry=registrar_test | ||
region=us-central1 | ||
key_gen=RS256 | ||
key_type=rsa-pem | ||
key_file=$device_dir/rsa_public.pem | ||
|
||
$ROOT_DIR/bin/keygen $key_gen $device_dir | ||
|
||
gcloud_opts="--device=$device --registry=$registry --region=$region --project=$project" | ||
yes | gcloud iot devices credentials clear $gcloud_opts | ||
gcloud iot devices credentials create $gcloud_opts --type=$key_type --path=$key_file | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/bin/bash -e | ||
|
||
ETC_DIR=/etc/mosquitto | ||
CONF_FILE=$ETC_DIR/mosquitto.conf | ||
UDMI_FILE=$ETC_DIR/confg.d/udmi.conf | ||
PASS_FILE=$ETC_DIR/mosquitto.passwd | ||
DYN_FILE=$ETC_DIR/dynamic_security.json | ||
|
||
AUTH_USER=scrumptious | ||
AUTH_PASS=aardvark | ||
echo Configuring MQTT user: $AUTH_USER | ||
|
||
sudo sed -i 's/allow_anonymous true/allow_anonymous false/' $CONF_FILE | ||
sudo sed -i 's/#listener/listener/' $CONF_FILE | ||
fgrep $PASS_FILE $CONF_FILE || (echo password_file ${PASS_FILE} | sudo tee -a $CONF_FILE) | ||
|
||
if ! fgrep -q $DYN_FILE $CONF_FILE; then | ||
PLUGIN_FILE=$(whereis -b mosquitto_dynamic_security.so | awk '{print $2}') | ||
ls -l "$PLUGIN_FILE" | ||
echo Installing dynamic security plugin $PLUGIN_FILE | ||
echo plugin $PLUGIN_FILE | sudo tee -a $CONF_FILE | ||
echo plugin_opt_config_file $DYN_FILE | sudo tee -a $CONF_FILE | ||
fi | ||
|
||
if [[ ! -f $DYN_FILE ]]; then | ||
echo Creating new $DYN_FILE | ||
sudo mosquitto_ctrl dynsec init $DYN_FILE $AUTH_USER $AUTH_PASS | ||
sudo chgrp mosquitto $DYN_FILE | ||
sudo chmod 0660 $DYN_FILE | ||
fi | ||
|
||
sudo chown mosquitto $ETC_DIR | ||
|
||
sudo touch $PASS_FILE | ||
sudo mosquitto_passwd -b ${PASS_FILE} ${AUTH_USER} ${AUTH_PASS} | ||
|
||
sudo systemctl restart mosquitto | ||
|
||
CTRL_CONNECT="-u $AUTH_USER -P $AUTH_PASS" | ||
mosquitto_ctrl $CTRL_CONNECT dynsec createRole device | ||
mosquitto_ctrl $CTRL_CONNECT dynsec addRoleACL device subscribePattern '/#' allow | ||
mosquitto_ctrl $CTRL_CONNECT dynsec addRoleACL device publishClientSend '/#' allow | ||
mosquitto_ctrl $CTRL_CONNECT dynsec createRole service | ||
mosquitto_ctrl $CTRL_CONNECT dynsec addRoleACL service subscribePattern '/#' allow | ||
mosquitto_ctrl $CTRL_CONNECT dynsec addRoleACL service publishClientSend '/#' allow | ||
|
||
clients=$(mosquitto_ctrl -u ${AUTH_USER} -P ${AUTH_PASS} dynsec listClients) | ||
if [[ $clients =~ ${AUTH_USER} ]]; then | ||
echo Found expected client $AUTH_USER | ||
else | ||
fail Improper client: $clients | ||
fi | ||
|
||
echo use: systemctl status mosquitto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.