Top Description Fields Constructors Methods
org.apache.sshd.common.config.keys.loader.openssh

public Class OpenSSHKeyPairResourceParser

extends AbstractKeyPairResourceParser
Class Inheritance
Imports
java.io.ByteArrayInputStream, .EOFException, .IOException, .InputStream, .StreamCorruptedException, java.nio.charset.StandardCharsets, java.security.GeneralSecurityException, .InvalidKeyException, .Key, .KeyPair, .NoSuchAlgorithmException, .PrivateKey, .PublicKey, java.util.AbstractMap.SimpleImmutableEntry, .ArrayList, .Arrays, .Collection, .Collections, .HashMap, .List, .Map, .Objects, .TreeMap, javax.security.auth.login.FailedLoginException, org.apache.sshd.common.NamedResource, org.apache.sshd.common.cipher.BuiltinCiphers, .CipherFactory, org.apache.sshd.common.config.keys.FilePasswordProvider, .KeyEntryResolver, .KeyUtils, .PrivateKeyEntryDecoder, .PublicKeyEntryDecoder, org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser, org.apache.sshd.common.config.keys.loader.openssh.kdf.BCryptKdfOptions, .RawKdfOptions, org.apache.sshd.common.session.SessionContext, org.apache.sshd.common.util.GenericUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.BufferUtils, org.apache.sshd.common.util.io.IoUtils, org.apache.sshd.common.util.security.SecurityUtils

Basic support for OpenSSH key file(s)
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
public static final String
private static final byte[]
public static final String
public static final List<String>
private static final Map<Class<?>, PrivateKeyEntryDecoder<?, ?>>
private static final Map<String, PrivateKeyEntryDecoder<?, ?>>
public static final String
public static final List<String>
public static final OpenSSHKeyPairResourceParser

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Collection<KeyPair>
extractKeyPairs(SessionContext
The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).
session
,
NamedResource
A hint as to the origin of the text lines
resourceKey
,
String
The line containing the begin marker
beginMarker
,
String
The line containing the end marker
endMarker
,
FilePasswordProvider
The FilePasswordProvider to use in case the data is encrypted - may be null if no encrypted
passwordProvider
,
InputStream
The decoded data InputStream
stream
,
Map<String, String>
Any headers that may have been available when data was read
headers
)

Implements abstract org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

public static PrivateKeyEntryDecoder<?, ?>

Returns:

The registered PrivateKeyEntryDecoder or {code null} if not found
getPrivateKeyEntryDecoder
(String
The OpenSSH key type string - e.g., ssh-rsa, ssh-dss - ignored if null/empty
keyType
)

public static PrivateKeyEntryDecoder<?, ?>

Returns:

The matching PrivateKeyEntryDecoder provided both the public and private keys have the same decoder - null if no match found
getPrivateKeyEntryDecoder
(KeyPair
The KeyPair to examine - ignored if null
kp
)

public static PrivateKeyEntryDecoder<?, ?>

Returns:

The registered PrivateKeyEntryDecoder for this key or {code null} if no match found
getPrivateKeyEntryDecoder
(Key
The Key (public or private) - ignored if null
key
)

public static PrivateKeyEntryDecoder<?, ?>

Returns:

The registered PrivateKeyEntryDecoder or {code null} if no match found
getPrivateKeyEntryDecoder
(Class<?>
The key Class - ignored if null or not a Key compatible type
keyType
)

protected Map.Entry<PrivateKey, String>
readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream)

protected List<KeyPair>
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)

public static void
registerPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?, ?>
The decoder to register
decoder
)

protected OpenSSHKdfOptions
resolveKdfOptions(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, InputStream stream, Map<String, String> headers)

protected <S extends InputStream> S
validateStreamMagicMarker(SessionContext session, NamedResource resourceKey, S stream)

Inherited from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser:
canExtractKeyPairsextractKeyPairsextractKeyPairsgetBeginnersgetEndersgetEndingMarkersloadKeyPairsseparateDataLinesFromHeaders

Field Detail

AUTH_MAGICback to summary
public static final String AUTH_MAGIC
AUTH_MAGIC_BYTESback to summary
private static final byte[] AUTH_MAGIC_BYTES
BEGIN_MARKERback to summary
public static final String BEGIN_MARKER
BEGINNERSback to summary
public static final List<String> BEGINNERS
BY_KEY_CLASS_DECODERS_MAPback to summary
private static final Map<Class<?>, PrivateKeyEntryDecoder<?, ?>> BY_KEY_CLASS_DECODERS_MAP
BY_KEY_TYPE_DECODERS_MAPback to summary
private static final Map<String, PrivateKeyEntryDecoder<?, ?>> BY_KEY_TYPE_DECODERS_MAP
END_MARKERback to summary
public static final String END_MARKER
ENDERSback to summary
public static final List<String> ENDERS
INSTANCEback to summary
public static final OpenSSHKeyPairResourceParser INSTANCE

Constructor Detail

OpenSSHKeyPairResourceParserback to summary
public OpenSSHKeyPairResourceParser()

Method Detail

extractKeyPairsback to summary
public Collection<KeyPair> extractKeyPairs(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, FilePasswordProvider passwordProvider, InputStream stream, Map<String, String> headers) throws IOException, GeneralSecurityException

Implements abstract org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

Parameters
session:SessionContext

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

The SessionContext for invoking this load command - may be null if not invoked within a session context (e.g., offline tool or session unknown).

resourceKey:NamedResource

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

A hint as to the origin of the text lines

beginMarker:String

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

The line containing the begin marker

endMarker:String

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

The line containing the end marker

passwordProvider:FilePasswordProvider

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

The FilePasswordProvider to use in case the data is encrypted - may be null if no encrypted

stream:InputStream

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

The decoded data InputStream

headers:Map<String, String>

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

Any headers that may have been available when data was read

Returns:Collection<KeyPair>

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

The extracted KeyPairs - may be null/empty if none.

Annotations
@Override
Exceptions
IOException:

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

If failed to parse the data

GeneralSecurityException:

Doc from org.apache.sshd.common.config.keys.loader.AbstractKeyPairResourceParser.extractKeyPairs.

If failed to generate the keys

getPrivateKeyEntryDecoderback to summary
public static PrivateKeyEntryDecoder<?, ?> getPrivateKeyEntryDecoder(String keyType)
Parameters
keyType:String

The OpenSSH key type string - e.g., ssh-rsa, ssh-dss - ignored if null/empty

Returns:PrivateKeyEntryDecoder<?, ?>

The registered PrivateKeyEntryDecoder or {code null} if not found

getPrivateKeyEntryDecoderback to summary
public static PrivateKeyEntryDecoder<?, ?> getPrivateKeyEntryDecoder(KeyPair kp)
Parameters
kp:KeyPair

The KeyPair to examine - ignored if null

Returns:PrivateKeyEntryDecoder<?, ?>

The matching PrivateKeyEntryDecoder provided both the public and private keys have the same decoder - null if no match found

See Also
getPrivateKeyEntryDecoder(Key)
getPrivateKeyEntryDecoderback to summary
public static PrivateKeyEntryDecoder<?, ?> getPrivateKeyEntryDecoder(Key key)
Parameters
key:Key

The Key (public or private) - ignored if null

Returns:PrivateKeyEntryDecoder<?, ?>

The registered PrivateKeyEntryDecoder for this key or {code null} if no match found

See Also
getPrivateKeyEntryDecoder(Class)
getPrivateKeyEntryDecoderback to summary
public static PrivateKeyEntryDecoder<?, ?> getPrivateKeyEntryDecoder(Class<?> keyType)
Parameters
keyType:Class<?>

The key Class - ignored if null or not a Key compatible type

Returns:PrivateKeyEntryDecoder<?, ?>

The registered PrivateKeyEntryDecoder or {code null} if no match found

readPrivateKeyback to summary
protected Map.Entry<PrivateKey, String> readPrivateKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, String keyType, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException
readPrivateKeysback to summary
protected List<KeyPair> readPrivateKeys(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, Collection<? extends PublicKey> publicKeys, FilePasswordProvider passwordProvider, InputStream stream) throws IOException, GeneralSecurityException
readPublicKeyback to summary
protected PublicKey readPublicKey(SessionContext session, NamedResource resourceKey, OpenSSHParserContext context, InputStream stream, Map<String, String> headers) throws IOException, GeneralSecurityException
registerPrivateKeyEntryDecoderback to summary
public static void registerPrivateKeyEntryDecoder(PrivateKeyEntryDecoder<?, ?> decoder)
Parameters
decoder:PrivateKeyEntryDecoder<?, ?>

The decoder to register

Exceptions
IllegalArgumentException:
if no decoder or not key type or no supported names for the decoder
See Also
PrivateKeyEntryDecoder#getPublicKeyType(), PrivateKeyEntryDecoder#getSupportedKeyTypes()
resolveKdfOptionsback to summary
protected OpenSSHKdfOptions resolveKdfOptions(SessionContext session, NamedResource resourceKey, String beginMarker, String endMarker, InputStream stream, Map<String, String> headers) throws IOException, GeneralSecurityException
validateStreamMagicMarkerback to summary
protected <S extends InputStream> S validateStreamMagicMarker(SessionContext session, NamedResource resourceKey, S stream) throws IOException