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 usingaddPublicKey(PublicKey)
.
-
-
Constructor Summary
Constructors Constructor Description GitSshServer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPublicKey(PublicKey publicKey)
int
getPort()
void
start(Path repositoryRoot)
void
stop()
void
writePrivateKeyAsPkcs8(Path file, String passphrase)
Writes a private key which is accepted by this server to the specified file in PKCS8 format.
-
-
-
Constructor Detail
-
GitSshServer
public GitSshServer() throws GeneralSecurityException
- Throws:
GeneralSecurityException
-
-
Method Detail
-
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 topassphrase
- the passphrase for encryption, or null for unencrypted- Throws:
IOException
- if an I/O error occursGeneralSecurityException
- if a security 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
-
-