Skip to content

Commit

Permalink
Initial script for generating Mender client keys,
Browse files Browse the repository at this point in the history
especially useful for preauthorizing devices.

ChangeLog: Mender client key generator script

Signed-off-by: Eystein Måløy Stenberg <[email protected]>
(cherry picked from commit 5d8be7d)
  • Loading branch information
estenberg committed May 25, 2018
1 parent 5f1cab7 commit 520c938
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions support/keygen-client
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -e

FILE_NAME_PRIVATE_KEY="private.key"
FILE_NAME_PUBLIC_KEY="public.key"

# verify openssl is present and sufficiently recent (genpkey seems to require openssl 1.0+)
command -v openssl >/dev/null 2>&1 || { echo >&2 "ERROR: Please install the openssl utility version 1.0.0 or newer to generate keys."; exit 1; }

OPENSSL_VERSION_REGEX_MAJOR_BACKREF="OpenSSL ([0-9]+).*"
OPENSSL_VERSION_STRING=$(openssl version)
OPENSSL_VERSION_MAJOR=$(echo "$OPENSSL_VERSION_STRING" | sed -En "s/$OPENSSL_VERSION_REGEX_MAJOR_BACKREF/\1/p")

if [ "$OPENSSL_VERSION_MAJOR" != "1" ]; then
echo "ERROR: openssl is too old, need version 1.0.0 or newer"
echo "ERROR: OPENSSL_VERSION_STRING=$OPENSSL_VERSION_STRING"
exit 1
fi

CLIENT_KEYS_DIR=$(pwd)/keys-client-generated

mkdir -p "$CLIENT_KEYS_DIR"
cd "$CLIENT_KEYS_DIR"

openssl genpkey -algorithm RSA -out $FILE_NAME_PRIVATE_KEY -pkeyopt rsa_keygen_bits:3072

# convert to RSA private key format
openssl rsa -in $FILE_NAME_PRIVATE_KEY -out $FILE_NAME_PRIVATE_KEY

# extract public key (e.g. for preauthorization)
openssl rsa -in $FILE_NAME_PRIVATE_KEY -out $FILE_NAME_PUBLIC_KEY -pubout

echo "A Mender client keypair has been generated in $CLIENT_KEYS_DIR."
echo "You can use the public key ($FILE_NAME_PUBLIC_KEY) to preauthorize the device in the Mender server."
echo "For more information please see https://docs.mender.io/server-integration/preauthorizing-devices."

0 comments on commit 520c938

Please sign in to comment.