Skip to content

Instantly share code, notes, and snippets.

@plisken1

plisken1/signjar Secret

Created July 10, 2020 09:29
Show Gist options
  • Save plisken1/7861b93a3f01f79ae4d728ae101fb460 to your computer and use it in GitHub Desktop.
Save plisken1/7861b93a3f01f79ae4d728ae101fb460 to your computer and use it in GitHub Desktop.
A script to automate the signing of jar files
#!/bin/bash
clear
function checkforfiles
{
echo "Checking for eToken.cfg and bundle.pem"
if [[ -f "eToken.cfg" && -f "bundle.pem" ]];
then
echo "Found eToken.cfg and bundle.pem."
echo
else
echo "Cant find eToken.cfg and/or bundle.pem, attempting to copy..."
cp /Volumes/D_SLAVE/My\ Documents/My\ Projects/Certificate/to011220/bundle.pem .
cp /Volumes/D_SLAVE/My\ Documents/My\ Projects/Certificate/to011220/eToken.cfg .
fi
}
function checkforjar
{
if [ -f $1 ]; then
echo "$1 exists, looking good..."
else
echo "$1 NOT found, exiting..."
exit 1
fi
}
echo "Harry's jarsigner script version 2.0"
echo ""
if [ "$1" != "" ]; then
checkforjar $1
else
echo "USAGE signjar filename.jar [OPTIONS -v <verify jar>, -vb <verbose verify>]"
exit 1
fi
checkforfiles
if [[ -f "eToken.cfg" && -f "bundle.pem" ]];
then
echo "Attempting to sign $1"
echo ""
jarsigner -keystore NONE -certchain "bundle.pem" -tsa "http://time.certum.pl" -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg "eToken.cfg" -storepass "REMOVED" "$1" "serialNumberRemoved"
else
echo "Still cant find eToken.cfg and/or bundle.pem, cant continue..."
echo "jar NOT signed."
exit 1
fi
#Verification
if [ "$2" != "" ]; then
if [ "$2" = "-v" ];then
jarsigner -verify -certs -keystore NONE -tsa "http://time.certum.pl" -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg "eToken.cfg" -storepass "REMOVED" "$1" "serialNumberRemoved"
fi
if [ "$2" = "-vb" ];then
jarsigner -verify -verbose -certs -keystore NONE -tsa "http://time.certum.pl" -storetype PKCS11 -providerClass sun.security.pkcs11.SunPKCS11 -providerArg "eToken.cfg" -storepass "REMOVED" "$1" "serialNumberRemoved"
fi
fi
echo "Complete, check above for errors..."
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment