<commit_before>#!/bin/bash
#
# validates if ssh key and its pub key are matched 
#

[[ -n "$1" ]] || { echo "Usage: sshKeyFile [sshPubFile]"; exit 1; }

sshkeyfile="$1"
if [[ -z "$2" ]]; then
  sshpubfile="${1}.pub"
else
  sshpubfile="$2"
fi

[[ -f $sshkeyfile ]] || { echo "ERROR: could not find ssh keyfile $sshkeyfile";exit 2; }
keyperms=$(stat -c '%a' $sshkeyfile)
if [[ $keyperms -gt 600 ]]; then
  echo "ERROR, the key permissions are > 600 for $sshkeyfile, use 'chmod 600'"
  exit 3
fi

keyfingerprint=$(ssh-keygen -y -f $sshkeyfile | ssh-keygen -lf -)
echo "key: $keyfingerprint"

if [[ ! -f $sshpubfile ]]; then
  echo ""
  echo "WARNING: did not find pub file ${sshpubfile}, but here is what the public cert and fingerprint should be (based on the private key):"
  ssh-keygen -y -f $sshkeyfile
  echo ""
  ssh-keygen -y -f $sshkeyfile | ssh-keygen -l -f $sshkeyfile
  exit 0
fi


pubperms=$(stat -c '%a' $sshpubfile)
echo $pubperms
gperm=$((pubperms % 100))
operm=$((pubperms % 10))
if [[ $pubperms -ge 700 || $gperm -ge 50 || $operm -ge 5 ]] ; then
  echo "ERROR, the file permissions are too wide for the public $sshpubfile, use 'chmod 644'"
  exit 3
fi
pubfingerprint=$(ssh-keygen -l -f $sshpubfile)
echo "pub: $pubfingerprint"
<commit_msg>explanation for why -e will not work for our purposes<commit_after>#!/bin/bash
#
# validates if ssh key and its pub key are matched 
#

[[ -n "$1" ]] || { echo "Usage: sshKeyFile [sshPubFile]"; exit 1; }

sshkeyfile="$1"
if [[ -z "$2" ]]; then
  sshpubfile="${1}.pub"
else
  sshpubfile="$2"
fi

[[ -f $sshkeyfile ]] || { echo "ERROR: could not find ssh keyfile $sshkeyfile";exit 2; }
keyperms=$(stat -c '%a' $sshkeyfile)
if [[ $keyperms -gt 600 ]]; then
  echo "ERROR, the key permissions are > 600 for $sshkeyfile, use 'chmod 600'"
  exit 3
fi

# intentionally not using '-e' which echoes .pub file when it exists!
keyfingerprint=$(ssh-keygen -y -f $sshkeyfile | ssh-keygen -lf -)
echo "key: $keyfingerprint"

if [[ ! -f $sshpubfile ]]; then
  echo ""
  echo "WARNING: did not find pub file ${sshpubfile}, but here is what the public cert and fingerprint should be (based on the private key):"
  ssh-keygen -y -f $sshkeyfile
  echo ""
  ssh-keygen -y -f $sshkeyfile | ssh-keygen -l -f $sshkeyfile
  exit 0
fi


pubperms=$(stat -c '%a' $sshpubfile)
echo $pubperms
gperm=$((pubperms % 100))
operm=$((pubperms % 10))
if [[ $pubperms -ge 700 || $gperm -ge 50 || $operm -ge 5 ]] ; then
  echo "ERROR, the file permissions are too wide for the public $sshpubfile, use 'chmod 644'"
  exit 3
fi
pubfingerprint=$(ssh-keygen -l -f $sshpubfile)
echo "pub: $pubfingerprint"

{'fraction_non_alphanumeric': 0.15711009174311927, 'fraction_numerical': 0.02522935779816514, 'mean_word_length': 3.8195211786372005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5264105', 'n_tokens_mistral': 1092, 'n_tokens_neox': 964, 'n_words': 346}