devvthedev commented on issue #532: URL: https://github.com/apache/mina-sshd/issues/532#issuecomment-2314955083
Hi @tomaswolf I've moved to using JGit's own binding to Apache MINA sshd as suggested but have some questions on using the SshdSessionFactoryBuilder. I'm building a SshdSessionFactory where I supply a key pair programmatically (`.setDefaultKeysProvider`). However, the factory builder requires me to set both HomeDirectory and SshDirectory despite the Javadoc stating: `may be null, in which case the home directory as defined by FS.userHome() is assumed` If I pass null or omit these setters from the builder, I get a null pointer exception for both directories: `Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.File.isAbsolute()" because "homeDir" is null` `Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.io.File.isAbsolute()" because "sshDir" is null ` <br> Since I am providing the key pair programatically, I don't want to use the ssh directory on disk. This has led to me having to specify a directory for these: ``` .setHomeDirectory(directory) // Need to set despite Javadoc .setSshDirectory(directory) // Need to set despite Javadoc ``` <br> Full code example setting key and passphrase on builder: ``` String privateKeyContent = "private key contents" String passphrase "private key passphrase contents" Iterable<KeyPair> keyPairs = SecurityUtils.loadKeyPairIdentities(null, null, new ByteArrayInputStream(privateKeyContent.getBytes()), (session, resourceKey, retryIndex) -> passphrase); SshdSessionFactory sshSessionFactory = new SshdSessionFactoryBuilder() .setPreferredAuthentications("publickey") .setDefaultKeysProvider(ignoredSshDirBecauseWeUseAnInMemorySetOfKeyPairs -> keyPairs) .setHomeDirectory(directory) // Need to set despite Javadoc .setSshDirectory(directory) // Need to set despite Javadoc .build(null); ``` I've seen some examples across GitHub where the `directory` specified in `.setHomeDirectory(directory)` and `.setSshDirectory(directory)` is the directory that is being cloned to but I'm not convinced this is the correct approach? e.g. `newSshdSessionFactory` method: https://github.com/thingsboard/thingsboard/blob/02d3382731a5540f60e530f9c9c90a935b131c67/common/version-control/src/main/java/org/thingsboard/server/service/sync/vc/GitRepository.java#L503-L504 where directory is the repository directory: https://github.com/thingsboard/thingsboard/blob/master/common/version-control/src/main/java/org/thingsboard/server/service/sync/vc/DefaultGitRepositoryService.java#L295 What would you suggest here? Is there a way to omit setting the ssh folder and home directory? Should I use a temporary directory instead? Thanks -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@mina.apache.org For additional commands, e-mail: dev-h...@mina.apache.org