Subject: Where to find protocol spec for SCP under SSH-1

From: [email-masked] (Karol Zielonko)
Date: Thu, 3 Mar 2005 05:14:04 -0500 (EST)

I'm a relative newbie to the SSH space. At the highest level I think I'm looking
for an old SSH-1 protocol specification to try to understand how SCP worked.

A customer has hit the problem described at:

  http://www.snailbook.com/faq/scp-ossh-to-ssh2.auto.html

with our SSH implementation (OpenVMS).  In a nutshell this problem involves the
SCP client (RH Linux in our case) sending "scp -f file.name" as an rexec style
command to our SSH-2 only implementation. (Our implementation expects SCP to be
implemented "layered" on SFTP.) Our implementation is fprintfing the following
text to stderr:

  tcpip$ssh_scp2.exe: warning: Executing scp1 compatibility.
  tcpip$ssh_scp2.exe: FATAL: Executing ssh1 in compatibility mode failed (Check
    that scp1 is in your PATH).

In our implementation of SSH stderr turns out to be the PTY going to the SSH
server parent process and all data sent to the PTY from the child (which is
running the "scp -f file.name" command) ends up being sent over the encrypted
channel to the client. However the data is not being displayed to the client as
an error message. Instead we get this at the client:

  [user@rhlinux user]$ scp user@serverhost:z.z z.z
  protocol error: unexpected <newline>
  [user@rhlinux user]$

What I would like to see is:

  [user@rhlinux user]$ scp user@serverhost:z.z z.z
  tcpip$ssh_scp2.exe: warning: Executing scp1 compatibility.
  tcpip$ssh_scp2.exe: FATAL: Executing ssh1 in compatibility mode failed (Check
      that scp1 is in your PATH).
  [user@rhlinux user]$

Well, we should change our code to use different text, since scp1 is simply not
implemented on our platform. So we might have:

  [user@rhlinux user]$ scp user@serverhost:z.z z.z
  tcpip$ssh_scp2.exe: FATAL: scp1 compatibility mode is not supported
  [user@rhlinux user]$

The point is that I want to be able to package the error text data being sent
back to the client in such a way that the client recognizes the data as error
text and displays it to the user as such.

Is there a way to do this? I would think that to find out if there is I need to
know what sort of data the scp client is expecting to see on the wire. Perhaps
there is a provision for the server to send an error text message? In some debug
traces I have seen that the client is apparently sending a single byte of 0 to
our side at the beginning of all of this. Some sort of SCP message? In some
other cases I've seen it send its own error text, "protocol error: unexpected
<newline>", with a single leading byte of 1. Here's a dump from our ssh server
parent log:

  debug: SshUnixFdStream/SSHUNIXFDSTREAM.C:663: ssh_stream_fd_write wrote 43 bytes
  debug: SshUnixFdStream/SSHUNIXFDSTREAM.C:665: data:
  debug: 00000000: 0173 6370 3a20 7072 6f74 6f63 6f6c 2065  .scp: protocol e
  debug: 00000010: 7272 6f72 3a20 756e 6578 7065 6374 6564  rror: unexpected
  debug: 00000020: 203c 6e65 776c 696e 653e 0a               <newline>.

Note that the first byte of the sequence is 01. Is this an old-style scp message
type byte? I dunno.  Anyway I think I need a spec to figure it out.

Thanks in advance,

Karol

---

From: [email-masked] (Niels Möller)
Date: 03 Mar 2005 22:26:58 +0100

[email-masked] (Karol Zielonko) writes:

> channel to the client.

I guess this is where you get stderr and stdout mixed up.

> text and displays it to the user as such.

I think the Right Way to do this is to have sshd spawn the process
with a pty only for its stdin and stdout, and a plain pipe for stderr.
And then forward data from the stderr pipe as
SSH_MSG_CHANNEL_EXTENDED_DATA. Then the ssh client end has sufficient
information to do the right thing. And I'd expect most instances of
foo-over-ssh will Just Work, as the ssh client will forward data
between the ssh connection and the foo application, and direct and
SSH_MSG_CHANNEL_EXTENDED_DATA to the terminal.

Unfortunately, on the server side, some interactive programs, e.g.
bash, are confused if stderr is a pipe or other non-tty. If that is a
problem, you can have sshd create *two* pty pairs, one for
stdin/stdout, and one for stderr. Slightly overkill, but it should
work.

Regards,
/Niels

---

From: "Karol Zielonko" <[email-masked]>
Date: Thu, 3 Mar 2005 19:23:36 -0500

Thanks. After doing a lot of poking around on the web I was able to find an
SSH1 protocol spec but it made no explicit mention of scp1. I was unable
to find a spec for scp1. I did find this rather unencouraging text:

The protocol it uses (let's call it "SCP1") remained entirely undocumented,
even when Ylönen wrote the first RFC documenting the SSH-1 protocol.

at http://www.hn.edu.cn/book/NetWork/NetworkingBookshelf_2ndEd/ssh/ch03_08.htm

After a few hacks I managed to get

We now prepend the \001 byte to the string "scp1 compatibility mode is not supported."
in the SCP2 mainline, running in the SSH server child process, and write
the text to stderr  when -f or -t are being employed. (For our implementation on OpenVMS
stderr and stdout both point to the PTY.) After solving some
problems with the VMS PTY driver polluting the text with CRLFs
I managed to get the text coming cleanly out of the PTY code (no formatting characters
added) into the SSH server parent process. This data is sent over the channel
to the client and, voila:

  [user@rhlinux user]$ scp [email-masked]:z.z z.z
  scp1 compatibility mode is not supported.
  lost connection
  [user@rhlinux user]$

This is not graceful, granted, with the lost connection but
for our purposes it's fine.

Thanks for the confirmation.

Karol Zielonko
----- Original Message ----- 
From: "denis bider" <[email-masked]>
To: "'Karol Zielonko'" <[email-masked]>; <[email-masked]>
Sent: Thursday, March 03, 2005 6:42 PM
Subject: RE: Where to find protocol spec for SCP under SSH-1

> > Note that the first byte of the sequence is 01. Is this an
> > old-style scp message type byte?
>
> Yes, you need to prefix error messages with \001. I also think that you can
> just send them to stdout.
>
> denis
>
>
>

---

From: "denis bider" <[email-masked]>
Date: Fri, 4 Mar 2005 00:42:41 +0100

denis

---

From: [email-masked] (Niels Möller)
Date: 04 Mar 2005 08:46:51 +0100

> even when Ylönen wrote the first RFC documenting the SSH-1 protocol.

If I have understood history correctly, scp uses is exactly the same
protocol as rcp. That may help you when searching for a spec.

But I still think you're attacking the problem at the wrong level; the
ssh implementation shouldn't need to know anything about the structure
in the contents of a data channel.

Regards,
/Niels