dsa2ssh.c 784 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <u.h>
  2. #include <libc.h>
  3. #include <auth.h>
  4. #include <mp.h>
  5. #include <libsec.h>
  6. #include "rsa2any.h"
  7. void
  8. usage(void)
  9. {
  10. fprint(2, "usage: auth/dsa2ssh [-c comment] [file]\n");
  11. exits("usage");
  12. }
  13. void
  14. main(int argc, char **argv)
  15. {
  16. DSApriv *k;
  17. char *comment;
  18. uchar buf[8192], *p;
  19. fmtinstall('B', mpfmt);
  20. fmtinstall('[', encodefmt);
  21. comment = "";
  22. ARGBEGIN{
  23. case 'c':
  24. comment = EARGF(usage());
  25. break;
  26. default:
  27. usage();
  28. }ARGEND
  29. if(argc > 1)
  30. usage();
  31. if((k = getdsakey(argc, argv, 0, nil)) == nil)
  32. sysfatal("%r");
  33. p = buf;
  34. p = put4(p, 7);
  35. p = putn(p, "ssh-dss", 7);
  36. p = putmp2(p, k->pub.p);
  37. p = putmp2(p, k->pub.q);
  38. p = putmp2(p, k->pub.alpha);
  39. p = putmp2(p, k->pub.key);
  40. print("ssh-dss %.*[ %s\n", (int)(p - buf), buf, comment);
  41. exits(nil);
  42. }