Skip to content

Commit

Permalink
Merge pull request EVerest#82 from US-JOET/simplify_demo_script
Browse files Browse the repository at this point in the history
♻️ 🔥 🔒 🐛 Clean up the demo script before start the upgrade
  • Loading branch information
shankari authored Nov 12, 2024
2 parents 4e4f148 + a628831 commit 0ab95e1
Show file tree
Hide file tree
Showing 12 changed files with 219 additions and 170 deletions.
3 changes: 3 additions & 0 deletions citrineos/apply-patches.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

echo "No patches to apply"
16 changes: 16 additions & 0 deletions citrineos/build-and-run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

echo "Build and run"

echo "CitrineOS does not currently build due to issues with npm dependencies. It is disabled until we roll forward. Apologies for the inconvenience!"
exit 1

pushd Server || exit 1

docker compose build
if ! docker compose --project-name "${DEMO_CSMS}"-csms up -d --wait; then
echo "Failed to start ${DEMO_CSMS}"
exit 1
fi

popd || exit 1
35 changes: 35 additions & 0 deletions citrineos/copy-certs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

mkdir -p Server/data/certificates

echo "Copying certs into ${DEMO_DIR}/citrineos-csms/Server/data/certificates"
tar xf cached_certs_correct_name_emaid.tar.gz

# Leaf key
cp dist/etc/everest/certs/client/csms/CSMS_LEAF.key Server/data/certificates/leafKey.pem

#Cert chain
cat dist/etc/everest/certs/client/csms/CSMS_LEAF.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> Server/data/certificates/certChain.pem

# SubCA
cp dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.key Server/data/certificates/subCAKey.pem

#TrustedSubCAChain
cat dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> Server/data/certificates/rootCertificate.pem

#Actual root cert
cp dist/etc/everest/certs/ca/v2g/V2G_ROOT_CA.pem Server/data/certificates/root-V2G-cert.pem

#ACME key
cp ../everest-demo/citrineos/acme_account_key.pem Server/data/certificates/acme_account_key.pem

echo "Validating that the certificates are set up correctly"
openssl verify -show_chain \
-CAfile Server/data/certificates/root-V2G-cert.pem \
-untrusted Server/data/certificates/rootCertificate.pem \
Server/data/certificates/certChain.pem
235 changes: 74 additions & 161 deletions demo-iso15118-2-ocpp-201.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ MAEVE_BRANCH="set_charging_profile"
CITRINEOS_REPO="https://github.com/citrineos/citrineos-core.git"
CITRINEOS_BRANCH="feature/everest-demo"


START_OPTION="auto"

usage="usage: $(basename "$0") [-r <repo>] [-b <branch>] [-c <csms>] [1|2|3] [-h]
Expand All @@ -21,22 +21,24 @@ Pro Tip: to use a local copy of this everest-demo repo, provide the current
directory to the -r option (e.g., '-r \$(pwd)').
where:
-r URL to everest-demo repo to use (default: $DEMO_REPO)
-r URL to everest-demo repo to use (default: $DEMO_REPO, '$PWD' uses the current dir)
-b Branch of everest-demo repo to use (default: $DEMO_BRANCH)
-1 OCPP v2.0.1 Security Profile 1
-2 OCPP v2.0.1 Security Profile 2
-3 OCPP v2.0.1 Security Profile 3
-c Use CitrineOS CSMS (default: MaEVe)
-m Start the manager manually (useful while debugging to stop and restart)
-h Show this message"


DEMO_VERSION=
DEMO_COMPOSE_FILE_NAME=
DEMO_CSMS=maeve

DEMO_CSMS_REPO=$MAEVE_REPO
DEMO_CSMS_BRANCH=$MAEVE_BRANCH

