Add modules to repository

This commit is contained in:
Sebastian Kinne
2017-11-16 16:42:22 +11:00
commit d0aa1e38ef
707 changed files with 96750 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#!/bin/sh
# Author: sud0nick
# Date: Feb 2016
help() {
echo "Usage: ./addAuthKey.sh <keydir> <opts>";
echo '';
echo 'Parameters:';
echo '';
echo -e '\t-k:\tName of key to be used';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
SSH_STORE='/pineapple/modules/Papers/includes/ssh/';
KEY='';
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-k" ]]; then
KEY="$2";
fi
shift
done
cat $SSH_STORE$KEY.pub >> /root/.ssh/authorized_keys

View File

@@ -0,0 +1,117 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
help() {
echo "Usage: ./buildCert.sh <opts>";
echo '';
echo 'Required Parameters:';
echo -e '\t-k,--keyName:\tName of exported key files';
echo '';
echo 'Optional Parameters:';
echo '';
echo -e '\t-b,--bitSize:\tBitsize of keys (Default: 2048)';
echo -e '\t-d,--days:\tNumber days keys will be valid (Default: 365)';
echo -e '\t-sa,--sigAlgo:\tSignature algorithm (Default: SHA-256)';
echo '';
echo 'Distinguished Name Options:';
echo '';
echo -e '\t-c,--country:\t\t\tCountry Code';
echo -e '\t-st,--state:\t\t\tState or Province';
echo -e '\t-l,--locality:\t\t\tCity or Locality';
echo -e '\t-o,--orgnaization:\t\tOrganization';
echo -e '\t-ou,--organizationalUnit:\tOrganizational Unit';
echo -e '\t-cn,--commonName:\t\tCommon Name';
echo -e '\t-email,--emailAddress:\t\tEmail Address';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
# Defaults
SIGALGO="sha256";
BITSIZE=2048;
DAYS=365;
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-d" || "$1" == "--days" ]]; then
DAYS="$2";
fi
if [[ "$1" == "-b" || "$1" == "--bitSize" ]]; then
BITSIZE="$2";
fi
if [[ "$1" == "-k" || "$1" == "--keyName" ]]; then
KEYNAME="$2";
fi
if [[ "$1" == "-sa" || "$1" == "--sigAlgo" ]]; then
SIGALGO="$2";
fi
if [[ "$1" == "-c" || "$1" == "--country" ]]; then
COUNTRY="$2"
fi
if [[ "$1" == "-st" || "$1" == "--state" ]]; then
STATE="$2"
fi
if [[ "$1" == "-l" || "$1" == "--locality" ]]; then
LOCALITY="$2"
fi
if [[ "$1" == "-o" || "$1" == "--organization" ]]; then
ORGANIZATION="$2"
fi
if [[ "$1" == "-ou" || "$1" == "--organizationalUnit" ]]; then
OU="$2"
fi
if [[ "$1" == "-cn" || "$1" == "--commonName" ]]; then
CN="$2"
fi
if [[ "$1" == "-email" || "$1" == "--emailAddress" ]]; then
EMAIL="$2"
fi
shift
done
if [ -z "$DAYS" ] || [ -z "$BITSIZE" ] || [ -z "$KEYNAME" ]; then
echo "[-] You must enter at least key name, bitsize, and days valid parameters.";
help;
exit;
fi
subj="";
ssl_store="/pineapple/modules/Papers/includes/ssl/";
if [ -n "$COUNTRY" ]; then
subj="$subj/C=$COUNTRY";
fi
if [ -n "$STATE" ]; then
subj="$subj/ST=$STATE";
fi
if [ -n "$LOCALITY" ]; then
subj="$subj/L=$LOCALITY";
fi
if [ -n "$ORGANIZATION" ]; then
subj=$subj"/O=$ORGANIZATION";
fi
if [ -n "$OU" ]; then
subj="$subj/OU=$OU";
fi
if [ -n "$CN" ]; then
subj="$subj/CN=$CN";
fi
if [ -n "$EMAIL" ]; then
subj="$subj/emailAddress=$EMAIL";
fi
if [ -n "$subj" ]; then
openssl req -x509 -nodes -batch -days $DAYS -newkey rsa:$BITSIZE -$SIGALGO -keyout $ssl_store$KEYNAME.pem -out $ssl_store$KEYNAME.cer -subj "$subj";
else
openssl req -x509 -nodes -batch -days $DAYS -newkey rsa:$BITSIZE -$SIGALGO -keyout $ssl_store$KEYNAME.pem -out $ssl_store$KEYNAME.cer;
fi
echo "Complete";

View File

@@ -0,0 +1,121 @@
# Author: sud0nick
# Date: Apr 2016
from subprocess import call
import os
class ConfigHelper:
def __init__(self, sslDir = "/etc/nginx/ssl/"):
self.nginxConf = "/etc/nginx/nginx.conf"
self.lines = [f for f in open(self.nginxConf)]
self.ssl_dir = sslDir
self.serverBlockIndex = self.getServerBlockIndex()
self.currentSSLCerts = self.getCurrentSSLCerts()
def checkSSLCertsExist(self):
flags = [".pem", ".cer"]
if os.path.isdir(self.ssl_dir):
for file in os.listdir(self.ssl_dir):
for flag in flags:
if flag in file:
flags.remove(flag)
if flags:
return False
else:
return True
def getCurrentSSLCerts(self):
certs = []
index = self.serverBlockIndex
for line in self.lines[index:]:
if "ssl_certificate" in line:
i = line.rfind("/")
certs.append(line[i+1:].strip(";\n"))
return certs
def getServerBlockIndex(self):
index = 0
for line in self.lines:
if ("listen" in line) and not ("80" in line or "443" in line):
return index
index = index + 1
return False
def checkSSLConfigStatus(self):
index = self.serverBlockIndex
for line in self.lines[index:]:
if "1471 ssl;" in line:
return True
return False
def addSSLConfig(self, keyName):
# Check if SSL has already been configured for port 1471
if self.checkSSLConfigStatus():
return True
index = 0
cert = keyName + ".cer"
key = keyName + ".pem"
with open(self.nginxConf, "w") as out:
for line in self.lines:
if index == self.serverBlockIndex:
line = "\t\tlisten\t1471 ssl;\n"
if index > self.serverBlockIndex:
if "root /pineapple/;" in line:
self.lines.insert(index + 1, "\t\tssl_certificate /etc/nginx/ssl/" + cert + ";\n"
"\t\tssl_certificate_key /etc/nginx/ssl/" + key + ";\n"
"\t\tssl_protocols TLSv1 TLSv1.1 TLSv1.2;\n")
index = index + 1
out.write(line)
call(["/etc/init.d/nginx", "reload"])
return True
def replaceSSLConfig(self, newKey):
cert = newKey + ".cer"
key = newKey + ".pem"
currentKey = self.currentSSLCerts[0].rsplit(".")[0]
index = 0
with open(self.nginxConf, "w") as out:
for line in self.lines:
if index > self.serverBlockIndex:
if (currentKey + ".cer") in line:
line = "\t\tssl_certificate /etc/nginx/ssl/" + cert + ";\n"
if (currentKey + ".pem") in line:
line = "\t\tssl_certificate_key /etc/nginx/ssl/" + key + ";\n"
index = index + 1
out.write(line)
call(["/etc/init.d/nginx", "reload"])
def removeSSLConfig(self):
index = 0
with open(self.nginxConf, "w") as out:
for line in self.lines:
if index == self.serverBlockIndex:
line = "\t\tlisten\t1471;\n"
if index > self.serverBlockIndex:
if "ssl_certificate" in line or "ssl_protocols" in line:
continue
index = index + 1
out.write(line)
call(["/etc/init.d/nginx", "reload"])

View File

@@ -0,0 +1,47 @@
#!/usr/bin/python
# Author: sud0nick
# Date: Jan 2016
import sys
import argparse
from cfgHelper import ConfigHelper
parser = argparse.ArgumentParser(description='Nginx Configuration Tool')
parser.add_argument('-k', action='store', dest='keyName', help='Name of the keys to use for SSL configuration')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--add', action='store_true', dest='addSSL', help='Configure Nginx to use SSL. Requires -k to be set.')
group.add_argument('--replace', action='store_true', dest='replaceSSL', help='Replace current SSL certificates. Requires -k to be set.')
group.add_argument('--remove', action='store_true', dest='removeSSL', help='Remove SSL configuration from Nginx.')
group.add_argument('--getSSLCerts', action='store_true', dest='getSSLCerts', help="Get the current certs being used for SSL in Nginx.")
args = parser.parse_args()
if (args.addSSL and not args.keyName) or (args.replaceSSL and not args.keyName):
parser.error("The option selected requires the -k option be provided as well.")
# Create a new instance of ConfigHelper that points to the
# nginx SSL store (default is /etc/nginx/ssl/)
helper = ConfigHelper()
# Add the configuration to the nginx config file
if args.addSSL:
if not helper.checkSSLCertsExist():
print "SSL certs must first be generated"
quit()
if not helper.addSSLConfig(args.keyName):
print "An error has occurred while attempting to configure SSL"
else:
print "Complete"
elif args.replaceSSL:
helper.replaceSSLConfig(args.keyName)
print "Complete"
elif args.removeSSL:
helper.removeSSLConfig()
print "Complete"
elif args.getSSLCerts:
if len(helper.currentSSLCerts) > 0:
print "\n".join(helper.currentSSLCerts)

View File

@@ -0,0 +1,14 @@
#!/bin/sh
testZip=$(opkg list-installed | grep -w 'zip')
testUnzip=$(opkg list-installed | grep -w 'unzip')
if [ -z "$testZip" ]; then
echo "Not Installed";
else
if [ -z "$testUnzip" ]; then
echo "Not Installed";
else
echo "Installed";
fi
fi

View File

@@ -0,0 +1,42 @@
#!/bin/sh
# Author: sud0nick
# Date: Feb 2016
help() {
echo "Usage: ./checkSSHKey.sh <keydir> <opts>";
echo '';
echo 'Parameters:';
echo '';
echo -e '\t-k:\tName of key to be checked';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
SSH_STORE='/pineapple/modules/Papers/includes/ssh/';
KEY='';
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-k" ]]; then
if [ -e "$SSH_STORE$2.pub" ]; then
KEY=$(cat "$SSH_STORE$2.pub");
else
exit;
fi
fi
shift
done
RES=$(cat /root/.ssh/authorized_keys | grep "$KEY")
if [[ -z "$RES" ]]; then
echo "FALSE";
else
echo "TRUE";
fi

View File

@@ -0,0 +1,12 @@
#!/bin/bash
# Author: sud0nick
# Date: Jan 2016
if ! cp $1.pem /etc/nginx/ssl/; then
echo "Failed to copy $1.pem to /etc/nginx/ssl/";
fi
if ! cp $1.cer /etc/nginx/ssl/; then
echo "Failed to copy $1.cer to /etc/nginx/ssl/";
fi

View File

@@ -0,0 +1,110 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
# Location of SSL keys
ssl_store="/pineapple/modules/Papers/includes/ssl/";
help() {
echo "Encryption/Export script for OpenSSL certificates";
echo "Usage: ./encryptKeys.sh <opts>";
echo "Use './encryptKeys.sh --examples' to see example commands";
echo '';
echo 'NOTE:';
echo "Current SSL store is at $ssl_store";
echo '';
echo 'Parameters:';
echo '';
echo -e '\t-k:\tName of key to be encrypted';
echo '';
echo 'Encryption Options:';
echo '';
echo -e '\t--encrypt:\tMust be supplied to encrypt keys';
echo -e '\t-a:\t\tAlgorithm to use for key encryption (aes256, 3des, camellia256, etc)';
echo -e '\t-p:\t\tPassword to use for encryption';
echo '';
echo 'Container Options:';
echo '';
echo -e '\t-c:\tContainer type (pkcs12, pkcs8)';
echo -e '\t-calgo:\tEncyrption algorithm for container. (Default is the value supplied for -a)';
echo -e '\t-cpass:\tPassword for container. (Default is the password supplied for -p)';
echo '';
}
examples() {
echo '';
echo 'Examples:';
echo 'Encrypt private key:';
echo './encryptKeys.sh -k keyName --encrypt -a aes256 -p password';
echo '';
echo 'Export keys to PKCS#12 container:';
echo './encryptKeys.sh -k keyName -c pkcs12 -calgo aes256 -cpass password';
echo '';
echo 'Encrypt private key and export to PKCS#12 container using same algo and pass:';
echo './encryptKeys.sh -k keyName --encrypt -a aes256 -p password -c pkcs12';
echo '';
echo 'Encrypt private key and export to PKCS#12 container using different algo and pass:';
echo './encryptKeys.sh -k keyName --encrypt -a aes256 -p password -c pkcs12 -calgo camellia256 -cpass diffpass';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
ENCRYPT_KEYS=false;
while [ "$#" -gt 0 ]
do
if [[ "$1" == "--examples" ]]; then
examples;
exit;
fi
if [[ "$1" == "--encrypt" ]]; then
ENCRYPT_KEYS=true;
fi
if [[ "$1" == "-a" ]]; then
ALGO="$2";
fi
if [[ "$1" == "-k" ]]; then
KEY="$2";
fi
if [[ "$1" == "-p" ]]; then
PASS="$2";
fi
if [[ "$1" == "-c" ]]; then
CONTAINER="$2";
fi
if [[ "$1" == "-calgo" ]]; then
CALGO="$2";
fi
if [[ "$1" == "-cpass" ]]; then
CPASS="$2";
fi
shift
done;
# Generate a password on the private key
if [ $ENCRYPT_KEYS = true ]; then
openssl rsa -$ALGO -in $ssl_store$KEY.pem -out $ssl_store$KEY.pem -passout pass:"$PASS";
fi
# If a container type is present but not an algo or pass then use
# the same algo and pass from the private key
if [ -n "$CONTAINER" ]; then
if [ -z "$CALGO" ]; then
CALGO="$ALGO";
fi
if [ -z "$CPASS" ]; then
CPASS="$PASS";
fi
# Generate a container for the public and private keys
openssl $CONTAINER -$CALGO -export -nodes -out $ssl_store$KEY.pfx -inkey $ssl_store$KEY.pem -in $ssl_store$KEY.cer -passin pass:"$PASS" -passout pass:"$CPASS";
fi
echo "Complete"

View File

@@ -0,0 +1,59 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
help() {
echo "Usage: ./genSSHKeys.sh <opts>";
echo '';
echo 'Required Parameters:';
echo -e '\t-k,--keyName:\tName of exported key files';
echo '';
echo 'Optional Parameters:';
echo '';
echo -e '\t-b,--bitSize:\tBitsize of keys (Default: 2048)';
echo -e '\t-p,--pass:\tPassword for private key';
echo -e '\t-c,--comment:\tInclude a comment in the public key (Default: root@Pineapple)';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
# Defaults
BITSIZE=2048;
PASSWORD='';
SSH_STORE="/pineapple/modules/Papers/includes/ssh/";
COMMENT='root@Pineapple';
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-k" || "$1" == "--keyName" ]]; then
KEYNAME="$2";
fi
if [[ "$1" == "-b" || "$1" == "--bitSize" ]]; then
BITSIZE="$2";
fi
if [[ "$1" == "-p" || "$1" == "--pass" ]]; then
PASSWORD="$2";
fi
if [[ "$1" == "-c" || "$1" == "--comment" ]]; then
COMMENT="$2"
fi
shift
done
if [[ -z $KEYNAME ]]; then
help;
exit;
fi
ssh-keygen -q -b $BITSIZE -t rsa -N "$PASSWORD" -f $SSH_STORE$KEYNAME.pem -C $COMMENT
mv $SSH_STORE$KEYNAME.pem.pub $SSH_STORE$KEYNAME.pub

View File

@@ -0,0 +1,8 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
opkg update > /dev/null;
opkg install zip unzip > /dev/null;
echo "Complete"

View File

@@ -0,0 +1,49 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
help() {
echo "Usage: ./packKeys.sh <keydir> <opts>";
echo '';
echo 'Parameters:';
echo '';
echo -e '\tkeydir:\tDirectory where the key resides';
echo -e '\t-f:\tFile names as string value';
echo -e '\t-o:\tName of output file';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
# Define and clear out the download directory
DL_DIR="/pineapple/modules/Papers/includes/download/";
rm -rf $DL_DIR*
# Get the key directory and shift it out of the argument vectors
KEY_DIR="$1";
shift;
FILES='';
OUTPUT='';
export IFS=" ";
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-f" ]]; then
for word in $2; do
FILES="$FILES $KEY_DIR$word";
done
fi
if [[ "$1" == "-o" ]]; then
OUTPUT="$2";
fi
shift
done;
zip -j $DL_DIR$OUTPUT $FILES > /dev/null;

View File

@@ -0,0 +1,18 @@
#!/bin/bash
# Author: sud0nick
# Date: April 6, 2016
IN_SERVER_BLOCK=false;
while read p; do
if [[ $IN_SERVER_BLOCK == false ]]; then
if [[ $p == *"listen"* && $p == *"1471"* ]]; then
IN_SERVER_BLOCK=true;
fi
else
if [[ $p == *".cer;" || $p == *".pem;" ]]; then
echo $p | cut -d '/' -f 5 | tr -d ';';
fi
fi
done < /etc/nginx/nginx.conf

View File

@@ -0,0 +1,6 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
opkg remove zip unzip > /dev/null;

View File

@@ -0,0 +1,11 @@
#!/bin/sh
# Author: sud0nick
# Date: Jan 2016
SSL_DIR="/etc/nginx/ssl/";
while [[ $# -gt 0 ]]; do
rm -rf $SSL_DIR$1;
shift;
done

View File

@@ -0,0 +1,34 @@
#!/bin/sh
# Author: sud0nick
# Date: Feb 2016
help() {
echo "Usage: ./revokeSSHKey.sh <keydir> <opts>";
echo '';
echo 'Parameters:';
echo '';
echo -e '\t-k:\tName of key to be revoked';
echo '';
}
if [ "$#" -lt 1 ]; then
help;
exit;
fi
SSH_STORE='/pineapple/modules/Papers/includes/ssh/';
KEY='';
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-k" ]]; then
KEY=$(cat "$SSH_STORE$2.pub");
fi
shift
done
# Revoke the key from /root/.ssh/authorized_keys
grep -v "$KEY" /root/.ssh/authorized_keys > /root/.ssh/authorized_keys.new; mv /root/.ssh/authorized_keys.new /root/.ssh/authorized_keys

View File

@@ -0,0 +1,35 @@
#!/bin/sh
help() {
echo "Usage: ./testEncrypt.sh <opts>";
echo '';
echo 'Parameters:';
echo '';
echo -e '\t-d:\tDirectory where key resides';
echo -e '\t-k:\tName of key to test';
echo '';
}
if [ "$#" -lt 2 ]; then
help;
exit;
fi
KEY=''
KEYDIR=''
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-k" ]]; then
KEY="$2.pem"
fi
if [[ "$1" == "-d" ]]; then
KEYDIR="$2"
fi
shift
done;
openssl rsa -in $KEYDIR$KEY -passin pass: | awk 'NR==0;'

View File

@@ -0,0 +1,53 @@
#!/bin/bash
# Author: sud0nick
# Date: Sept 2016
help() {
echo "Usage: ./unpackKeyArchive.sh -f <fileName>";
echo '';
echo 'Parameters:';
echo '';
echo -e '\t-f:\tFile name without extension';
echo '';
}
if [ "$#" -lt 2 ]; then
help;
exit;
fi
# Define and clear out the download directory
DL_DIR="/pineapple/modules/Papers/includes/upload/";
FILE='';
export IFS=" ";
while [ "$#" -gt 0 ]
do
if [[ "$1" == "-f" ]]; then
FILE="$DL_DIR$2"
fi
shift
done;
output=$(unzip $FILE.zip -d $DL_DIR);
# If the archive contained a .pub these
# keys are destined for the SSH directory
if [[ $output == *".pub"* ]]; then
mv $FILE.pub /pineapple/modules/Papers/includes/ssh/
mv $FILE.pem /pineapple/modules/Papers/includes/ssh/
fi
# If the archive contained a .cer these
# keys are destined for the SSL directory
if [[ $output == *".cer"* ]]; then
mv $FILE.cer /pineapple/modules/Papers/includes/ssl/
mv $FILE.pem /pineapple/modules/Papers/includes/ssl/
fi
# Clear the download directory
rm -rf $DL_DIR*