Commit Graph

6646 Commits

Author SHA1 Message Date
Thomas Wolf c56fa51709 Apache MINA sshd: use NumberOfPasswordPrompts for encrypted keys
sshd only asks exactly once for the password. C.f. upstream issue
SSHD-850.[1] So we have to work around this limitation for now.
Once we move to sshd > 2.1.0, this can be simplified somewhat.

[1] https://issues.apache.org/jira/browse/SSHD-850

Bug: 520927
Change-Id: Id65650228486c5ed30affa9c62eac982e01ae207
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-14 04:47:33 -08:00
David Pursehouse c949da0d5f Merge "Format BUILD files with buildifier" 2018-11-14 00:27:01 -05:00
David Pursehouse f4c0189f25 Format BUILD files with buildifier
Change-Id: I7eb83e0560b1826c4f8567e9bc5fbdb2ae3fe9d0
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-13 18:33:41 -08:00
Thomas Wolf ec1116627f Apache MINA sshd client: properly handle HostKeyAlgorithms config
By default sshd will use its default built-in list, which matches
the one of openssh (as far as the algorithms exist in sshd at all).
But it doesn't handle HostKeyAlgorithms from the ssh config at all.

Implement this as in openssh, including the '+' and '-' modifiers
and reordering the default if there are known host keys for a
server already.

Add tests for the reordering.

Also use a more robust reader for the known hosts file. The default
aborts on the first error.

Bug: 520927
Change-Id: Ib1684440bfe2e96140536aa1a93c4bd4a0d35916
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 63a87b398f Apache MINA sshd client: respect NumberOfPasswordPrompts
Set the internal property on the session as defined in the ssh config.

Note that NumberOfPasswordPrompts in openssh applies independently to
both user logins in keyboard-interactive authentication _and_ to
passphrases for identity files (encrypted keys). Apache MINA sshd uses
the setting only for keyboard-interactive authentication, but not for
identity file passphrase prompts. For identity files, it asks exactly
once. This has been reported as issue SSHD-850 upstream.[1]

[1] https://issues.apache.org/jira/browse/SSHD-850

Bug: 520927
Change-Id: I390ffe9e1c52b96d3e8e28fd8edbdc73dde9edb4
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 8001f4c1fe Apache MINA sshd client: add gssapi-with-mic authentication
sshd does support gssapi-with-mic on the server side, but has no
built-in client-side support for this authentication mechanism.

Add our own implementation for it, following RFC 4462.[1] To avoid
needlessly re-trying mechanisms that aren't even configured on the
client, we disable mechanisms that fail on the very first attempt
to use them.

Since we have no real Kerberos5 test setup, this cannot be fully
tested in CI. The disabling of the authentication mechanism and
that it is skipped when not successful _is_ tested.

[1] https://www.ietf.org/rfc/rfc4462.txt

Bug: 520927
Change-Id: I5d0cdb14103588a57c52f927df541b589ab88d88
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 06387d4bfd Add ssh tests for PreferredAuthentications
Tests that it works with unknown authentications in the list, and
fails if there are no common authentications between server and
client. The latter also tests that the ssh config setting is taken
into account at all.

And promptly the JGit sshd client didn't. Add a fix for this. It's
a tiny bit hacky: Apache MINA looks up a custom property set on a
hierarchy of "PropertyResolver"s starting with the session. On the
session itself this property can never be set since it's read
already in the session constructor before anyone had any chance
to set it. The next element in the resolver hierarchy is the sshd
SshClient, and so we set that property there. Since we use one
SshClient and one ClientSession per JGit SshdSession, this is OK.

Bug: 520927
Change-Id: I62446fc1fffde125a8965c030240f0918ae234b7
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 9b31969f3c Add features for the Apache MINA sshd implementation
Bug: 520927
Change-Id: Ida3e218e0552848ef6285de1dc1e41866f7f873e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 488d95571f Apache MINA sshd client
Add a new ssh client implementation based on Apach MINA sshd 2.0.0.

This implementation uses JGit's own config file parser and host entry
resolver. Code inspection of the Apache MINA implementation revealed
a few bugs or idiosyncrasies that immediately would re-introduce bugs
already fixed in the past in JGit.

