Top Description Fields Constructors Methods
org.apache.sshd.client.config.keys

public final Class ClientIdentity

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.file.Files, .LinkOption, .Path, java.security.GeneralSecurityException, .KeyPair, java.util.Collection, .Collections, .Map, .TreeMap, java.util.function.Function, org.apache.sshd.common.NamedResource, org.apache.sshd.common.config.keys.BuiltinIdentities, .FilePasswordProvider, .IdentityUtils, .KeyUtils, .PublicKeyEntry, org.apache.sshd.common.keyprovider.KeyPairProvider, org.apache.sshd.common.session.SessionContext, org.apache.sshd.common.util.GenericUtils, .ValidateUtils, org.apache.sshd.common.util.io.FileInfoExtractor, .IoUtils

Provides keys loading capability from the user's keys folder - e.g., id_rsa
Author
Apache MINA SSHD Project
See Also
org.apache.sshd.common.util.security.SecurityUtils#getKeyPairResourceParser()

Field Summary

Modifier and TypeField and Description
public static final String
public static final String
public static final Function<String, String>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static String
public static String

Returns:

The matching file name for the identity - null if no name
getIdentityFileName
(String
The identity type - e.g., rsa - ignored if null/empty
type
)

public static String

Returns:

The identity type - null if cannot determine it - e.g., does not start with the ID_FILE_PREFIX
getIdentityType
(String
The file name - ignored if null/empty
name
)

public static Map<String, KeyPair>

Returns:

A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity
loadDefaultIdentities
(boolean
If true then files that do not have the required access rights are excluded from consideration
strict
,
FilePasswordProvider
A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
provider
,
LinkOption...
The LinkOptions to apply when checking for existence
options
)

public static Map<String, KeyPair>

Returns:

A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity
loadDefaultIdentities
(Path
The folder to scan for the built-in identities
dir
,
boolean
If true then files that do not have the required access rights are excluded from consideration
strict
,
FilePasswordProvider
A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
provider
,
LinkOption...
The LinkOptions to apply when checking for existence
options
)

public static KeyPairProvider

Returns:

A KeyPair for the identities - null if no identities available (e.g., after filtering unsupported ones or strict permissions)
loadDefaultKeyPairProvider
(boolean
If true then files that do not have the required access rights are excluded from consideration
strict
,
boolean
If true then ignore identities that are not supported internally
supportedOnly
,
FilePasswordProvider
A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
provider
,
LinkOption...
The LinkOptions to apply when checking for existence
options
)

public static KeyPairProvider

Returns:

A KeyPair for the identities - null if no identities available (e.g., after filtering unsupported ones or strict permissions)
loadDefaultKeyPairProvider
(Path
The folder to scan for the built-in identities
dir
,
boolean
If true then files that do not have the required access rights are excluded from consideration
strict
,
boolean
If true then ignore identities that are not supported internally
supportedOnly
,
FilePasswordProvider
A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
provider
,
LinkOption...
The LinkOptions to apply when checking for existence
options
)

public static Map<String, KeyPair>

Returns:

A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity
loadIdentities
(SessionContext
The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
session
,
Path
The Path of the folder to scan - ignored if not exists
dir
,
boolean
If true then files that do not have the required access rights are excluded from consideration
strict
,
Collection<String>
The identity types - ignored if null/empty
types
,
Function<? super String, String>
A Function to derive the file name holding the specified type
idGenerator
,
FilePasswordProvider
A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded
provider
,
LinkOption...
The LinkOptions to apply when checking for existence
options
)

Scans a folder and loads all available identity files

public static Map<String, Path>

Returns:

A Map of the found files where key=identity type (case insensitive), value=the Path of the file holding the key
scanIdentitiesFolder
(Path
The Path of the folder to scan - ignored if not exists
dir
,
boolean
If true then files that do not have the required access rights are excluded from consideration
strict
,
Collection<String>
The identity types - ignored if null/empty
types
,
Function<? super String, String>
A Function to derive the file name holding the specified type
idGenerator
,
LinkOption...
The LinkOptions to apply when checking for existence
options
)

Scans a folder for possible identity files

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ID_FILE_PREFIXback to summary
public static final String ID_FILE_PREFIX
ID_FILE_SUFFIXback to summary
public static final String ID_FILE_SUFFIX
ID_GENERATORback to summary
public static final Function<String, String> ID_GENERATOR

Constructor Detail

ClientIdentityback to summary
private ClientIdentity()

Method Detail

getIdentityFileNameback to summary
public static String getIdentityFileName(NamedResource r)
getIdentityFileNameback to summary
public static String getIdentityFileName(String type)
Parameters
type:String

The identity type - e.g., rsa - ignored if null/empty

Returns:String

The matching file name for the identity - null if no name

See Also
ID_FILE_PREFIX, ID_FILE_SUFFIX, IdentityUtils#getIdentityFileName(String, String, String)
getIdentityTypeback to summary
public static String getIdentityType(String name)
Parameters
name:String