# loop through positional options/arguments
while getopts ':r:b:c123h' option; do
while getopts ':r:b:123chm' option; do
case "$option" in
r) DEMO_REPO="$OPTARG" ;;
b) DEMO_BRANCH="$OPTARG" ;;
Expand All @@ -46,7 +48,10 @@ while getopts ':r:b:c123h' option; do
DEMO_COMPOSE_FILE_NAME="docker-compose.ocpp201.yml" ;;
3) DEMO_VERSION="v2.0.1-sp3"
DEMO_COMPOSE_FILE_NAME="docker-compose.ocpp201.yml" ;;
c) DEMO_CSMS="citrineos" ;;
c) DEMO_CSMS="citrineos"
DEMO_CSMS_REPO=$CITRINEOS_REPO
DEMO_CSMS_BRANCH=$CITRINEOS_BRANCH ;;
m) START_OPTION="manual" ;;
h) echo -e "$usage"; exit ;;
\?) echo -e "illegal option: -$OPTARG\n" >&2
echo -e "$usage" >&2
Expand Down Expand Up @@ -76,154 +81,71 @@ delete_temporary_directory() { rm -rf "${DEMO_DIR}"; }
trap delete_temporary_directory EXIT


echo "DEMO REPO: $DEMO_REPO"
echo "DEMO BRANCH: $DEMO_BRANCH"
echo "DEMO VERSION: $DEMO_VERSION"
echo "DEMO CONFIG: $DEMO_COMPOSE_FILE_NAME"
echo "DEMO DIR: $DEMO_DIR"
echo "DEMO CSMS: $DEMO_CSMS"
echo "DEMO REPO: $DEMO_REPO"
echo "DEMO BRANCH: $DEMO_BRANCH"
echo "DEMO VERSION: $DEMO_VERSION"
echo "DEMO CONFIG: $DEMO_COMPOSE_FILE_NAME"
echo "DEMO DIR: $DEMO_DIR"
echo "DEMO CSMS: $DEMO_CSMS"
echo "DEMO CSMS REPO: $DEMO_CSMS_REPO"
echo "DEMO CSMS BRANCH: $DEMO_CSMS_BRANCH"


cd "${DEMO_DIR}" || exit 1


echo "Cloning EVerest from ${DEMO_REPO} into ${DEMO_DIR}/everest-demo"
git clone --branch "${DEMO_BRANCH}" "${DEMO_REPO}" everest-demo
if [[ "$DEMO_REPO" =~ "http" || "$DEMO_REPO" =~ "git" ]]; then
git clone --branch "${DEMO_BRANCH}" "${DEMO_REPO}" everest-demo
else
cp -r "$DEMO_REPO" everest-demo
fi

if [[ "$DEMO_CSMS" == maeve ]]; then
echo "Cloning ${DEMO_CSMS} CSMS from ${MAEVE_REPO} into ${DEMO_DIR}/${DEMO_CSMS}-csms and starting it"
git clone --branch "${MAEVE_BRANCH}" "${MAEVE_REPO}" ${DEMO_CSMS}-csms
# BEGIN: Setting up the CSMS
echo "Cloning ${DEMO_CSMS} CSMS from ${DEMO_CSMS_REPO} into ${DEMO_DIR}/${DEMO_CSMS}-csms and starting it"
git clone --branch "${DEMO_CSMS_BRANCH}" "${DEMO_CSMS_REPO}" ${DEMO_CSMS}-csms

pushd maeve-csms || exit 1
pushd ${DEMO_CSMS}-csms || exit 1

cp ../everest-demo/manager/cached_certs_correct_name_emaid.tar.gz .

# Set up certificates for SP2 and SP3
if [[ "$DEMO_VERSION" =~ sp2 || "$DEMO_VERSION" =~ sp3 ]]; then
echo "Copying certs into ${DEMO_DIR}/maeve-csms/config/certificates"
tar xf cached_certs_correct_name_emaid.tar.gz
cat dist/etc/everest/certs/client/csms/CSMS_LEAF.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> config/certificates/csms.pem
cat dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> config/certificates/trust.pem
cp dist/etc/everest/certs/client/csms/CSMS_LEAF.key config/certificates/csms.key
cp dist/etc/everest/certs/ca/v2g/V2G_ROOT_CA.pem config/certificates/root-V2G-cert.pem
cp dist/etc/everest/certs/ca/mo/MO_ROOT_CA.pem config/certificates/root-MO-cert.pem

