Files
app/native-ssh/cmake/PatchLibssh.cmake
T
Claude e567071ad9 Android: SSH on libdmodemssh through JNI, sshj gone
The SSH client is the same as iOS's and the GUI's now: native-ssh, on
libssh, loaded as libdmodem_ssh_jni.so (NativeSsh.kt). SshLink polls
it on its own thread; its channels carry the shell, commands, the
port forwards (-L, -R, -D) and the forwarded agent's requests. Keys
stay the app's: SSH's wire form (SshWire.kt), OpenSSH's and PEM keys
read through the engine, PuTTY's .ppk read here, all on BouncyCastle.

The engine: commands can forward the agent, a write tells what's still
kept for the server (forwards hold back a fast sender), libssh built
WITH_SERVER (its callbacks for the agent's channels need it), and its
remote listen on port 0 patched to take the port from its own reply.

The unit tests build the JNI library for the host (buildHostSsh) and
run against it: OpenSSH's sshd, puttygen and Apache MINA's server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B82eRSV65geuGd6zMt2V6r
2026-11-12 13:46:38 +00:00

50 lines
1.7 KiB
CMake

# libssh's remote listen on port 0 told the port the server picked from
# its own reply: libssh reads it from whatever packet came in last, which
# is often another one (its own "FIXME"), and then fails a listen that
# the server took. The reply's port kept in the session as it comes.
# Run in libssh's source tree by BundledLibssh.cmake.
# (a replace that must take: else this libssh isn't the one patched for)
function(dmodem_patch file from to)
file(READ ${file} _text)
string(FIND "${_text}" "${to}" _done)
if(_done GREATER -1)
return()
endif()
string(FIND "${_text}" "${from}" _at)
if(_at LESS 0)
message(FATAL_ERROR "PatchLibssh: ${file} isn't as expected")
endif()
string(REPLACE "${from}" "${to}" _text "${_text}")
file(WRITE ${file} "${_text}")
endfunction()
dmodem_patch(include/libssh/session.h
" enum ssh_channel_request_state_e global_req_state;"
" enum ssh_channel_request_state_e global_req_state;
/* D-Modem: bound port, from a global request's success */
int dmodem_bound_port;")
dmodem_patch(src/channels.c
" } else {
session->global_req_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
}"
" } else {
/* D-Modem: bound port */
uint32_t bound = 0;
session->global_req_state=SSH_CHANNEL_REQ_STATE_ACCEPTED;
session->dmodem_bound_port =
ssh_buffer_unpack(packet, \"d\", &bound) == SSH_OK ? (int)bound : 0;
}")
dmodem_patch(src/channels.c
" if (rc == SSH_OK && port == 0 && bound_port != NULL) {
rc = ssh_buffer_unpack(session->in_buffer, \"d\", bound_port);
if (rc != SSH_OK)
*bound_port = 0;
}"
" if (rc == SSH_OK && port == 0 && bound_port != NULL) {
/* D-Modem: bound port, as the success packet had it */
*bound_port = session->dmodem_bound_port;
}")