Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix handling of prefix type in login CLI #176

Merged
merged 1 commit into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions cli/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,18 @@ int login(int argc, char **argv) {
fprintf(stderr, "handshake size is invalid in path %s\n", path);
goto out;
}
if ((handshake[0] & 0x80) != 0) {
fprintf(stderr,
"only \"service-key-indicator\" prefix type is supported\n");
goto out;
if ((handshake[0] & 0x80) == 0) {
uint8_t public_key[GLOME_MAX_PUBLIC_KEY_LENGTH] = {0};
if (glome_derive_key(private_key, public_key)) {
fprintf(stderr, "unable to generate a public key\n");
goto out;
}
// Most significant bit is not set for X25519 key (see RFC 7748).
uint8_t public_key_msb = public_key[GLOME_MAX_PUBLIC_KEY_LENGTH - 1];
if (handshake[0] != public_key_msb) {
fprintf(stderr, "unexpected public key prefix\n");
goto out;
}
}
uint8_t peer_key[GLOME_MAX_PRIVATE_KEY_LENGTH] = {0};
memcpy(peer_key, handshake + 1, GLOME_MAX_PUBLIC_KEY_LENGTH);
Expand Down
12 changes: 8 additions & 4 deletions cli/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ for n in 1 2; do
done

key="$t/vector-2/a"
path="v2/R4cvQ1u4uJ0OOtYqouURB07hleHDnvaogAFBi-ZW48N2/myhost/exec=%2Fbin%2Fsh/"
expected_tag="ZmxczN4x3g4goXu-A2AuuEEVftgS6xM-6gYj-dRrlis="
tag=$("$binary" login --key "$key" "$path")
if [ "$tag" != "$expected_tag" ]; then
for path in \
"v2/R4cvQ1u4uJ0OOtYqouURB07hleHDnvaogAFBi-ZW48N2/myhost/exec=%2Fbin%2Fsh/" \
"v2/x4cvQ1u4uJ0OOtYqouURB07hleHDnvaogAFBi-ZW48N2/myhost/exec=%2Fbin%2Fsh/"
do
tag=$("$binary" login --key "$key" "$path")
if [ "$tag" != "$expected_tag" ]; then
echo "Generated wrong tag for test path $path" >&2
echo "$expected_tag <- expected" >&2
echo "$tag <- actual" >&2
errors=$((errors + 1))
fi
fi
done

exit "$errors"
Loading