echo "Validating that the certificates are set up correctly"
openssl verify -show_chain \
-CAfile config/certificates/root-V2G-cert.pem \
-untrusted config/certificates/trust.pem \
config/certificates/csms.pem

echo "Patching the CSMS to enable EVerest organization"
patch -p1 -i ../everest-demo/maeve/maeve-csms-everest-org.patch

echo "Patching the CSMS to enable local mo root"
patch -p1 -i ../everest-demo/maeve/maeve-csms-local-mo-root.patch

echo "Patching the CSMS to enable local mo root"
patch -p1 -i ../everest-demo/maeve/maeve-csms-ignore-ocsp.patch

else
echo "Patching the CSMS to disable WSS"
patch -p1 -i ../everest-demo/maeve/maeve-csms-no-wss.patch
source ../everest-demo/${DEMO_CSMS}/copy-certs.sh
fi

docker compose build
docker compose up -d
source ../everest-demo/${DEMO_CSMS}/apply-patches.sh

echo "Waiting 5s for MaEVe CSMS to start..."
sleep 5
source ../everest-demo/${DEMO_CSMS}/build-and-run.sh

if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 1 (note: profiles in MaEVe start with 0 so SP-0 == OCPP SP-1)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' \
-d '{"securityProfile": 0, "base64SHA256Password": "3oGi4B5I+Y9iEkYtL7xvuUxrvGOXM/X2LQrsCwf/knA="}'
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 2 (note: profiles in MaEVe start with 0 so SP-1 == OCPP SP-2)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' \
-d '{"securityProfile": 1, "base64SHA256Password": "3oGi4B5I+Y9iEkYtL7xvuUxrvGOXM/X2LQrsCwf/knA="}'
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 3 (note: profiles in MaEVe start with 0 so SP-2 == OCPP SP-3)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' -d '{"securityProfile": 2}'
fi

echo "Charge station added, adding user token"

curl http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{
"countryCode": "GB",
"partyId": "TWK",
"type": "RFID",
"uid": "DEADBEEF",
"contractId": "GBTWK012345678V",
"issuer": "Thoughtworks",
"valid": true,
"cacheMode": "ALWAYS"
}'
# note that docker compose --wait only waits for the
# containers to be up, not necessarily the services in those
# containers.
echo "Waiting 5s for ${DEMO_CSMS} services to finish starting..."
sleep 5

curl http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{"countryCode": "UK", "partyId": "Switch", "contractId": "UKSWI123456789G", "uid": "UKSWI123456789G", "issuer": "Switch", "valid": true, "cacheMode": "ALWAYS"}'
echo "Adding a charger and RFID card to ${DEMO_CSMS}"
source ../everest-demo/${DEMO_CSMS}/add-charger-and-rfid-card.sh

popd || exit 1
fi

if [[ "$DEMO_CSMS" == 'citrineos' ]]; then
echo "Cloning CitrineOS CSMS from ${CITRINEOS_REPO} into ${DEMO_DIR}/citrineos-csms and starting it"
git clone --branch "${CITRINEOS_BRANCH}" "${CITRINEOS_REPO}" citrineos-csms

pushd citrineos-csms || exit 1

cp ../everest-demo/manager/cached_certs_correct_name_emaid.tar.gz .

mkdir -p Server/data/certificates

echo "Copying certs into ${DEMO_DIR}/citrineos-csms/Server/data/certificates"
tar xf cached_certs_correct_name_emaid.tar.gz

# Leaf key
cp dist/etc/everest/certs/client/csms/CSMS_LEAF.key Server/data/certificates/leafKey.pem

#Cert chain
cat dist/etc/everest/certs/client/csms/CSMS_LEAF.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> Server/data/certificates/certChain.pem
# END: Setting up the CSMS

