[
https://issues.apache.org/jira/browse/SSHD-1297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17611977#comment-17611977
]
Thomas Wolf commented on SSHD-1297:
-----------------------------------
I've just merged [PR 249|https://github.com/apache/mina-sshd/pull/249], which
avoids this {{OutOfMemoryError}} and adds a {{KeyUtils.loadPublicKey()}}
utility method.
> 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: [email protected]
For additional commands, e-mail: [email protected]