Apache MINA sshd is not without quirks either, and I had to configure
and override more than I had expected. But at least it was all doable
in clean ways.

Apache MINA boasts support for Bouncy Castle, so in theory this should
open the way to using more ssh key algorithms, such as ed25519.

The implementation is in a separate bundle and is still not used in
the core org.eclipse.jgit bundle. The tests re-use the ssh tests from
the core test bundle.

Bug: 520927
Change-Id: Ib35e73c35799140fe050d1ff4fb18d0d3596580e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 0173b25415 Add more ssh tests: pushing, known_host file handling, etc.
Add support for git-receive-pack to the ssh git server and add two
new tests for pushing.

This actually uncovered an undocumented requirement in TransportSftp:
the FTP rename operation assumes POSIX semantics, i.e., that the
target is removed. This works as written only for servers that
support and advertise the "posix-rename@openssh.com" FTP extension.

Our little Apache MINA server does not advertise this extension.

Fix the FtpChannel implementation for Jsch to handle this case in a
meaningful way so that it can pass the new "push over sftp" test.

Add more tests to test the behavior of server host key checking.

Also refactor the tests generally to separate better the test
framework from the actual tests.

Bug: 520927
Change-Id: Ia4bb85e17ddacde7b36ee8c2d5d454bbfa66dfc3
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:49:26 -08:00
Thomas Wolf 705691ee51 TransportSftp: eliminate dependency on Jsch
Introduce an FtpChannel abstraction, which can be obtained from a
RemoteSession. In JSchSession, wrap a JSch ChannelSftp as such an
FtpChannel. The JSch-specific SftpException is also mapped to a
generic FtpException. Rewrite TransportSftp to use only the new
abstraction layer.

This makes it possible to provide alternate ssh/sftp implementations.

Bug: 520927
Change-Id: I379026f7d4122f34931df909a28e73c02cd8a1da
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-13 10:46:00 -08:00
David Pursehouse a630b45e50 Upgrade maven-shade-plugin to 3.2.1
Change-Id: I4f194008bb02ab58eba6d44d1be0424c47be4d81
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-12 08:34:20 -08:00
Masaya Suzuki ad379793c7 Call unlockPack in finally
The lock is obtained in receivePackAndCheckConnectivity. It seems to me
the structure that requres the caller to unlock the lock is wrong, but
at least by calling in finally ensures it is called even if an exception
is thrown.

Change-Id: I123841b017baf5acffe0064d1004ef11a0a5e6c2
Signed-off-by: Masaya Suzuki <masayasuzuki@google.com>
2018-11-11 17:28:20 -08:00
Michael Keppler ddde209655 Remove line break from sslFailureInfo text
Do not add an artificial line break to the message, since it may become
much wider due to the embedded exception messages anyway.

The layout shall be controlled by the egit supplied message dialog using
layout constraints.

Bug: 540537
Change-Id: I4257b52e5e59689dfcbab47bd7c075b3fd031837
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
2018-11-11 11:35:44 +01:00
Håvard Wall f9de917547 Fix git-describe tie-breakers
Correct behaviour as git 1.7.1.1 is to resolve tie-breakers to choose
the most recent tag.

https://github.com/git/git/blob/master/Documentation/RelNotes/1.7.1.1.txt:
* "git describe" did not tie-break tags that point at the same commit
   correctly; newer ones are preferred by paying attention to the
   tagger date now.

Bug: 538610
Change-Id: Ib0b2a301997bb7f75935baf7005473f4de952a64
Signed-off-by: Håvard Wall <haavardw@gmail.com>
2018-11-09 08:54:44 +01:00
David Pursehouse 54dd1d112a Merge changes I97c062d0,Ib4e1f37c
* changes:
  Simplify RevWalk#iterator by factoring out common code
  Simplify exception handling in RevWalk#iterator
2018-11-08 22:51:48 -05:00
Jonathan Nieder a0cd400c37 Simplify RevWalk#iterator by factoring out common code
Factor out a helper that calls next() and tunnels IOException in a
RuntimeException, similar to TunnelException.tunnel(RevWalk::next) in
Guava terms[1].

This should make the code a little more readable.  No functional
change intended.

[1] https://github.com/google/guava/issues/2828#issuecomment-304187823