# SubCA
cp dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.key Server/data/certificates/subCAKey.pem

#TrustedSubCAChain
cat dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem \
dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem \
> Server/data/certificates/rootCertificate.pem
pushd everest-demo || exit 1
echo "API calls to CSMS finished, Starting everest"
docker compose --project-name everest-ac-demo --file "${DEMO_COMPOSE_FILE_NAME}" up -d --wait
docker cp manager/config-sil-ocpp201-pnc.yaml everest-ac-demo-manager-1:/ext/source/config/config-sil-ocpp201-pnc.yaml

#ACME key
cp ../everest-demo/citrineos/acme_account_key.pem Server/data/certificates/acme_account_key.pem
echo "Configuring and restarting nodered"
docker cp nodered/config/config-sil-iso15118-ac-flow.json everest-ac-demo-nodered-1:/config/config-sil-two-evse-flow.json
docker restart everest-ac-demo-nodered-1

pushd Server || exit 1
echo "Starting the CitrineOS CSMS"
cat ./docker-compose.yml
docker compose -f ./docker-compose.yml build
if ! docker compose --project-name citrineos-csms -f ./docker-compose.yml up -d --wait; then
echo "Failed to start CitrineOS."
exit 1
fi
echo "Copying over EVerest patches"
docker cp manager/enable_payment_method_in_python.patch everest-ac-demo-manager-1:/tmp/

echo "Adding a charger and RFID card to CitrineOS"
../../everest-demo/citrineos/add-charger-and-rfid-card.sh
echo "Now applying the patches"
docker cp manager/enable_evcc_logging.cfg everest-ac-demo-manager-1:/ext/source/build/dist/etc/everest/default_logging.cfg
docker exec everest-ac-demo-manager-1 /bin/bash -c "apk add patch"
docker exec everest-ac-demo-manager-1 /bin/bash -c "cd /ext && patch -p0 -i /tmp/enable_payment_method_in_python.patch"

popd || exit 1
popd || exit 1

fi

pushd everest-demo || exit 1
echo "API calls to CSMS finished, Starting everest"
docker compose --project-name everest-ac-demo --file "${DEMO_COMPOSE_FILE_NAME}" up -d --wait
docker cp config-sil-ocpp201-pnc.yaml everest-ac-demo-manager-1:/ext/source/config/config-sil-ocpp201-pnc.yaml
if [[ "$DEMO_VERSION" =~ sp2 || "$DEMO_VERSION" =~ sp3 ]]; then
docker cp manager/cached_certs_correct_name_emaid.tar.gz everest-ac-demo-manager-1:/ext/source/build
docker exec everest-ac-demo-manager-1 /bin/bash -c "pushd /ext/source/build && tar xf cached_certs_correct_name_emaid.tar.gz"
Expand All @@ -232,39 +154,30 @@ if [[ "$DEMO_VERSION" =~ sp2 || "$DEMO_VERSION" =~ sp3 ]]; then
docker exec everest-ac-demo-manager-1 /bin/bash -c "pushd /ext/source/build && openssl verify -show_chain -CAfile dist/etc/everest/certs/ca/v2g/V2G_ROOT_CA.pem --untrusted dist/etc/everest/certs/ca/csms/CPO_SUB_CA1.pem --untrusted dist/etc/everest/certs/ca/csms/CPO_SUB_CA2.pem dist/etc/everest/certs/client/csms/CSMS_LEAF.pem"
fi

if [[ "$DEMO_CSMS" == 'maeve' ]]; then
if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "Copying device DB, configured to SecurityProfile: 1"
docker cp manager/device_model_storage_maeve_sp1.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "Copying device DB, configured to SecurityProfile: 2"
docker cp manager/device_model_storage_maeve_sp2.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "Copying device DB, configured to SecurityProfile: 3"
docker cp manager/device_model_storage_maeve_sp3.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
fi
fi

