You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SshConstants.java 5.6KB

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>
5 years ago
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>
5 years ago
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>
5 years ago
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>
5 years ago
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>
5 years ago
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>
5 years ago
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>
5 years ago
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>
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * Copyright (C) 2018, 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.transport;
  11. import org.eclipse.jgit.lib.Constants;
  12. /**
  13. * Constants relating to ssh.
  14. *
  15. * @since 5.2
  16. */
  17. @SuppressWarnings("nls")
  18. public final class SshConstants {
  19. private SshConstants() {
  20. // No instances, please.
  21. }
  22. /** IANA assigned port number for ssh. */
  23. public static final int SSH_DEFAULT_PORT = 22;
  24. /** URI scheme for ssh. */
  25. public static final String SSH_SCHEME = "ssh";
  26. /** URI scheme for sftp. */
  27. public static final String SFTP_SCHEME = "sftp";
  28. /** Default name for a ssh directory. */
  29. public static final String SSH_DIR = ".ssh";
  30. /** Name of the ssh config file. */
  31. public static final String CONFIG = Constants.CONFIG;
  32. /** Default name of the user "known hosts" file. */
  33. public static final String KNOWN_HOSTS = "known_hosts";
  34. // Config file keys
  35. /** Key in an ssh config file. */
  36. public static final String BATCH_MODE = "BatchMode";
  37. /** Key in an ssh config file. */
  38. public static final String CANONICAL_DOMAINS = "CanonicalDomains";
  39. /** Key in an ssh config file. */
  40. public static final String CERTIFICATE_FILE = "CertificateFile";
  41. /** Key in an ssh config file. */
  42. public static final String CIPHERS = "Ciphers";
  43. /** Key in an ssh config file. */
  44. public static final String COMPRESSION = "Compression";
  45. /** Key in an ssh config file. */
  46. public static final String CONNECTION_ATTEMPTS = "ConnectionAttempts";
  47. /** Key in an ssh config file. */
  48. public static final String CONTROL_PATH = "ControlPath";
  49. /** Key in an ssh config file. */
  50. public static final String GLOBAL_KNOWN_HOSTS_FILE = "GlobalKnownHostsFile";
  51. /**
  52. * Key in an ssh config file.
  53. *
  54. * @since 5.5
  55. */
  56. public static final String HASH_KNOWN_HOSTS = "HashKnownHosts";
  57. /** Key in an ssh config file. */
  58. public static final String HOST = "Host";
  59. /** Key in an ssh config file. */
  60. public static final String HOST_KEY_ALGORITHMS = "HostKeyAlgorithms";
  61. /** Key in an ssh config file. */
  62. public static final String HOST_NAME = "HostName";
  63. /** Key in an ssh config file. */
  64. public static final String IDENTITIES_ONLY = "IdentitiesOnly";
  65. /** Key in an ssh config file. */
  66. public static final String IDENTITY_AGENT = "IdentityAgent";
  67. /** Key in an ssh config file. */
  68. public static final String IDENTITY_FILE = "IdentityFile";
  69. /** Key in an ssh config file. */
  70. public static final String KEX_ALGORITHMS = "KexAlgorithms";
  71. /** Key in an ssh config file. */
  72. public static final String LOCAL_COMMAND = "LocalCommand";
  73. /** Key in an ssh config file. */
  74. public static final String LOCAL_FORWARD = "LocalForward";
  75. /** Key in an ssh config file. */
  76. public static final String MACS = "MACs";
  77. /** Key in an ssh config file. */
  78. public static final String NUMBER_OF_PASSWORD_PROMPTS = "NumberOfPasswordPrompts";
  79. /** Key in an ssh config file. */
  80. public static final String PORT = "Port";
  81. /** Key in an ssh config file. */
  82. public static final String PREFERRED_AUTHENTICATIONS = "PreferredAuthentications";
  83. /**
  84. * Key in an ssh config file; defines signature algorithms for public key
  85. * authentication as a comma-separated list.
  86. *
  87. * @since 5.11
  88. */
  89. public static final String PUBKEY_ACCEPTED_ALGORITHMS = "PubkeyAcceptedAlgorithms";
  90. /** Key in an ssh config file. */
  91. public static final String PROXY_COMMAND = "ProxyCommand";
  92. /**
  93. * Comma-separated list of jump hosts, defining a jump host chain <em>in
  94. * reverse order</em>. Each jump host is a SSH URI or "[user@]host[:port]".
  95. * <p>
  96. * Reverse order means: to connect A->B->target, one can do in
  97. * {@code ~/.ssh/config} either of:
  98. * </p>
  99. *
  100. * <pre>
  101. * Host target
  102. * ProxyJump B,A
  103. * </pre>
  104. * <p>
  105. * <em>or</em>
  106. * </p>
  107. *
  108. * <pre>
  109. * Host target
  110. * ProxyJump B
  111. *
  112. * Host B
  113. * ProxyJump A
  114. * </pre>
  115. *
  116. * @since 5.10
  117. */
  118. public static final String PROXY_JUMP = "ProxyJump";
  119. /** Key in an ssh config file. */
  120. public static final String REMOTE_COMMAND = "RemoteCommand";
  121. /** Key in an ssh config file. */
  122. public static final String REMOTE_FORWARD = "RemoteForward";
  123. /** Key in an ssh config file. */
  124. public static final String SEND_ENV = "SendEnv";
  125. /** Key in an ssh config file. */
  126. public static final String STRICT_HOST_KEY_CHECKING = "StrictHostKeyChecking";
  127. /** Key in an ssh config file. */
  128. public static final String USER = "User";
  129. /** Key in an ssh config file. */
  130. public static final String USER_KNOWN_HOSTS_FILE = "UserKnownHostsFile";
  131. // Values
  132. /** Flag value. */
  133. public static final String YES = "yes";
  134. /** Flag value. */
  135. public static final String ON = "on";
  136. /** Flag value. */
  137. public static final String TRUE = "true";
  138. /** Flag value. */
  139. public static final String NO = "no";
  140. /** Flag value. */
  141. public static final String OFF = "off";
  142. /** Flag value. */
  143. public static final String FALSE = "false";
  144. // Default identity file names
  145. /** Name of the default RSA private identity file. */
  146. public static final String ID_RSA = "id_rsa";
  147. /** Name of the default DSA private identity file. */
  148. public static final String ID_DSA = "id_dsa";
  149. /** Name of the default ECDSA private identity file. */
  150. public static final String ID_ECDSA = "id_ecdsa";
  151. /** Name of the default ECDSA private identity file. */
  152. public static final String ID_ED25519 = "id_ed25519";
  153. /** All known default identity file names. */
  154. public static final String[] DEFAULT_IDENTITIES = { //
  155. ID_RSA, ID_DSA, ID_ECDSA, ID_ED25519
  156. };
  157. }