dsa2ssh.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <auth.h>
  12. #include <mp.h>
  13. #include <libsec.h>
  14. #include "rsa2any.h"
  15. void
  16. usage(void)
  17. {
  18. fprint(2, "usage: auth/dsa2ssh [-c comment] [file]\n");
  19. exits("usage");
  20. }
  21. void
  22. main(int argc, char **argv)
  23. {
  24. DSApriv *k;
  25. char *comment;
  26. unsigned char buf[8192], *p;
  27. fmtinstall('B', mpfmt);
  28. fmtinstall('[', encodefmt);
  29. comment = "";
  30. ARGBEGIN{
  31. case 'c':
  32. comment = EARGF(usage());
  33. break;
  34. default:
  35. usage();
  36. }ARGEND
  37. if(argc > 1)
  38. usage();
  39. if((k = getdsakey(argc, argv, 0, nil)) == nil)
  40. sysfatal("%r");
  41. p = buf;
  42. p = put4(p, 7);
  43. p = putn(p, "ssh-dss", 7);
  44. p = putmp2(p, k->pub.p);
  45. p = putmp2(p, k->pub.q);
  46. p = putmp2(p, k->pub.alpha);
  47. p = putmp2(p, k->pub.key);
  48. print("ssh-dss %.*[ %s\n", (int)(p - buf), buf, comment);
  49. exits(nil);
  50. }