comparison dropbearkey.c @ 478:d4f32c3443ac dbclient-netcat-alike

propagate from branch 'au.asn.ucc.matt.dropbear' (head f21045c791002d81fc6b8dde6537ea481e513eb2) to branch 'au.asn.ucc.matt.dropbear.dbclient-netcat-alike' (head d1f69334581dc4c35f9ca16aa5355074c9dd315d)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 14 Sep 2008 06:47:51 +0000
parents e430a26064ee
children 3aa74a4d83ae 76097ec1a29a
comparison
equal deleted inserted replaced
296:6b41e2cbf071 478:d4f32c3443ac
73 #ifdef DROPBEAR_DSS 73 #ifdef DROPBEAR_DSS
74 " dss\n" 74 " dss\n"
75 #endif 75 #endif
76 "-f filename Use filename for the secret key\n" 76 "-f filename Use filename for the secret key\n"
77 "-s bits Key size in bits, should be a multiple of 8 (optional)\n" 77 "-s bits Key size in bits, should be a multiple of 8 (optional)\n"
78 " (DSS has a fixed size of 1024 bits)\n"
78 "-y Just print the publickey and fingerprint for the\n private key in <filename>.\n" 79 "-y Just print the publickey and fingerprint for the\n private key in <filename>.\n"
79 #ifdef DEBUG_TRACE 80 #ifdef DEBUG_TRACE
80 "-v verbose\n" 81 "-v verbose\n"
81 #endif 82 #endif
82 ,progname); 83 ,progname);
185 if (sizetext) { 186 if (sizetext) {
186 if (sscanf(sizetext, "%u", &bits) != 1) { 187 if (sscanf(sizetext, "%u", &bits) != 1) {
187 fprintf(stderr, "Bits must be an integer\n"); 188 fprintf(stderr, "Bits must be an integer\n");
188 exit(EXIT_FAILURE); 189 exit(EXIT_FAILURE);
189 } 190 }
190 191
191 if (bits < 512 || bits > 4096 || (bits % 8 != 0)) { 192 if (keytype == DROPBEAR_SIGNKEY_DSS && bits != 1024) {
193 fprintf(stderr, "DSS keys have a fixed size of 1024 bits\n");
194 exit(EXIT_FAILURE);
195 } else if (bits < 512 || bits > 4096 || (bits % 8 != 0)) {
192 fprintf(stderr, "Bits must satisfy 512 <= bits <= 4096, and be a" 196 fprintf(stderr, "Bits must satisfy 512 <= bits <= 4096, and be a"
193 " multiple of 8\n"); 197 " multiple of 8\n");
194 exit(EXIT_FAILURE); 198 exit(EXIT_FAILURE);
195 } 199 }
196 200
281 285
282 out: 286 out:
283 buf_burn(buf); 287 buf_burn(buf);
284 buf_free(buf); 288 buf_free(buf);
285 buf = NULL; 289 buf = NULL;
286 sign_key_free(key); 290 if (key) {
287 key = NULL; 291 sign_key_free(key);
292 key = NULL;
293 }
288 exit(err); 294 exit(err);
289 } 295 }
290 296
291 static void printpubkey(sign_key * key, int keytype) { 297 static void printpubkey(sign_key * key, int keytype) {
292 298
295 unsigned long base64len; 301 unsigned long base64len;
296 int err; 302 int err;
297 const char * typestring = NULL; 303 const char * typestring = NULL;
298 char *fp = NULL; 304 char *fp = NULL;
299 int len; 305 int len;
306 struct passwd * pw = NULL;
307 char * username = NULL;
308 char hostname[100];
300 309
301 buf = buf_new(MAX_PUBKEY_SIZE); 310 buf = buf_new(MAX_PUBKEY_SIZE);
302 buf_put_pub_key(buf, key, keytype); 311 buf_put_pub_key(buf, key, keytype);
303 buf_setpos(buf, 4); 312 buf_setpos(buf, 4);
304 313
313 322
314 typestring = signkey_name_from_type(keytype, &err); 323 typestring = signkey_name_from_type(keytype, &err);
315 324
316 fp = sign_key_fingerprint(buf_getptr(buf, len), len); 325 fp = sign_key_fingerprint(buf_getptr(buf, len), len);
317 326
318 printf("Public key portion is:\n%s %s\nFingerprint: %s\n", 327 /* a user@host comment is informative */
319 typestring, base64key, fp); 328 username = "";
329 pw = getpwuid(getuid());
330 if (pw) {
331 username = pw->pw_name;
332 }
333
334 gethostname(hostname, sizeof(hostname));
335 hostname[sizeof(hostname)-1] = '\0';
336
337 printf("Public key portion is:\n%s %s %s@%s\nFingerprint: %s\n",
338 typestring, base64key, username, hostname, fp);
320 339
321 m_free(fp); 340 m_free(fp);
322 buf_free(buf); 341 buf_free(buf);
323 } 342 }
324 343