aboutsummaryrefslogtreecommitdiff
path: root/maint/keygen-openssh-test/generate
blob: 21353fca99d1849e4f7b7b3fc6db1fa219623634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env bash

# The script that was used to generate the OpenSSH keys from this directory.

set -eou pipefail

DIR=$(dirname "$0")
GENERATE_PATH=$(realpath "$DIR")
PACKAGE="keygen-openssh-test"
BIN_PATH="$GENERATE_PATH/../../target/debug/${PACKAGE}"
EXPANDED_ED25519="ed25519_expanded_openssh"
X25519="x25519_openssh"
# Make keygen deterministic
export ARTI_TEST_PRNG=${ARTI_TEST_PRNG:-deterministic}

if ! test -d "./crates/tor-keymgr"; then
    echo "Did not find './crates/tor-keymgr' directory in $(pwd). Cannot proceed." 1>&2
    echo "Hint: run this script from the workspace root" 1>&2
    exit 1
fi

cd crates/tor-keymgr
mkdir -p testdata
cd testdata

mangle_ed25519_private() (
    sed -i '2ahello' "$1"
)

mangle_ed25519_public() (
    sed -i 's/ssh-ed25519 /\0garbage/' "$1"
)

cargo build -p $PACKAGE

"$BIN_PATH" --key-type dsa \
   --private \
   --name dsa_openssh \
   --comment [email protected]

# Generate an ed25519 key
"$BIN_PATH" --key-type ed25519 \
   --private \
   --public \
   --name ed25519_openssh \
   --comment [email protected]

# Generate an invalid ed25519 key
"$BIN_PATH" --key-type ed25519 \
   --private \
   --public \
   --name ed25519_openssh_bad \
   --comment [email protected]

mangle_ed25519_private ed25519_openssh_bad.private
mangle_ed25519_public ed25519_openssh_bad.public

"$BIN_PATH" --key-type expanded-ed25519 \
   --private \
   --name "${EXPANDED_ED25519}"

"$BIN_PATH" --key-type ed25519 \
   --public \
   --name "${EXPANDED_ED25519}"  \
   --comment [email protected]

# Pretend the key type is expanded-ed
sed -i 's/ssh-ed25519/[email protected]/' "${EXPANDED_ED25519}.public"

"$BIN_PATH" --key-type expanded-ed25519 \
   --private \
   --name "${EXPANDED_ED25519}_bad"

mangle_ed25519_private "${EXPANDED_ED25519}_bad.private"

"$BIN_PATH" --key-type x25519 \
   --private \
   --public \
   --name "$X25519"

"$BIN_PATH" --key-type x25519 \
   --private \
   --algorithm [email protected] \
   --name "${X25519}_unknown_algorithm"

"$BIN_PATH" --key-type x25519 \
   --public \
   --algorithm [email protected] \
   --name "${X25519}_unknown_algorithm"