snapshot: ssh-keyscan problems
mouring at etoh.eviladmin.org
mouring at etoh.eviladmin.org
Mon Dec 11 14:09:53 EST 2000
On Sun, 10 Dec 2000, Markus Friedl wrote:
> > General observations: for RSA keys only?
>
> yes, only for ssh-1, feel free to update for SSH-2 :)
>
How does this patch stack up against what you want for added feature
to ssh-keyscan?
I'm not promising it's pretty, but it does not job and I can't find
where it breaks as of yet. =)
- Ben
--- ../openssh/ssh-keyscan.c Wed Dec 6 16:47:55 2000
+++ ssh-keyscan.c Sun Dec 10 21:07:36 2000
@@ -27,8 +27,6 @@
#include "buffer.h"
#include "bufaux.h"
-static int argno = 1; /* Number of argument currently being parsed */
-
int family = AF_UNSPEC; /* IPv4, IPv6 or both */
#define PORT 22
@@ -86,6 +84,12 @@
void (*errfun) (const char *,...);
} Linebuf;
+struct {
+ int dsa;
+ int rsa;
+ int rsa1;
+} keylists = { 0, 0, 0 };
+
static inline Linebuf *
Linebuf_alloc(const char *filename, void (*errfun) (const char *,...))
{
@@ -241,15 +245,15 @@
}
void
-keyprint(char *host, char *output_name, char *kd, int len)
+keyprint(int key,char *host, char *output_name, char *kd, int len)
{
- static Key *rsa;
+ static Key *k;
static Buffer msg;
- if (rsa == NULL) {
+ if (k == NULL) {
buffer_init(&msg);
- rsa = key_new(KEY_RSA1);
}
+ k = key_new(key);
buffer_append(&msg, kd, len);
buffer_consume(&msg, 8 - (len & 7)); /* padding */
if (buffer_get_char(&msg) != (int) SSH_SMSG_PUBLIC_KEY) {
@@ -261,17 +265,27 @@
/* server key */
(void) buffer_get_int(&msg);
- buffer_get_bignum(&msg, rsa->rsa->e);
- buffer_get_bignum(&msg, rsa->rsa->n);
+ if (key == KEY_DSA) {
+ buffer_get_bignum(&msg, k->dsa->p);
+ buffer_get_bignum(&msg, k->dsa->q);
+ } else {
+ buffer_get_bignum(&msg, k->rsa->e);
+ buffer_get_bignum(&msg, k->rsa->n);
+ }
/* host key */
(void) buffer_get_int(&msg);
- buffer_get_bignum(&msg, rsa->rsa->e);
- buffer_get_bignum(&msg, rsa->rsa->n);
+ if (key == KEY_DSA) {
+ buffer_get_bignum(&msg, k->dsa->p);
+ buffer_get_bignum(&msg, k->dsa->q);
+ } else {
+ buffer_get_bignum(&msg, k->rsa->e);
+ buffer_get_bignum(&msg, k->rsa->n);
+ }
buffer_clear(&msg);
fprintf(stdout, "%s ", output_name ? output_name : host);
- key_write(rsa, stdout);
+ key_write(k, stdout);
fputs("\n", stdout);
}
@@ -446,7 +460,12 @@
c->c_status = CS_KEYS;
break;
case CS_KEYS:
- keyprint(c->c_name, c->c_output_name, c->c_data, c->c_plen);
+ if (keylists.rsa1)
+ keyprint(KEY_RSA1,c->c_name, c->c_output_name, c->c_data, c->c_plen);
+ if (keylists.rsa)
+ keyprint(KEY_RSA,c->c_name, c->c_output_name, c->c_data, c->c_plen);
+ if (keylists.dsa)
+ keyprint(KEY_DSA,c->c_name, c->c_output_name, c->c_data, c->c_plen);
confree(s);
return;
break;
@@ -501,50 +520,10 @@
}
}
-char *
-nexthost(int argc, char **argv)
-{
- static Linebuf *lb;
-
- for (;;) {
- if (!lb) {
- if (argno >= argc)
- return (NULL);
- if (argv[argno][0] != '-')
- return (argv[argno++]);
- if (!strcmp(argv[argno], "--")) {
- if (++argno >= argc)
- return (NULL);
- return (argv[argno++]);
- } else if (!strncmp(argv[argno], "-f", 2)) {
- char *fname;
- if (argv[argno][2])
- fname = &argv[argno++][2];
- else if (++argno >= argc) {
- error("missing filename for `-f'");
- return (NULL);
- } else
- fname = argv[argno++];
- if (!strcmp(fname, "-"))
- fname = NULL;
- lb = Linebuf_alloc(fname, error);
- } else
- error("ignoring invalid/misplaced option `%s'", argv[argno++]);
- } else {
- char *line;
- line = getline(lb);
- if (line)
- return (line);
- Linebuf_free(lb);
- lb = NULL;
- }
- }
-}
-
static void
usage(void)
{
- fatal("usage: %s [-t timeout] { [--] host | -f file } ...\n", prog);
+ fatal("usage: %s [-1RD] [-t timeout] { [--] host | -f file } ...\n", prog);
return;
}
@@ -552,6 +531,10 @@
main(int argc, char **argv)
{
char *host = NULL;
+ char ch;
+ int defaultkey = 1;
+ Linebuf *lb = NULL;
+ extern int optind;
TAILQ_INIT(&tq);
@@ -560,24 +543,35 @@
else
prog = argv[0];
- if (argc <= argno)
- usage();
-
- if (argv[1][0] == '-' && argv[1][1] == 't') {
- argno++;
- if (argv[1][2])
- timeout = atoi(&argv[1][2]);
- else {
- if (argno >= argc)
+ while ((ch = getopt(argc,argv,"t:f:1DR")) != EOF)
+ switch(ch) {
+ case 't':
+ timeout = atoi(optarg);
+ break;
+ case 'f':
+ lb = Linebuf_alloc(optarg, error);
+ break;
+ case '1':
+ keylists.rsa1=1;
+ defaultkey=0;
+ break;
+ case 'D':
+ keylists.dsa=1;
+ defaultkey=0;
+ break;
+ case 'R':
+ keylists.rsa=1;
+ defaultkey=0;
+ break;
+ default:
usage();
- timeout = atoi(argv[argno++]);
}
- if (timeout <= 0)
- usage();
- }
- if (argc <= argno)
- usage();
+ argc -= optind;
+ argv += optind;
+ if (defaultkey)
+ keylists.rsa1=1;
+
maxfd = fdlim_get(1);
if (maxfd < 0)
fatal("%s: fdlim_get: bad value\n", prog);
@@ -593,7 +587,17 @@
while (ncon < maxcon) {
char *name;
- host = nexthost(argc, argv);
+ if (!lb) {
+ host = argv[0];
+ argv++;
+ } else {
+ host = getline(lb);
+ if (host == NULL) {
+ Linebuf_free(lb);
+ lb = NULL;
+ }
+ }
+
if (host == NULL)
break;
name = strnnsep(&host, " \t\n");
More information about the openssh-unix-dev
mailing list