if [[ "$DEMO_CSMS" == 'citrineos' ]]; then
if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "Copying device DB, configured to SecurityProfile: 1"
docker cp manager/device_model_storage_citrineos_sp1.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "Copying device DB, configured to SecurityProfile: 2"
docker cp manager/device_model_storage_citrineos_sp2.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "Copying device DB, configured to SecurityProfile: 3"
docker cp manager/device_model_storage_citrineos_sp3.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
fi
if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "Copying device DB, configured to SecurityProfile: 1"
docker cp manager/device_model_storage_${DEMO_CSMS}_sp1.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
docker cp manager/disable_iso_tls.patch everest-ac-demo-manager-1:/tmp/
docker exec everest-ac-demo-manager-1 /bin/bash -c "pushd /ext/source && patch -p0 -i /tmp/disable_iso_tls.patch"
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "Copying device DB, configured to SecurityProfile: 2"
docker cp manager/device_model_storage_${DEMO_CSMS}_sp2.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
docker cp manager/disable_iso_tls.patch everest-ac-demo-manager-1:/tmp/
docker exec everest-ac-demo-manager-1 /bin/bash -c "pushd /ext/source && patch -p0 -i /tmp/disable_iso_tls.patch"
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "Copying device DB, configured to SecurityProfile: 3"
docker cp manager/device_model_storage_${DEMO_CSMS}_sp3.db \
everest-ac-demo-manager-1:/ext/source/build/dist/share/everest/modules/OCPP201/device_model_storage.db
fi

if [[ "$DEMO_VERSION" =~ v2.0.1 ]]; then
echo "Starting software in the loop simulation"
if [[ "$START_OPTION" == "auto" ]]; then
echo "Starting software in the loop simulation automatically"
docker exec everest-ac-demo-manager-1 sh /ext/source/build/run-scripts/run-sil-ocpp201-pnc.sh
else
echo "Please start the software in the loop simulation manually by running"
echo "on your laptop: docker exec -it everest-ac-demo-manager-1 /bin/bash"
echo "in the container: sh /ext/source/build/run-scripts/run-sil-ocpp201-pnc.sh"
echo "You can now stop and restart the manager without re-creating the container"
fi
32 changes: 32 additions & 0 deletions maeve/add-charger-and-rfid-card.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

echo "While running subscript, DEMO_VERSION is " $DEMO_VERSION

if [[ "$DEMO_VERSION" =~ sp1 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 1 (note: profiles in MaEVe start with 0 so SP-0 == OCPP SP-1)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' \
-d '{"securityProfile": 0, "base64SHA256Password": "3oGi4B5I+Y9iEkYtL7xvuUxrvGOXM/X2LQrsCwf/knA="}'
elif [[ "$DEMO_VERSION" =~ sp2 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 2 (note: profiles in MaEVe start with 0 so SP-1 == OCPP SP-2)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' \
-d '{"securityProfile": 1, "base64SHA256Password": "3oGi4B5I+Y9iEkYtL7xvuUxrvGOXM/X2LQrsCwf/knA="}'
elif [[ "$DEMO_VERSION" =~ sp3 ]]; then
echo "MaEVe CSMS started, adding charge station with Security Profile 3 (note: profiles in MaEVe start with 0 so SP-2 == OCPP SP-3)"
curl http://localhost:9410/api/v0/cs/cp001 -H 'content-type: application/json' -d '{"securityProfile": 2}'
fi

echo "Charge station added, adding user token"

curl http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{
"countryCode": "GB",
"partyId": "TWK",
"type": "RFID",
"uid": "DEADBEEF",
"contractId": "GBTWK012345678V",
"issuer": "Thoughtworks",
"valid": true,
"cacheMode": "ALWAYS"
}'

curl http://localhost:9410/api/v0/token -H 'content-type: application/json' -d '{"countryCode": "UK", "partyId": "Switch", "contractId": "UKSWI123456789G", "uid": "UKSWI123456789G", "issuer": "Switch", "valid": true, "cacheMode": "ALWAYS"}'

Loading

0 comments on commit 0ab95e1

Please sign in to comment.