The file name - ignored if null/empty

Returns:String

The identity type - null if cannot determine it - e.g., does not start with the ID_FILE_PREFIX

loadDefaultIdentitiesback to summary
public static Map<String, KeyPair> loadDefaultIdentities(boolean strict, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException
Parameters
strict:boolean

If true then files that do not have the required access rights are excluded from consideration

provider:FilePasswordProvider

A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded

options:LinkOption[]

The LinkOptions to apply when checking for existence

Returns:Map<String, KeyPair>

A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity

Exceptions
IOException:
If failed to access the file system
GeneralSecurityException:
If failed to load the keys
See Also
PublicKeyEntry#getDefaultKeysFolderPath(), loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...)
loadDefaultIdentitiesback to summary
public static Map<String, KeyPair> loadDefaultIdentities(Path dir, boolean strict, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException
Parameters
dir:Path

The folder to scan for the built-in identities

strict:boolean

If true then files that do not have the required access rights are excluded from consideration

provider:FilePasswordProvider

A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded

options:LinkOption[]

The LinkOptions to apply when checking for existence

Returns:Map<String, KeyPair>

A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity

Exceptions
IOException:
If failed to access the file system
GeneralSecurityException:
If failed to load the keys
See Also
BuiltinIdentities
loadDefaultKeyPairProviderback to summary
public static KeyPairProvider loadDefaultKeyPairProvider(boolean strict, boolean supportedOnly, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException
Parameters
strict:boolean

If true then files that do not have the required access rights are excluded from consideration

supportedOnly:boolean

If true then ignore identities that are not supported internally

provider:FilePasswordProvider

A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded

options:LinkOption[]

The LinkOptions to apply when checking for existence

Returns:KeyPairProvider

A KeyPair for the identities - null if no identities available (e.g., after filtering unsupported ones or strict permissions)

Exceptions
IOException:
If failed to access the file system
GeneralSecurityException:
If failed to load the keys
See Also
PublicKeyEntry#getDefaultKeysFolderPath(), loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...)
loadDefaultKeyPairProviderback to summary
public static KeyPairProvider loadDefaultKeyPairProvider(Path dir, boolean strict, boolean supportedOnly, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException
Parameters
dir:Path

The folder to scan for the built-in identities

strict:boolean

If true then files that do not have the required access rights are excluded from consideration

supportedOnly:boolean

If true then ignore identities that are not supported internally

provider:FilePasswordProvider

A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded

options:LinkOption[]

The LinkOptions to apply when checking for existence

Returns:KeyPairProvider

A KeyPair for the identities - null if no identities available (e.g., after filtering unsupported ones or strict permissions)

Exceptions
IOException:
If failed to access the file system
GeneralSecurityException:
If failed to load the keys
See Also
loadDefaultIdentities(Path, boolean, FilePasswordProvider, LinkOption...), IdentityUtils#createKeyPairProvider(Map, boolean)
loadIdentitiesback to summary
public static Map<String, KeyPair> loadIdentities(SessionContext session, Path dir, boolean strict, Collection<String> types, Function<? super String, String> idGenerator, FilePasswordProvider provider, LinkOption... options) throws IOException, GeneralSecurityException

Scans a folder and loads all available identity files

Parameters
session:SessionContext

The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).

dir:Path

The Path of the folder to scan - ignored if not exists

strict:boolean

If true then files that do not have the required access rights are excluded from consideration

types:Collection<String>

The identity types - ignored if null/empty

idGenerator:Function<? super String, String>

A Function to derive the file name holding the specified type

provider:FilePasswordProvider

A FilePasswordProvider - may be null if the loaded keys are guaranteed not to be encrypted. The argument to FilePasswordProvider#getPassword is the path of the file whose key is to be loaded

options:LinkOption[]

The LinkOptions to apply when checking for existence

Returns:Map<String, KeyPair>

A Map of the found files where key=identity type (case insensitive), value=the KeyPair of the identity

Exceptions
IOException:
If failed to access the file system
GeneralSecurityException:
If failed to load the keys
scanIdentitiesFolderback to summary
public static Map<String, Path> scanIdentitiesFolder(Path dir, boolean strict, Collection<String> types, Function<? super String, String> idGenerator, LinkOption... options) throws IOException

Scans a folder for possible identity files

Parameters
dir:Path

The Path of the folder to scan - ignored if not exists

strict:boolean

If true then files that do not have the required access rights are excluded from consideration

types:Collection<String>

The identity types - ignored if null/empty

idGenerator:Function<? super String, String>

A Function to derive the file name holding the specified type

options:LinkOption[]

The LinkOptions to apply when checking for existence

Returns:Map<String, Path>

A Map of the found files where key=identity type (case insensitive), value=the Path of the file holding the key

Exceptions
IOException:
If failed to access the file system
See Also
KeyUtils#validateStrictKeyFilePermissions(Path, LinkOption...)