Class GitSshServer

java.lang.Object
org.apache.maven.scm.provider.git.GitSshServer

public class GitSshServer extends Object
Local Git SSH server for testing purposes. It acts on top of an existing repository root directory. It uses Apache MINA SSHD for the SSH server implementation.

The server generates a key pair during initialization and accepts connections using the private key which can be extracted via writePrivateKeyAsPkcs8(Path, String). Alternatively one may use a custom key pair and add the public key using addPublicKey(PublicKey).

  • Field Details

    • sshServer

      protected final org.apache.sshd.server.SshServer sshServer
    • keyPair

      protected final KeyPair keyPair
    • acceptedPublicKeys

      protected final List<PublicKey> acceptedPublicKeys
  • Constructor Details

  • Method Details

    • writePrivateKeyAsPkcs8

      public void writePrivateKeyAsPkcs8(Path file, String passphrase) throws IOException, GeneralSecurityException
      Writes a private key which is accepted by this server to the specified file in PKCS8 format. If a passphrase is provided, the key will be encrypted using OpenSSH's format. If no passphrase is provided, the key will be written as an unencrypted PKCS8 private key. For the same server instance the private key is always the same, so it can be reused.
      Parameters:
      file - the file to write the private key to
      passphrase - the passphrase for encryption, or null for unencrypted
      Throws:
      GeneralSecurityException - if a security error occurs
      IOException - if an I/O error occurs
    • addPublicKey

      public void addPublicKey(PublicKey publicKey)
    • getPort

      public int getPort()
    • start

      public void start(Path repositoryRoot) throws IOException
      Throws:
      IOException
    • stop

      public void stop() throws IOException
      Throws:
      IOException