comparison tests/sshprotoext.py @ 35976:48a3a9283f09

sshpeer: initial definition and implementation of new SSH protocol The existing SSH protocol has several design flaws. Future commits will elaborate on these flaws as new features are introduced to combat these flaws. For now, hopefully you can take me for my word that a ground up rewrite of the SSH protocol is needed. This commit lays the foundation for a new SSH protocol by defining a mechanism to upgrade the SSH transport channel away from the default (version 1) protocol to something modern (which we'll call "version 2" for now). This upgrade process is detailed in the internals documentation for the wire protocol. The gist of it is the client sends a request line preceding the "hello" command/line which basically says "I'm requesting an upgrade: here's what I support." If the server recognizes that line, it processes the upgrade request and the transport channel is switched to use the new version of the protocol. If not, it sends an empty response, which is how all Mercurial SSH servers from the beginning of time reacted to unknown commands. The upgrade request is effectively ignored and the client continues to use the existing version of the protocol as if nothing happened. The new version of the SSH protocol is completely identical to version 1 aside from the upgrade dance and the bytes that follow. The immediate bytes that follow the protocol switch are defined to be a length framed "capabilities: " line containing the remote's advertised capabilities. In reality, this looks very similar to what the "hello" response would look like. But it will evolve quickly. The methodology by which the protocol will evolve is important. I'm not going to introduce the new protocol all at once. That would likely lead to endless bike shedding and forward progress would stall. Instead, I intend to tricle out new features and diversions from the existing protocol in small, incremental changes. To support the gradual evolution of the protocol, the on-the-wire advertised protocol name contains an "exp" to denote "experimental" and a 4 digit field to capture the sub-version of the protocol. Whenever we make a BC change to the wire protocol, we can increment this version and lock out all older clients because it will appear as a completely different protocol version. This means we can incur as many breaking changes as we want. We don't have to commit to supporting any one feature or idea for a long period of time. We can even evolve the handshake mechanism, because that is defined as being an implementation detail of the negotiated protocol version! Hopefully this lowers the barrier to accepting changes to the protocol and for experimenting with "radical" ideas during its development. In core, sshpeer received most of the attention. We haven't even implemented the server bits for the new protocol in core yet. Instead, we add very primitive support to our test server, mainly just to exercise the added code paths in sshpeer. Differential Revision: https://phab.mercurial-scm.org/D2061 # no-check-commit because of required foo_bar naming
author Gregory Szorc <gregory.szorc@gmail.com>
date Tue, 06 Feb 2018 11:08:36 -0800
parents 80a2b8ae42a1
children 5767664d39a5
comparison
equal deleted inserted replaced
35975:40d94ea51402 35976:48a3a9283f09
51 rsp = wireproto.dispatch(self._repo, self, b'between') 51 rsp = wireproto.dispatch(self._repo, self, b'between')
52 self._handlers[rsp.__class__](self, rsp) 52 self._handlers[rsp.__class__](self, rsp)
53 53
54 super(prehelloserver, self).serve_forever() 54 super(prehelloserver, self).serve_forever()
55 55
56 class upgradev2server(wireprotoserver.sshserver):
57 """Tests behavior for clients that issue upgrade to version 2."""
58 def serve_forever(self):
59 name = wireprotoserver.SSHV2
60 l = self._fin.readline()
61 assert l.startswith(b'upgrade ')
62 token, caps = l[:-1].split(b' ')[1:]
63 assert caps == b'proto=%s' % name
64
65 # Filter hello and between requests.
66 l = self._fin.readline()
67 assert l == b'hello\n'
68 l = self._fin.readline()
69 assert l == b'between\n'
70 l = self._fin.readline()
71 assert l == 'pairs 81\n'
72 self._fin.read(81)
73
74 # Send the upgrade response.
75 self._fout.write(b'upgraded %s %s\n' % (token, name))
76 servercaps = wireproto.capabilities(self._repo, self)
77 rsp = b'capabilities: %s' % servercaps
78 self._fout.write(b'%d\n' % len(rsp))
79 self._fout.write(rsp)
80 self._fout.write(b'\n')
81 self._fout.flush()
82
83 super(upgradev2server, self).serve_forever()
84
56 def performhandshake(orig, ui, stdin, stdout, stderr): 85 def performhandshake(orig, ui, stdin, stdout, stderr):
57 """Wrapped version of sshpeer._performhandshake to send extra commands.""" 86 """Wrapped version of sshpeer._performhandshake to send extra commands."""
58 mode = ui.config(b'sshpeer', b'handshake-mode') 87 mode = ui.config(b'sshpeer', b'handshake-mode')
59 if mode == b'pre-no-args': 88 if mode == b'pre-no-args':
60 ui.debug(b'sending no-args command\n') 89 ui.debug(b'sending no-args command\n')
83 112
84 if servermode == b'banner': 113 if servermode == b'banner':
85 wireprotoserver.sshserver = bannerserver 114 wireprotoserver.sshserver = bannerserver
86 elif servermode == b'no-hello': 115 elif servermode == b'no-hello':
87 wireprotoserver.sshserver = prehelloserver 116 wireprotoserver.sshserver = prehelloserver
117 elif servermode == b'upgradev2':
118 wireprotoserver.sshserver = upgradev2server
88 elif servermode: 119 elif servermode:
89 raise error.ProgrammingError(b'unknown server mode: %s' % servermode) 120 raise error.ProgrammingError(b'unknown server mode: %s' % servermode)
90 121
91 peermode = ui.config(b'sshpeer', b'mode') 122 peermode = ui.config(b'sshpeer', b'mode')
92 123