Change-Id: I97c062d03a17663d5c40895fd3d2c6a7306d4f39
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-11-08 18:19:01 -08:00
Jonathan Nieder aeba003200 Simplify exception handling in RevWalk#iterator
MissingObjectException and IncorrectObjectTypeException are subclasses
of IOException.

Change-Id: Ib4e1f37ce1b0b08e69ba3375bbdb6ee82ee4f036
Signed-off-by: Jonathan Nieder <jrn@google.com>
2018-11-08 17:55:19 -08:00
Jonathan Tan df21eec1ad DepthGenerator: fix multi-child boundary handling
Suppose that a repository has the following commit graph:

 B   C
  \ /
   A

and it was cloned with --shallow-exclude=A. DepthGenerator does not mark
C as shallow, causing an invalid repository to be produced on the
client, because A is not sent. (A similar issue occurs when
--shallow-since is used to exclude A but neither B nor C.)

This happens whenever an excluded commit has more than one child that is
to be sent to the client. Fix DepthGenerator to handle this case
correctly.

While we're editing DepthWalk.Commit, fix the documentation of
DepthWalk.Commit#isBoundary.

Change-Id: I7068abf0fe0c864d1b0e56e1616dad1aa8719411
Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
2018-11-08 15:33:23 -08:00
David Pursehouse 1385f4b3da Bazel: Increase severity of ClassCanBeStatic to ERROR
Change-Id: I8250fd15cfff6bbba54a238be31b3cf772edab3f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-08 11:09:54 +09:00
David Pursehouse 58bcbf89b0 SshTestBase: Make inner class TestCredentialsProvider static
Change-Id: Id5ba87b24e8a29157d49e9e5b151d65bdbcab37a
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-08 11:09:26 +09:00
David Pursehouse 28cfda5440 org.eclipse.jgit.test/BUILD: Format with buildifier
Change-Id: Ia70f2af8f8c7a85f891a1963ab146695262e7ce2
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-07 15:56:05 +09:00
David Pursehouse fcf41731a3 Bazel: Consume versions directly from lib:versions.bzl in skylib
Avoid loading versions from @bazel_skylib//:lib.bzl, because it is now
deprecated and is going to be removed in future skylib versions:

https://github.com/bazelbuild/bazel-skylib/blob/master/lib.bzl#L17

Change-Id: Ie722351de5254f611cf3489c8689922c8346af7f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-07 15:55:35 +09:00
Thomas Wolf cc000f93a8 Factor out a JSch-independent ssh config parser
Move the bulk of the basic parsing and host entry handling into a
new class OpenSshConfigFile that has no dependencies on any concrete
ssh implementation. Make the existing OpenSshConfig use the new
parser.

Introduce a new class SshConstants collecting all the various ssh-
related string literals. Also use TreeMaps with a case-insensitive
key comparator instead of converting keys to uppercase. Add a test
to verify that keys are matched case-insensitively.

Most of the parsing code was simply moved, except that the new
parser supports looking up entries given host name, port, and user
name, and can thus handle more %-substitutions correctly. This
feature is not yet used and cannot be used with JSch since JSch
only has a ConfigRepository.getConfig(String) interface.

The split is still worth the trouble as it opens the way to using
another ssh client altogether. Apache MINA sshd, for instance,
resolves host entries giving host name, port, and user name.

(Apache MINA has a built-in ssh config handling, but that has
problems, too: its pattern matching is case-insensitive, and its
merging of host entries if several match is not the same as in
OpenSsh. But with this refactoring, it will be possible to plug in
OpenSshConfigFile into an Apache MINA sshd  client without dragging
along JSch.)

One test case that doesn't make sense anymore has been removed. It
tested that repeatedly querying for a host entry returned the same
object. That is no longer true since the caching has been moved to
a deeper level.

Bug: 520927
Change-Id: I6381d52b29099595e6eaf8b05c786aeeaefbf9cc
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-06 13:17:22 +01:00
Thomas Wolf 08b0a8632d Ssh tests with an Apache MINA sshd test git server
Add a simple ssh git server based on Apache MINA sshd, and use it
in new tests that verify ssh operations and in particular a number
of bugs that had cropped up over time in JSch.

The git server supports fetching only, and sftp access.

