Skip to content

Commit

Permalink
executable bndrun, welcomeMessage
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Bischof <[email protected]>
  • Loading branch information
stbischof committed Mar 14, 2021
1 parent 475e402 commit 7a053a2
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package biz.aQute.shell.sshd.config;

public interface Config {

static String banner = "aQute ssh, welcome!";
int getPort();

String getHost();

String getKeyPath();

String getWelcomeBanner();

static Config toConfig(SshdConfigInsecure config) {
return new Config() {

@Override
public int getPort() {
return config.port();
}

@Override
public String getKeyPath() {
return config.hostkey();
}

@Override
public String getHost() {

return "localhost";
}

@Override
public String getWelcomeBanner() {
return config.welcomeBanner();
}
};
}

static Config toConfig(SshdConfig config) {
return new Config() {

@Override
public int getPort() {
return config.port();
}

@Override
public String getKeyPath() {
return config.hostkey();
}

@Override
public String getHost() {

return config.address();
}

@Override
public String getWelcomeBanner() {
return config.welcomeBanner();
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
@ObjectClassDefinition( description = "Configuration for the Gogo SSH interface.")
public @interface SshdConfig {
String PID = "biz.aQute.shell.sshd";
static String PID = "biz.aQute.shell.sshd";

/**
* The port to run on, by default this is {@value}
Expand Down Expand Up @@ -42,4 +42,10 @@
*/
@AttributeDefinition(description = "Permission for a command. The default value is gogo.command:none, this does not allow general commands. Replace `none` with a glob expression for allowable commands")
String permission() default "gogo.command:none";

/**
* WelcomeBanner that would be printed after authentication.
*/
@AttributeDefinition(description = "WelcomeBanner that would be printed after authentication.")
String welcomeBanner() default Config.banner;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
@ObjectClassDefinition(description = "Configuration for the Gogo SSH interface in an insecure mode.")
public @interface SshdConfigInsecure {
String PID = "biz.aQute.shell.sshd.insecure";
static String PID = "biz.aQute.shell.sshd.insecure";

/**
* The port to run on, by default this is {@value}
Expand All @@ -28,12 +28,18 @@
* The only accepted user name
*/
@AttributeDefinition(description = "The only accepted user name")
String user() default "brave";
String user() default "unsafe";

/**
* The only accepted user name. THIS IS NOT SECURE!
* This name starts with full stop. Is is available to the component instance but not available as service properties of the registered service.
*/
@AttributeDefinition(name = ".password", type = AttributeType.PASSWORD, description = "The only accepted password. THIS IS NOT SECURE!")
String password() default "insecure";
String password() default "unsafe";

/**
* WelcomeBanner that would be printed after authentication.
*/
@AttributeDefinition(description = "WelcomeBanner that would be printed after authentication.")
String welcomeBanner() default Config.banner;
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.slf4j.LoggerFactory;

import aQute.lib.io.IO;
import biz.aQute.shell.sshd.config.Config;

abstract class AbstractGogoSshd {
final static Logger logger = LoggerFactory.getLogger("GogoSshd");
Expand All @@ -28,18 +29,23 @@ abstract class AbstractGogoSshd {

volatile int port;

AbstractGogoSshd(BundleContext context, CommandProcessor processor, String keypath, String host, int port)
AbstractGogoSshd(BundleContext context, CommandProcessor processor, Config config )
throws IOException {
this.context = context;
this.processor = processor;
this.sshd = SshServer.setUpDefaultServer();

this.sshd.setPort(port);
this.sshd.setHost(host);
this.sshd.setPort(config.getPort());
this.sshd.setHost(config.getHost());

if(config.getWelcomeBanner()!=null) {
String banner=config.getWelcomeBanner();
sshd.getProperties().put(SshServer.WELCOME_BANNER, banner);
}

this.sshd.setCommandFactory((s, c) -> getCommand(processor));

File keyFile = IO.getFile(keypath);
File keyFile = IO.getFile(config.getKeyPath());
keyFile.getParentFile().mkdirs();
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(keyFile.toPath()));
this.sshd.setShellFactory((ChannelSession channel) -> getCommand(processor));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package biz.aQute.shell.sshd.provider;

import static biz.aQute.shell.sshd.config.Config.toConfig;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -27,7 +29,7 @@ public class GogoSshdInsecure extends AbstractGogoSshd {
@Activate
public GogoSshdInsecure(BundleContext context, @Reference CommandProcessor processor, SshdConfigInsecure config)
throws IOException {
super(context, processor, config.hostkey(), "localhost", config.port());
super(context, processor, toConfig(config));
logger.warn("starting insecure ssh server on port localhost:{}", config.port());

sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package biz.aQute.shell.sshd.provider;

import static biz.aQute.shell.sshd.config.Config.toConfig;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
Expand Down Expand Up @@ -46,7 +48,7 @@ public GogoSshdSecure(BundleContext context, @Reference CommandProcessor process
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY) Authority authority,
@Reference(cardinality = ReferenceCardinality.OPTIONAL, policyOption = ReferencePolicyOption.GREEDY) AuthorityAdmin admin,
SshdConfig config) throws IOException {
super(context, processor, config.hostkey(), config.address(), config.port());
super(context, processor, toConfig(config));
this.authenticator = authenticator;
this.authority = authority;
this.admin = admin;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

-runproperties \
configurator.initial='{ "biz.aQute.authenticator.unsafe":{ "userid":"unsafe", "password":"unsafe"}}', \
biz.aQute.gogo.console=true
configurator.initial='{ ":configurator:version" : "1", ":configurator:symbolic-name":"sn", "biz.aQute.shell.sshd.insecure":{ "port":2222}}'\
biz.aQute.gogo.console=true

-runsystempackages: sun.misc
-runpath: slf4j.api, slf4j.simple
-runrequires: \
Expand All @@ -11,7 +11,8 @@
osgi.identity;filter:='(osgi.identity=org.apache.felix.http.jetty)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.configadmin)',\
osgi.identity;filter:='(osgi.identity=org.apache.felix.metatype)',\
osgi.identity;filter:='(osgi.identity=biz.aQute.gogo.commands.provider)'
osgi.identity;filter:='(osgi.identity=biz.aQute.gogo.commands.provider)',\
bnd.identity;id='org.apache.felix.configurator'
-runfw: org.apache.felix.framework;version='[6.0.2,6.0.2]'
-runee: JavaSE-1.8
-runbundles: \
Expand All @@ -31,4 +32,6 @@
org.apache.felix.inventory;version='[1.0.4,1.0.5)',\
org.apache.felix.webconsole;version='[4.3.8,4.3.9)',\
org.apache.felix.webconsole.plugins.ds;version='[2.1.0,2.1.1)',\
org.apache.felix.metatype;version='[1.2.2,1.2.3)'
org.apache.felix.metatype;version='[1.2.2,1.2.3)',\
org.osgi.service.component;version='[1.4.0,1.4.1)',\
org.apache.felix.configurator;version='[1.0.8,1.0.9)'

0 comments on commit 7a053a2

Please sign in to comment.