Class OpenSSHKeyPairResourceParser
- java.lang.Object
-
- org.apache.sshd.common.util.logging.AbstractLoggingBean
-
- org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser
-
- org.apache.sshd.common.config.keys.loader.openssh.OpenSSHKeyPairResourceParser
-
- All Implemented Interfaces:
KeyPairResourceLoader
,KeyPairResourceParser
public class OpenSSHKeyPairResourceParser extends AbstractKeyPairResourceParser
Basic support for OpenSSH key file(s)- Author:
- Apache MINA SSHD Project
-
-
Field Summary
Fields Modifier and Type Field Description static String
AUTH_MAGIC
static String
BEGIN_MARKER
static List<String>
BEGINNERS
static String
END_MARKER
static List<String>
ENDERS
static OpenSSHKeyPairResourceParser
INSTANCE
-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader
MAX_CIPHER_NAME_LENGTH, MAX_KEY_COMMENT_LENGTH, MAX_KEY_TYPE_NAME_LENGTH, MAX_PRIVATE_KEY_DATA_SIZE, MAX_PUBLIC_KEY_DATA_SIZE
-
Fields inherited from interface org.apache.sshd.common.config.keys.loader.KeyPairResourceParser
EMPTY
-
-
Constructor Summary
Constructors Constructor Description OpenSSHKeyPairResourceParser()
-
Method Summary
-
Methods inherited from class org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser
canExtractKeyPairs, extractKeyPairs, extractKeyPairs, getBeginners, getEnders, getEndingMarkers, loadKeyPairs, separateDataLinesFromHeaders
-
Methods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
getSimplifiedLogger
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader
loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs, loadKeyPairs
-
-
-
-
Field Detail
-
BEGIN_MARKER
public static final String BEGIN_MARKER
- See Also:
- Constant Field Values
-
END_MARKER
public static final String END_MARKER
- See Also:
- Constant Field Values
-
AUTH_MAGIC
public static final String AUTH_MAGIC
- See Also:
- Constant Field Values
-
INSTANCE
public static final OpenSSHKeyPairResourceParser INSTANCE
-
-
Method Detail
-
extractKeyPairs
public Collection<KeyPair> extractKeyPairs(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, InputStream stream, Map<String,String> headers) throws IOException, GeneralSecurityException
- Specified by:
extractKeyPairs
in classAbstractKeyPairResourceParser
- Parameters:
session
- TheSessionContext
for invoking this load command - may benull
if not invoked within a session context (e.g., offline tool or session unknown).resourceKey
- A hint as to the origin of the text linesbeginMarker
- The line containing the begin markerendMarker
- The line containing the end markerpasswordProvider
- TheFilePasswordProvider
to use in case the data is encrypted - may benull
if no encryptedstream
- The decoded dataInputStream
headers
- Any headers that may have been available when data was read- Returns:
- The extracted
KeyPair
s - may benull
/empty if none. - Throws:
IOException
- If failed to parse the dataGeneralSecurityException
- If failed to generate the keys
-
resolveKdfOptions
protected OpenSSHKdfOptions resolveKdfOptions(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, InputStream stream, Map<String,String> headers) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
readPublicKey
protected PublicKey readPublicKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, InputStream stream, Map<String,String> headers) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
readPrivateKeys
protected List<KeyPair> readPrivateKeys(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, Collection<? extends PublicKey> publicKeys, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
readPrivateKey
protected Map.Entry<PrivateKey,String> readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException
- Throws:
IOException
GeneralSecurityException
-
validateStreamMagicMarker
protected <S extends InputStream> S validateStreamMagicMarker(SessionContext session, NamedResource resourceKey, S stream) throws IOException
- Throws:
IOException
-
registerPrivateKeyEntryDecoder
public static void registerPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?,?> decoder)
- Parameters:
decoder
- The decoder to register- Throws:
IllegalArgumentException
- if no decoder or not key type or no supported names for the decoder- See Also:
IdentityResourceLoader.getPublicKeyType()
,KeyTypeNamesSupport.getSupportedKeyTypes()
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(String keyType)
- Parameters:
keyType
- TheOpenSSH
key type string - e.g.,ssh-rsa, ssh-dss
- ignored ifnull
/empty- Returns:
- The registered
PrivateKeyEntryDecoder
or {code null} if not found
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(KeyPair kp)
- Parameters:
kp
- TheKeyPair
to examine - ignored ifnull
- Returns:
- The matching
PrivateKeyEntryDecoder
provided both the public and private keys have the same decoder -null
if no match found - See Also:
getPrivateKeyEntryDecoder(Key)
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(Key key)
- Parameters:
key
- TheKey
(public or private) - ignored ifnull
- Returns:
- The registered
PrivateKeyEntryDecoder
for this key or {code null} if no match found - See Also:
getPrivateKeyEntryDecoder(Class)
-
getPrivateKeyEntryDecoder
public static PrivateKeyEntryDecoder<?,?> getPrivateKeyEntryDecoder(Class<?> keyType)
- Parameters:
keyType
- The keyClass
- ignored ifnull
or not aKey
compatible type- Returns:
- The registered
PrivateKeyEntryDecoder
or {code null} if no match found
-
-