|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.maverick.ssh.PublicKeyAuthentication
Public key based authentication implementation. Public-key authentication uses public-key cryptography to verify the client's identity. To access an account on an SSH server machine, the client proves that it possesses a secret key. A key is authorized if its public component is contained in the accounts authorization file (typically ~/.ssh/authorized_keys).
This class implements a basic publickey SshAuthentication that can be passed into the SshClient to authenticate. As a username is required to establish a connection it is not required that it be set on the authentication object, however if you wish to change the username you can do so (this may not be allowed by some server implementations).
First you need to load a public/private key pair; a set of utility classes based on the SSHTools public key formats is available in the com.sshtools.publickey package. These currently provide for the reading of SSHTools, OpenSSH and SSH1 private keys.
FileInputStream in = new FileInputStream("someprivatekey"); ByteArrayOutputStream out = new ByteArrayOutputStream(); int read; while((read = in.read()) > -1) out.write(read); in.close(); SshPrivateKeyFile pkf = SshPrivateKeyFileFactory.parse(out.toByteArray()); SshKeyPair pair = pkf.toKeyPair("mypassphrase"); PublicKeyAuthentication pk = new PublicKeyAuthentication(); pk.setPrivateKey(pair.getPrivateKey()); pk.setPublicKey(pair.getPublicKey()); if(ssh.authenticate(pk)==SshAuthentication.COMPLETE) System.out.println("Authentication completed");
Field Summary |
Fields inherited from interface com.maverick.ssh.SshAuthentication |
CANCELLED, COMPLETE, FAILED, FURTHER_AUTHENTICATION_REQUIRED, PUBLIC_KEY_ACCEPTABLE |
Constructor Summary | |
PublicKeyAuthentication()
|
Method Summary | |
java.lang.String |
getMethod()
The SSH authentication method name |
SshPrivateKey |
getPrivateKey()
Get the private key for this authentication. |
SshPublicKey |
getPublicKey()
Get the public key for this authentication. |
java.lang.String |
getUsername()
Get the username for this authentication attempt. |
boolean |
isAuthenticating()
Is the authentication attempt actually going to perform an authentication or are we simply just checking the suitability of a public key. |
void |
setAuthenticating(boolean authenticating)
If true the authentication will proceed as normal and the result will either be a success or failure. |
void |
setPrivateKey(SshPrivateKey privatekey)
Set the private key for this authentication. |
void |
setPublicKey(SshPublicKey publickey)
Set the public key for this authentication. |
void |
setUsername(java.lang.String username)
Set the username for this authentication attempt. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public PublicKeyAuthentication()
Method Detail |
public void setUsername(java.lang.String username)
SshAuthentication
setUsername
in interface SshAuthentication
username
- public java.lang.String getUsername()
SshAuthentication
getUsername
in interface SshAuthentication
public void setPrivateKey(SshPrivateKey privatekey)
privatekey
- public java.lang.String getMethod()
SshAuthentication
getMethod
in interface SshAuthentication
public SshPrivateKey getPrivateKey()
public void setPublicKey(SshPublicKey publickey)
publickey
- public SshPublicKey getPublicKey()
public void setAuthenticating(boolean authenticating)
authenticating
- public boolean isAuthenticating()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |