llaves y firmas con ssh
This commit is contained in:
parent
2d7088e16c
commit
7c4981bb29
1 changed files with 6 additions and 8 deletions
|
@ -11,27 +11,25 @@ get_stack () {
|
|||
|
||||
|
||||
# Generar una llave privada ECDSA si no existe
|
||||
#
|
||||
# Uso: generate_private_key "comentario"
|
||||
generate_private_key () {
|
||||
test -f "$private_key" && return 1
|
||||
|
||||
ssh-keygen -t ecdsa -f "$private_key" -N "" -m PEM
|
||||
ssh-keygen -t ecdsa -f "$private_key" -N "" -C "$@"
|
||||
}
|
||||
|
||||
# Firmar el archivo usando la llave privada.
|
||||
#
|
||||
# Uso: sign_file archivo.json
|
||||
# Devuelve: archivo.json.sign
|
||||
# Devuelve: La firma
|
||||
sign_file () {
|
||||
local _file="$1"
|
||||
|
||||
test ! -f "$_file" && return 1
|
||||
test -f "$_file.sig" || ssh-keygen -Y sign -f "$private_key" -n file "$_file" 2>&1 >/dev/null
|
||||
|
||||
if ! openssl dgst -sha512 -sign "$private_key" "$_file" | base64 | tr -d "\n" > "$_file.sign" ; then
|
||||
rm -f "$_file.sign"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo "$_file.sign"
|
||||
cat "${_file}.sig" | grep -v SIGNATURE | tr -d "\n"
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue