10 Commits
2.0.0 ... 2.1.0

Author SHA1 Message Date
Justin
189a61b8f6 updated README.md 2017-11-24 12:48:52 -08:00
Justin
f095991dff refactor PR #2 2017-11-24 12:45:24 -08:00
Justin Keller
3c135da789 Merge pull request #2 from int9h/master
add bash completion
2017-11-24 12:41:57 -08:00
Manuel Wildauer
c4afe5a0db update README.md 2017-11-24 13:23:00 +01:00
Manuel Wildauer
b076b60dc4 add bash completion 2017-10-05 11:40:19 +02:00
Justin
2cc256c5ff 2.1.0 - See CHANGELOG.md 2017-10-04 18:29:59 -07:00
Justin
7f511eddad 2.1.0 - See CHANGELOG.md 2017-10-04 18:22:50 -07:00
Justin
274b3c5d0d first pass at writing a test 2017-10-02 23:42:59 -07:00
Justin
538fe24621 2.0.1 - See CHANGELOG.md 2017-10-02 02:36:00 -07:00
Justin
ceed4339a8 small optimization, removed uneeded function 2017-10-02 02:30:50 -07:00
6 changed files with 87 additions and 12 deletions

View File

@@ -1 +1,2 @@
- Justin Keller ([nodesocket](https://github.com/nodesocket))
- Manuel Wildauer ([int9h](https://github.com/int9h))

View File

@@ -1,6 +1,16 @@
CHANGELOG
=========
## 2.1.0 - *10/4/2017*
- You may now define the password to use when encrypting and decrypting using the `CRYPTR_PASSWORD` environment variable. This change enables non-interactive/batch operations.
- Added a test script `tests/test.bash`.
## 2.0.1 - *10/2/2017*
- Small optimization, removed unneeded function `cryptr_info()`.
## 2.0.0 - *10/2/2017*
*BREAKING CHANGE*

View File

@@ -9,6 +9,10 @@ git clone https://github.com/nodesocket/cryptr.git
ln -s "$PWD"/cryptr/cryptr.bash /usr/local/bin/cryptr
```
### Bash tab completion
Add `tools/cryptr-bash-completion.bash` to your tab completion file directory.
## API/Commands
### encrypt
@@ -27,6 +31,11 @@ Verifying - enter aes-256-cbc encryption password:
-rw-r--r-- 1 user group 1.0G Oct 1 13:34 secrets-file.aes
```
You may optionally define the password to use when encrypting using the `CRYPTR_PASSWORD` environment variable. This enables non-interactive/batch operations.
```
➜ CRYPTR_PASSWORD=A1EO7S9SsQYcPChOr47n cryptr encrypt ./secrets-file
```
### decrypt
@@ -48,6 +57,12 @@ enter aes-256-cbc decryption password:
-rw-r--r-- 1 user group 1.0G Oct 1 13:34 secrets-file.aes
```
You may optionally define the password to use when decrypting using the `CRYPTR_PASSWORD` environment variable. This enables non-interactive/batch operations.
```
➜ CRYPTR_PASSWORD=A1EO7S9SsQYcPChOr47n cryptr decrypt ./secrets-file.aes
```
### help
> help - Displays help
@@ -69,7 +84,7 @@ Usage: cryptr command <command-specific-options>
```
➜ cryptr version
cryptr 2.0.0
cryptr 2.1.0
```
### default
@@ -78,7 +93,7 @@ cryptr 2.0.0
```
➜ cryptr
cryptr 2.0.0
cryptr 2.1.0
Usage: cryptr command <command-specific-options>

View File

@@ -18,18 +18,13 @@
set -eo pipefail; [[ $TRACE ]] && set -x
readonly VERSION="2.0.0"
readonly OPENSSL_CIPHER="aes-256-cbc"
readonly VERSION="2.1.0"
readonly OPENSSL_CIPHER_TYPE="aes-256-cbc"
cryptr_version() {
echo "cryptr $VERSION"
}
cryptr_info() {
cryptr_version
echo
}
cryptr_help() {
echo "Usage: cryptr command <command-specific-options>"
echo
@@ -49,7 +44,12 @@ cryptr_encrypt() {
exit 4
fi
openssl $OPENSSL_CIPHER -salt -in "$_file" -out "$_file".aes
if [[ ! -z "${CRYPTR_PASSWORD}" ]]; then
echo "Using environment variable CRYPTR_PASSWORD for the password"
openssl $OPENSSL_CIPHER_TYPE -salt -in "$_file" -out "$_file".aes -pass env:CRYPTR_PASSWORD
else
openssl $OPENSSL_CIPHER_TYPE -salt -in "$_file" -out "$_file".aes
fi
}
cryptr_decrypt() {
@@ -59,14 +59,20 @@ local _file="$1"
exit 5
fi
openssl $OPENSSL_CIPHER -d -salt -in "$_file" -out "${_file%\.aes}"
if [[ ! -z "${CRYPTR_PASSWORD}" ]]; then
echo "Using environment variable CRYPTR_PASSWORD for the password"
openssl $OPENSSL_CIPHER_TYPE -d -salt -in "$_file" -out "${_file%\.aes}" -pass env:CRYPTR_PASSWORD
else
openssl $OPENSSL_CIPHER_TYPE -d -salt -in "$_file" -out "${_file%\.aes}"
fi
}
cryptr_main() {
local _command="$1"
if [[ -z $_command ]]; then
cryptr_info
cryptr_version
echo
cryptr_help
exit 0
fi

29
tests/test.bash Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eo pipefail; [[ $TRACE ]] && set -x
plaintext=$(mktemp /tmp/cryptr.XXXXXXXX)
dd if=/dev/urandom bs=4096 count=1 2> /dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c512 > "$plaintext"
plaintext_sha=($(openssl dgst -sha256 "$plaintext"))
export CRYPTR_PASSWORD
CRYPTR_PASSWORD=$(dd if=/dev/urandom bs=200 count=1 2> /dev/null | LC_ALL=C tr -dc 'A-Za-z0-9' | head -c32)
cryptr encrypt "$plaintext"
rm -f "$plaintext"
if [[ ! -f "$plaintext".aes ]]; then
printf "Encrypted out file %s was not created" "$plaintext".aes 1>&2
exit 3
fi
cryptr decrypt "$plaintext".aes
decrypted_sha=($(openssl dgst -sha256 "$plaintext"))
rm -f "$plaintext".aes
rm -f "$plaintext"
if [ "${plaintext_sha[1]}" != "${decrypted_sha[1]}" ]; then
printf "Hash mismatch\n\t%s != %s" "${plaintext_sha[1]}" "${decrypted_sha[1]}" 1>&2
exit 4
fi

View File

@@ -0,0 +1,14 @@
_cryptr_complete()
{
local cur_word prev_word type_list
COMPREPLY=()
cur_word="${COMP_WORDS[COMP_CWORD]}"
prev_word="${COMP_WORDS[COMP_CWORD-1]}"
opts='encrypt decrypt'
COMPREPLY=( $(compgen -W "${opts}" -- ${cur_word}) )
return 0
}
complete -F _cryptr_complete cryptr.bash cryptr