- File privateKeyFile = new File(path);
- String privateKeyPEMString = null;
- if (privateKeyFile.exists() == false) {
- try {
- privateKeyPEMString = PEMGenerator.generateTo(privateKeyFile);
- } catch (Exception e) {
- logger.error("Exception occurred while generating PEM string {}",e);
- }
- } else {
- // read from file
- try (FileInputStream fis = new FileInputStream(path)) {
- privateKeyPEMString = IOUtils.toString(fis);
- } catch (IOException e) {
- logger.error("Error reading RSA key from file '{}'", path);
- throw new IllegalStateException("Error reading RSA key from file " + path);
- }
- }
- AuthProvider authProvider = null;
- try {
- this.defaultPassword = NetconfConfigUtil.getSSHDefaultPassword(context);
- this.defaultUser = NetconfConfigUtil.getSSHDefaultUser(context);
- // Since there is no user data store yet (ldap, ...) this adds default user/password to UserManager
- // if these parameters are set in netconf configuration file.
- if (defaultUser.isPresent() &&
- defaultPassword.isPresent()){
- logger.trace(String.format("Default username and password for netconf ssh bridge found. Adding user %s to user manager.",defaultUser.get()));
- List<String> roles = new ArrayList<String>(1);
- roles.add(UserLevel.SYSTEMADMIN.toString());
- iUserManager.addLocalUser(new UserConfig(defaultUser.get(), defaultPassword.get(), roles));
- }
- authProvider = new AuthProvider(iUserManager, privateKeyPEMString);
- } catch (Exception e) {
- logger.error("Error instantiating AuthProvider {}",e);
- }
- this.server = NetconfSSHServer.start(sshSocketAddressOptional.get().getPort(),tcpSocketAddress,authProvider);
-
- Thread serverThread = new Thread(server,"netconf SSH server thread");
- serverThread.setDaemon(true);
- serverThread.start();
- logger.trace("Netconf SSH bridge up and running.");
- } else {
- logger.trace("No valid connection configuration for SSH bridge found.");
- throw new IllegalStateException("No valid connection configuration for SSH bridge found.");