1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Make ssh_keyalg's supported_flags a method.

It's a class method rather than an object method, so it doesn't allow
keys with the same algorithm to make different choices about what
flags they support. But that's not what I wanted it for: the real
purpose is to allow one key algorithm to delegate supported_flags to
another, by having its method implementation call the one from the
delegate class.

(If only C's compile/link model permitted me to initialise a field of
one global const struct variable to be a copy of that of another, I
wouldn't need the runtime overhead of this method! But object file
formats don't let you even specify that.)

Most key algorithms support no flags at all, so they all want to use
the same implementation of this method. So I've started a file of
stubs utils/nullkey.c to contain the common stub version.
This commit is contained in:
Simon Tatham 2022-04-19 17:05:36 +01:00
parent 6143a50ed2
commit f9775a7b67
7 changed files with 30 additions and 5 deletions

View File

@ -498,6 +498,7 @@ const ssh_keyalg ssh_dsa = {
.cache_str = dsa_cache_str,
.components = dsa_components,
.pubkey_bits = dsa_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.ssh_id = "ssh-dss",
.cache_id = "dss",
};

View File

@ -1257,6 +1257,7 @@ const ssh_keyalg ssh_ecdsa_ed25519 = {
.cache_str = eddsa_cache_str,
.components = eddsa_components,
.pubkey_bits = ec_shared_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.ssh_id = "ssh-ed25519",
.cache_id = "ssh-ed25519",
.extra = &sign_extra_ed25519,
@ -1280,6 +1281,7 @@ const ssh_keyalg ssh_ecdsa_ed448 = {
.cache_str = eddsa_cache_str,
.components = eddsa_components,
.pubkey_bits = ec_shared_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.ssh_id = "ssh-ed448",
.cache_id = "ssh-ed448",
.extra = &sign_extra_ed448,
@ -1307,6 +1309,7 @@ const ssh_keyalg ssh_ecdsa_nistp256 = {
.cache_str = ecdsa_cache_str,
.components = ecdsa_components,
.pubkey_bits = ec_shared_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.ssh_id = "ecdsa-sha2-nistp256",
.cache_id = "ecdsa-sha2-nistp256",
.extra = &sign_extra_nistp256,
@ -1334,6 +1337,7 @@ const ssh_keyalg ssh_ecdsa_nistp384 = {
.cache_str = ecdsa_cache_str,
.components = ecdsa_components,
.pubkey_bits = ec_shared_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.ssh_id = "ecdsa-sha2-nistp384",
.cache_id = "ecdsa-sha2-nistp384",
.extra = &sign_extra_nistp384,
@ -1361,6 +1365,7 @@ const ssh_keyalg ssh_ecdsa_nistp521 = {
.cache_str = ecdsa_cache_str,
.components = ecdsa_components,
.pubkey_bits = ec_shared_pubkey_bits,
.supported_flags = nullkey_supported_flags,
.ssh_id = "ecdsa-sha2-nistp521",
.cache_id = "ecdsa-sha2-nistp521",
.extra = &sign_extra_nistp521,

View File

@ -839,6 +839,11 @@ static char *rsa2_invalid(ssh_key *key, unsigned flags)
return NULL;
}
static unsigned ssh_rsa_supported_flags(const ssh_keyalg *self)
{
return SSH_AGENT_RSA_SHA2_256 | SSH_AGENT_RSA_SHA2_512;
}
static const struct ssh2_rsa_extra
rsa_extra = { 0 },
rsa_sha256_extra = { SSH_AGENT_RSA_SHA2_256 },
@ -863,21 +868,21 @@ static const struct ssh2_rsa_extra
const ssh_keyalg ssh_rsa = {
COMMON_KEYALG_FIELDS,
.ssh_id = "ssh-rsa",
.supported_flags = SSH_AGENT_RSA_SHA2_256 | SSH_AGENT_RSA_SHA2_512,
.supported_flags = ssh_rsa_supported_flags,
.extra = &rsa_extra,
};
const ssh_keyalg ssh_rsa_sha256 = {
COMMON_KEYALG_FIELDS,
.ssh_id = "rsa-sha2-256",
.supported_flags = 0,
.supported_flags = nullkey_supported_flags,
.extra = &rsa_sha256_extra,
};
const ssh_keyalg ssh_rsa_sha512 = {
COMMON_KEYALG_FIELDS,
.ssh_id = "rsa-sha2-512",
.supported_flags = 0,
.supported_flags = nullkey_supported_flags,
.extra = &rsa_sha512_extra,
};

View File

@ -432,7 +432,7 @@ static void signop_coroutine(PageantAsyncOp *pao)
signop_unlink(so);
}
uint32_t supported_flags = ssh_key_alg(so->pk->skey->key)->supported_flags;
uint32_t supported_flags = ssh_key_supported_flags(so->pk->skey->key);
if (so->flags & ~supported_flags) {
/*
* We MUST reject any message containing flags we don't

9
ssh.h
View File

@ -834,12 +834,12 @@ struct ssh_keyalg {
/* 'Class methods' that don't deal with an ssh_key at all */
int (*pubkey_bits) (const ssh_keyalg *self, ptrlen blob);
unsigned (*supported_flags) (const ssh_keyalg *self);
/* Constant data fields giving information about the key type */
const char *ssh_id; /* string identifier in the SSH protocol */
const char *cache_id; /* identifier used in PuTTY's host key cache */
const void *extra; /* private to the public key methods */
const unsigned supported_flags; /* signature-type flags we understand */
};
static inline ssh_key *ssh_key_new_pub(const ssh_keyalg *self, ptrlen pub)
@ -877,6 +877,13 @@ static inline const char *ssh_key_ssh_id(ssh_key *key)
{ return key->vt->ssh_id; }
static inline const char *ssh_key_cache_id(ssh_key *key)
{ return key->vt->cache_id; }
static inline const unsigned ssh_key_supported_flags(ssh_key *key)
{ return key->vt->supported_flags(key->vt); }
static inline const unsigned ssh_keyalg_supported_flags(const ssh_keyalg *self)
{ return self->supported_flags(self); }
/* Stub functions shared between multiple key types */
unsigned nullkey_supported_flags(const ssh_keyalg *self);
/*
* SSH2 ECDH key exchange vtable

View File

@ -35,6 +35,7 @@ add_sources_from_current_dir(utils
memory.c
memxor.c
null_lp.c
nullkey.c
nullseat.c
nullstrcmp.c
out_of_memory.c

6
utils/nullkey.c Normal file
View File

@ -0,0 +1,6 @@
#include "ssh.h"
unsigned nullkey_supported_flags(const ssh_keyalg *self)
{
return 0;
}