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

public final Class KeyUtils

extends Object
Class Inheritance
Imports
java.io.IOException, java.math.BigInteger, java.nio.charset.Charset, .StandardCharsets, java.nio.file.Files, .LinkOption, .Path, java.nio.file.attribute.PosixFilePermission, java.security.GeneralSecurityException, .Key, .KeyFactory, .KeyPair, .PrivateKey, .PublicKey, java.security.interfaces.DSAKey, .DSAParams, .DSAPrivateKey, .DSAPublicKey, .ECKey, .ECPrivateKey, .ECPublicKey, .RSAKey, .RSAPrivateCrtKey, .RSAPrivateKey, .RSAPublicKey, java.security.spec.DSAPublicKeySpec, .ECParameterSpec, .InvalidKeySpecException, .RSAPublicKeySpec, java.util.AbstractMap.SimpleImmutableEntry, .ArrayList, .Arrays, .Collection, .Collections, .EnumSet, .HashSet, .LinkedHashMap, .List, .Map, .NavigableSet, .Objects, .Set, .TreeMap, .TreeSet, java.util.concurrent.atomic.AtomicReference, org.apache.sshd.common.Factory, org.apache.sshd.common.cipher.ECCurves, org.apache.sshd.common.config.keys.impl.DSSPublicKeyEntryDecoder, .ECDSAPublicKeyEntryDecoder, .OpenSSHCertificateDecoder, .RSAPublicKeyDecoder, .SkECDSAPublicKeyEntryDecoder, .SkED25519PublicKeyEntryDecoder, org.apache.sshd.common.config.keys.u2f.SkED25519PublicKey, .SkEcdsaPublicKey, org.apache.sshd.common.digest.BuiltinDigests, .Digest, .DigestFactory, .DigestUtils, org.apache.sshd.common.keyprovider.KeyPairProvider, org.apache.sshd.common.util.GenericUtils, .MapEntryUtils.MapBuilder, .MapEntryUtils.NavigableMapBuilder, .OsUtils, .ValidateUtils, org.apache.sshd.common.util.buffer.Buffer, .ByteArrayBuffer, org.apache.sshd.common.util.io.IoUtils, org.apache.sshd.common.util.security.SecurityUtils

Utility class for keys
Author
Apache MINA SSHD Project

Field Summary

Modifier and TypeField and Description
private static final Map<Class<?>, PublicKeyEntryDecoder<?, ?>>
private static final Map<String, PublicKeyEntryDecoder<?, ?>>
private static final AtomicReference<DigestFactory>
public static final DigestFactory
public static final BigInteger
DEFAULT_RSA_PUBLIC_EXPONENT

The most commonly used RSA public key exponent

public static final String
DSS_ALGORITHM

Name of algorithm for DSS keys to be used when calling security provider

public static final String
EC_ALGORITHM

Name of algorithm for EC keys to be used when calling security provider

public static final String
KEY_FINGERPRINT_FACTORY_PROP

System property that can be used to control the default fingerprint factory used for keys.

private static final Map<String, String>
public static final String
RSA_ALGORITHM

Name of algorithm for RSA keys to be used when calling security provider

public static final String
public static final String
public static final String
public static final String
private static final Map<String, String>
public static final Set<PosixFilePermission>
STRICTLY_PROHIBITED_FILE_PERMISSION

The Set of PosixFilePermission not allowed if strict permissions are enforced on key files

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AbstractMap.SimpleImmutableEntry<Boolean, String>

Returns:

SimpleImmutableEntry - key is success indicator, value is actual fingerprint, null if no key.
checkFingerPrint
(String
The expected fingerprint if null or empty then returns a failure with the default fingerprint.
expected
,
PublicKey
the PublicKey - if null then returns null.
key
)

public static AbstractMap.SimpleImmutableEntry<Boolean, String>

Returns:

SimpleImmutableEntry - key is success indicator, value is actual fingerprint, null if no key.
checkFingerPrint
(String
The expected fingerprint if null or empty then returns a failure with the default fingerprint.
expected
,
Factory<? extends Digest>
The Factory to be used to generate the default Digest for the key
f
,
PublicKey
the PublicKey - if null then returns null.
key
)

