|
osdir.com mailing list archive F.A.Q. -since 2001! |
|
|
|
Subject: Script for loop-AES key generation - msg#00001List: linux.cryptography
by Date: Prev Next Date Index by Thread: Prev Next Thread Index
Hey all,
I've found that, whenever I want to create a new loop-AES key, I always refer to README and look up/copy the exact command. More than once I typoed and ended up with a bad key. So I thought, why not make this into a short shell script. Attached is one which does just that, along with a man page that describes the available options. The script has been included in the Debian package loop-aes-utils for about a year or so and seems to generally work fine. It should work with any POSIX- compliant shell (tested with bash, dash, posh, busybox sh). Let me know if you encounter any problems using it or have suggestions/patches for improvement. :-) Features: - Check for unsafe swap - Support for v1/v2/v3 type keys - Symmetric/asymmetric GnuPG encryption - Configurable cipher cheers, Max #!/bin/sh # # loop-aes-keygen - Create loop-AES encryption keys # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; version 2 dated June, 1991. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. # # Copyright 2005-2006, Max Vozeler <xam@xxxxxxxxxx> # # $Id: loop-aes-keygen 1104 2006-03-17 15:43:11Z max $ # set -e umask 077 cipher= userids= rnd=/dev/random version=3 usage() { cat << USAGE usage: loop-aes-keygen [opts] <keyfile> -v <1|2|3> Key format (Default: $version) -u userid Encrypt for GnuPG pubkey <userid> -c cipher Use GnuPG cipher <cipher> USAGE } get_options() { while getopts 'v:s:c:u:h' f do case $f in v) version=$OPTARG ;; c) cipher=$OPTARG ;; s) rnd=$OPTARG ;; u) userids="$userids $OPTARG" ;; h) usage exit 0 ;; esac done shift `expr $OPTIND - 1` keyfile=$1 if [ -z $keyfile ]; then echo No output file. Aborting usage exit 1 fi if [ $version -lt 1 ] || [ $version -gt 3 ]; then echo Unsupported key format: $version exit 1 fi } check_safe_loop() { loopdev=$1 opts=$(/sbin/losetup $loopdev 2>&1) if [ $? -ne 0 ]; then echo "Error: Check for $loopdev failed ($opts)" exit 1 fi # If loop entry has an encryption= option assume it's safe if echo "$opts" | grep -q encryption=; then return 0 fi return 1 } check_safe_swap() { if [ ! -r /proc/swaps ]; then echo Error: Cannot read /proc/swaps exit 1 fi unsafe= while read line do set -- $line case $1 in /dev/loop*) if ! check_safe_loop $1; then unsafe=$1 break fi ;; Filename*) ;; *) unsafe=$1 break ;; esac done < /proc/swaps if [ $unsafe ]; then echo Fatal: Unsafe swap detected: $unsafe exit 1 fi return 0 } keygen() { version=$1 keyfile=$2 gpgargs=$3 # These are the known loop-AES key formats: # v1.x 1 45 bytes AES key # v2.x 64 2880 bytes(45 * 64) AES keys # v3.x 65 2925 bytes(45 * 65) #65 is md5 seed case $version in 1) nkeys=1 ;; 2) nkeys=64 ;; 3) nkeys=65 ;; *) return 1 ;; esac bytes=$((45*$nkeys)) head -c $bytes $rnd | uuencode -m - | head -n $(($nkeys+1)) | tail -n $nkeys | gpg $gpgargs > $keyfile } get_options $* if ! check_safe_swap; then exit 1 fi if ! [ -x /usr/bin/gpg ]; then echo "Error: gpg not found" exit 1 fi if ! [ -x /usr/bin/uuencode ]; then echo "Error: uuencode not found - see package sharutils" exit 1 fi if [ -e $keyfile ]; then echo "Keyfile $keyfile exists. Aborting." exit 1 fi gpgargs="--armor" if [ "$userids" ]; then gpgargs="$gpgargs --encrypt" for id in $userids; do gpgargs="$gpgargs --recipient $id" done else gpgargs="$gpgargs --symmetric" fi if [ $cipher ]; then gpgargs="$gpgargs --cipher-algo=$cipher" fi if ! keygen $version $keyfile "$gpgargs"; then echo An error occured while creating the key file. exit 1 fi exit 0
Thread at a glance:
Previous Message by Date:Alert from eSafe: text.ziptext.scr Infected with Win32.Mydoom.m====================================================== Bapco detected hostile or unwanted content in this message. If you believe this is in error, please resend the whole message to: bapcoitd@xxxxxxxxx Please make sure that you specify the recipient email address(es) in your message. Your email will be manually inspected and if found to be safe and in accordance with Bapco's email policy, itwill be forwarded to the intended recipient. ====================================================== Time: 02 Nov 2006 09:19:40 Scan result: Mail modified to remove malicious content Protocol: SMTP in File Name\Mail Subject: Delivery reports about your e-mail Source: 67.10.187.183 Destination: Mail Sender: linux-crypto@xxxxxxxxxxxx Mail Recipients: alquraan_aek@xxxxxxxxx Details: text.zip\text.scr Infected with Win32.Mydoom.m, Blocked - Linux-crypto: cryptography in and on the Linux system Archive: http://mail.nl.linux.org/linux-crypto/ Next Message by Date:loop-AES integrated into SUSE 10.1LOOP_MULTI__KEY_SETUP_V3 seems completely missing from SUSE 10.1. Has someone put together a loop_aes.c sub-module for same? It looks like a simple cut and past job from the latest loop-AES-3.1e. PagCal - Linux-crypto: cryptography in and on the Linux system Archive: http://mail.nl.linux.org/linux-crypto/ Previous Message by Thread:Alert from eSafe: text.ziptext.scr Infected with Win32.Mydoom.m====================================================== Bapco detected hostile or unwanted content in this message. If you believe this is in error, please resend the whole message to: bapcoitd@xxxxxxxxx Please make sure that you specify the recipient email address(es) in your message. Your email will be manually inspected and if found to be safe and in accordance with Bapco's email policy, itwill be forwarded to the intended recipient. ====================================================== Time: 02 Nov 2006 09:19:40 Scan result: Mail modified to remove malicious content Protocol: SMTP in File Name\Mail Subject: Delivery reports about your e-mail Source: 67.10.187.183 Destination: Mail Sender: linux-crypto@xxxxxxxxxxxx Mail Recipients: alquraan_aek@xxxxxxxxx Details: text.zip\text.scr Infected with Win32.Mydoom.m, Blocked - Linux-crypto: cryptography in and on the Linux system Archive: http://mail.nl.linux.org/linux-crypto/ Next Message by Thread:Re: Script for loop-AES key generationMax Vozeler wrote: > Let me know if you encounter any problems using it or have > suggestions/patches for improvement. :-) There have been few cases where v3 key file and v2 losetup/mount were used to set up a file system, and after upgrade to v3 losetup/mount, mounting the file system failed. There is a warning about this problem in loop-AES README file, but not everyone reads README files. May I suggest adding a check that losetup is recent enough. Something like this: strings /sbin/losetup | grep -q -s multi-key-v3 if [ $? != 0 ] ; then echo "too old losetup version" fi -- Jari Ruusu 1024R/3A220F51 5B 4B F9 BB D3 3F 52 E9 DB 1D EB E3 24 0E A9 DD - Linux-crypto: cryptography in and on the Linux system Archive: http://mail.nl.linux.org/linux-crypto/
blog comments powered by Disqus
|
|