mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-03-22 14:39:24 -05:00
Utility functions to get the algorithm from a public key.
Every time I've had to do this before, I've always done the three-line dance of initialising a BinarySource and calling get_string on it. It's long past time I wrapped that up into a convenient subroutine.
This commit is contained in:
parent
e7d51505c7
commit
a5c0205b87
5
cmdgen.c
5
cmdgen.c
@ -1280,9 +1280,8 @@ int main(int argc, char **argv)
|
|||||||
} else {
|
} else {
|
||||||
assert(ssh2blob);
|
assert(ssh2blob);
|
||||||
|
|
||||||
BinarySource src[1];
|
ptrlen algname = pubkey_blob_to_alg_name(
|
||||||
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(ssh2blob));
|
ptrlen_from_strbuf(ssh2blob));
|
||||||
ptrlen algname = get_string(src);
|
|
||||||
const ssh_keyalg *alg = find_pubkey_alg_len(algname);
|
const ssh_keyalg *alg = find_pubkey_alg_len(algname);
|
||||||
if (!alg) {
|
if (!alg) {
|
||||||
fprintf(stderr, "puttygen: cannot extract key components "
|
fprintf(stderr, "puttygen: cannot extract key components "
|
||||||
|
3
ssh.h
3
ssh.h
@ -1331,6 +1331,9 @@ extern const size_t n_keyalgs;
|
|||||||
const ssh_keyalg *find_pubkey_alg(const char *name);
|
const ssh_keyalg *find_pubkey_alg(const char *name);
|
||||||
const ssh_keyalg *find_pubkey_alg_len(ptrlen name);
|
const ssh_keyalg *find_pubkey_alg_len(ptrlen name);
|
||||||
|
|
||||||
|
ptrlen pubkey_blob_to_alg_name(ptrlen blob);
|
||||||
|
const ssh_keyalg *pubkey_blob_to_alg(ptrlen blob);
|
||||||
|
|
||||||
/* Convenient wrappers on the LoadedFile mechanism suitable for key files */
|
/* Convenient wrappers on the LoadedFile mechanism suitable for key files */
|
||||||
LoadedFile *lf_load_keyfile(const Filename *filename, const char **errptr);
|
LoadedFile *lf_load_keyfile(const Filename *filename, const char **errptr);
|
||||||
LoadedFile *lf_load_keyfile_fp(FILE *fp, const char **errptr);
|
LoadedFile *lf_load_keyfile_fp(FILE *fp, const char **errptr);
|
||||||
|
@ -353,10 +353,8 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl)
|
|||||||
|
|
||||||
/* Also, extract the algorithm string from the start
|
/* Also, extract the algorithm string from the start
|
||||||
* of the public-key blob. */
|
* of the public-key blob. */
|
||||||
BinarySource src[1];
|
s->agent_keys[i].algorithm = pubkey_blob_to_alg_name(
|
||||||
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(
|
ptrlen_from_strbuf(s->agent_keys[i].blob));
|
||||||
s->agent_keys[i].blob));
|
|
||||||
s->agent_keys[i].algorithm = get_string(src);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ppl_logevent("Pageant has %"SIZEu" SSH-2 keys", nkeys);
|
ppl_logevent("Pageant has %"SIZEu" SSH-2 keys", nkeys);
|
||||||
|
12
sshpubk.c
12
sshpubk.c
@ -585,6 +585,18 @@ const ssh_keyalg *find_pubkey_alg(const char *name)
|
|||||||
return find_pubkey_alg_len(ptrlen_from_asciz(name));
|
return find_pubkey_alg_len(ptrlen_from_asciz(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ptrlen pubkey_blob_to_alg_name(ptrlen blob)
|
||||||
|
{
|
||||||
|
BinarySource src[1];
|
||||||
|
BinarySource_BARE_INIT_PL(src, blob);
|
||||||
|
return get_string(src);
|
||||||
|
}
|
||||||
|
|
||||||
|
const ssh_keyalg *pubkey_blob_to_alg(ptrlen blob)
|
||||||
|
{
|
||||||
|
return find_pubkey_alg_len(pubkey_blob_to_alg_name(blob));
|
||||||
|
}
|
||||||
|
|
||||||
struct ppk_cipher {
|
struct ppk_cipher {
|
||||||
const char *name;
|
const char *name;
|
||||||
size_t blocklen, keylen, ivlen;
|
size_t blocklen, keylen, ivlen;
|
||||||
|
@ -368,10 +368,8 @@ static void keylist_update_callback(
|
|||||||
* overflow past the bit-count tab stop and leave out a tab
|
* overflow past the bit-count tab stop and leave out a tab
|
||||||
* character. Urgh.
|
* character. Urgh.
|
||||||
*/
|
*/
|
||||||
BinarySource src[1];
|
const ssh_keyalg *alg = pubkey_blob_to_alg(
|
||||||
BinarySource_BARE_INIT_PL(src, ptrlen_from_strbuf(key->blob));
|
ptrlen_from_strbuf(key->blob));
|
||||||
ptrlen algname = get_string(src);
|
|
||||||
const ssh_keyalg *alg = find_pubkey_alg_len(algname);
|
|
||||||
|
|
||||||
bool include_bit_count = (alg == &ssh_dsa || alg == &ssh_rsa);
|
bool include_bit_count = (alg == &ssh_dsa || alg == &ssh_rsa);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user