public static AbstractMap.SimpleImmutableEntry<Boolean, String>

Returns:

SimpleImmutableEntry - key is success indicator, value is actual fingerprint, null if no key.
checkFingerPrint
(String
The expected fingerprint if null or empty then returns a failure with the default fingerprint.
expected
,
Digest
The Digest to be used to generate the default fingerprint for the key
d
,
PublicKey
the PublicKey - if null then returns null.
key
)

public static KeyPair

Returns:

The cloned instance
cloneKeyPair
(String
The key type - OpenSSH name - e.g., ssh-rsa, ssh-dss
keyType
,
KeyPair
The KeyPair to clone - ignored if null
kp
)

Performs a deep-clone of the original KeyPair - i.e., creates new public/private keys that are clones of the original one

public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static boolean
public static PublicKey

Returns:

The matching PublicKey from the keys or null if no match found
findMatchingKey
(PublicKey
The PublicKey to be checked - ignored if null
key
,
PublicKey...
The keys to be searched - ignored if null/empty
keySet
)

public static PublicKey

Returns:

The matching PublicKey from the keys or null if no match found
findMatchingKey
(PublicKey
The PublicKey to be checked - ignored if null
key
,
Collection<? extends PublicKey>
The keys to be searched - ignored if null/empty
keySet
)

public static KeyPair

Returns:

A KeyPair of the specified type and size
generateKeyPair
(String
The key type - OpenSSH name - e.g., ssh-rsa, ssh-dss
keyType
,
int
The key size (in bits)
keySize
)

public static List<String>

Returns:

A List of they canonical key name and all its aliases
getAllEquivalentKeyTypes
(String
A key type name - ignored if null/empty
keyType
)

public static String

Returns:

The canonical key type - same as input if no alias registered for the provided key type
getCanonicalKeyType
(String
The available key-type - ignored if null/empty
keyType
)

public static DigestFactory
public static String

Returns:

the fingerprint or null if no key

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(PublicKey
the public key - ignored if null
key
)

public static String

Returns:

The fingerprint - null if null/empty input

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(String
The String to digest - ignored if null/empty, otherwise its UTF-8 representation is used as input for the fingerprint
password
)

public static String

Returns:

The fingerprint - null if null/empty input

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(String
The String to digest - ignored if null/empty
password
,
Charset
The Charset to use in order to convert the string to its byte representation to use as input for the fingerprint
charset
)

public static String

Returns:

the fingerprint or null if no key

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(Factory<? extends Digest>
The Factory to create the Digest to use
f
,
PublicKey
the public key - ignored if null
key
)

public static String

Returns:

the fingerprint or null if no key

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(Digest
The Digest to use
d
,
PublicKey
the public key - ignored if null
key
)

public static String

Returns:

The fingerprint - null if null/empty input

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(Factory<? extends Digest>
The Factory to create the Digest to use
f
,
String
The String to digest - ignored if null/empty, otherwise its UTF-8 representation is used as input for the fingerprint
s
)

public static String

Returns:

The fingerprint - null if null/empty input Note: if exception encountered then returns the exception's simple class name
getFingerPrint
(Factory<? extends Digest>
The Factory to create the Digest to use
f
,
String
The String to digest - ignored if null/empty
s
,
Charset
The Charset to use in order to convert the string to its byte representation to use as input for the fingerprint
charset
)

public static String

Returns:

The fingerprint - null if null/empty input

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(Digest
The Digest to use
d
,
String
The String to digest - ignored if null/empty, otherwise its UTF-8 representation is used as input for the fingerprint
s
)

public static String

Returns:

The fingerprint - null if null/empty input

Note

if exception encountered then returns the exception's simple class name

getFingerPrint
(Digest
The Digest to use to calculate the fingerprint
d
,
String
The string to digest - ignored if null/empty
s
,
Charset
The Charset to use in order to convert the string to its byte representation to use as input for the fingerprint
charset
)

public static int

Returns:

The key size - non-positive value if cannot determine it
getKeySize
(Key
The Key to examine - ignored if null
key
)

Determines the key size in bits

public static String

Returns:

