From 32eb4a205eeb6c20a16e43496a7e4229641889cc Mon Sep 17 00:00:00 2001 From: Stefan Kreutz Date: Tue, 12 Oct 2021 15:07:02 +0200 Subject: Add initial implementation --- Makefile | 9 +++++++ README.md | 18 ++++++++++++++ jotpass.1 | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ jotpass.ksh | 55 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 jotpass.1 create mode 100755 jotpass.ksh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..552ebda --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +MAN= jotpass.1 +BINDIR= /usr/local/bin +MANDIR= /usr/local/man/man + +beforeinstall: + ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \ + ${.CURDIR}/jotpass.ksh ${DESTDIR}${BINDIR}/jotpass + +.include diff --git a/README.md b/README.md new file mode 100644 index 0000000..b087357 --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# Jotpass + +Jotpass is a BSD utility that facilitates generating random passwords suitable for handwriting. +See [this](https://www.skreutz.com/posts/readable-random-passwords-with-jot/) blog post for an introduction, and refer to the man page for details. + +## Install + +Run `make install` as root to install the `jotpass` utility and man page. + +## Release + +Create an annotated tag, and an archive as follows, replacing `0.1.0` with the +current version. + + $ git tag --annotate --message "Version 0.1.0" 0.1.0 + $ git archive --format=tar.gz --prefix=jotpass-0.1.0/ \ + --output jotpass-0.1.0.tar.gz 0.1.0 + diff --git a/jotpass.1 b/jotpass.1 new file mode 100644 index 0000000..2aa9bf6 --- /dev/null +++ b/jotpass.1 @@ -0,0 +1,78 @@ +.\" Copyright (c) 2021 Stefan Kreutz +.\" +.\" Permission to use, copy, modify, and distribute this software for any +.\" purpose with or without fee is hereby granted, provided that the above +.\" copyright notice and this permission notice appear in all copies. +.\" +.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +.Dd $Mdocdate: October 12 2021 $ +.Dt JOTPASS 1 +.Os +.Sh NAME +.Nm jotpass +.Nd Print readable random passwords +.Sh SYNOPSIS +.Nm jotpass +.Op Fl v +.Op Fl a Ar alphabet +.Op Fl g Ar groups +.Op Fl w Ar width +.Op Fl s Ar separator +.Sh DESCRIPTION +The +.Nm +utility facilitates generating random passwords suitable for handwriting. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl v +Enable verbose mode. +Causes +.Nm +to print the entropy of the generated password to standard error. +.It Fl a Ar alphabet +Draw characters from the given +.Ar alphabet . +Defaults to alphanumeric ASCII characters, excluding 01klnuvIO +to improve legibility. +.It Fl g Ar groups +Set the number of +.Ar groups . +Defaults to 12. +.It Fl w Ar width +Set the +.Ar width +of the groups. +Defaults to 4 characters. +.It Fl s Ar separator +Set the group +.Ar separator +character. +Defaults to dash (-). +.El +.Sh EXIT STATUS +.Ex -std jotpass +.Sh EXAMPLES +Print a random password: +.Bd -literal -offset indent +$ jotpass +P6ji-4pRZ-Ze7m-q7Bp-Vpye-HCjr-hygF-6TwQ-oRJT-yx6p-SyMB-AwUm +.Ed +.Pp +Specify a custom format: +.Bd -literal -offset indent +$ jotpass -a 0123456789abcdef -g 8 -w 2 -s ' ' -v +49 1b 6e b0 e2 fc 16 b1 +The generated password has an entropy of 64 bits. +.Ed +.Sh SEE ALSO +.Xr jot 1 , +.Xr arc4random 3 +.Sh AUTHORS +.An Stefan Kreutz Aq Mt mail@skreutz.com diff --git a/jotpass.ksh b/jotpass.ksh new file mode 100755 index 0000000..c1b14aa --- /dev/null +++ b/jotpass.ksh @@ -0,0 +1,55 @@ +#! /bin/ksh + +# Copyright (c) 2021 Stefan Kreutz +# +# Permission to use, copy, modify, and distribute this software for any +# purpose with or without fee is hereby granted, provided that the above +# copyright notice and this permission notice appear in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + +set -o errexit +set -o nounset +set -o pipefail + +alphabet=23456789abcdefghijmopqrstwxyzABCDEFGHJKLMNPQRSTUVWXYZ +groups=12 +width=4 +separator=- +verbosity=0 + +while getopts :va:g:w:s: option; do + case "$option" in + v) verbosity=$((verbosity+1)) ;; + a) alphabet="$OPTARG" ;; + g) groups="$OPTARG" ;; + w) width="$OPTARG" ;; + s) separator="$OPTARG" ;; + :) print -u2 -- "missing argument for option -$OPTARG"; exit 1 ;; + ?) print -u2 -- "illegal option: -$OPTARG"; exit 1 ;; + esac +done +shift $((OPTIND-1)) + +# shellcheck disable=SC2046 +set -A symbol -- $( echo "$alphabet" | fold -w 1 | sort -u | tr -d '\n' | sed 's/./& /g' ) + +# shellcheck disable=SC2154 +symbols=${#symbol[*]} + +jot -r $((groups*width)) 0 $((symbols-1)) | + while IFS= read -r i; do echo "${symbol[$i]}"; done | + tr -d '\n' | + fold -w "$width" | + paste -s -d "$separator" - + +if [ $verbosity -gt 0 ]; then + entropy="$( printf 'e = (%d * %d * l(%d))/l(2); scale = 0; e/1\n' "$groups" "$width" "$symbols" | bc -l )" + print -u2 -- "The generated password has an entropy of ${entropy} bits." +fi -- cgit v1.2.3