1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-07 14:25:40 -05:00

cmdgen: add a --dump option.

Also spelled '-O text', this takes a public or private key as input,
and produces on standard output a dump of all the actual numbers
involved in the key: the exponent and modulus for RSA, the p,q,g,y
parameters for DSA, the affine x and y coordinates of the public
elliptic curve point for ECC keys, and all the extra bits and pieces
in the private keys too.

Partly I expect this to be useful to me for debugging: I've had to
paste key files a few too many times through base64 decoders and hex
dump tools, then manually decode SSH marshalling and paste the result
into the Python REPL to get an integer object. Now I should be able to
get _straight_ to text I can paste into Python.

But also, it's a way that other applications can use the key
generator: if you need to generate, say, an RSA key in some format I
don't support (I've recently heard of an XML-based one, for example),
then you can run 'puttygen -t rsa --dump' and have it print the
elements of a freshly generated keypair on standard output, and then
all you have to do is understand the output format.
This commit is contained in:
Simon Tatham
2020-02-17 19:53:19 +00:00
parent 96f1fb9456
commit c18e5dc8fb
13 changed files with 317 additions and 8 deletions

View File

@ -83,6 +83,23 @@ static char *dss_cache_str(ssh_key *key)
return strbuf_to_str(sb);
}
static key_components *dss_components(ssh_key *key)
{
struct dss_key *dss = container_of(key, struct dss_key, sshk);
key_components *kc = key_components_new();
key_components_add_text(kc, "key_type", "DSA");
assert(dss->p);
key_components_add_mp(kc, "p", dss->p);
key_components_add_mp(kc, "q", dss->q);
key_components_add_mp(kc, "g", dss->g);
key_components_add_mp(kc, "public_y", dss->y);
if (dss->x)
key_components_add_mp(kc, "private_x", dss->x);
return kc;
}
static char *dss_invalid(ssh_key *key, unsigned flags)
{
/* No validity criterion will stop us from using a DSA key at all */
@ -478,6 +495,7 @@ const ssh_keyalg ssh_dss = {
dss_private_blob,
dss_openssh_blob,
dss_cache_str,
dss_components,
dss_pubkey_bits,