Files
i2p.scripts/plugin/makeplugin.sh

138 lines
3.5 KiB
Bash
Raw Normal View History

2010-02-09 01:26:34 +00:00
#!/bin/sh
#
# basic packaging up of a plugin
#
2010-02-11 19:46:47 +00:00
# usage: makeplugin.sh plugindir
#
2010-02-09 01:26:34 +00:00
# zzz 2010-02
2014-08-07 21:20:21 +00:00
# zzz 2014-08 added support for su3 files
2010-02-09 01:26:34 +00:00
#
PUBKEYDIR=$HOME/.i2p-plugin-keys
PUBKEYFILE=$PUBKEYDIR/plugin-public-signing.key
PRIVKEYFILE=$PUBKEYDIR/plugin-private-signing.key
B64KEYFILE=$PUBKEYDIR/plugin-public-signing.txt
2014-08-07 21:20:21 +00:00
PUBKEYSTORE=$PUBKEYDIR/plugin-su3-public-signing.crt
PRIVKEYSTORE=$PUBKEYDIR/plugin-su3-keystore.ks
KEYTYPE=RSA_SHA512_4096
2010-02-09 01:26:34 +00:00
# put your files in here
2010-02-11 19:46:47 +00:00
PLUGINDIR=${1:-plugin}
2010-02-09 01:26:34 +00:00
PC=plugin.config
PCT=${PC}.tmp
2014-08-07 21:20:21 +00:00
if [ ! -d $PLUGINDIR ]
then
echo "You must have a $PLUGINDIR directory"
exit 1
fi
if [ ! -f $PLUGINDIR/$PC ]
then
echo "You must have a $PLUGINDIR/$PC file"
exit 1
fi
SIGNER=`grep '^signer=' $PLUGINDIR/$PC`
if [ "$?" -ne "0" ]
then
echo "You must have a plugin name in $PC"
echo 'For example name=foo'
exit 1
fi
SIGNER=`echo $SIGNER | cut -f 2 -d '='`
2010-02-09 01:26:34 +00:00
if [ ! -f $PRIVKEYFILE ]
then
2014-08-07 21:20:21 +00:00
echo "Creating new XPI2P DSA keys"
mkdir -p $PUBKEYDIR || exit 1
java -cp $I2P/lib/i2p.jar net.i2p.crypto.TrustedUpdate keygen $PUBKEYFILE $PRIVKEYFILE || exit 1
java -cp $I2P/lib/i2p.jar net.i2p.data.Base64 encode $PUBKEYFILE $B64KEYFILE || exit 1
2010-02-11 19:46:47 +00:00
rm -rf logs/
chmod 444 $PUBKEYFILE $B64KEYFILE
2010-02-09 01:26:34 +00:00
chmod 400 $PRIVKEYFILE
2014-08-07 21:20:21 +00:00
echo "Created new XPI2P keys: $PUBKEYFILE $PRIVKEYFILE"
2010-02-09 01:26:34 +00:00
fi
2014-08-07 21:20:21 +00:00
if [ ! -f $PRIVKEYSTORE ]
2010-02-09 01:26:34 +00:00
then
2014-08-07 21:20:21 +00:00
echo "Creating new SU3 $KEYTYPE keys for $SIGNER"
java -cp $I2P/lib/i2p.jar net.i2p.crypto.SU3File keygen -t $KEYTYPE $PUBKEYSTORE $PRIVKEYSTORE $SIGNER || exit 1
echo '*** Save your password in a safe place!!! ***'
rm -rf logs/
# copy to the router dir so verify will work
CDIR=$I2P/certificates/plugin
mkdir -p $CDIR || exit 1
CFILE=$CDIR/`echo $SIGNER | sed s/@/_at_/`.crt
cp $PUBKEYSTORE $CFILE
chmod 444 $PUBKEYSTORE
chmod 400 $PRIVKEYSTORE
chmod 644 $CFILE
echo "Created new SU3 keys: $PUBKEYSTORE $PRIVKEYSTORE"
echo "Copied public key to $CFILE for testing"
2010-02-09 01:26:34 +00:00
fi
2014-08-07 21:20:21 +00:00
rm -f plugin.zip
OPWD=$PWD
2010-02-09 01:26:34 +00:00
cd $PLUGINDIR
grep -q '^name=' $PC
if [ "$?" -ne "0" ]
then
echo "You must have a plugin name in $PC"
2014-08-07 21:20:21 +00:00
echo 'For example name=foo'
2010-02-09 01:26:34 +00:00
exit 1
fi
grep -q '^version=' $PC
if [ "$?" -ne "0" ]
then
echo "You must have a version in $PC"
2014-08-07 21:20:21 +00:00
echo 'For example version=0.1.2'
2010-02-09 01:26:34 +00:00
exit 1
fi
# update the date
grep -v '^date=' $PC > $PCT
DATE=`date '+%s000'`
echo "date=$DATE" >> $PCT
mv $PCT $PC || exit 1
2010-02-09 01:26:34 +00:00
# add our Base64 key
grep -v '^key=' $PC > $PCT
B64KEY=`cat $B64KEYFILE`
echo "key=$B64KEY" >> $PCT
mv $PCT $PC || exit 1
2010-02-09 01:26:34 +00:00
# zip it
zip -r $OPWD/plugin.zip * || exit 1
2010-02-09 01:26:34 +00:00
# get the version and use it for the sud header
VERSION=`grep '^version=' $PC | cut -f 2 -d '='`
# get the name and use it for the file name
NAME=`grep '^name=' $PC | cut -f 2 -d '='`
XPI2P=${NAME}.xpi2p
2014-08-07 21:20:21 +00:00
SU3=${NAME}.su3
cd $OPWD
2010-02-09 01:26:34 +00:00
# sign it
2014-08-07 21:20:21 +00:00
echo 'Signing. ...'
java -cp $I2P/lib/i2p.jar net.i2p.crypto.TrustedUpdate sign plugin.zip $XPI2P $PRIVKEYFILE $VERSION || exit 1
2014-08-07 21:20:21 +00:00
java -cp $I2P/lib/i2p.jar net.i2p.crypto.SU3File sign -c PLUGIN -t $KEYTYPE plugin.zip $SU3 $PRIVKEYSTORE $VERSION $SIGNER || exit 1
2010-02-09 01:26:34 +00:00
rm -f plugin.zip
# verify
echo 'Verifying. ...'
java -cp $I2P/lib/i2p.jar net.i2p.crypto.TrustedUpdate showversion $XPI2P || exit 1
java -cp $I2P/lib/i2p.jar -Drouter.trustedUpdateKeys=$B64KEY net.i2p.crypto.TrustedUpdate verifysig $XPI2P || exit 1
2014-08-07 21:20:21 +00:00
java -cp $I2P/lib/i2p.jar -Di2p.dir.base=$I2P net.i2p.crypto.SU3File showversion $SU3 || exit 1
java -cp $I2P/lib/i2p.jar -Di2p.dir.base=$I2P net.i2p.crypto.SU3File verifysig $SU3 || exit 1
2010-02-11 19:46:47 +00:00
rm -rf logs/
2010-02-09 01:26:34 +00:00
2014-08-07 21:20:21 +00:00
echo 'Plugin files created: '
2010-02-09 01:26:34 +00:00
wc -c $XPI2P
2014-08-07 21:20:21 +00:00
wc -c $SU3
exit 0