[ https://issues.apache.org/jira/browse/SSHD-1297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17608872#comment-17608872 ]
Thomas Wolf commented on SSHD-1297: ----------------------------------- Your code is loading ASCII data and then tries to read a binary public key from it. No wonder that doesn't work. Treat the public key file as a single-line {{authorized_keys}} file: {code:java} PublicKey myPublicKey; Path pubKeyFile = Paths.get("/home/my-user/tmp/test_rsa_key.pub"); if (Files.isRegularFile(pubKeyFile, LinkOption.NOFOLLOW_LINKS)) { myPublicKey = AuthorizedKeyEntry.readAuthorizedKeys(pubKeyFile).get(0) .resolvePublicKey(null, PublicKeyEntryResolver.IGNORING); } {code} > Load public key from file > ------------------------- > > Key: SSHD-1297 > URL: https://issues.apache.org/jira/browse/SSHD-1297 > Project: MINA SSHD > Issue Type: Bug > Affects Versions: 2.9.1 > Environment: org.apache.sshd:sshd-sftp:2.9.1 > + > openjdk version "17.0.3" 2022-04-19 > OpenJDK Runtime Environment Temurin-17.0.3+7 (build 17.0.3+7) > OpenJDK 64-Bit Server VM Temurin-17.0.3+7 (build 17.0.3+7, mixed mode, > sharing) > Reporter: Daniel Hammer > Priority: Minor > > Hi SSHD gurus, > I'm attempting to utilize > {{org.apache.sshd.common.util.buffer.ByteArrayBuffer}} to load a > {{java.security.PublicKey}}, in-order to subsequently register the public key > in a {{{}org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator{}}}. > Ie. the idea is something like this > {code:java} > PublicKey myPublicKey; > try (InputStream is = new > FileInputStream("/home/my-user/tmp/test_rsa_key.pub")) { > ByteArrayBuffer buffer = new > ByteArrayBuffer(org.apache.sshd.common.util.io.IoUtils.IoUtils.toByteArray(is)); > myPublicKey = buffer.getPublicKey(); // -> OutOfMemoryError: Java heap > space ..? > // myPublicKey = buffer.getRawPublicKey(); // -> Underflow ..? > } > ServerBuilder.builder() > .publickeyAuthenticator(new KeySetPublickeyAuthenticator("my id", > List.of(myPublicKey))) > .build(); > {code} > Resulting in the below exceptions, caused by internal guarding in > {{ByteArrayBuffer}} before the {{ByteArrayBuffer.data}} would be processed. > {{{}getPublicKey(){}}}: > {code:java} > java.lang.OutOfMemoryError: Java heap space > at > org.apache.sshd.common.util.buffer.ByteArrayBuffer.ensureCapacity(ByteArrayBuffer.java:277) > at > org.apache.sshd.common.util.buffer.Buffer.ensureCapacity(Buffer.java:1105) > at > org.apache.sshd.common.util.buffer.ByteArrayBuffer.wpos(ByteArrayBuffer.java:139) > at > org.apache.sshd.common.util.buffer.Buffer.getPublicKey(Buffer.java:521) > at > org.apache.sshd.common.util.buffer.Buffer.getPublicKey(Buffer.java:505) > {code} > {{{}getRawPublicKey(){}}}: > {code:java} > org.apache.sshd.common.util.buffer.BufferException: Underflow: > requested=1936943149, available=737 > at > org.apache.sshd.common.util.buffer.Buffer.ensureAvailable(Buffer.java:640) > at > org.apache.sshd.common.util.buffer.ByteArrayBuffer.getString(ByteArrayBuffer.java:241) > at org.apache.sshd.common.util.buffer.Buffer.getString(Buffer.java:309) > at > org.apache.sshd.common.util.buffer.Buffer.getRawPublicKey(Buffer.java:541) > at > org.apache.sshd.common.util.buffer.Buffer.getRawPublicKey(Buffer.java:530) > {code} > Seemingly my approach is incompatible with the available logic, unfortunately > I've been unable to uncover documentation or Javadoc that could aid. > So as a last resort I'm turning to you gurus, in hopes of enlightenment (+ > perhaps a PR guiding future developers in the desired direction via > documentation / Javadoc). > Thanks in advance 🙏 -- This message was sent by Atlassian Jira (v8.20.10#820010) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For additional commands, e-mail: dev-h...@mina.apache.org