From 68c780f2e746eedb714ff6e17c6815fbffddeff6 Mon Sep 17 00:00:00 2001
From: Guillaume Nodet
Date: Fri, 17 Jul 2020 11:33:21 +0200
Subject: [PATCH 1/1] [SSHD-1035] Move property definitions tocommon locations
---
.../java/org/apache/sshd/common/Property.java | 408 +++++++++++
.../sshd/core/CoreModuleProperties.java | 681 ++++++++++++++++++
2 files changed, 1089 insertions(+)
create mode 100644 sshd-common/src/main/java/org/apache/sshd/common/Property.java
create mode 100644 sshd-core/src/main/java/org/apache/sshd/core/CoreModuleProperties.java
diff --git a/sshd-common/src/main/java/org/apache/sshd/common/Property.java b/sshd-common/src/main/java/org/apache/sshd/common/Property.java
new file mode 100644
index 0000000..f5ad335
--- /dev/null
+++ b/sshd-common/src/main/java/org/apache/sshd/common/Property.java
@@ -0,0 +1,408 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common;
+
+import java.nio.charset.Charset;
+import java.time.Duration;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.function.Consumer;
+
+/**
+ * Property definition.
+ *
+ * @author Apache MINA SSHD Project
+ */
+public interface Property {
+
+ static Property string(String name) {
+ return new StringProperty(name);
+ }
+
+ static Property string(String name, String def) {
+ return new StringProperty(name, def);
+ }
+
+ static Property bool(String name) {
+ return new BooleanProperty(name);
+ }
+
+ static Property bool(String name, boolean def) {
+ return new BooleanProperty(name, def);
+ }
+
+ static Property integer(String name) {
+ return new IntProperty(name);
+ }
+
+ static Property integer(String name, int def) {
+ return new IntProperty(name, def);
+ }
+
+ // CHECKSTYLE:OFF
+ static Property long_(String name) {
+ return new LongProperty(name);
+ }
+
+ static Property long_(String name, long def) {
+ return new LongProperty(name, def);
+ }
+
+ static > Property enum_(String name, Class type) {
+ return new EnumProperty<>(name, type);
+ }
+
+ static > Property enum_(String name, Class type, T def) {
+ return new EnumProperty<>(name, type, def);
+ }
+ // CHECKSTYLE:ON
+
+ static Property duration(String name) {
+ return new DurationProperty(name);
+ }
+
+ static Property duration(String name, Duration def) {
+ return new DurationProperty(name, def);
+ }
+
+ static Property durationSec(String name) {
+ return new DurationInSecondsProperty(name);
+ }
+
+ static Property durationSec(String name, Duration def) {
+ return new DurationInSecondsProperty(name, def);
+ }
+
+ static Property charset(String name) {
+ return new CharsetProperty(name);
+ }
+
+ static Property charset(String name, Charset def) {
+ return new CharsetProperty(name, def);
+ }
+
+ static Property
+ *
+ *
+ *
A {@link java.net.URI} or a string starting with "file:/", in which case it will be converted to a
+ * {@link java.nio.file.Path} and handled accordingly.
+ *
+ *
+ *
+ *
A string containing a special value indicator - e.g., {@link #AUTO_WELCOME_BANNER_VALUE}, in which case the
+ * relevant banner content will be generated.
+ *
+ *
+ *
+ *
Any other object whose {@code toString()} value yields a non empty string will be used as the banner
+ * contents.
+ *
+ *
+ *
+ * @see RFC-4252 section 5.4
+ */
+ public static final Property WELCOME_BANNER
+ = Property.object("welcome-banner");
+
+ /**
+ * Special value that can be set for the {@link #WELCOME_BANNER} property indicating that the server should generate
+ * a banner consisting of the random art of the server's keys (if any are provided). If no server keys are
+ * available, then no banner will be sent
+ */
+ public static final String AUTO_WELCOME_BANNER_VALUE = "#auto-welcome-banner";
+
+ /**
+ * Key used to denote the language code for the welcome banner (if such a banner is configured).
+ */
+ public static final Property WELCOME_BANNER_LANGUAGE
+ = Property.string("welcome-banner-language", "en");
+
+ /**
+ * The {@link WelcomeBannerPhase} value - either as an enum or a string
+ */
+ public static final Property WELCOME_BANNER_PHASE
+ = Property.enum_("welcome-banner-phase", WelcomeBannerPhase.class, WelcomeBannerPhase.IMMEDIATE);
+
+ /**
+ * The charset to use if the configured welcome banner points to a file - if not specified (either as a string or a
+ * {@link java.nio.charset.Charset} then the local default is used.
+ */
+ public static final Property WELCOME_BANNER_CHARSET
+ = Property.charset("welcome-banner-charset", Charset.defaultCharset());
+
+ /**
+ * This key is used when configuring multi-step authentications. The value needs to be a blank separated list of
+ * comma separated list of authentication method names. For example, an argument of
+ * publickey,password publickey,keyboard-interactive would require the user to complete public key
+ * authentication, followed by either password or keyboard interactive authentication. Only methods that are next in
+ * one or more lists are offered at each stage, so for this example, it would not be possible to attempt password or
+ * keyboard-interactive authentication before public key.
+ */
+ public static final Property AUTH_METHODS
+ = Property.string("auth-methods");
+
+ /**
+ * Key used to retrieve the value of the maximum concurrent open session count per username. If not set, then
+ * unlimited
+ */
+ public static final Property MAX_CONCURRENT_SESSIONS
+ = Property.integer("max-concurrent-sessions");
+
+ /**
+ * Key used to retrieve any extra lines to be sent during initial protocol handshake before the
+ * identification. The configured string value should use {@value #SERVER_EXTRA_IDENT_LINES_SEPARATOR} character to
+ * denote line breaks
+ */
+ public static final Property SERVER_EXTRA_IDENTIFICATION_LINES
+ = Property.string("server-extra-identification-lines");
+
+ /**
+ * Separator used in the {@link #SERVER_EXTRA_IDENTIFICATION_LINES} configuration string to indicate new line break
+ */
+ public static final char SERVER_EXTRA_IDENT_LINES_SEPARATOR = '|';
+
+ /**
+ * Key used to retrieve the value of the server identification string. If set, then it is appended to the
+ * (standard) "SSH-2.0-" prefix. Otherwise a default is sent that consists of "SSH-2.0-" plus
+ * the current SSHD artifact name and version in uppercase - e.g., "SSH-2.0-APACHE-SSHD-1.0.0"
+ */
+ public static final Property SERVER_IDENTIFICATION
+ = Property.string("server-identification");
+
+ /**
+ * Key used to configure the timeout used when receiving a close request on a channel to wait until the command
+ * cleanly exits after setting an EOF on the input stream.
+ */
+ public static final Property COMMAND_EXIT_TIMEOUT
+ = Property.duration("command-exit-timeout", Duration.ofMillis(5L));
+
+ /**
+ * A URL pointing to the moduli file. If not specified, the default internal file will be used.
+ */
+ public static final Property MODULI_URL
+ = Property.string("moduli-url");
+
+ /**
+ * See {@link org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator}.
+ */
+ public static final Property KB_SERVER_INTERACTIVE_NAME
+ = Property.string("kb-server-interactive-name", "Password authentication");
+
+ /**
+ * See {@link org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator}.
+ */
+ public static final Property KB_SERVER_INTERACTIVE_INSTRUCTION
+ = Property.string("kb-server-interactive-instruction", "");
+
+ /**
+ * See {@link org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator}.
+ */
+ public static final Property KB_SERVER_INTERACTIVE_LANG
+ = Property.string("kb-server-interactive-language", "en-US");
+
+ /**
+ * See {@link org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator}.
+ */
+ public static final Property KB_SERVER_INTERACTIVE_PROMPT
+ = Property.string("kb-server-interactive-prompt", "Password: ");
+
+ /**
+ * See {@link org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator}.
+ */
+ public static final Property KB_SERVER_INTERACTIVE_ECHO_PROMPT
+ = Property.bool("kb-server-interactive-echo-prompt", false);
+
+ /**
+ * Maximum amount of extended (a.k.a. STDERR) data allowed to be accumulated until a {@link ChannelDataReceiver} for
+ * the data is registered
+ */
+ public static final Property MAX_EXTDATA_BUFSIZE
+ = Property.integer("channel-session-max-extdata-bufsize", 0);
+
+ /**
+ * See {@link org.apache.sshd.server.kex.DHGEXServer}.
+ */
+ public static final Property PROP_DHGEX_SERVER_MIN_KEY
+ = Property.integer("dhgex-server-min");
+
+ /**
+ * See {@link org.apache.sshd.server.kex.DHGEXServer}.
+ */
+ public static final Property PROP_DHGEX_SERVER_MAX_KEY
+ = Property.integer("dhgex-server-max");
+ /**
+ * Value used by the {@link org.apache.sshd.server.shell.InvertedShellWrapper} to control the "busy-wait"
+ * sleep time (millis) on the pumping loop if nothing was pumped - must be positive.
+ */
+ public static final Property PUMP_SLEEP_TIME
+ = Property.duration("inverted-shell-wrapper-pump-sleep", Duration.ofMillis(1));
+
+ /**
+ * Value used by the {@link org.apache.sshd.server.shell.InvertedShellWrapper} to control copy buffer size.
+ */
+ public static final Property BUFFER_SIZE
+ = Property.integer("inverted-shell-wrapper-buffer-size", IoUtils.DEFAULT_COPY_SIZE);
+
+ /**
+ * Configuration value for the {@link org.apache.sshd.server.x11.X11ForwardSupport} to control the channel open
+ * timeout.
+ */
+ public static final Property X11_OPEN_TIMEOUT
+ = Property.duration("x11-fwd-open-timeout", Duration.ofSeconds(30L));
+
+ /**
+ * Configuration value for the {@link org.apache.sshd.server.x11.X11ForwardSupport} to control from which X11
+ * display number to start looking for a free value.
+ */
+ public static final Property X11_DISPLAY_OFFSET
+ = Property.integer("x11-fwd-display-offset", 10);
+
+ /**
+ * Configuration value for the {@link org.apache.sshd.server.x11.X11ForwardSupport} to control up to which (but not
+ * including) X11 display number to look or a free value.
+ */
+ public static final Property X11_MAX_DISPLAYS
+ = Property.integer("x11-fwd-max-display", 1000);
+
+ /**
+ * Configuration value for the {@link org.apache.sshd.server.x11.X11ForwardSupport} to control the base port number
+ * for the X11 display number socket binding.
+ */
+ public static final Property X11_BASE_PORT
+ = Property.integer("x11-fwd-base-port", 6000);
+
+ /**
+ * Configuration value for the {@link org.apache.sshd.server.x11.X11ForwardSupport} to control the host used to bind
+ * to for the X11 display when looking for a free port.
+ */
+ public static final Property X11_BIND_HOST
+ = Property.string("x11-fwd-bind-host", SshdSocketAddress.LOCALHOST_IPV4);
+
+ private CoreModuleProperties() {
+ // private
+ }
+
+}
--
2.27.0