deicidus
2 years ago
2 changed files with 28 additions and 0 deletions
@ -0,0 +1,17 @@ |
|||||||
|
#!/bin/sh |
||||||
|
|
||||||
|
# POSIX compliant regular expressions |
||||||
|
# Matches any string that contains a null byte or begins or ends with a / |
||||||
|
REGEX1='(^/|/$|\\0)' |
||||||
|
# Matches any string longer than 255 characters (for a single filename) |
||||||
|
REGEX2='^.{256,}$' |
||||||
|
# Matches any string longer than 4096 characters (for a full path) |
||||||
|
REGEX3='^.{4097,}$' |
||||||
|
|
||||||
|
if echo "$1" | grep -Eq "$REGEX1" || echo "$1" | grep -Eq "$REGEX2" || echo "$1" | grep -Eq "$REGEX3"; then |
||||||
|
# If any regex matches, this is an invalid path |
||||||
|
exit 1 |
||||||
|
else |
||||||
|
# Otherwise, it's valid |
||||||
|
exit 0 |
||||||
|
fi |
@ -0,0 +1,11 @@ |
|||||||
|
!/bin/sh |
||||||
|
|
||||||
|
read -p "Enter the SSH key: " ssh_key |
||||||
|
|
||||||
|
# Check if the SSH key is in the correct format |
||||||
|
if ! echo "$ssh_key" | grep -E '^ssh-([a-zA-Z0-9]+) ([A-Za-z0-9+/]+=*) ([A-Za-z0-9]+@[A-Za-z0-9]+)?$' > /dev/null; then |
||||||
|
echo "Invalid SSH key format." |
||||||
|
exit 1 |
||||||
|
fi |
||||||
|
|
||||||
|
echo "Valid SSH key." |
Loading…
Reference in new issue