Details
Description
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
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();
Resulting in the below exceptions, caused by internal guarding in ByteArrayBuffer before the ByteArrayBuffer.data would be processed.
getPublicKey():
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)
getRawPublicKey():
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)
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 🙏