The tests are all in an abstract base class; the concrete JschSshTest
class only provides ssh-specific test setup. So the same tests could
be run easily also with some other ssh client.

Bug: 520927
Change-Id: Ide6687b717fb497a29fc83f22b07390a26dfce1d
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-06 13:17:21 +01:00
David Pursehouse 3ec3ca0f09 Bazel: Format tools/BUILD with buildifier
Change-Id: I292613a0e40d2022bc68c6acbd45d37a54c1e613
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-06 13:50:04 +09:00
David Pursehouse 1cee6c7d51 Merge changes I91883560,I1b12a976
* changes:
  Fix package exports in org.eclipse.jgit MANIFEST.MF
  TransportSftp: remove final modifiers from parameters
2018-11-05 18:24:08 -05:00
Thomas Wolf f8d2738ff4 Fix package exports in org.eclipse.jgit MANIFEST.MF
Do not export o.e.j.internal.transport.parser as public package;
restrict visibility to org.eclipse.jgit.test only.

Add two packages that were not listed at all (o.e.j.internal.revwalk
and o.e.j.internal.submodule) marked as x-internal:=true.

Change-Id: I9188356075515ad354b724102fbd6304b682de6a
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-05 12:56:36 +01:00
Thomas Wolf 2429ea2c41 TransportSftp: remove final modifiers from parameters
Change-Id: I1b12a9765575a1368e0c6bd11d87084b2064a17e
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-05 12:08:55 +01:00
David Pursehouse 797a5b7a8f Upgrade Spotbugs to 3.1.8
Change-Id: Ie283ab9d9925c4eae3fad2a3ad2d94bdcb80f75f
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-05 19:27:08 +09:00
David Pursehouse a6da0591ae Bazel: Add missing test dependency on ObjectIdMatcher
Test plan:

  bazel build //...

Change-Id: I28a8d3cfa54b46b95043ddd7bfdd1412c6b54865
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-11-05 11:20:53 +09:00
Jonathan Nieder 416c40aefc Merge changes from topic 'client-caps-v0-test'
* changes:
  Add test for protocol v0 parser
  ObjectIdMatcher: Custom matcher for sets of ObjectIds
2018-11-02 23:44:14 -04:00
Thomas Wolf bb5180469c Fix test setup for Eclipse Photon and greater
When a source folder is marked as a test folder, JDT requires that it
has an output folder different from the one used for regular sources.
Therefore give the test folders in org.eclipse.jgit.test a separate
output folder "bin-tst".

Moreover JDT reports errors if non-test classes have dependencies on
test classes. Therefore remove the "test" annotation from
org.eclipse.jgit.junit.

Change-Id: Ib527439ff5b7d7b570b8a60819ecaa70f59c63a3
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-02 18:50:26 +01:00
Thomas Wolf 9175099e48 Update JGit target platforms to Orbit I20181102163257
Remove the S20181031145145 Orbit definition; that one was for our
purposes broken (mistakes in the org.apache.sshd-core and
net.i2p.crypto.eddsa receipes).

Change-Id: I8246d0837bc80165dd23780236b58fd9fe2fe0bc
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
2018-11-02 18:50:25 +01:00
David Ostrovsky 9625db20a5 Upgrade to Bazel 0.19.0
Also replace native git_repository rule with Starlark rule. This is
needed because in recent Bazel versions native git_repository rule
is deprecated.

Change-Id: I2c19fd31693a930d7d35fdbb93bfa4abf21fa2aa
Signed-off-by: David Ostrovsky <david@ostrovsky.org>
2018-11-01 23:49:10 +01:00
Matthias Sohn 00472a6d7c Silence API errors introduced by f648a3bd
The removed method and the new interface method only affect implementors
which is ok in a minor release following OSGi semantic versioning.

Change-Id: Ia5e55bd803965c7590c9278eecc6bdd36241383f
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-11-01 20:28:00 +01:00
David Pursehouse 56e74095a2 Merge "Update 2018-12 Orbit repository to S20181031145145" 2018-10-31 21:45:33 -04:00
Ivan Frade e64ce267f8 RepoCommand: Preserve executable bit in <copyfile>
The copyfile entry in the manifest file copies the contents of the file
but doesn't keep the executable flag. This is inconsistent with repo
tool behaviour, plus is natural to expect that the copy of a executable
file is executable.

