public class PublicKeyEntry extends Object implements Serializable, KeyTypeIndicator
Represents a PublicKey
whose data is formatted according to
the OpenSSH format:
<key-type> <base64-encoded-public-key-data>
Modifier and Type | Field and Description |
---|---|
static char |
COMMENT_CHAR
Character used to denote a comment line in the keys file
|
static String |
STD_KEYFILE_FOLDER_NAME
Standard folder name used by OpenSSH to hold key files
|
Constructor and Description |
---|
PublicKeyEntry() |
PublicKeyEntry(String keyType,
byte... keyData) |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
groupByKeyType
public static final char COMMENT_CHAR
public static final String STD_KEYFILE_FOLDER_NAME
public PublicKeyEntry()
public PublicKeyEntry(String keyType, byte... keyData)
public String getKeyType()
getKeyType
in interface KeyTypeIndicator
public void setKeyType(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 PublicKey resolvePublicKey(SessionContext session, PublicKeyEntryResolver fallbackResolver) throws IOException, 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).fallbackResolver
- 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 thrownIOException
- If failed to decode the keyGeneralSecurityException
- If failed to generate the keypublic PublicKey appendPublicKey(SessionContext session, Appendable sb, PublicKeyEntryResolver fallbackResolver) throws IOException, 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 itIOException
- If failed to decode/encode the keyGeneralSecurityException
- If failed to generate the keyresolvePublicKey(SessionContext, PublicKeyEntryResolver)
protected boolean isEquivalent(PublicKeyEntry e)
public static List<PublicKey> resolvePublicKeyEntries(SessionContext session, Collection<? extends PublicKeyEntry> entries, PublicKeyEntryResolver fallbackResolver) throws IOException, 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 resolvedIOException
- If failed to decode the key dataGeneralSecurityException
- If failed to generate the PublicKey
from the decoded dataresolvePublicKey(SessionContext, PublicKeyEntryResolver)
public static void registerKeyDataEntryResolver(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(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(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(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 NavigableMap<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(String encData) throws 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 dataIllegalArgumentException
- if bad format foundparsePublicKeyEntry(String, PublicKeyEntryDataResolver)
public static PublicKeyEntry parsePublicKeyEntry(String encData, PublicKeyEntryDataResolver decoder) throws 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 dataIllegalArgumentException
- if bad format foundparsePublicKeyEntry(PublicKeyEntry, String, PublicKeyEntryDataResolver)
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, String encData) throws 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
/emptyIllegalArgumentException
- if bad format foundparsePublicKeyEntry(PublicKeyEntry, String, PublicKeyEntryDataResolver)
public static <E extends PublicKeyEntry> E parsePublicKeyEntry(E entry, String encData, PublicKeyEntryDataResolver decoder) throws 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
IllegalArgumentException
- if bad format foundpublic static String toString(PublicKey key) throws IllegalArgumentException
key
- The PublicKey
OpenSSH
encoded dataIllegalArgumentException
- If failed to encodetoString(PublicKey, PublicKeyEntryDataResolver)
public static String toString(PublicKey key, PublicKeyEntryDataResolver encoder) throws 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 dataIllegalArgumentException
- If failed to encodeappendPublicKeyEntry(Appendable, PublicKey, PublicKeyEntryDataResolver)
public static <A extends Appendable> A appendPublicKeyEntry(A sb, PublicKey key) throws IOException
parsePublicKeyEntry(String)
expects itA
- The generic appendable classsb
- The Appendable
instance to encode the data intokey
- The PublicKey
- ignored if null
IOException
- If failed to append the dataappendPublicKeyEntry(Appendable, PublicKey, PublicKeyEntryDataResolver)
public static <A extends Appendable> A appendPublicKeyEntry(A sb, PublicKey key, PublicKeyEntryDataResolver encoder) throws 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
IOException
- If failed to append the datapublic static Path getDefaultKeysFolderPath()
known_hosts
, authorized_keys
, etc.Copyright © 2008–2022 The Apache Software Foundation. All rights reserved.