From 46f2537cf5947ced95d73cde6dbb165c461d6b0f Mon Sep 17 00:00:00 2001 From: "Endi S. Dewata" Date: Sat, 20 Aug 2016 04:41:00 +0200 Subject: Fixed LunaSA scripts. --- tools/lunasa-del | 123 +++++++++++++++++++++++++++++++++++++++++++++++++++ tools/lunasa-del.sh | 123 --------------------------------------------------- tools/lunasa-find | 56 +++++++++++++++++++++++ tools/lunasa-find.sh | 56 ----------------------- 4 files changed, 179 insertions(+), 179 deletions(-) create mode 100755 tools/lunasa-del delete mode 100755 tools/lunasa-del.sh create mode 100755 tools/lunasa-find delete mode 100755 tools/lunasa-find.sh diff --git a/tools/lunasa-del b/tools/lunasa-del new file mode 100755 index 0000000..a5cfe8a --- /dev/null +++ b/tools/lunasa-del @@ -0,0 +1,123 @@ +#!/bin/sh + +verbose= +password_file= +run=1 + +# read the options +TEMP=`getopt -o f:nv --long help -n 'lunasa-del' -- "$@"` +eval set -- "$TEMP" + +# extract options and their arguments into variables. +while true ; do + case "$1" in + -f) + password_file=$2 + shift 2 + ;; + --help) + echo "Usage: lunasa-del -f [OPTIONS]" + echo + echo "Options:" + echo " -f File containing LunaSA password." + echo " -n Dry run. Do not delete objects." + echo " -v Run in verbose mode." + echo " --help Show help message." + exit 0 + ;; + -n) + run= + shift + ;; + -v) + verbose=1 + shift + ;; + --) + shift + break + ;; + *) + echo "Error: invalid option $1" >&2 + echo "Run lunasa-del --help for help." >&2 + exit 1 + ;; + esac +done + +prefix=$1 + +if [[ "$verbose" != "" ]] +then + echo "prefix: $prefix" +fi + +if [[ "$prefix" == "" ]] +then + echo "Error: missing prefix" >&2 + echo "Run lunasa-del --help for help." >&2 + exit 1 +fi + +if [[ "$verbose" != "" ]] +then + echo "password file: $password_file" +fi + +if [[ "$password_file" == "" ]] +then + echo "Error: missing password file" >&2 + echo "Run lunasa-del --help for help." >&2 + exit 1 +fi + +password="`cat $password_file`" + +if [[ "$verbose" != "" ]] +then + echo "run: $run" +fi + +echo "Searching for objects with prefix: $prefix" + +/usr/safenet/lunaclient/bin/cmu list -display handle,id,label -class certificate -password $password | while read cert +do + label=$(echo $cert | cut -d' ' -f3 | cut -d= -f2) + + if [[ "$label" == "$prefix"* ]] + then + + echo "object: $label" + + id=$(echo $cert | cut -d' ' -f2 | cut -d= -f2) + echo " - id: $id" + + certHandle=$(echo $cert | cut -d' ' -f1 | cut -d= -f2) + echo " - certificate: $certHandle" + + if [ "$run" == "1" ] + then + /usr/safenet/lunaclient/bin/cmu delete -handle $certHandle -force -password $password + fi + + publicKey=$(/usr/safenet/lunaclient/bin/cmu list -display handle -id $id -class public -password $password) + publicKeyHandle=$(echo $publicKey | cut -d' ' -f1 | cut -d= -f2) + echo " - public key: $publicKeyHandle" + + if [ "$run" == "1" ] + then + /usr/safenet/lunaclient/bin/cmu delete -handle $publicKeyHandle -force -password $password + fi + + privateKey=$(/usr/safenet/lunaclient/bin/cmu list -display handle -id $id -class private -password $password) + privateKeyHandle=$(echo $privateKey | cut -d' ' -f1 | cut -d= -f2) + echo " - private key: $privateKeyHandle" + + if [ "$run" == "1" ] + then + /usr/safenet/lunaclient/bin/cmu delete -handle $privateKeyHandle -force -password $password + fi + + fi + +done diff --git a/tools/lunasa-del.sh b/tools/lunasa-del.sh deleted file mode 100755 index cfc4bc5..0000000 --- a/tools/lunasa-del.sh +++ /dev/null @@ -1,123 +0,0 @@ -#!/bin/sh - -verbose= -password_file= -run=1 - -# read the options -TEMP=`getopt -o f:nv --long help -n 'lunasa-del.sh' -- "$@"` -eval set -- "$TEMP" - -# extract options and their arguments into variables. -while true ; do - case "$1" in - -f) - password_file=$2 - shift 2 - ;; - --help) - echo "Usage: lunasa-del.sh -f [OPTIONS]" - echo - echo "Options:" - echo " -f File containing LunaSA password." - echo " -n Dry run. Do not delete objects." - echo " -v Run in verbose mode." - echo " --help Show help message." - exit 0 - ;; - -n) - run= - shift - ;; - -v) - verbose=1 - shift - ;; - --) - shift - break - ;; - *) - echo "Error: invalid option $1" >&2 - echo "Run lunasa-del.sh --help for help." >&2 - exit 1 - ;; - esac -done - -prefix=$1 - -if [[ "$verbose" != "" ]] -then - echo "prefix: $prefix" -fi - -if [[ "$prefix" == "" ]] -then - echo "Error: missing prefix" >&2 - echo "Run lunasa-del.sh --help for help." >&2 - exit 1 -fi - -if [[ "$verbose" != "" ]] -then - echo "password file: $password_file" -fi - -if [[ "$password_file" == "" ]] -then - echo "Error: missing password file" >&2 - echo "Run lunasa-del.sh --help for help." >&2 - exit 1 -fi - -password="`cat $password_file`" - -if [[ "$verbose" != "" ]] -then - echo "run: $run" -fi - -echo "Searching for objects with prefix: $prefix" - -/usr/safenet/lunaclient/bin/cmu list -display handle,id,label -class certificate -password $password | while read cert -do - label=$(echo $cert | cut -d' ' -f3 | cut -d= -f2) - - if [[ "$label" == "$prefix"* ]] - then - - echo "object: $label" - - id=$(echo $cert | cut -d' ' -f2 | cut -d= -f2) - echo " - id: $id" - - certHandle=$(echo $cert | cut -d' ' -f1 | cut -d= -f2) - echo " - certificate: $certHandle" - - if [ "$run" == "1" ] - then - /usr/safenet/lunaclient/bin/cmu delete -handle $certHandle -force -password $password - fi - - publicKey=$(/usr/safenet/lunaclient/bin/cmu list -display handle -id $id -class public -password $password) - publicKeyHandle=$(echo $publicKey | cut -d' ' -f1 | cut -d= -f2) - echo " - public key: $publicKeyHandle" - - if [ "$run" == "1" ] - then - /usr/safenet/lunaclient/bin/cmu delete -handle $publicKeyHandle -force -password $password - fi - - privateKey=$(/usr/safenet/lunaclient/bin/cmu list -display handle -id $id -class private -password $password) - privateKeyHandle=$(echo $privateKey | cut -d' ' -f1 | cut -d= -f2) - echo " - private key: $privateKeyHandle" - - if [ "$run" == "1" ] - then - /usr/safenet/lunaclient/bin/cmu delete -handle $privateKeyHandle -force -password $password - fi - - fi - -done diff --git a/tools/lunasa-find b/tools/lunasa-find new file mode 100755 index 0000000..7d4fc65 --- /dev/null +++ b/tools/lunasa-find @@ -0,0 +1,56 @@ +#!/bin/sh + +verbose= +password_file= + +# read the options +TEMP=`getopt -o f:v --long help -n 'lunasa-find' -- "$@"` +eval set -- "$TEMP" + +# extract options and their arguments into variables. +while true ; do + case "$1" in + -f) + password_file=$2 + shift 2 + ;; + --help) + echo "Usage: lunasa-find -f [OPTIONS]" + echo + echo "Options:" + echo " -f File containing LunaSA password." + echo " -v Run in verbose mode." + echo " --help Show help message." + exit 0 + ;; + -v) + verbose=1 + shift + ;; + --) + shift + break + ;; + *) + echo "Error: invalid option $1" >&2 + echo "Run lunasa-find --help for help." >&2 + exit 1 + ;; + esac +done + +if [[ "$verbose" != "" ]] +then + echo "password file: $password_file" +fi + +if [[ "$password_file" == "" ]] +then + echo "Error: missing password file" >&2 + echo "Run lunasa-find --help for help." >&2 + exit 1 +fi + +password="`cat $password_file`" + +/usr/safenet/lunaclient/bin/cmu list -display handle,id,class,label -password "$password" diff --git a/tools/lunasa-find.sh b/tools/lunasa-find.sh deleted file mode 100755 index 7f36897..0000000 --- a/tools/lunasa-find.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/sh - -verbose= -password_file= - -# read the options -TEMP=`getopt -o f:v --long help -n 'lunasa-find.sh' -- "$@"` -eval set -- "$TEMP" - -# extract options and their arguments into variables. -while true ; do - case "$1" in - -f) - password_file=$2 - shift 2 - ;; - --help) - echo "Usage: lunasa-find.sh -f [OPTIONS]" - echo - echo "Options:" - echo " -f File containing LunaSA password." - echo " -v Run in verbose mode." - echo " --help Show help message." - exit 0 - ;; - -v) - verbose=1 - shift - ;; - --) - shift - break - ;; - *) - echo "Error: invalid option $1" >&2 - echo "Run lunasa-find.sh --help for help." >&2 - exit 1 - ;; - esac -done - -if [[ "$verbose" != "" ]] -then - echo "password file: $password_file" -fi - -if [[ "$password_file" == "" ]] -then - echo "Error: missing password file" >&2 - echo "Run lunasa-del.sh --help for help." >&2 - exit 1 -fi - -password="`cat $password_file`" - -/usr/safenet/lunaclient/bin/cmu list -display handle,id,class,label -password "$password" -- cgit