Browse Source

stargates are 5 shared ipns keys exchanged by friends related to stars.level

pull/34/head
fred 3 months ago
parent
commit
e441068471
  1. 86
      zen/create_subkeys_for_my_friends.sh
  2. 103
      zen/manage_stargates.sh

86
zen/create_subkeys_for_my_friends.sh

@ -1,6 +1,6 @@
#!/bin/bash
########################################################################
# Author:
# Author:
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
@ -20,50 +20,50 @@ read
########################################################################
for FRIEND in $(ls ~/.zen/ipfs/.$IPFSNODEID/FRIENDS); do
[[ "$FRIEND" == "index.html" ]] && continue
echo "$FRIEND ?"
[[ "$FRIEND" == "index.html" ]] && continue
echo "$FRIEND ?"
for MEDIAKEY in $(ls ~/.zen/ipfs/.$IPFSNODEID/KEY); do
echo "MEDIAKEY=$MEDIAKEY"
## Do I have this IPNS key?
ISKEY=$(ipfs key list -l | grep "$MEDIAKEY.4FRIENDS" | cut -d ' ' -f 2)
echo "ISKEY=$ISKEY"
## Is there any key already from swarm for that MEDIAKEY
PREVKEY=$(ls ~/.zen/ipfs_swarm/.12D*/KEY/$MEDIAKEY/*/$G1PUB/ 2>/dev/null)
echo "PREVKEY=$ISKEY"
## A key is found in my swam
if [[ $PREVKEY ]]; then
echo "I found a MEDIAKEY for $MEDIAKEY : $PREVKEY"
## Do I have it localy available?
if [[ ! $ISKEY ]]; then
echo "don't have it local..."
# decrypting PREVKEY to my ipfs keystore
$MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "~/.zen/ipfs_swarm/.12D*/KEY/$MEDIAKEY/*/$G1PUB/$PREVKEY" -o "$HOME/.ipfs/keystore/${PREVKEY%.*}"
## Checking if ipfs deamon have it
ISKEY=$(ipfs key list -l | grep "$MEDIAKEY.4FRIENDS" | cut -d ' ' -f 2)
echo ".ipfs/keystore/${PREVKEY%.*} added..."
[[ ! $ISKEY ]] && echo "Restarting ipfs..." && sudo service ipfs restart
fi
## Station is Not spreading swarm key... just getting it back.
continue
fi
for MEDIAKEY in $(ls ~/.zen/ipfs/.$IPFSNODEID/KEY); do
echo "MEDIAKEY=$MEDIAKEY"
## Do I have this IPNS key?
ISKEY=$(ipfs key list -l | grep "$MEDIAKEY.4FRIENDS" | cut -d ' ' -f 2)
echo "ISKEY=$ISKEY"
## Is there any key already from swarm for that MEDIAKEY
PREVKEY=$(ls ~/.zen/ipfs_swarm/.12D*/KEY/$MEDIAKEY/*/$G1PUB/ 2>/dev/null)
echo "PREVKEY=$ISKEY"
## A key is found in my swam
if [[ $PREVKEY ]]; then
echo "I found a MEDIAKEY for $MEDIAKEY : $PREVKEY"
## Do I have it localy available?
if [[ ! $ISKEY ]]; then
echo "don't have it local..."
# decrypting PREVKEY to my ipfs keystore
$MY_PATH/tools/natools.py decrypt -f pubsec -k "$HOME/.zen/secret.dunikey" -i "~/.zen/ipfs_swarm/.12D*/KEY/$MEDIAKEY/*/$G1PUB/$PREVKEY" -o "$HOME/.ipfs/keystore/${PREVKEY%.*}"
## Checking if ipfs deamon have it
ISKEY=$(ipfs key list -l | grep "$MEDIAKEY.4FRIENDS" | cut -d ' ' -f 2)
echo ".ipfs/keystore/${PREVKEY%.*} added..."
[[ ! $ISKEY ]] && echo "Restarting ipfs..." && sudo service ipfs restart
fi
## Station is Not spreading swarm key... just getting it back.
continue
fi
echo "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/"
## No swarm or local MEDIAKEY, we are the first $MEDIAKEY creator in the swarm
[[ ! $ISKEY ]] && echo "Creating $MEDIAKEY.4FRIENDS IPNS key" && IPNSKEY=$(ipfs key gen "$MEDIAKEY.4FRIENDS") && IPNSKEYFILE=$(ls -t ~/.ipfs/keystore/ | head -n 1)
echo "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/"
## No swarm or local MEDIAKEY, we are the first $MEDIAKEY creator in the swarm
[[ ! $ISKEY ]] && echo "Creating $MEDIAKEY.4FRIENDS IPNS key" && IPNSKEY=$(ipfs key gen "$MEDIAKEY.4FRIENDS") && IPNSKEYFILE=$(~/.zen/astrXbian/zen/tools/give_me_keystore_filename.py "$MEDIAKEY.4FRIENDS")
## Sending encrypted MEDIAKEY to my swarm (sign if you want more security, but code ipfs signature verification is enough and better)
if [[ ! -d ~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/ ]]; then
echo "MEDIAKEY $MEDIAKEY is missing to my $FRIEND"
mkdir -p "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/"
$MY_PATH/tools/natools.py encrypt -p $FRIEND -i "~/.ipfs/keystore/$IPNSKEYFILE" -o "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/$IPNSKEYFILE.encrypt"
echo "Spreading ~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/$IPNSKEYFILE.encrypt"
fi
## TODO : CHECK FOR DISAPEARED FRIENDS.
read
done
read
## Sending encrypted MEDIAKEY to my swarm (sign if you want more security, but code ipfs signature verification is enough and better)
if [[ ! -d ~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/ ]]; then
echo "MEDIAKEY $MEDIAKEY is missing to my $FRIEND"
mkdir -p "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/"
$MY_PATH/tools/natools.py encrypt -p $FRIEND -i "~/.ipfs/keystore/$IPNSKEYFILE" -o "~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/$IPNSKEYFILE.encrypt"
echo "Spreading ~/.zen/ipfs/.$IPFSNODEID/KEY/$MEDIAKEY/$G1PUB/$FRIEND/$IPNSKEYFILE.encrypt"
fi
## TODO : CHECK FOR DISAPEARED FRIENDS.
read
done
read
done

103
zen/manage_stargates.sh

@ -1,6 +1,6 @@
#!/bin/bash
########################################################################
# Author:
# Author:
# Version: 0.1
# License: AGPL-3.0 (https://choosealicense.com/licenses/agpl-3.0/)
########################################################################
@ -25,16 +25,17 @@ IPFSNODEID=$(ipfs id -f='<id>\n')
## ipns key generation procedure
########################################################################
if [[ ! $(ipfs key list -l | grep "star_") ]]; then
[[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5
stargate_1=$(ipfs key gen star_1) && key_1=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_1 ~/.zen/key/1/ && echo "$stargate_1" > ~/.zen/key/1/stargate
stargate_2=$(ipfs key gen star_2) && key_2=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_2 ~/.zen/key/2/ && echo "$stargate_2" > ~/.zen/key/2/stargate
stargate_3=$(ipfs key gen star_3) && key_3=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_3 ~/.zen/key/3/ && echo "$stargate_3" > ~/.zen/key/3/stargate
stargate_4=$(ipfs key gen star_4) && key_4=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_4 ~/.zen/key/4/ && echo "$stargate_4" > ~/.zen/key/4/stargate
stargate_5=$(ipfs key gen star_5) && key_5=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_5 ~/.zen/key/5/ && echo "$stargate_5" > ~/.zen/key/5/stargate
[[ ! -d ~/.zen/key/ ]] && mkdir -p ~/.zen/key/1 ~/.zen/key/2 ~/.zen/key/3 ~/.zen/key/4 ~/.zen/key/5
# TODO key name are always the same... =$(~/.zen/astrXbian/zen/tools/give_me_keystore_filename.py "star_1")
stargate_1=$(ipfs key gen star_1) && key_1=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_1 ~/.zen/key/1/ && echo "$stargate_1" > ~/.zen/key/1/stargate
stargate_2=$(ipfs key gen star_2) && key_2=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_2 ~/.zen/key/2/ && echo "$stargate_2" > ~/.zen/key/2/stargate
stargate_3=$(ipfs key gen star_3) && key_3=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_3 ~/.zen/key/3/ && echo "$stargate_3" > ~/.zen/key/3/stargate
stargate_4=$(ipfs key gen star_4) && key_4=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_4 ~/.zen/key/4/ && echo "$stargate_4" > ~/.zen/key/4/stargate
stargate_5=$(ipfs key gen star_5) && key_5=$(ls -t ~/.ipfs/keystore/ | head -n 1) && cp ~/.ipfs/keystore/$key_5 ~/.zen/key/5/ && echo "$stargate_5" > ~/.zen/key/5/stargate
else
ipfs key list -l | grep "star_"
echo "IPNS star keys already existing... Please remove all 'star_*' ipns keys before running"
exit 1
ipfs key list -l | grep "star_"
echo "IPNS star keys already existing... Please remove all 'star_*' ipns keys before running"
exit 1
fi
echo "******************************************************************"
@ -49,49 +50,49 @@ echo "******************************************************************"
## ipns 5 stargates keys distribution to friends
########################################################################
for friendgate in $(ls -d ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/*/); do
echo "*************************************************************"
fg1pub=$(echo $friendgate | cut -d '/' -f 8 )
stars=$(cat ${friendgate}stars.level)
echo "OPENING $stars STARGATES"
echo "FRIEND : $fg1pub"
echo "$friendgate"
echo "*************************************************************"
fg1pub=$(echo $friendgate | cut -d '/' -f 8 )
stars=$(cat ${friendgate}stars.level)
echo "OPENING $stars STARGATES"
echo "FRIEND : $fg1pub"
echo "$friendgate"
[[ "$stars" == "" && "$fg1pub" != "" ]] && echo "NO STAR NO FRIEND" && rm -Rf ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub && continue
[[ "$stars" == "" && "$fg1pub" != "" ]] && echo "NO STAR NO FRIEND" && rm -Rf ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub && continue
# DELETE OLD TRANSMITED STARGATES IPNS LINKS
rm -f ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate*
# DISTRIBUTE ENCRYPT AND PUBLISH NEW STARGATES KEY
case $stars in
1)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
;;
2)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
;;
3)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
;;
4)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt"
;;
5)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/5/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate5.encrypt"
;;
esac
ls ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/
echo "http://127.0.0.1:8181/ipns/$IPFSNODEID/.$IPFSNODEID/FRIENDS/$fg1pub/"
echo ""
# DELETE OLD TRANSMITED STARGATES IPNS LINKS
rm -f ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate*
# DISTRIBUTE ENCRYPT AND PUBLISH NEW STARGATES KEY
case $stars in
1)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
;;
2)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
;;
3)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
;;
4)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt"
;;
5)
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/1/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate1.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/2/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate2.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/3/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate3.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/4/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate4.encrypt"
$MY_PATH/tools/natools.py encrypt -p $fg1pub -i ~/.zen/key/5/stargate -o "$HOME/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/stargate5.encrypt"
;;
esac
ls ~/.zen/ipfs/.$IPFSNODEID/FRIENDS/$fg1pub/
echo "http://127.0.0.1:8181/ipns/$IPFSNODEID/.$IPFSNODEID/FRIENDS/$fg1pub/"
echo ""
done

Loading…
Cancel
Save