Class SecurityUtils
java.lang.Object
org.apache.sshd.common.util.security.SecurityUtils
Specific security providers related code
- Author:
- Apache MINA SSHD Project
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringBouncy CastleSecurityProviderRegistrarname.static final StringKey and signature algorithm name for ed25519.static final StringEDDSA (net.i2p)SecurityProviderRegistrarname.static final StringA boolean system property that can be set to"true"to enable FIPS mode.static final intstatic final StringSystem property used to configure the value for the maximum supported Diffie-Hellman Group Exchange key size.static final intThe min. key size value used for testing whether Diffie-Hellman Group Exchange is supported or not.static final StringSystem property used to configure the value for the minimum supported Diffie-Hellman Group Exchange key size.static final intstatic final Stringstatic final StringComma separated list of fully qualifiedSecurityProviderRegistrars to automatically register -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanstatic booleanstatic SecurityEntityFactorycreateSecurityEntityFactory(Predicate<? super SecurityProviderRegistrar> entitySelector) static KeyPairextractEDDSAKeyPair(Buffer buffer, String keyType) static AlgorithmParametersgetAlgorithmParameters(String algorithm) static Decryptorstatic KeyPairResourceParserstatic CertificateFactorygetCertificateFactory(String type) static Cipherstatic SecurityProviderChoicestatic KEMstatic KeyAgreementgetKeyAgreement(String algorithm) static KeyFactorygetKeyFactory(String algorithm) static KeyPairGeneratorgetKeyPairGenerator(String algorithm) static KeyPairResourceParser///////////////////////////////////////////////////////////////////////static Macstatic intstatic MessageDigestgetMessageDigest(String algorithm) static intstatic PrivateKeyEntryDecoderstatic RandomFactorystatic SecurityProviderRegistrargetRegisteredProvider(String provider) static SecurityEntityFactorygetSecurityEntityProvider(SecurityProviderRegistrar registrar, SecurityProviderChoice defaultProvider) static SignaturegetSignature(String algorithm) static booleanstatic booleanstatic booleanstatic booleanisDHGroupExchangeSupported(int maxKeySize) static booleanisDHOakelyGroupSupported(int keySize) static booleanstatic booleanTells whether FIPS mode is enabled, either through the system propertyFIPS_ENABLEDor viasetFipsMode().static booleanisProviderRegistered(String provider) static booleanloadKeyPairIdentities(SessionContext session, NamedResource resourceKey, InputStream inputStream, FilePasswordProvider provider) static PublicKeystatic SecurityProviderRegistrarstatic SecurityEntityFactoryresolveSecurityEntityFactory(Class<?> entityType, String algorithm, Predicate<? super SecurityProviderRegistrar> entitySelector) ///////////////////////// Security entities factories /////////////////////////////static voidsetAPrioriDisabledProvider(String name, boolean disabled) Marks a provider's registrar as "a-priori" programatically so that when itsSecurityProviderRegistrar.isEnabled()is eventually consulted it will returnfalseregardless of the configured value for the specific provider registrar instance.static voidstatic voidUnconditionally set FIPS mode, overriding theFIPS_ENABLEDsystem property.static voidstatic voidsetMaxDHGroupExchangeKeySize(int keySize) Set programmatically the reported value forgetMaxDHGroupExchangeKeySize()static voidsetMinDHGroupExchangeKeySize(int keySize) Set programmatically the reported value forgetMinDHGroupExchangeKeySize()
-
Field Details
-
BOUNCY_CASTLE
-
EDDSA
EDDSA (net.i2p)SecurityProviderRegistrarname. Also the algorithm name thatKey.getAlgorithm()returns for ed25519 keys generated by net.i2p or by SunEC.- See Also:
-
ED25519
Key and signature algorithm name for ed25519. A Bouncy Castle Ed25519 key returns this asKey.getAlgorithm().- See Also:
-
MIN_DHGEX_KEY_SIZE_PROP
System property used to configure the value for the minimum supported Diffie-Hellman Group Exchange key size. If not set, then an internal auto-discovery mechanism is employed. If set to negative value then Diffie-Hellman Group Exchange is disabled. If set to a negative value then Diffie-Hellman Group Exchange is disabled- See Also:
-
MAX_DHGEX_KEY_SIZE_PROP
System property used to configure the value for the maximum supported Diffie-Hellman Group Exchange key size. If not set, then an internal auto-discovery mechanism is employed. If set to negative value then Diffie-Hellman Group Exchange is disabled. If set to a negative value then Diffie-Hellman Group Exchange is disabled- See Also:
-
MIN_DHGEX_KEY_SIZE
public static final int MIN_DHGEX_KEY_SIZEThe min. key size value used for testing whether Diffie-Hellman Group Exchange is supported or not. According to RFC 4419 section 3: Servers and clients SHOULD support groups with a modulus length of k bits, where 1024 <= k <= 8192. Note: this has been amended by RFC 8270- See Also:
-
PREFERRED_DHGEX_KEY_SIZE
public static final int PREFERRED_DHGEX_KEY_SIZE- See Also:
-
MAX_DHGEX_KEY_SIZE
public static final int MAX_DHGEX_KEY_SIZE- See Also:
-
SECURITY_PROVIDER_REGISTRARS
Comma separated list of fully qualifiedSecurityProviderRegistrars to automatically register- See Also:
-
DEFAULT_SECURITY_PROVIDER_REGISTRARS
-
PROP_DEFAULT_SECURITY_PROVIDER
- See Also:
-
FIPS_ENABLED
A boolean system property that can be set to"true"to enable FIPS mode. In FIPS mode, crypto-algorithms not approved in FIPS-140 will not be available.Note: if this system property is not
"true", it can be overridden viasetFipsMode().- See Also:
-
-
Method Details
-
setFipsMode
public static void setFipsMode()Unconditionally set FIPS mode, overriding theFIPS_ENABLEDsystem property.- Throws:
IllegalStateException- if a call toisFipsMode()had already occurred and returnedfalse.
-
isFipsMode
public static boolean isFipsMode()Tells whether FIPS mode is enabled, either through the system propertyFIPS_ENABLEDor viasetFipsMode().- Returns:
trueif FIPS mode is enabled,falseotherwise.
-
isAPrioriDisabledProvider
- Parameters:
name- The provider's name - nevernull/empty- Returns:
trueif the provider is marked as disabled a-priori- See Also:
-
setAPrioriDisabledProvider
Marks a provider's registrar as "a-priori" programatically so that when itsSecurityProviderRegistrar.isEnabled()is eventually consulted it will returnfalseregardless of the configured value for the specific provider registrar instance. Note: has no effect if the provider has already been registered.- Parameters:
name- The provider's name - nevernull/emptydisabled-truewhether to disable it a-priori- See Also:
-
getAPrioriDisabledProviders
-
isDHGroupExchangeSupported
public static boolean isDHGroupExchangeSupported()- Returns:
trueif Diffie-Hellman Group Exchange is supported- See Also:
-
isDHOakelyGroupSupported
public static boolean isDHOakelyGroupSupported(int keySize) - Parameters:
keySize- The expected key size- Returns:
trueif Oakely Diffie-Hellman Group Exchange is supported for the specified key size- See Also:
-
getMinDHGroupExchangeKeySize
public static int getMinDHGroupExchangeKeySize()- Returns:
- The minimum supported Diffie-Hellman Group Exchange key size, or non-positive if not supported
-
setMinDHGroupExchangeKeySize
public static void setMinDHGroupExchangeKeySize(int keySize) Set programmatically the reported value forgetMinDHGroupExchangeKeySize()- Parameters:
keySize- The reported key size - if zero, then it will be auto-detected, if negative then DH group exchange will be disabled
-
getMaxDHGroupExchangeKeySize
public static int getMaxDHGroupExchangeKeySize()- Returns:
- The maximum supported Diffie-Hellman Group Exchange key size, or non-positive if not supported
-
setMaxDHGroupExchangeKeySize
public static void setMaxDHGroupExchangeKeySize(int keySize) Set programmatically the reported value forgetMaxDHGroupExchangeKeySize()- Parameters:
keySize- The reported key size - if zero, then it will be auto-detected, if negative then DH group exchange will be disabled
-
isDHGroupExchangeSupported
public static boolean isDHGroupExchangeSupported(int maxKeySize) -
getDefaultProviderChoice
-
setDefaultProviderChoice
-
getRegisteredProviders
-
isBouncyCastleRegistered
public static boolean isBouncyCastleRegistered() -
isProviderRegistered
-
getRegisteredProvider
-
isRegistrationCompleted
public static boolean isRegistrationCompleted() -
registerSecurityProvider
public static SecurityProviderRegistrar registerSecurityProvider(SecurityProviderRegistrar registrar) - Parameters:
registrar- The registrar instance to register- Returns:
- The registered instance - may be different than required if already registered. Returns
nullif not already registered and not enabled or not supported registrar.
-
loadKeyPairIdentities
public static Iterable<KeyPair> loadKeyPairIdentities(SessionContext session, NamedResource resourceKey, InputStream inputStream, FilePasswordProvider provider) throws IOException, GeneralSecurityException - Parameters:
session- TheSessionContextfor invoking this load command - may benullif not invoked within a session context (e.g., offline tool).resourceKey- An identifier of the key being loaded - used as argument to theFilePasswordProvider#getPasswordinvocationinputStream- TheInputStreamfor the private keyprovider- AFilePasswordProvider- may benullif the loaded key is guaranteed not to be encrypted- Returns:
- The loaded
KeyPair-s - ornullif none loaded - Throws:
IOException- If failed to read/parse the input streamGeneralSecurityException- If failed to generate the keys
-
createGeneratorHostKeyProvider
-
getBouncycastleKeyPairResourceParser
-
getBouncycastleEncryptedPrivateKeyInfoDecryptor
-
getRandomFactory
- Returns:
- If
isBouncyCastleRegistered()then aBouncyCastleRandomFactoryinstance, otherwise aJceRandomFactoryone
-
isEDDSACurveSupported
public static boolean isEDDSACurveSupported()- Returns:
trueif EDDSA curves (e.g.,ed25519) are supported
-
getOpenSSHEDDSAPrivateKeyEntryDecoder
-
compareEDDSAPPublicKeys
-
compareEDDSAPrivateKeys
-
recoverEDDSAPublicKey
- Throws:
GeneralSecurityException
-
extractEDDSAKeyPair
public static KeyPair extractEDDSAKeyPair(Buffer buffer, String keyType) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
getKeyPairResourceParser
/////////////////////////////////////////////////////////////////////// -
setKeyPairResourceParser
- Parameters:
parser- The system-wideKeyPairResourceParserto use. If set tonull, then the default parser will be re-constructed on next call togetKeyPairResourceParser()
-
resolveSecurityEntityFactory
public static SecurityEntityFactory resolveSecurityEntityFactory(Class<?> entityType, String algorithm, Predicate<? super SecurityProviderRegistrar> entitySelector) ///////////////////////// Security entities factories ///////////////////////////// -
createSecurityEntityFactory
public static SecurityEntityFactory createSecurityEntityFactory(Predicate<? super SecurityProviderRegistrar> entitySelector) -
getSecurityEntityProvider
public static SecurityEntityFactory getSecurityEntityProvider(SecurityProviderRegistrar registrar, SecurityProviderChoice defaultProvider) -
getAlgorithmParameters
public static AlgorithmParameters getAlgorithmParameters(String algorithm) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
getKeyFactory
- Throws:
GeneralSecurityException
-
getCipher
- Throws:
GeneralSecurityException
-
getMessageDigest
- Throws:
GeneralSecurityException
-
getKeyPairGenerator
public static KeyPairGenerator getKeyPairGenerator(String algorithm) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
getKeyAgreement
- Throws:
GeneralSecurityException
-
getMac
- Throws:
GeneralSecurityException
-
getSignature
- Throws:
GeneralSecurityException
-
getCertificateFactory
- Throws:
GeneralSecurityException
-
getKEM
- Throws:
GeneralSecurityException
-