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
Basic support for OpenSSH
key file(s)
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
private static final byte[]
static final String
private static final Map<Class<?>,
PrivateKeyEntryDecoder<?, ?>> private static final Map<String,
PrivateKeyEntryDecoder<?, ?>> static final String
static final OpenSSHKeyPairResourceParser
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 -
Method Summary
Modifier and TypeMethodDescriptionextractKeyPairs
(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, InputStream stream, Map<String, String> headers) static PrivateKeyEntryDecoder<?,
?> getPrivateKeyEntryDecoder
(Class<?> keyType) static PrivateKeyEntryDecoder<?,
?> getPrivateKeyEntryDecoder
(String keyType) static PrivateKeyEntryDecoder<?,
?> static PrivateKeyEntryDecoder<?,
?> protected Map.Entry<PrivateKey,
String> readPrivateKey
(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream) readPrivateKeys
(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, Collection<? extends PublicKey> publicKeys, FilePasswordProvider passwordProvider, InputStream stream) protected PublicKey
readPublicKey
(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, InputStream stream, Map<String, String> headers) static void
registerPrivateKeyEntryDecoder
(PrivateKeyEntryDecoder<?, ?> decoder) protected OpenSSHKdfOptions
resolveKdfOptions
(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, InputStream stream, Map<String, String> headers) protected <S extends InputStream>
SvalidateStreamMagicMarker
(SessionContext session, NamedResource resourceKey, S stream) 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
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warn
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 Details
-
BEGIN_MARKER
- See Also:
-
BEGINNERS
-
END_MARKER
- See Also:
-
ENDERS
-
AUTH_MAGIC
- See Also:
-
INSTANCE
-
AUTH_MAGIC_BYTES
private static final byte[] AUTH_MAGIC_BYTES -
BY_KEY_TYPE_DECODERS_MAP
-
BY_KEY_CLASS_DECODERS_MAP
-
-
Constructor Details
-
OpenSSHKeyPairResourceParser
public OpenSSHKeyPairResourceParser()
-
-
Method Details
-
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
- Parameters:
decoder
- The decoder to register- Throws:
IllegalArgumentException
- if no decoder or not key type or no supported names for the decoder- See Also:
-
getPrivateKeyEntryDecoder
- 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
- 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
- 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
- Parameters:
keyType
- The keyClass
- ignored ifnull
or not aKey
compatible type- Returns:
- The registered
PrivateKeyEntryDecoder
or {code null} if no match found
-