diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6434aaf --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +./key +./key.pub diff --git a/functions b/functions index 1f0f68e..809fc40 100644 --- a/functions +++ b/functions @@ -6,5 +6,22 @@ get_stack () { fi } +# Generar una llave privada ECDSA si no existe +generate_private_key () { + test -f "$private_key" && return 1 + ssh-keygen -t ecdsa -f "$private_key" -N "" -C "$@" +} +# Firmar el archivo usando la llave privada. +# +# Uso: sign_file archivo.json +# 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 + + cat "${_file}.sig" | grep -v SIGNATURE | tr -d "\n" +} diff --git a/nodemecu.conf.sample b/nodemecu.conf.sample index bfb5883..84b73a1 100644 --- a/nodemecu.conf.sample +++ b/nodemecu.conf.sample @@ -14,3 +14,4 @@ stack=$install_dir/stack historical=$install_dir/historical log=$install_dir/errors.log corrupt=$install_dir/corrupt +private_key=$install_dir/key