public class PublicKeyEntry extends java.lang.Object implements java.io.Serializable, KeyTypeIndicator
Represents a PublicKey
whose data is formatted according to the
OpenSSH format:
<key-type> <base64-encoded-public-key-data>
Modifier and Type | Class and Description |
---|---|
private static class |
PublicKeyEntry.LazyDefaultKeysFolderHolder |
Modifier and Type | Field and Description |
---|---|
static char |
COMMENT_CHAR
Character used to denote a comment line in the keys file
|
private static java.util.NavigableMap<java.lang.String,PublicKeyEntryDataResolver> |
KEY_DATA_RESOLVERS |
private byte[] |
keyData |
private PublicKeyEntryDataResolver |
keyDataResolver |
private java.lang.String |
keyType |
private static long |
serialVersionUID |
static java.lang.String |
STD_KEYFILE_FOLDER_NAME
Standard folder name used by OpenSSH to hold key files
|
Constructor and Description |
---|
PublicKeyEntry() |
PublicKeyEntry(java.lang.String keyType,
byte... keyData) |
Modifier and Type | Method and Description |
---|---|
java.security.PublicKey |
appendPublicKey(SessionContext session,
java.lang.Appendable sb,
PublicKeyEntryResolver fallbackResolver) |
static <A extends java.lang.Appendable> |
appendPublicKeyEntry(A sb,
java.security.PublicKey key)
Encodes a public key data the same way as the
parsePublicKeyEntry(String) expects it |
static <A extends java.lang.Appendable> |
appendPublicKeyEntry(A sb,
java.security.PublicKey key,
PublicKeyEntryDataResolver encoder) |
boolean |
equals(java.lang.Object obj) |
static java.nio.file.Path |
getDefaultKeysFolderPath() |
byte[] |
getKeyData() |
static PublicKeyEntryDataResolver |
getKeyDataEntryResolver(java.lang.String keyType) |
PublicKeyEntryDataResolver |
getKeyDataResolver() |
java.lang.String |
getKeyType() |
static java.util.NavigableMap<java.lang.String,PublicKeyEntryDataResolver> |
getRegisteredKeyDataEntryResolvers() |
int |
hashCode() |
protected boolean |
isEquivalent(PublicKeyEntry e) |
static <E extends PublicKeyEntry> |
parsePublicKeyEntry(E entry,
java.lang.String encData) |
static <E extends PublicKeyEntry> |
parsePublicKeyEntry(E entry,
java.lang.String encData,
PublicKeyEntryDataResolver decoder) |
static PublicKeyEntry |
parsePublicKeyEntry(java.lang.String encData) |
static PublicKeyEntry |
parsePublicKeyEntry(java.lang.String encData,
PublicKeyEntryDataResolver decoder) |
static void |
registerKeyDataEntryResolver(java.lang.String keyType,
PublicKeyEntryDataResolver resolver)
Registers a specialized decoder for the public key entry data bytes instead of the
default one. |
static PublicKeyEntryDataResolver |
resolveKeyDataEntryResolver(java.lang.String keyType) |
java.security.PublicKey |
resolvePublicKey(SessionContext session,
java.util.Map<java.lang.String,java.lang.String> headers,
PublicKeyEntryResolver fallbackResolver) |
static java.util.List<java.security.PublicKey> |
resolvePublicKeyEntries(SessionContext session,
java.util.Collection<? extends PublicKeyEntry> entries,
PublicKeyEntryResolver fallbackResolver) |
PublicKeyEntryDataResolver |
resolvePublicKeyEntryDataResolver()
If a
PublicKeyEntryDataResolver has been set, then uses it - otherwise uses the
default one . |
void |
setKeyData(byte[] value) |
void |
setKeyDataResolver(PublicKeyEntryDataResolver keyDataResolver) |
void |
setKeyType(java.lang.String value) |
java.lang.String |
toString() |
static java.lang.String |
toString(java.security.PublicKey key) |
static java.lang.String |
toString(java.security.PublicKey key,
PublicKeyEntryDataResolver encoder) |
static PublicKeyEntryDataResolver |
unregisterKeyDataEntryResolver(java.lang.String keyType) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
groupByKeyType
public static final char COMMENT_CHAR
public static final java.lang.String STD_KEYFILE_FOLDER_NAME
private static final long serialVersionUID
private static final java.util.NavigableMap<java.lang.String,PublicKeyEntryDataResolver> KEY_DATA_RESOLVERS
private java.lang.String keyType
private byte[] keyData
private PublicKeyEntryDataResolver keyDataResolver
public PublicKeyEntry()
public PublicKeyEntry(java.lang.String keyType, byte... keyData)
public java.lang.String getKeyType()
getKeyType
in interface KeyTypeIndicator
public void setKeyType(java.lang.String value)
public byte[] getKeyData()
public void setKeyData(byte[] value)
public PublicKeyEntryDataResolver getKeyDataResolver()
public void setKeyDataResolver(PublicKeyEntryDataResolver keyDataResolver)
public PublicKeyEntryDataResolver resolvePublicKeyEntryDataResolver()
PublicKeyEntryDataResolver
has been set, then uses it - otherwise uses the
default one
.public java.security.PublicKey resolvePublicKey(SessionContext session, java.util.Map<java.lang.String,java.lang.String> headers, PublicKeyEntryResolver fallbackResolver) throws java.io.IOException, java.security.GeneralSecurityException
session
- 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
- Any headers that may have been available when data was readfallbackResolver
- 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.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 thrownjava.io.IOException
- If failed to decode the keyjava.security.GeneralSecurityException
- If failed to generate the keypublic java.security.PublicKey appendPublicKey(SessionContext session, java.lang.Appendable sb, PublicKeyEntryResolver fallbackResolver) throws java.io.IOException, java.security.GeneralSecurityException
session
- The SessionContext
for invoking this command - may be null
if
not invoked within a session context (e.g., offline tool or session unknown).sb
- The Appendable
instance to encode the data intofallbackResolver
- 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.PublicKey
or null
if could not resolve itjava.io.IOException
- If failed to decode/encode the keyjava.security.GeneralSecurityException
- If failed to generate the keyresolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
public int hashCode()
hashCode
in class java.lang.Object
protected boolean isEquivalent(PublicKeyEntry e)
public boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public static java.util.List<java.security.PublicKey> resolvePublicKeyEntries(SessionContext session, java.util.Collection<? extends PublicKeyEntry> entries, PublicKeyEntryResolver fallbackResolver) throws java.io.IOException, java.security.GeneralSecurityException
session
- The SessionContext
for invoking this command - may be null
if
not invoked within a session context (e.g., offline tool or session unknown).entries
- The entries to convert - ignored if null
/emptyfallbackResolver
- 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.List
of all PublicKey
-s that have been resolvedjava.io.IOException
- If failed to decode the key datajava.security.GeneralSecurityException
- If failed to generate the PublicKey
from the decoded dataresolvePublicKey(SessionContext, Map, PublicKeyEntryResolver)
public static void registerKeyDataEntryResolver(java.lang.String keyType, PublicKeyEntryDataResolver resolver)
default
one.keyType
- The key-type value (case insensitive) that will trigger the usage of this decoder - e.g.,
"ssh-rsa", "pgp-sign-dss", etc.resolver
- The decoder to usepublic static PublicKeyEntryDataResolver getKeyDataEntryResolver(java.lang.String keyType)
keyType
- The key-type value (case insensitive) that may have been previously
registered
- e.g.,
"ssh-rsa", "pgp-sign-dss", etc.null
if none was registeredpublic static PublicKeyEntryDataResolver unregisterKeyDataEntryResolver(java.lang.String keyType)
keyType
- The key-type value (case insensitive) that may have been previously
registered
- e.g.,
"ssh-rsa", "pgp-sign-dss", etc.null
if none was registeredpublic static PublicKeyEntryDataResolver resolveKeyDataEntryResolver(java.lang.String keyType)
keyType
- keyType The key-type value (case insensitive) whose data is to be resolved - e.g.,
"ssh-rsa", "pgp-sign-dss", etc.registered
then uses
it, otherwise the default
one.public static java.util.NavigableMap<java.lang.String,PublicKeyEntryDataResolver> getRegisteredKeyDataEntryResolvers()
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 typepublic static PublicKeyEntry parsePublicKeyEntry(java.lang.String encData) throws java.lang.IllegalArgumentException
encData
- Assumed to contain at least key-type base64-data
(anything beyond the
BASE64 data is ignored) - ignored if null
/emptyPublicKeyEntry
or null
if no datajava.lang.IllegalArgumentException
- if bad format foundparsePublicKeyEntry(String, PublicKeyEntryDataResolver)
public static PublicKeyEntry parsePublicKeyEntry(java.lang.String encData, PublicKeyEntryDataResolver decoder) throws java.lang.IllegalArgumentException
encData
- Assumed to contain at least key-type base64-data
(anything beyond the
BASE64 data is ignored) - ignored if null
/emptydecoder
- The PublicKeyEntryDataResolver
to use in order to decode the key data
string into its bytes - if null
then one is automatically
resolved
PublicKeyEntry
or null
if no datajava.lang.IllegalArgumentException
- if bad format foundparsePublicKeyEntry(PublicKeyEntry, String, PublicKeyEntryDataResolver)
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, java.lang.String encData) throws java.lang.IllegalArgumentException
E
- The generic entry typeentry
- The PublicKeyEntry
whose contents are to be updated - ignored if
null
encData
- Assumed to contain at least key-type base64-data
(anything beyond the
BASE64 data is ignored) - ignored if null
/emptyjava.lang.IllegalArgumentException
- if bad format foundparsePublicKeyEntry(PublicKeyEntry, String, PublicKeyEntryDataResolver)
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, java.lang.String encData, PublicKeyEntryDataResolver decoder) throws java.lang.IllegalArgumentException
E
- The generic entry typeentry
- The PublicKeyEntry
whose contents are to be updated - ignored if
null
encData
- Assumed to contain at least key-type base64-data
(anything beyond the
BASE64 data is ignored) - ignored if null
/emptydecoder
- The PublicKeyEntryDataResolver
to use in order to decode the key data
string into its bytes - if null
then one is automatically
resolved
java.lang.IllegalArgumentException
- if bad format foundpublic static java.lang.String toString(java.security.PublicKey key) throws java.lang.IllegalArgumentException
key
- The PublicKey
OpenSSH
encoded datajava.lang.IllegalArgumentException
- If failed to encodetoString(PublicKey, PublicKeyEntryDataResolver)
public static java.lang.String toString(java.security.PublicKey key, PublicKeyEntryDataResolver encoder) throws java.lang.IllegalArgumentException
key
- The PublicKey
encoder
- The PublicKeyEntryDataResolver
to use in order to encode the key data
bytes into a string representation - if null
then one is automatically
resolved
OpenSSH
encoded datajava.lang.IllegalArgumentException
- If failed to encodeappendPublicKeyEntry(Appendable, PublicKey, PublicKeyEntryDataResolver)
public static <A extends java.lang.Appendable> A appendPublicKeyEntry(A sb, java.security.PublicKey key) throws java.io.IOException
parsePublicKeyEntry(String)
expects itA
- The generic appendable classsb
- The Appendable
instance to encode the data intokey
- The PublicKey
- ignored if null
java.io.IOException
- If failed to append the dataappendPublicKeyEntry(Appendable, PublicKey, PublicKeyEntryDataResolver)
public static <A extends java.lang.Appendable> A appendPublicKeyEntry(A sb, java.security.PublicKey key, PublicKeyEntryDataResolver encoder) throws java.io.IOException
A
- The generic appendable classsb
- The Appendable
instance to encode the data intokey
- The PublicKey
- ignored if null
encoder
- The PublicKeyEntryDataResolver
to use in order to encode the key data bytes into a
string representation - if null
then one is automatically
resolved
java.io.IOException
- If failed to append the datapublic static java.nio.file.Path getDefaultKeysFolderPath()
known_hosts
, authorized_keys
,
etc.