Skip to content

Commit dfa183d

Browse files
rinneTimo Rinne
authored andcommitted
SSH agent forwarding patches re-merged as one patch.
Signed-off-by: Timo J. Rinne <[email protected]>
1 parent b742e95 commit dfa183d

27 files changed

Lines changed: 1306 additions & 31 deletions

‎Makefile.am‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ clean-local:
3232
cppcheck: $(BUILT_SOURCES) config.h
3333
cppcheck --enable=all --template=gcc -include config.h -I . \
3434
-I src/crypto -I src/frontend -I src/network -I src/protobufs \
35-
-I src/statesync -I src/terminal -I src/util \
35+
-I src/statesync -I src/terminal -I src/util -I src/agent \
3636
-I /usr/include -I /usr/include/google/protobuf -I/usr/include/openssl \
3737
.
3838

‎configure.ac‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,21 @@ AS_IF([test x"$with_utempter" != xno],
172172
[AC_MSG_WARN([Unable to find libutempter; utmp entries will not be made.])],
173173
[AC_MSG_ERROR([--with-utempter was given but libutempter was not found.])])])])
174174

175+
# Handle --disable-agent-forwarding
176+
AC_ARG_ENABLE(agent-forwarding,
177+
AS_HELP_STRING([--disable-agent-forwarding],
178+
[disable ssh agent forwarding in compile time]),
179+
, enable_agent_forwarding=yes)
180+
181+
175182
AC_SEARCH_LIBS([compress], [z], , [AC_MSG_ERROR([Unable to find zlib.])])
176183

177184
AC_SEARCH_LIBS([socket], [socket])
178185
AC_SEARCH_LIBS([inet_addr], [nsl])
179186

180187
# Checks for header files.
181188
AC_CHECK_HEADERS(m4_normalize([
189+
errno.h
182190
fcntl.h
183191
langinfo.h
184192
limits.h
@@ -206,6 +214,8 @@ AC_CHECK_HEADERS([endian.h sys/endian.h])
206214
AC_CHECK_HEADERS([utmpx.h])
207215
AC_CHECK_HEADERS([termio.h])
208216
AC_CHECK_HEADERS([sys/uio.h])
217+
AC_CHECK_HEADERS([sys/un.h])
218+
AC_CHECK_HEADERS([sys/types.h])
209219

210220
# Checks for typedefs, structures, and compiler characteristics.
211221
AC_HEADER_STDBOOL
@@ -415,6 +425,11 @@ AC_CHECK_DECL([IUTF8],
415425
[AC_MSG_WARN([No IUTF8 termios mode; character-erase of multibyte character sequence probably does not work properly in canonical mode on this platform.])],
416426
[[#include <termios.h>]])
417427

428+
if test "$enable_agent_forwarding" = "yes"; then
429+
AC_DEFINE([SUPPORT_AGENT_FORWARDING], [], [
430+
Define to enable support for SSH agent forwarding])
431+
fi
432+
418433
# Checks for protobuf
419434
PKG_CHECK_MODULES([protobuf], [protobuf])
420435

@@ -438,6 +453,7 @@ AC_CONFIG_FILES([
438453
src/protobufs/Makefile
439454
src/statesync/Makefile
440455
src/terminal/Makefile
456+
src/agent/Makefile
441457
src/util/Makefile
442458
scripts/Makefile
443459
src/examples/Makefile

‎man/mosh.1‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ OpenSSH command to remotely execute mosh-server on remote machine (default: "ssh
105105

106106
An alternate ssh port can be specified with, \fIe.g.\fP, \-\-ssh="ssh \-p 2222".
107107

108+
.TP
109+
.B \-\-forward-agent
110+
Enable ssh authentication agent forwarding. If you use this, please be
111+
aware of the security implications.
112+
108113
.TP
109114
.B \-\-predict=\fIWHEN\fP
110115
Controls use of speculative local echo. WHEN defaults to `adaptive'
@@ -119,6 +124,10 @@ confident. This generally means a previous prediction on the same row
119124
of the terminal has been confirmed by the server, without any
120125
intervening control character keystrokes.
121126

127+
.TP
128+
.B \-A
129+
Synonym for \-\-forward-agent
130+
122131
.TP
123132
.B \-a
124133
Synonym for \-\-predict=always

‎scripts/mosh.pl‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252

5353
my $term_init = 1;
5454

55+
my $forward_agent = 0;
56+
5557
my $localhost = undef;
5658

5759
my $help = undef;
@@ -82,6 +84,8 @@
8284
(example: "ssh -p 2222")
8385
(default: "ssh")
8486
87+
-A --forward-agent enable ssh agent forwarding
88+
8589
--no-init do not send terminal initialization string
8690
8791
--local run mosh-server locally without using ssh
@@ -121,6 +125,8 @@ sub predict_check {
121125
'6' => sub { $family = 'inet6' },
122126
'p=s' => \$port_request,
123127
'ssh=s' => sub { @ssh = shellwords($_[1]); },
128+
'A' => \$forward_agent,
129+
'forward-agent!' => \$forward_agent,
124130
'init!' => \$term_init,
125131
'local' => \$localhost,
126132
'help' => \$help,
@@ -275,6 +281,10 @@ sub predict_check {
275281

276282
my @server = ( 'new' );
277283

284+
if ( $forward_agent ) {
285+
push @server, ( '-A' );
286+
}
287+
278288
push @server, ( '-c', $colors );
279289

280290
push @server, @bind_arguments;
@@ -342,7 +352,14 @@ sub predict_check {
342352
$ENV{ 'MOSH_KEY' } = $key;
343353
$ENV{ 'MOSH_PREDICTION_DISPLAY' } = $predict;
344354
$ENV{ 'MOSH_NO_TERM_INIT' } = '1' if !$term_init;
345-
exec {$client} ("$client @cmdline |", $ip, $port);
355+
356+
my @client_av = ();
357+
if ( $forward_agent ) {
358+
push @client_av, ( '-A' );
359+
}
360+
push @client_av, ( $ip, $port );
361+
362+
exec {$client} ("$client @cmdline |", @client_av);
346363
}
347364

348365
sub shell_quote { join ' ', map {(my $a = $_) =~ s/'/'\\''/g; "'$a'"} @_ }

‎src/Makefile.am‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
SUBDIRS = protobufs util crypto terminal network statesync frontend examples tests
1+
SUBDIRS = protobufs util crypto terminal network statesync agent frontend examples tests

‎src/agent/Makefile.am‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
AM_CPPFLAGS = -I$(srcdir)/../util -I$(srcdir)/../crypto -I$(srcdir)/../network -I../protobufs $(protobuf_CFLAGS) $(TINFO_CFLAGS)
2+
AM_CXXFLAGS = $(WARNING_CXXFLAGS) $(PICKY_CXXFLAGS) $(HARDEN_CFLAGS) $(MISC_CXXFLAGS)
3+
4+
noinst_LIBRARIES = libmoshagent.a
5+
6+
libmoshagent_a_SOURCES = agent.h agent.cc
7+

0 commit comments

Comments
 (0)