mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: ptxdist@pengutronix.de
Subject: [ptxdist] [PATCH v2 1/2] openssh/rc-once: deduplicate some data
Date: Sat,  8 Aug 2020 10:34:55 +0200	[thread overview]
Message-ID: <20200808083456.26483-1-u.kleine-koenig@pengutronix.de> (raw)

The create_keys() function passed the key type three times. Now it's
only passed once.

Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
 projectroot/etc/rc.once.d/openssh | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/projectroot/etc/rc.once.d/openssh b/projectroot/etc/rc.once.d/openssh
index 4a3c594cc3ae..bfec7064181a 100644
--- a/projectroot/etc/rc.once.d/openssh
+++ b/projectroot/etc/rc.once.d/openssh
@@ -18,32 +18,29 @@ host_keys_required() {
 }
 
 create_key() {
-	msg="$1"
+	keytype="$1"
+	prettykeytype="$(echo $_type | tr a-z A-Z)"
 	shift
 	hostkeys="$1"
 	shift
-	file="$1"
-	shift
+
+	file="/etc/ssh/ssh_host_${keytype}_key"
 
 	if echo "$hostkeys" | grep -x "$file" >/dev/null; then
-		echo "$msg; this may take some time ..."
+		echo "Create $prettykeytype key; this may take some time ..."
 		rm -f $file &&
-		ssh-keygen -q -f "$file" -N '' "$@" || return
-		echo "$msg; done."
+		ssh-keygen -q -f "$file" -N '' -t "$keytype" "$@" || return
+		echo "Created $prettykeytype key."
 	fi
 }
 
 create_keys() {
 	hostkeys="$(host_keys_required)"
 
-	create_key "Creating DSA key" \
-		"$hostkeys" /etc/ssh/ssh_host_dsa_key -t dsa &&
-	create_key "Creating ECDSA key" \
-		"$hostkeys" /etc/ssh/ssh_host_ecdsa_key -t ecdsa &&
-	create_key "Creating ED25519 key" \
-		"$hostkeys" /etc/ssh/ssh_host_ed25519_key -t ed25519 &&
-	create_key "Creating RSA key" \
-		"$hostkeys" /etc/ssh/ssh_host_rsa_key -t rsa -b 4096
+	create_key "dsa" "$hostkeys" &&
+	create_key "ecdsa" "$hostkeys" &&
+	create_key "ed25519" "$hostkeys" &&
+	create_key "rsa" "$hostkeys" -b 4096
 }
 
 if ! create_keys; then
-- 
2.28.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de
To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de

             reply	other threads:[~2020-08-08  8:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-08  8:34 Uwe Kleine-König [this message]
2020-08-08  8:34 ` [ptxdist] [PATCH v2 2/2] openssh/rc-once: use fixed string grep to match filename Uwe Kleine-König
2020-08-17  6:18   ` [ptxdist] [APPLIED] " Michael Olbrich
2020-08-17  6:18 ` [ptxdist] [APPLIED] openssh/rc-once: deduplicate some data Michael Olbrich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200808083456.26483-1-u.kleine-koenig@pengutronix.de \
    --to=u.kleine-koenig@pengutronix.de \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox