Top Description Inners Fields Constructors Methods
org.apache.sshd.common.config.keys

public Class PublicKeyEntry

extends Object
implements Serializable, KeyTypeIndicator
Class Inheritance
All Implemented Interfaces
org.apache.sshd.common.keyprovider.KeyTypeIndicator, java.io.Serializable
Known Direct Subclasses
org.apache.sshd.common.config.keys.AuthorizedKeyEntry
Imports
java.io.ByteArrayOutputStream, .IOException, .Serializable, .StreamCorruptedException, java.nio.file.Path, java.security.GeneralSecurityException, .PublicKey, java.security.spec.InvalidKeySpecException, java.util.ArrayList, .Arrays, .Collection, .Collections, .List, .Map, .NavigableMap, .Objects, .TreeMap, org.apache.sshd.common.keyprovider.KeyTypeIndicator, org.apache.sshd.common.session.SessionContext, org.apache.sshd.common.util.GenericUtils, .NumberUtils, .ValidateUtils, org.apache.sshd.common.util.io.PathUtils

Represents a PublicKey whose data is formatted according to the OpenSSH format:
<key-type> <base64-encoded-public-key-data>
Author
Apache MINA SSHD Project

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public static final char
COMMENT_CHAR

Character used to denote a comment line in the keys file

private static final NavigableMap<String, PublicKeyEntryDataResolver>
private byte[]
private PublicKeyEntryDataResolver
private String
public static final String
PUBKEY_FILE_SUFFIX

Standard suffix for SSH public key files

private static final long
public static final String
STD_KEYFILE_FOLDER_NAME

Standard folder name used by OpenSSH to hold key files

Constructor Summary

AccessConstructor and Description
public
public
PublicKeyEntry(String keyType, byte... keyData)

Method Summary

Modifier and TypeMethod and Description
public PublicKey

Returns:

The PublicKey or null if could not resolve it
appendPublicKey
(SessionContext
The SessionContext for invoking this command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
session
,
Appendable
The Appendable instance to encode the data into
sb
,
PublicKeyEntryResolver
The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.
fallbackResolver
)

public static <
The generic appendable class
A extends Appendable
>
A

Returns:

The updated appendable instance
appendPublicKeyEntry
(A
The Appendable instance to encode the data into
sb
,
PublicKey
The PublicKey - ignored if null
key
)

Encodes a public key data the same way as the parsePublicKeyEntry(String) expects it

public static <
The generic appendable class
A extends Appendable
>
A

Returns:

The updated appendable instance
appendPublicKeyEntry
(A
The Appendable instance to encode the data into
sb
,
PublicKey
The PublicKey - ignored if null
key
,
PublicKeyEntryDataResolver
The PublicKeyEntryDataResolver to use in order to encode the key data bytes into a string representation - if null then one is automatically resolved
encoder
)

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public static Path

Returns:

The default OpenSSH folder used to hold key files - e.g., known_hosts, authorized_keys, etc.
getDefaultKeysFolderPath
()

public byte[]
public static PublicKeyEntryDataResolver

Returns:

The registered resolver instance - null if none was registered
getKeyDataEntryResolver
(String
The key-type value (case insensitive) that may have been previously registered - e.g., "ssh-rsa", "pgp-sign-dss", etc.
keyType
)

public PublicKeyEntryDataResolver
public String
public static NavigableMap<String, PublicKeyEntryDataResolver>

Returns:

A snapshot of the currently registered specialized PublicKeyEntryDataResolver-s, where key=the key-type value (case insensitive) - e.g., "ssh-rsa", "pgp-sign-dss", etc., value=the associated PublicKeyEntryDataResolver for the key type
getRegisteredKeyDataEntryResolvers
()

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

protected boolean
public static PublicKeyEntry

Returns:

A PublicKeyEntry or null if no data
parsePublicKeyEntry
(String
Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty
encData
)

public static PublicKeyEntry

Returns:

A PublicKeyEntry or null if no data
parsePublicKeyEntry
(String
Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty
encData
,
PublicKeyEntryDataResolver
The PublicKeyEntryDataResolver to use in order to decode the key data string into its bytes - if null then one is automatically resolved
decoder
)

public static <
The generic entry type
E extends PublicKeyEntry
>
E

Returns:

The updated entry instance
parsePublicKeyEntry
(E
The PublicKeyEntry whose contents are to be updated - ignored if null
entry
,
String
Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty
encData
)

public static <
The generic entry type
E extends PublicKeyEntry
>
E

Returns:

The updated entry instance
parsePublicKeyEntry
(E
The PublicKeyEntry whose contents are to be updated - ignored if null
entry
,
String
Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty
encData
,
PublicKeyEntryDataResolver
The PublicKeyEntryDataResolver to use in order to decode the key data string into its bytes - if null then one is automatically resolved
decoder
)

public static void
registerKeyDataEntryResolver(String
The key-type value (case insensitive) that will trigger the usage of this decoder - e.g., "ssh-rsa", "pgp-sign-dss", etc.
keyType
,
PublicKeyEntryDataResolver
The decoder to use
resolver
)

Registers a specialized decoder for the public key entry data bytes instead of the default one.

public static PublicKeyEntryDataResolver

Returns:

If a specific resolver has been previously registered then uses it, otherwise the default one.
resolveKeyDataEntryResolver
(String
keyType The key-type value (case insensitive) whose data is to be resolved - e.g., "ssh-rsa", "pgp-sign-dss", etc.
keyType
)

public PublicKey

Returns:

The resolved PublicKey - or null if could not be resolved

Note

may be called only after key type and data bytes have been set or exception(s) may be thrown

resolvePublicKey
(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
,
Map<String, String>
Any headers that may have been available when data was read
headers
,
PublicKeyEntryResolver
The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.
fallbackResolver
)

public static List<PublicKey>

Returns:

The List of all PublicKey-s that have been resolved
resolvePublicKeyEntries
(SessionContext
The SessionContext for invoking this command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
session
,
Collection<? extends PublicKeyEntry>
The entries to convert - ignored if null/empty
entries
,
PublicKeyEntryResolver
The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.
fallbackResolver
)

public PublicKeyEntryDataResolver

Returns:

The resolved instance
resolvePublicKeyEntryDataResolver
()

If a PublicKeyEntryDataResolver has been set, then uses it - otherwise uses the default one.

public void
setKeyData(byte[] value)

public void
public void
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

public static String

Returns:

The OpenSSH encoded data
toString
(PublicKey key)

public static String

Returns:

The OpenSSH encoded data
toString
(PublicKey key, PublicKeyEntryDataResolver
The PublicKeyEntryDataResolver to use in order to encode the key data bytes into a string representation - if null then one is automatically resolved
encoder
)

public static PublicKeyEntryDataResolver

Returns:

The un-registered resolver instance - null if none was registered
unregisterKeyDataEntryResolver
(String
The key-type value (case insensitive) that may have been previously registered - e.g., "ssh-rsa", "pgp-sign-dss", etc.
keyType
)

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

COMMENT_CHARback to summary
public static final char COMMENT_CHAR

Character used to denote a comment line in the keys file

KEY_DATA_RESOLVERSback to summary
private static final NavigableMap<String, PublicKeyEntryDataResolver> KEY_DATA_RESOLVERS
keyDataback to summary
private byte[] keyData
keyDataResolverback to summary
private PublicKeyEntryDataResolver keyDataResolver
keyTypeback to summary
private String keyType
PUBKEY_FILE_SUFFIXback to summary
public static final String PUBKEY_FILE_SUFFIX

Standard suffix for SSH public key files

serialVersionUIDback to summary
private static final long serialVersionUID
STD_KEYFILE_FOLDER_NAMEback to summary
public static final String STD_KEYFILE_FOLDER_NAME

Standard folder name used by OpenSSH to hold key files

Constructor Detail

PublicKeyEntryback to summary
public PublicKeyEntry()
PublicKeyEntryback to summary
public PublicKeyEntry(String keyType, byte... keyData)

Method Detail

appendPublicKeyback to summary
public PublicKey appendPublicKey(SessionContext session, Appendable sb, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
Parameters
session:SessionContext

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

sb:Appendable

The Appendable instance to encode the data into

fallbackResolver:PublicKeyEntryResolver

The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.

Returns:PublicKey

The PublicKey or null if could not resolve it

Exceptions
IOException:
If failed to decode/encode the key
GeneralSecurityException:
If failed to generate the key
See Also
resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
appendPublicKeyEntryback to summary
public static <A extends Appendable> A appendPublicKeyEntry(A sb, PublicKey key) throws IOException

Encodes a public key data the same way as the parsePublicKeyEntry(String) expects it

Parameters
<A>
The generic appendable class
sb:A

The Appendable instance to encode the data into

key:PublicKey

The PublicKey - ignored if null

Returns:A

The updated appendable instance

Exceptions
IOException:
If failed to append the data
See Also
appendPublicKeyEntry(Appendable, PublicKey, PublicKeyEntryDataResolver)
appendPublicKeyEntryback to summary
public static <A extends Appendable> A appendPublicKeyEntry(A sb, PublicKey key, PublicKeyEntryDataResolver encoder) throws IOException
Parameters
<A>
The generic appendable class
sb:A

The Appendable instance to encode the data into

key:PublicKey

The PublicKey - ignored if null

encoder:PublicKeyEntryDataResolver

The PublicKeyEntryDataResolver to use in order to encode the key data bytes into a string representation - if null then one is automatically resolved

Returns:A

The updated appendable instance

Exceptions
IOException:
If failed to append the data
equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getDefaultKeysFolderPathback to summary
public static Path getDefaultKeysFolderPath()
Returns:Path

The default OpenSSH folder used to hold key files - e.g., known_hosts, authorized_keys, etc.

Annotations
@SuppressWarnings:synthetic-access
getKeyDataback to summary
public byte[] getKeyData()
getKeyDataEntryResolverback to summary
public static PublicKeyEntryDataResolver getKeyDataEntryResolver(String keyType)
Parameters
keyType:String

The key-type value (case insensitive) that may have been previously registered - e.g., "ssh-rsa", "pgp-sign-dss", etc.

Returns:PublicKeyEntryDataResolver

The registered resolver instance - null if none was registered

getKeyDataResolverback to summary
public PublicKeyEntryDataResolver getKeyDataResolver()
getKeyTypeback to summary
public String getKeyType()

Implements org.apache.sshd.common.keyprovider.KeyTypeIndicator.getKeyType.

Returns:String

Doc from org.apache.sshd.common.keyprovider.KeyTypeIndicator.getKeyType.

The SSH key type name - e.g., "ssh-rsa", "sshd-dss" etc.

Annotations
@Override
getRegisteredKeyDataEntryResolversback to summary
public static NavigableMap<String, PublicKeyEntryDataResolver> getRegisteredKeyDataEntryResolvers()
Returns:NavigableMap<String, PublicKeyEntryDataResolver>

A snapshot of the currently registered specialized PublicKeyEntryDataResolver-s, where key=the key-type value (case insensitive) - e.g., "ssh-rsa", "pgp-sign-dss", etc., value=the associated PublicKeyEntryDataResolver for the key type

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
isEquivalentback to summary
protected boolean isEquivalent(PublicKeyEntry e)
parsePublicKeyEntryback to summary
public static PublicKeyEntry parsePublicKeyEntry(String encData) throws IllegalArgumentException
Parameters
encData:String

Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty

Returns:PublicKeyEntry

A PublicKeyEntry or null if no data

Exceptions
IllegalArgumentException:
if bad format found
See Also
parsePublicKeyEntry(String, PublicKeyEntryDataResolver)
parsePublicKeyEntryback to summary
public static PublicKeyEntry parsePublicKeyEntry(String encData, PublicKeyEntryDataResolver decoder) throws IllegalArgumentException
Parameters
encData:String

Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty

decoder:PublicKeyEntryDataResolver

The PublicKeyEntryDataResolver to use in order to decode the key data string into its bytes - if null then one is automatically resolved

Returns:PublicKeyEntry

A PublicKeyEntry or null if no data

Exceptions
IllegalArgumentException:
if bad format found
See Also
parsePublicKeyEntry(PublicKeyEntry, String, PublicKeyEntryDataResolver)
parsePublicKeyEntryback to summary
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, String encData) throws IllegalArgumentException
Parameters
<E>
The generic entry type
entry:E

The PublicKeyEntry whose contents are to be updated - ignored if null

encData:String

Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty

Returns:E

The updated entry instance

Exceptions
IllegalArgumentException:
if bad format found
See Also
parsePublicKeyEntry(PublicKeyEntry, String, PublicKeyEntryDataResolver)
parsePublicKeyEntryback to summary
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, String encData, PublicKeyEntryDataResolver decoder) throws IllegalArgumentException
Parameters
<E>
The generic entry type
entry:E

The PublicKeyEntry whose contents are to be updated - ignored if null

encData:String

Assumed to contain at least key-type base64-data (anything beyond the BASE64 data is ignored) - ignored if null/empty

decoder:PublicKeyEntryDataResolver

The PublicKeyEntryDataResolver to use in order to decode the key data string into its bytes - if null then one is automatically resolved

Returns:E

The updated entry instance

Exceptions
IllegalArgumentException:
if bad format found
registerKeyDataEntryResolverback to summary
public static void registerKeyDataEntryResolver(String keyType, PublicKeyEntryDataResolver resolver)

Registers a specialized decoder for the public key entry data bytes instead of the default one.

Parameters
keyType:String

The key-type value (case insensitive) that will trigger the usage of this decoder - e.g., "ssh-rsa", "pgp-sign-dss", etc.

resolver:PublicKeyEntryDataResolver

The decoder to use

resolveKeyDataEntryResolverback to summary
public static PublicKeyEntryDataResolver resolveKeyDataEntryResolver(String keyType)
Parameters
keyType:String

keyType The key-type value (case insensitive) whose data is to be resolved - e.g., "ssh-rsa", "pgp-sign-dss", etc.

Returns:PublicKeyEntryDataResolver

If a specific resolver has been previously registered then uses it, otherwise the default one.

resolvePublicKeyback to summary
public PublicKey resolvePublicKey(SessionContext session, Map<String, String> headers, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
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).

headers:Map<String, String>

Any headers that may have been available when data was read

fallbackResolver:PublicKeyEntryResolver

The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.

Returns:PublicKey

The resolved PublicKey - or null if could not be resolved

Note

may be called only after key type and data bytes have been set or exception(s) may be thrown

Exceptions
IOException:
If failed to decode the key
GeneralSecurityException:
If failed to generate the key
resolvePublicKeyEntriesback to summary
public static List<PublicKey> resolvePublicKeyEntries(SessionContext session, Collection<? extends PublicKeyEntry> entries, PublicKeyEntryResolver fallbackResolver) throws IOException, GeneralSecurityException
Parameters
session:SessionContext

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

entries:Collection<? extends PublicKeyEntry>

The entries to convert - ignored if null/empty

fallbackResolver:PublicKeyEntryResolver

The PublicKeyEntryResolver to consult if none of the built-in ones can be used. If null and no built-in resolver can be used then an InvalidKeySpecException is thrown.

Returns:List<PublicKey>

The List of all PublicKey-s that have been resolved

Exceptions
IOException:
If failed to decode the key data
GeneralSecurityException:
If failed to generate the PublicKey from the decoded data
See Also
resolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
resolvePublicKeyEntryDataResolverback to summary
public PublicKeyEntryDataResolver resolvePublicKeyEntryDataResolver()

If a PublicKeyEntryDataResolver has been set, then uses it - otherwise uses the default one.

Returns:PublicKeyEntryDataResolver

The resolved instance

setKeyDataback to summary
public void setKeyData(byte[] value)
setKeyDataResolverback to summary
public void setKeyDataResolver(PublicKeyEntryDataResolver keyDataResolver)
setKeyTypeback to summary
public void setKeyType(String value)
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override
toStringback to summary
public static String toString(PublicKey key) throws IllegalArgumentException
Parameters
key:PublicKey

The PublicKey

Returns:String

The OpenSSH encoded data

Exceptions
IllegalArgumentException:
If failed to encode
See Also
toString(PublicKey, PublicKeyEntryDataResolver)
toStringback to summary
public static String toString(PublicKey key, PublicKeyEntryDataResolver encoder) throws IllegalArgumentException
Parameters
key:PublicKey

The PublicKey

encoder:PublicKeyEntryDataResolver

The PublicKeyEntryDataResolver to use in order to encode the key data bytes into a string representation - if null then one is automatically resolved

Returns:String

The OpenSSH encoded data

Exceptions
IllegalArgumentException:
If failed to encode
See Also
appendPublicKeyEntry(Appendable, PublicKey, PublicKeyEntryDataResolver)
unregisterKeyDataEntryResolverback to summary
public static PublicKeyEntryDataResolver unregisterKeyDataEntryResolver(String keyType)
Parameters
keyType:String

The key-type value (case insensitive) that may have been previously registered - e.g., "ssh-rsa", "pgp-sign-dss", etc.

Returns:PublicKeyEntryDataResolver

The un-registered resolver instance - null if none was registered

org.apache.sshd.common.config.keys back to summary

private final Class PublicKeyEntry.LazyDefaultKeysFolderHolder

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.sshd.common.config.keys.PublicKeyEntry.LazyDefaultKeysFolderHolder

Field Summary

Modifier and TypeField and Description
private static final Path

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

PATHback to summary
private static final Path PATH

Constructor Detail

LazyDefaultKeysFolderHolderback to summary
private LazyDefaultKeysFolderHolder()