mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
New key component type KCT_BINARY.
This stores its data in the same format as the existing KCT_TEXT, but it displays differently in puttygen --dump, expecting that the data will be full of horrible control characters, invalid UTF-8, etc. The displayed data is of the form b64("..."), so you get a hint about what the encoding is, and can still paste into Python by defining the identifier 'b64' to be base64.b64decode or equivalent.
This commit is contained in:
parent
68514ac8a1
commit
62bc6c5448
32
cmdgen.c
32
cmdgen.c
@ -1327,6 +1327,38 @@ int main(int argc, char **argv)
|
||||
write_c_string_literal(fp, ptrlen_from_strbuf(comp->str));
|
||||
fputs("\"\n", fp);
|
||||
break;
|
||||
case KCT_BINARY: {
|
||||
/*
|
||||
* Display format for binary key components is to show
|
||||
* them as base64, with a wrapper so that the actual
|
||||
* printed string is along the lines of
|
||||
* 'b64("aGVsbG8sIHdvcmxkCg==")'.
|
||||
*
|
||||
* That's a compromise between not being too verbose
|
||||
* for a human reader, and still being reasonably
|
||||
* friendly to people pasting the output of this
|
||||
* 'puttygen --dump' option into Python code (which
|
||||
* the format is designed to permit in general).
|
||||
*
|
||||
* Python users pasting a dump containing one of these
|
||||
* will have to define a function 'b64' in advance
|
||||
* which takes a string, which you can do most easily
|
||||
* using this import statement, as seen in
|
||||
* cryptsuite.py:
|
||||
*
|
||||
* from base64 import b64decode as b64
|
||||
*/
|
||||
fputs("b64(\"", fp);
|
||||
char b64[4];
|
||||
for (size_t j = 0; j < comp->str->len; j += 3) {
|
||||
size_t len = comp->str->len - j;
|
||||
if (len > 3) len = 3;
|
||||
base64_encode_atom(comp->str->u + j, len, b64);
|
||||
fwrite(b64, 1, 4, fp);
|
||||
}
|
||||
fputs("\")\n", fp);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
unreachable("bad key component type");
|
||||
}
|
||||
|
6
ssh.h
6
ssh.h
@ -543,13 +543,13 @@ WeierstrassPoint *ecdsa_public(mp_int *private_key, const ssh_keyalg *alg);
|
||||
EdwardsPoint *eddsa_public(mp_int *private_key, const ssh_keyalg *alg);
|
||||
|
||||
typedef enum KeyComponentType {
|
||||
KCT_TEXT, KCT_MPINT
|
||||
KCT_TEXT, KCT_BINARY, KCT_MPINT
|
||||
} KeyComponentType;
|
||||
typedef struct key_component {
|
||||
char *name;
|
||||
KeyComponentType type;
|
||||
union {
|
||||
strbuf *str; /* used for KCT_TEXT */
|
||||
strbuf *str; /* used for KCT_TEXT and KCT_BINARY */
|
||||
mp_int *mp; /* used for KCT_MPINT */
|
||||
};
|
||||
} key_component;
|
||||
@ -560,6 +560,8 @@ typedef struct key_components {
|
||||
key_components *key_components_new(void);
|
||||
void key_components_add_text(key_components *kc,
|
||||
const char *name, const char *value);
|
||||
void key_components_add_binary(key_components *kc,
|
||||
const char *name, ptrlen value);
|
||||
void key_components_add_mp(key_components *kc,
|
||||
const char *name, mp_int *value);
|
||||
void key_components_free(key_components *kc);
|
||||
|
@ -1231,7 +1231,8 @@ strbuf *key_components_nth_str(key_components *kc, size_t n)
|
||||
{
|
||||
if (n >= kc->ncomponents)
|
||||
return NULL;
|
||||
if (kc->components[n].type != KCT_TEXT)
|
||||
if (kc->components[n].type != KCT_TEXT &&
|
||||
kc->components[n].type != KCT_BINARY)
|
||||
return NULL;
|
||||
return strbuf_dup(ptrlen_from_strbuf(kc->components[n].str));
|
||||
}
|
||||
|
@ -10,14 +10,26 @@ key_components *key_components_new(void)
|
||||
return kc;
|
||||
}
|
||||
|
||||
void key_components_add_text(key_components *kc,
|
||||
const char *name, const char *value)
|
||||
static void key_components_add_str(key_components *kc, const char *name,
|
||||
KeyComponentType type, ptrlen data)
|
||||
{
|
||||
sgrowarray(kc->components, kc->componentsize, kc->ncomponents);
|
||||
size_t n = kc->ncomponents++;
|
||||
kc->components[n].name = dupstr(name);
|
||||
kc->components[n].type = KCT_TEXT;
|
||||
kc->components[n].str = strbuf_dup_nm(ptrlen_from_asciz(value));
|
||||
kc->components[n].type = type;
|
||||
kc->components[n].str = strbuf_dup_nm(data);
|
||||
}
|
||||
|
||||
void key_components_add_text(key_components *kc,
|
||||
const char *name, const char *value)
|
||||
{
|
||||
key_components_add_str(kc, name, KCT_TEXT, ptrlen_from_asciz(value));
|
||||
}
|
||||
|
||||
void key_components_add_binary(key_components *kc,
|
||||
const char *name, ptrlen value)
|
||||
{
|
||||
key_components_add_str(kc, name, KCT_BINARY, value);
|
||||
}
|
||||
|
||||
void key_components_add_mp(key_components *kc,
|
||||
@ -40,6 +52,7 @@ void key_components_free(key_components *kc)
|
||||
mp_free(comp->mp);
|
||||
break;
|
||||
case KCT_TEXT:
|
||||
case KCT_BINARY:
|
||||
strbuf_free(comp->str);
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user