public interface HostKeyRepository
The library contains an implementation based on the OpenSSH known Hosts file format - this will be the default implementation if no other is given explicitely.
An application might want to implement this class to provide an alternative repository of valid server keys to use.
Modifier and Type | Field and Description |
---|---|
static int |
CHANGED
Constant for the result of
check(java.lang.String, byte[]) :
The host has another key. |
static int |
NOT_INCLUDED
Constant for the result of
check(java.lang.String, byte[]) :
The host does not exist yet in the list. |
static int |
OK
Constant for the result of
check(java.lang.String, byte[]) :
The host has the given key. |
Modifier and Type | Method and Description |
---|---|
void |
add(HostKey hostkey,
UserInfo ui)
Adds a hostname-key-pair to the repository.
|
int |
check(String host,
byte[] key)
Checks whether some host has a given key.
|
HostKey[] |
getHostKey()
returns all host keys in this repository.
|
HostKey[] |
getHostKey(String host,
String type)
returns all host keys of a certain host.
|
String |
getKnownHostsRepositoryID()
returns an identifier for this repository.
|
void |
remove(String host,
String type)
Removes a host key if there exists mached key with
host , type . |
void |
remove(String host,
String type,
byte[] key)
removes a specific key of a host from the repository.
|
static final int OK
check(java.lang.String, byte[])
:
The host has the given key.static final int NOT_INCLUDED
check(java.lang.String, byte[])
:
The host does not exist yet in the list.static final int CHANGED
check(java.lang.String, byte[])
:
The host has another key. (This could be indicating
a man-in-the-middle attack.)int check(String host, byte[] key)
host
- the host name to checkkey
- the public key the remote host
uses.OK
(this host is known to use
this key), NOT_INCLUDED
(the host is unknown) or
CHANGED
(the host is known to use another key).void add(HostKey hostkey, UserInfo ui)
hostkey
- the key to addui
- an UserInfo object which may be used to ask the
user whether to create the file (and directory), or other
similar questions, if necessary.void remove(String host, String type)
host
, type
.void remove(String host, String type, byte[] key)
host
- the host name whose key is to remove.type
- the type of key to remove. If null, all keys of
this host will be removed (without looking at key
).key
- the key to be removed. If null, all keys of the
given type and host will be removed.NullPointerException
- if host == null
.String getKnownHostsRepositoryID()
This will be used for messages to the user speaking about the repository.
HostKey[] getHostKey()
getHostKey(null,null)
.
This method should have been named getHostKeys()
.HostKey[] getHostKey(String host, String type)
getHostKeys(...)
.host
- a hostname used in searching host keys.
If null
is given, every host key will be listed.type
- a key type used in searching host keys,
and it should be "ssh-dss" or "ssh-rsa".
If null
is given, a key type type will not be ignored.This is a simplified version of the inofficial Javadoc created by PaĆlo Ebermann. Have a look at the official homepage.