[
https://issues.apache.org/jira/browse/SSHD-1297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17626093#comment-17626093
]
Daniel Hammer commented on SSHD-1297:
-------------------------------------
Thanks a bunch [~twolf] 🙏
I've incorporated your suggestion into a
[PR|https://github.com/spring-projects/spring-integration-samples/pull/334] for
the initial MINA sample in
[org.springframework.integration.samples.sftp.EmbeddedSftpServer|https://github.com/spring-projects/spring-integration-samples/blob/62319c8e5b1a517910ed0578d1960a39afd1f1c3/basic/sftp/src/test/java/org/springframework/integration/samples/sftp/EmbeddedSftpServer.java#L81]
that triggered a vibe of "not invented here" from the example and encouraged
me to look a bit deeper, and subsequently open SSHD-1297.
(the sample can most-likely be simplified when {{KeyUtils.loadPublicKey()}} is
released)
> 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]