Astroport.ONE/tools/VISA.new.sh

144 lines
7.1 KiB
Bash
Raw Normal View History

#!/bin/bash
################################################################################
# Author: Fred (support@qo-op.com)
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
################################################################################
################################################################################
#
[[ $1 != "quiet" ]] && echo "=============================================
MadeInZion DIPLOMATIC PASSPORT
=============================================
A cryptographic key pair to control your P2P Digital Life.
Solar Punk garden forest terraforming game.
2022-04-23 18:33:23 +02:00
Création de votre PSEUDO, votre PLAYER, votre PASS (6 chiffres)
Création de votre SALT PEPPER : compte Gchange et son portefeuille G1.
Création de votre clef DUNITER : la clef d'accès Cesium
Création de vos clef IPNS : vos balises de publication dans le réseau IPFS.
2022-04-26 14:16:57 +02:00
PLAYER, MOA & STARGATES
2022-04-23 18:33:23 +02:00
Vos identifiants 'Astronaute' sont:
"
################################################################################
MY_PATH="`dirname \"$0\"`" # relative
MY_PATH="`( cd \"$MY_PATH\" && pwd )`" # absolutized and normalized
ME="${0##*/}"
SALT=$(${MY_PATH}/diceware.sh 4 | xargs)
[[ $1 != "quiet" ]] && echo "-> SALT : $SALT"
PEPPER=$(${MY_PATH}/diceware.sh 4 | xargs)
[[ $1 != "quiet" ]] && echo "-> PEPPER : $PEPPER"
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "CHOISISSEZ UN PSEUDO" && read PSEUDO; PSEUDO=${PSEUDO,,} && [[ -d ~/.zen/game/players/$PSEUDO ]] && echo "CE PSEUDO EST DEJA UN PLAYER. EXIT" && exit 1
# PSEUDO=${PSEUDO,,} #lowercase
2022-04-23 18:33:23 +02:00
PLAYER=${PSEUDO}${RANDOM:0:2}$(${MY_PATH}/diceware.sh 1 | xargs)${RANDOM:0:2}
[[ ! $PSEUDO ]] && PSEUDO=$PLAYER
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "$PSEUDO voici votre identifiant Astronaute: $PLAYER"; sleep 1
PASS=$(echo "${RANDOM}${RANDOM}${RANDOM}${RANDOM}" | tail -c-7)
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "et votre PASS : $PASS"; sleep 2
PLAYERNS=$(ipfs key gen $PLAYER)
PLAYERKEYFILE=$(${MY_PATH}/give_me_keystore_filename.py "$PLAYER")
[[ $1 != "quiet" ]] && echo "Votre clef $PLAYER <=> $PLAYERNS ($PLAYERKEYFILE)"; sleep 2
MOANS=$(ipfs key gen moa_$PLAYER)
MOAKEYFILE=$(${MY_PATH}/give_me_keystore_filename.py "moa_$PLAYER")
echo "Votre coffre personnel constitués des média que vous aurez embarqué dans votre 'Astroport' (amis de niveau 3)"
[[ $1 != "quiet" ]] && echo "Votre clef moa_$PLAYER <=> $MOANS ($MOAKEYFILE)"; sleep 2
QOOPNS=$(ipfs key gen qo-op_$PLAYER)
QOOPKEYFILE=$(${MY_PATH}/give_me_keystore_filename.py "qo-op_$PLAYER")
echo "Votre journal de bord pubié dans le réseau des ambassades 'Astroport One' (zone 'publique' niveau 0 du réseau Astroport)"
[[ $1 != "quiet" ]] && echo "Votre clef qo-op_$PLAYER <=> $QOOPNS ($QOOPKEYFILE)"; sleep 2
## CREATE Player personnal files storage and IPFS publish directory
2022-04-26 14:16:57 +02:00
mkdir -p ~/.zen/game/players/$PLAYER/ipfs/
2022-04-26 14:16:57 +02:00
echo "$PSEUDO" > ~/.zen/game/players/$PLAYER/.pseudo
echo "$PLAYER" > ~/.zen/game/players/$PLAYER/.player
2022-04-26 14:16:57 +02:00
echo "$SALT" > ~/.zen/game/players/$PLAYER/secret.june
echo "$PEPPER" >> ~/.zen/game/players/$PLAYER/secret.june
[[ $1 != "quiet" ]] && echo "Rendez-vous sur https://gchange.fr
Utilisez ces identifiants pour rejoindre le réseau JUNE
$SALT
$PEPPER
2022-04-26 14:16:57 +02:00
"; sleep 3
G1PUB=$(python3 ${MY_PATH}/key_create_dunikey.py "$SALT" "$PEPPER")
2022-04-26 14:16:57 +02:00
2022-03-08 23:37:08 +01:00
if [[ ! $G1PUB ]]; then
[[ $1 != "quiet" ]] && echo "Désolé. Nous n'avons pas pu générer votre clef Cesium automatiquement."
else
2022-04-26 14:16:57 +02:00
########################################################################
echo "CREATING ~/.zen/game/players/$PLAYER/ipfs.config"
########################################################################
ipfs_ID=$(python3 ~/.zen/astrXbian/zen/tools/create_ipfsnodeid_from_tmp_secret.dunikey.py)
echo $ipfs_ID > ~/.zen/game/players/$PLAYER/secret.ipfs && source ~/.zen/game/players/$PLAYER/secret.ipfs
[[ $PrivKEY == "" ]] && echo "ERROR CREATING IPFS IDENTITY" && exit 1
jq -r --arg PeerID "$PeerID" '.Identity.PeerID=$PeerID' ~/.ipfs/config > ~/.zen/tmp/config.tmp
jq -r --arg PrivKEY "$PrivKEY" '.Identity.PrivKey=$PrivKEY' ~/.zen/tmp/config.tmp > ~/.zen/tmp/config.ipfs
jq '.Peering.Peers = []' ~/.zen/tmp/config.ipfs > ~/.zen/tmp/ipfs.config ## RESET .Peering.Peers FRIENDS
rm -f ~/.zen/tmp/config.tmp ~/.zen/tmp/config.ipfs
mv ~/.zen/tmp/ipfs.config ~/.zen/game/players/$PLAYER/
mkdir -p ~/.zen/game/players/$PLAYER/ipfs/.$PeerID # Prepare astrXbian datastructure
mv /tmp/secret.dunikey ~/.zen/game/players/$PLAYER/
qrencode -s 6 -o $HOME/.zen/game/players/$PLAYER/QR.png "$G1PUB"
secFromDunikey=$(cat ~/.zen/game/players/$PLAYER/secret.dunikey | grep "sec" | cut -d ' ' -f2)
echo "$secFromDunikey" > /tmp/${PSEUDO}.sec
openssl enc -aes-256-cbc -salt -in /tmp/${PSEUDO}.sec -out "/tmp/enc.${PSEUDO}.sec" -k $PASS 2>/dev/null
PASsec=$(cat /tmp/enc.${PSEUDO}.sec | base58) && rm -f /tmp/${PSEUDO}.sec
2022-04-26 14:16:57 +02:00
qrencode -s 6 -o $HOME/.zen/game/players/$PLAYER/QRsec.png $PASsec
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "Votre Clef publique G1 est : $G1PUB"; sleep 1
[[ $1 != "quiet" ]] && echo "SEC $secFromDunikey"; sleep 1
fi
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "Rendez-vous sur https://cesium.app et utilisez les mêmes identifiants pour accéder à votre portefeuille JUNE"; sleep 2
2022-04-26 14:16:57 +02:00
cp $HOME/.ipfs/keystore/$KEYFILE ~/.zen/game/players/$PLAYER/
qrencode -s 6 -o "$HOME/.zen/game/players/$PLAYER/QR.IPNSFL.PLAYER.png" "http://localhost:8080/ipns/$IPNS"
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo; echo; echo "*** Espace privé activé : ~/.zen/game/players/$PLAYER/"; sleep 1
[[ $1 != "quiet" ]] && echo; echo "*** Votre journal de bord : http://localhost:8080/ipns/$IPNS"; sleep 1
# PASS CRYPTING KEY
2022-04-26 14:16:57 +02:00
openssl enc -aes-256-cbc -salt -in "$HOME/.zen/game/players/$PLAYER/secret.june" -out "$HOME/.zen/game/players/$PLAYER/enc.secret.june" -k $PASS 2>/dev/null
openssl enc -aes-256-cbc -salt -in "$HOME/.zen/game/players/$PLAYER/secret.dunikey" -out "$HOME/.zen/game/players/$PLAYER/enc.secret.dunikey" -k $PASS 2>/dev/null
openssl enc -aes-256-cbc -salt -in "$HOME/.zen/game/players/$PLAYER/$KEYFILE -out" "$HOME/.zen/game/players/$PLAYER/enc.$KEYFILE" -k $PASS 2>/dev/null
## TODO MORE SECURE ?! USE opengpg, natools, etc ...
2022-04-26 14:16:57 +02:00
# ${MY_PATH}/natools.py encrypt -p $G1PUB -i ~/.zen/game/players/$PLAYER/secret.dunikey -o "$HOME/.zen/game/players/$PLAYER/secret.dunikey.oasis"
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "Sécurisation de vos clefs par chiffrage SSL... $PASS"; sleep 1
#################################################
# !!!! # DEV MODE. REMOVE FOR PRODUCTION STATION FORGET PASS
2022-04-26 14:16:57 +02:00
echo "$PASS" > ~/.zen/game/players/$PLAYER/.pass
#################################################
## SET CURRENT PLAYER
rm -f ~/.zen/game/players/.current
2022-04-26 14:16:57 +02:00
ln -s ~/.zen/game/players/$PLAYER ~/.zen/game/players/.current
## CLEANING CLEAR FILES
2022-04-26 14:16:57 +02:00
rm -f ~/.zen/game/players/$PLAYER/$KEYFILE
rm -f ~/.zen/game/players/$PLAYER/secret.dunikey
[[ $1 != "quiet" ]] && echo "_____DEBUG PLAYER REMOVE COMMANDS____"
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "rm -Rf ~/.zen/game/players/$PLAYER"
[[ $1 != "quiet" ]] && echo "ipfs key rm $PLAYER > /dev/null"
[[ $1 != "quiet" ]] && echo "_____DEBUG PLAYER REMOVE COMMANDS____"
2022-04-26 14:16:57 +02:00
[[ $1 != "quiet" ]] && echo "Bienvenue à toi Astronaute $PSEUDO ($PLAYER)"
2022-04-23 18:33:23 +02:00
echo $PSEUDO > ~/.zen/tmp/PSEUDO
exit 0