the key type or null if cannot determine it
getKeyType
(KeyPair
a key pair - ignored if null. If the private key is non-null then it is used to determine the type, otherwise the public one is used.
kp
)

public static String

Returns:

the key type or null if cannot determine it
getKeyType
(Key
a public or private key
key
)

public static PublicKeyEntryDecoder<?, ?>

Returns:

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

public static PublicKeyEntryDecoder<?, ?>

Returns:

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

public static PublicKeyEntryDecoder<?, ?>

Returns:

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

public static PublicKeyEntryDecoder<?, ?>

Returns:

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

public static byte[]
public static byte[]
public static byte[]
public static NavigableSet<String>

Returns:

A case insensitive NavigableSet of the currently registered key type "aliases".
getRegisteredKeyTypeAliases
()

public static String
getSignatureAlgorithm(String chosenAlgorithm, PublicKey key)

public static PublicKey

Returns:

the PublicKey, may be null if the file is empty
loadPublicKey
(Path
Path of the file to read; must not be null
path
)

Reads a single PublicKey from a public key file.

public static DSAPublicKey
public static RSAPublicKey
public static PublicKey
public static RSAPublicKey
public static RSAPublicKey
public static RSAPublicKey
recoverRSAPublicKey(BigInteger modulus, BigInteger publicExponent)

public static List<String>

Returns:

A List of the replaced aliases - empty if no previous aliases for the canonical name
registerCanonicalKeyTypes
(String
The (never null/empty) canonical name
keyType
,
Collection<String>
The (never null/empty) aliases
aliases
)

Registers a collection of aliases to a canonical key type

public static void
registerPublicKeyEntryDecoder(PublicKeyEntryDecoder<?, ?>
The decoder to register
decoder
)

public static PublicKeyEntryDecoder<?, ?>

Returns:

The previously registered decoder for this key type - null if none
registerPublicKeyEntryDecoderForKeyType
(String
The key (never null/empty) key type
keyType
,
PublicKeyEntryDecoder<?, ?>
The (never null) decoder to register
decoder
)

public static void
registerPublicKeyEntryDecoderKeyTypes(PublicKeyEntryDecoder<?, ?>
The (never null) decoder to register
decoder
)

Registers the specified decoder for all the types it supports

public static void
setDefaultFingerPrintFactory(DigestFactory
The DigestFactory of Digests to be used - may not be null
f
)

public static String

Returns:

The associated canonical key type - null if alias not registered
unregisterCanonicalKeyTypeAlias
(String
The alias to unregister (ignored if null/empty)
alias
)

public static NavigableSet<String>

Returns:

The case insensitive NavigableSet of all the effectively un-registered key types out of all the supported ones.
unregisterPublicKeyEntryDecoder
(PublicKeyEntryDecoder<?, ?>
The (never null) decoder to unregister
decoder
)

public static PublicKeyEntryDecoder<?, ?>

Returns:

The unregistered PublicKeyEntryDecoder - null if none registered for this key type
unregisterPublicKeyEntryDecoderForKeyType
(String
The key (never null/empty) key type
keyType
)

Unregister the decoder registered for the specified key type

public static NavigableSet<String>

Returns:

The case insensitive NavigableSet of all the effectively un-registered key types out of all the supported ones.
unregisterPublicKeyEntryDecoderKeyTypes
(PublicKeyEntryDecoder<?, ?>
The (never null) decoder to unregister
decoder
)

Unregisters the specified decoder for all the types it supports

public static AbstractMap.SimpleImmutableEntry<String, Object>

Returns:

The violated permission as SimpleImmutableEntry where key is a message and value is the offending object PosixFilePermission or String for owner - null if no violations detected
validateStrictKeyFilePermissions
(Path
The Path to be checked - ignored if null or does not exist
path
,
LinkOption...
The LinkOptions to use to query the file's permissions
options
)

Checks if a path has strict permissions

  • The path may not have PosixFilePermission#OTHERS_EXECUTE permission
  • (For Unix) The path may not have group or others permissions
  • (For Unix) If the path is a file, then its folder may not have group or others permissions
  • The path must be owned by current user.
  • (For Unix) The path may be owned by root.
  • (For Unix) If the path is a file, then its folder must also have valid owner.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait