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, waitgroupByKeyTypepublic 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 KeyTypeIndicatorpublic 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, Map<String,String> headers, 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).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 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, Map, 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, Map, 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
resolvedPublicKeyEntry 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
nullencData - 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
nullencData - 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
resolvedIllegalArgumentException - if bad format foundpublic static String toString(PublicKey key) throws IllegalArgumentException
key - The PublicKeyOpenSSH encoded dataIllegalArgumentException - If failed to encodetoString(PublicKey, PublicKeyEntryDataResolver)public static String toString(PublicKey key, PublicKeyEntryDataResolver encoder) throws IllegalArgumentException
key - The PublicKeyencoder - The PublicKeyEntryDataResolver to use in order to encode the key data
bytes into a string representation - if null then one is automatically
resolvedOpenSSH 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 nullIOException - 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 nullencoder - The PublicKeyEntryDataResolver to use in order to encode the key data bytes into a
string representation - if null then one is automatically
resolvedIOException - If failed to append the datapublic static Path getDefaultKeysFolderPath()
known_hosts, authorized_keys,
etc.Copyright © 2018–2020 The Apache Software Foundation. All rights reserved.