Transfer the executable bit when copying the file, aligning the
RepoCommand with repo tool and user expectations.

Change-Id: I01b24f482d5939e01d496f032388b3a5c02a912a
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-10-31 16:40:12 -07:00
Ivan Frade f648a3bd81 RepoCommand.RemoteReader: Add method to read contents and mode of file
The RepoCommand.RemoteReader interface doesn't offer access to the mode
of a file. Caller can only default to mark the copied objects as regular
files, losing e.g. the executable bit (if set).

Add a new method readFileWithMode that returns the contents and mode of
the remote file. It supersedes the readFile method, that is marked as
deprecated.

Now callers can set correctly the file mode of the copied file.

Change-Id: I8fce01e4bc5707434c0cbc4aebbae1b6b64756f0
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-10-31 16:40:06 -07:00
Matthias Sohn de37eb3a9d Update 2018-12 Orbit repository to S20181031145145
Add the following new bundles needed for new ssh implementation:
- net.i2p.crypto.eddsa 0.3.0
- net.i2p.crypto.eddsa.source 0.3.0
- org.apache.sshd.core 2.0.0
- org.apache.sshd.core.source 2.0.0
- org.apache.sshd.sftp 2.0.0
- org.apache.sshd.sftp.source 2.0.0

Change-Id: I336166dd71522cc382df2e3efc00e7126d2c0874
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-31 22:48:45 +01:00
Ivan Frade 17dbaa4fdd RepoCommandTest: Extract method to assert file contents
Many tests verify the contents of files in a try-with-resources
incantation that clutters the code.

Extract that verification to an "assertContents" method, that is easier
to read.

Change-Id: If430eac6f5b9ae352e42b2d43867ceb6cd618fbb
Signed-off-by: Ivan Frade <ifrade@google.com>
2018-10-30 13:08:16 -07:00
David Pursehouse d0f44d4396 Merge changes Ice585525,I73474dea
* changes:
  Update staging target platform for eclipse platform 4.10
  New target platform for 4.9
2018-10-29 23:21:07 -04:00
Matthias Sohn a91e934d05 Update staging target platform for eclipse platform 4.10
Change-Id: Ice585525209e20e7d675f24cb751315e18eb375d
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-30 00:29:19 +01:00
Matthias Sohn 7c03521f1a New target platform for 4.9
Change-Id: I73474deaecda4e594e5604213d3ae30c499a2ca7
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-30 00:29:15 +01:00
David Pursehouse a98a6044cf CLIText: Fix typo: remotes's -> remote's
Change-Id: I28494ffff6cd8042ef5f3de7da976d4a1569fe10
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-10-29 17:02:41 +09:00
David Pursehouse 9185ad8d5c CLIText: Fix typo: 'amd' -> 'and'
Change-Id: Ifa48c35f413bd1a92946ea54c1c7adc0d53ebc78
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
2018-10-29 16:56:04 +09:00
Matthias Sohn 6f359c1709 Silence API errors for new methods added to DepthWalk
237abe6a added method getDeepenNots() with a default implementation and
method getDeepenNotFlag() to the interface DepthWalk. This affects
implementers which is ok in minor release following OSGi semantic
versioning.

Change-Id: I1c872da261fc6825e1e310127761b8b8a6d397d4
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-29 00:43:48 +01:00
Matthias Sohn 06bce43338 Remove unused text "symlinkCannotBeWrittenAsTheLinkTarget"
The only reference to this externalized text was deleted in c88d34b0.

Change-Id: Iecc7cc89192d69431dddb6550a02f66f0b09accc
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-28 14:43:38 +01:00
Michael Keppler d9e67c8d8f Fix typos
s/occured/occurred/
s/stablished/established/

Change-Id: Ib052bef60bd18043001a30ed43754ee1a5182016
Signed-off-by: Michael Keppler <Michael.Keppler@gmx.de>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-28 14:41:22 +01:00
Matthias Sohn f9a142939d Update eclipse compiler org.eclipse.jdt:ecj to 3.15.0
Change-Id: Iabca86db71e166e6ce73db2f8ddc5058e58da11a
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
2018-10-28 01:50:46 +02:00