Uploaded image for project: 'MINA SSHD'
  1. MINA SSHD
  2. SSHD-984

Utility method to export KeyPair in OpenSSH format

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 2.4.0
    • 2.5.0
    • None

    Description

      There are ongoing efforts in Gerrit Code Review and JGit projects to remove dependency on JSch library: [1], [2]. Instead, MINA SSSD should be used on both: client and server sides.

      One difficulty we are facing is the fact the MINA SSHD currently doesn't provide any means to export generated KeyPair in OpenSSH format.

      Thomas Wolf added recently the ability to read encrypted OpenSSH private keys in context of SSHD-708.

      With JSch this code would do the job:

        public static com.jcraft.jsch.KeyPair genSshKey() throws JSchException {
          JSch jsch = new JSch();
          return KeyPair.genKeyPair(jsch, KeyPair.ECDSA, 256);
        }
      
        public static String publicKey(com.jcraft.jsch.KeyPair sshKey, @Nullable String comment)
            throws UnsupportedEncodingException {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          sshKey.writePublicKey(out, comment);
          return out.toString(US_ASCII.name()).trim();
        }
      
        public static byte[] privateKey(com.jcraft.jsch.KeyPair keyPair) {
          ByteArrayOutputStream out = new ByteArrayOutputStream();
          keyPair.writePrivateKey(out);
          return out.toByteArray();
        }
      

      [1] https://bugs.eclipse.org/bugs/show_bug.cgi?id=540727
      [2] https://bugs.chromium.org/p/gerrit/issues/detail?id=12599

      Attachments

        1. sshd_key_writing.zip
          9 kB
          Thomas Wolf

        Issue Links

          Activity

            People

              Unassigned Unassigned
              davido2 David Ostrovsky
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 1h 20m
                  1h 20m