-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Squash merge PR #27 feat: add checkkeylength command
* Add checkkeylength command * Add links of checkkeylength's code to README.md * Fix the md5s function for Mac - See #25 * Add the 'checkkeylength' script
- Loading branch information
Yuki Shimada
authored
Jun 1, 2021
1 parent
8d18dec
commit 1da7e3b
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/usr/bin/env bash | ||
|
||
# SSHキー(RSA)の鍵長をチェックします。 | ||
# ====================================== | ||
# | ||
# GitHub 上で公開されている(https://github.com/<user name>.keys で取得できる) | ||
# 相手の RSA 公開鍵の鍵長を調べます。 | ||
# 2021年現在、1024bit以下の鍵長は安全性に懸念が生じています。 | ||
# 最低でも2048bit、できれば4096bit以上を推奨します。 | ||
# | ||
# - 使い方の例: | ||
# $ ./checkkeylength.sh KEINOS | ||
# | ||
# - 注意:利用前にスクリプトに実行権限を与えるのを忘れないでください。 | ||
# | ||
|
||
# ヘルプ表示 | ||
# ---------- | ||
if [[ $# -lt 1 ]]; then | ||
echo | ||
echo "使い方: $0 <github user>" | ||
echo | ||
echo "- <github user> : 相手の GitHub アカウント名" | ||
echo | ||
exit 1 | ||
fi | ||
|
||
md5s() { | ||
if [ -e "$(which md5sum)" ]; then | ||
echo "$1" | md5sum | awk '{ print $1 }' | ||
elif [ -e "$(which md5)" ]; then | ||
md5 -q -s "$1" | ||
fi | ||
} | ||
|
||
# コマンド引数取得 | ||
# ---------------- | ||
USERNAME=$1 | ||
|
||
# trap の設定 | ||
# ----------- | ||
# スクリプト終了後一時ファイルを削除します。 | ||
# - 参考URL : https://qiita.com/m-yamashita/items/889c116b92dc0bf4ea7d | ||
trap 'rm -rf /tmp/${USERNAME}.*' 0 | ||
|
||
# 一時ファイル | ||
# ------------ | ||
TMP=$(md5s $RANDOM) | ||
PATHPUBKEY="/tmp/${USERNAME}.${TMP}.pub" | ||
|
||
# RSA 公開鍵の取得 | ||
# ---------------- | ||
# ユーザの GitHub の公開鍵一覧の1行目を取得 | ||
# - 取得先は: https://github.com/<user name>.keys | ||
# - 参考URL : https://qiita.com/m0r1/items/af16c41475d493ab6774 | ||
echo -n "${USERNAME} の GitHub 上の公開鍵を取得中 ... " | ||
|
||
if ! curl -s "https://github.com/${USERNAME}.keys" | head -n 1 >"$PATHPUBKEY"; then | ||
echo "NG:公開鍵を取得・保存できませんでした。" | ||
exit 1 | ||
fi | ||
echo "OK" | ||
|
||
# RSA公開鍵の鍵長を表示 | ||
# ------------------------ | ||
# - 参考URL : | ||
# - https://qiita.com/ledmonster/items/b57d48981ad7a9d41042 | ||
|
||
echo "以下に${USERNAME}の鍵長情報を表示します。" | ||
echo | ||
ssh-keygen -l -f "$PATHPUBKEY" | ||
echo | ||
|
||
echo "上記の鍵長を確認してください。RSAキーでは行頭の数字(鍵長)が1024以下のものは危険です。" | ||
echo "2048bit以上(できれば4096bit以上)のRSAキーへの作り直しを推奨します。keygenコマンドをご利用ください。" |