public class JcaTlsCrypto extends AbstractTlsCrypto
This class provides default implementations for everything. If you need to customise it, extend the class and override the appropriate methods.
| Modifier | Constructor and Description |
|---|---|
protected |
JcaTlsCrypto(org.bouncycastle.jcajce.util.JcaJceHelper helper,
java.security.SecureRandom entropySource,
java.security.SecureRandom nonceEntropySource)
Base constructor.
|
| Modifier and Type | Method and Description |
|---|---|
byte[] |
calculateKeyAgreement(java.lang.String agreementAlgorithm,
java.security.PrivateKey privateKey,
java.security.PublicKey publicKey,
java.lang.String secretAlgorithm) |
protected TlsAEADCipherImpl |
createAEADCipher(java.lang.String cipherName,
java.lang.String algorithm,
int keySize,
boolean isEncrypting)
If you want to create your own versions of the AEAD ciphers required, override this method.
|
protected TlsBlockCipherImpl |
createBlockCipher(java.lang.String cipherName,
java.lang.String algorithm,
int keySize,
boolean isEncrypting)
If you want to create your own versions of the block ciphers required, override this method.
|
protected TlsBlockCipherImpl |
createBlockCipherWithCBCImplicitIV(java.lang.String cipherName,
java.lang.String algorithm,
int keySize,
boolean isEncrypting)
If you want to create your own versions of the block ciphers for < TLS 1.1, override this method.
|
protected TlsBlockCipherImpl |
createCBCBlockCipherImpl(TlsCryptoParameters cryptoParams,
java.lang.String algorithm,
int cipherKeySize,
boolean forEncryption) |
TlsCertificate |
createCertificate(byte[] encoding)
Create a TlsCertificate from an ASN.1 binary encoding of an X.509 certificate.
|
TlsCertificate |
createCertificate(short type,
byte[] encoding)
Create a TlsCertificate from a ASN.1 binary encoding of a certificate.
|
protected TlsCipher |
createCipher_CBC(TlsCryptoParameters cryptoParams,
java.lang.String algorithm,
int cipherKeySize,
int macAlgorithm) |
TlsCipher |
createCipher(TlsCryptoParameters cryptoParams,
int encryptionAlgorithm,
int macAlgorithm)
Create a cipher for the specified encryption and MAC algorithms.
|
TlsDHDomain |
createDHDomain(TlsDHConfig dhConfig)
Create a domain object supporting the domain parameters described in dhConfig.
|
TlsECDomain |
createECDomain(TlsECConfig ecConfig)
Create a domain object supporting the domain parameters described in ecConfig.
|
TlsHash |
createHash(int cryptoHashAlgorithm)
Create a suitable hash for the hash algorithm identifier passed in.
|
protected TlsHash |
createHash(java.lang.String digestName)
If you want to create your own versions of Hash functions, override this method.
|
protected TlsHMAC |
createHMAC_SSL(int macAlgorithm) |
TlsHMAC |
createHMAC(int macAlgorithm)
Create a suitable HMAC for the MAC algorithm identifier passed in.
|
TlsHMAC |
createHMACForHash(int cryptoHashAlgorithm)
Create a suitable HMAC using the hash algorithm identifier passed in.
|
protected TlsHMAC |
createMAC(TlsCryptoParameters cryptoParams,
int macAlgorithm) |
TlsNonceGenerator |
createNonceGenerator(byte[] additionalSeedMaterial)
Create a nonce generator.
|
protected TlsNullCipher |
createNullCipher(TlsCryptoParameters cryptoParams,
int macAlgorithm)
To disable the null cipher suite, override this method with one that throws an IOException.
|
TlsSecret |
createSecret(byte[] data)
Create a TlsSecret object based on provided data.
|
TlsSRP6Client |
createSRP6Client(TlsSRPConfig srpConfig)
Create an SRP-6 client.
|
TlsSRP6Server |
createSRP6Server(TlsSRPConfig srpConfig,
java.math.BigInteger srpVerifier)
Create an SRP-6 server.
|
TlsSRP6VerifierGenerator |
createSRP6VerifierGenerator(TlsSRPConfig srpConfig)
Create an SRP-6 verifier generator.
|
protected TlsStreamSigner |
createStreamSigner(SignatureAndHashAlgorithm algorithm,
java.security.PrivateKey privateKey,
boolean needsRandom) |
protected TlsStreamSigner |
createStreamSigner(java.lang.String algorithmName,
java.security.spec.AlgorithmParameterSpec parameter,
java.security.PrivateKey privateKey,
boolean needsRandom) |
protected TlsStreamVerifier |
createStreamVerifier(DigitallySigned digitallySigned,
java.security.PublicKey publicKey) |
protected TlsStreamVerifier |
createStreamVerifier(java.lang.String algorithmName,
java.security.spec.AlgorithmParameterSpec parameter,
byte[] signature,
java.security.PublicKey publicKey) |
protected Tls13Verifier |
createTls13Verifier(java.lang.String algorithmName,
java.security.spec.AlgorithmParameterSpec parameter,
java.security.PublicKey publicKey) |
protected TlsStreamSigner |
createVerifyingStreamSigner(SignatureAndHashAlgorithm algorithm,
java.security.PrivateKey privateKey,
boolean needsRandom,
java.security.PublicKey publicKey) |
protected TlsStreamSigner |
createVerifyingStreamSigner(java.lang.String algorithmName,
java.security.spec.AlgorithmParameterSpec parameter,
java.security.PrivateKey privateKey,
boolean needsRandom,
java.security.PublicKey publicKey) |
TlsSecret |
generateRSAPreMasterSecret(ProtocolVersion version)
Create a TlsSecret object containing a randomly-generated RSA PreMasterSecret
|
org.bouncycastle.jcajce.util.JcaJceHelper |
getHelper() |
java.security.AlgorithmParameters |
getNamedGroupAlgorithmParameters(int namedGroup) |
java.security.SecureRandom |
getSecureRandom()
Return the primary (safest) SecureRandom for this crypto.
|
java.security.AlgorithmParameters |
getSignatureSchemeAlgorithmParameters(int signatureScheme) |
boolean |
hasAnyStreamVerifiers(java.util.Vector signatureAndHashAlgorithms)
Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.
|
boolean |
hasAnyStreamVerifiersLegacy(short[] clientCertificateTypes)
Return true if this TlsCrypto would use a stream verifier for any of the passed in algorithms.
|
boolean |
hasCryptoHashAlgorithm(int cryptoHashAlgorithm)
Return true if this TlsCrypto can support the passed in hash algorithm.
|
boolean |
hasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)
Return true if this TlsCrypto can support the passed in signature algorithm
(not necessarily in combination with EVERY hash algorithm).
|
boolean |
hasDHAgreement()
Return true if this TlsCrypto can support DH key agreement.
|
boolean |
hasECDHAgreement()
Return true if this TlsCrypto can support ECDH key agreement.
|
boolean |
hasEncryptionAlgorithm(int encryptionAlgorithm)
Return true if this TlsCrypto can support the passed in block/stream encryption algorithm.
|
boolean |
hasHKDFAlgorithm(int cryptoHashAlgorithm)
Return true if this TlsCrypto can support HKDF with the passed in hash algorithm.
|
boolean |
hasMacAlgorithm(int macAlgorithm)
Return true if this TlsCrypto can support the passed in MAC algorithm.
|
boolean |
hasNamedGroup(int namedGroup)
Return true if this TlsCrypto supports the passed in
named group value. |
boolean |
hasRSAEncryption()
Return true if this TlsCrypto can support RSA encryption/decryption.
|
boolean |
hasSignatureAlgorithm(short signatureAlgorithm)
Return true if this TlsCrypto can support the passed in signature algorithm
(not necessarily in combination with EVERY hash algorithm).
|
boolean |
hasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm)
Return true if this TlsCrypto can support the passed in signature algorithm.
|
boolean |
hasSignatureScheme(int signatureScheme)
Return true if this TlsCrypto can support the passed in signature scheme.
|
boolean |
hasSRPAuthentication()
Return true if this TlsCrypto can support SRP authentication.
|
TlsSecret |
hkdfInit(int cryptoHashAlgorithm)
Setup an initial "secret" for a chain of HKDF calls (RFC 5869), containing a string of HashLen zeroes.
|
protected java.lang.Boolean |
isSupportedEncryptionAlgorithm(int encryptionAlgorithm) |
protected java.lang.Boolean |
isSupportedNamedGroup(int namedGroup) |
protected boolean |
isUsableCipher(java.lang.String cipherAlgorithm,
int keySize) |
protected boolean |
isUsableMAC(java.lang.String macAlgorithm) |
adoptSecretprotected JcaTlsCrypto(org.bouncycastle.jcajce.util.JcaJceHelper helper,
java.security.SecureRandom entropySource,
java.security.SecureRandom nonceEntropySource)
helper - a JCA/JCE helper configured for the class's default provider.entropySource - primary entropy source, used for key generation.nonceEntropySource - secondary entropy source, used for nonce and IV generation.public TlsNonceGenerator createNonceGenerator(byte[] additionalSeedMaterial)
TlsCryptoTlsCrypto's entropy source, and from the provided additional seed material. The
output of each returned generator must be completely independent of the others.additionalSeedMaterial - context-specific seed materialTlsNonceGeneratorpublic java.security.SecureRandom getSecureRandom()
TlsCryptopublic byte[] calculateKeyAgreement(java.lang.String agreementAlgorithm,
java.security.PrivateKey privateKey,
java.security.PublicKey publicKey,
java.lang.String secretAlgorithm)
throws java.security.GeneralSecurityException
java.security.GeneralSecurityExceptionpublic TlsCertificate createCertificate(byte[] encoding) throws java.io.IOException
TlsCryptoencoding - DER/BER encoding of the certificate of interest.java.io.IOException - if there is an issue on decoding or constructing the certificate.public TlsCertificate createCertificate(short type, byte[] encoding) throws java.io.IOException
TlsCryptotype - Certificate type as per IANA TLS Certificate Types registryencoding - DER/BER encoding of the certificate of interest.java.io.IOException - if there is an issue on decoding or constructing the certificate.public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAlgorithm, int macAlgorithm) throws java.io.IOException
TlsCrypto
See enumeration classes EncryptionAlgorithm, MACAlgorithm for appropriate argument values.
cryptoParams - context specific parameters.encryptionAlgorithm - the encryption algorithm to be employed by the cipher.macAlgorithm - the MAC algorithm to be employed by the cipher.TlsCipher implementing the encryption and MAC algorithms.java.io.IOExceptionpublic TlsHMAC createHMAC(int macAlgorithm)
TlsCrypto
See enumeration class MACAlgorithm for appropriate argument values.
macAlgorithm - the MAC algorithm the HMAC needs to match.TlsHMAC.public TlsHMAC createHMACForHash(int cryptoHashAlgorithm)
TlsCrypto
See enumeration class CryptoHashAlgorithm for appropriate argument values.
cryptoHashAlgorithm - the hash algorithm the HMAC should use.TlsHMAC.protected TlsHMAC createHMAC_SSL(int macAlgorithm) throws java.security.GeneralSecurityException, java.io.IOException
java.security.GeneralSecurityExceptionjava.io.IOExceptionprotected TlsHMAC createMAC(TlsCryptoParameters cryptoParams, int macAlgorithm) throws java.security.GeneralSecurityException, java.io.IOException
java.security.GeneralSecurityExceptionjava.io.IOExceptionpublic TlsSRP6Client createSRP6Client(TlsSRPConfig srpConfig)
TlsCryptosrpConfig - client config.public TlsSRP6Server createSRP6Server(TlsSRPConfig srpConfig, java.math.BigInteger srpVerifier)
TlsCryptosrpConfig - server config.srpVerifier - the SRP6 verifier value.public TlsSRP6VerifierGenerator createSRP6VerifierGenerator(TlsSRPConfig srpConfig)
TlsCryptosrpConfig - generator config.public java.security.AlgorithmParameters getNamedGroupAlgorithmParameters(int namedGroup)
throws java.security.GeneralSecurityException
java.security.GeneralSecurityExceptionpublic java.security.AlgorithmParameters getSignatureSchemeAlgorithmParameters(int signatureScheme)
throws java.security.GeneralSecurityException
java.security.GeneralSecurityExceptionpublic boolean hasAnyStreamVerifiers(java.util.Vector signatureAndHashAlgorithms)
TlsCryptosignatureAndHashAlgorithms - A Vector of SignatureAndHashAlgorithm values.public boolean hasAnyStreamVerifiersLegacy(short[] clientCertificateTypes)
TlsCryptoclientCertificateTypes - An array of ClientCertificateType values.public boolean hasCryptoHashAlgorithm(int cryptoHashAlgorithm)
TlsCryptocryptoHashAlgorithm - the algorithm of interest.public boolean hasCryptoSignatureAlgorithm(int cryptoSignatureAlgorithm)
TlsCryptocryptoSignatureAlgorithm - the algorithm of interest.public boolean hasDHAgreement()
TlsCryptopublic boolean hasECDHAgreement()
TlsCryptopublic boolean hasEncryptionAlgorithm(int encryptionAlgorithm)
TlsCryptoencryptionAlgorithm - the algorithm of interest.public boolean hasHKDFAlgorithm(int cryptoHashAlgorithm)
TlsCryptocryptoHashAlgorithm - the algorithm of interest.public boolean hasMacAlgorithm(int macAlgorithm)
TlsCryptomacAlgorithm - the algorithm of interest.public boolean hasNamedGroup(int namedGroup)
TlsCryptonamed group value.named group value.public boolean hasRSAEncryption()
TlsCryptopublic boolean hasSignatureAlgorithm(short signatureAlgorithm)
TlsCryptosignatureAlgorithm - the algorithm of interest.public boolean hasSignatureAndHashAlgorithm(SignatureAndHashAlgorithm sigAndHashAlgorithm)
TlsCryptosigAndHashAlgorithm - the algorithm of interest.public boolean hasSignatureScheme(int signatureScheme)
TlsCryptosignatureScheme - the scheme of interest.public boolean hasSRPAuthentication()
TlsCryptopublic TlsSecret createSecret(byte[] data)
TlsCryptodata - the data to base the TlsSecret on.public TlsSecret generateRSAPreMasterSecret(ProtocolVersion version)
TlsCryptoversion - the client version to place in the first 2 bytespublic TlsHash createHash(int cryptoHashAlgorithm)
TlsCrypto
See enumeration class CryptoHashAlgorithm for appropriate argument values.
cryptoHashAlgorithm - the hash algorithm the hash needs to implement.TlsHash.public TlsDHDomain createDHDomain(TlsDHConfig dhConfig)
TlsCryptodhConfig - the config describing the DH parameters to use.public TlsECDomain createECDomain(TlsECConfig ecConfig)
TlsCryptoecConfig - the config describing the EC parameters to use.public TlsSecret hkdfInit(int cryptoHashAlgorithm)
TlsCryptocryptoHashAlgorithm - the hash algorithm to instantiate HMAC with. See CryptoHashAlgorithm for values.protected TlsAEADCipherImpl createAEADCipher(java.lang.String cipherName, java.lang.String algorithm, int keySize, boolean isEncrypting) throws java.security.GeneralSecurityException
cipherName - the full name of the cipher (algorithm/mode/padding)algorithm - the base algorithm namekeySize - keySize (in bytes) for the cipher key.isEncrypting - true if the cipher is for encryption, false otherwise.java.security.GeneralSecurityException - in case of failure.protected TlsBlockCipherImpl createBlockCipher(java.lang.String cipherName, java.lang.String algorithm, int keySize, boolean isEncrypting) throws java.security.GeneralSecurityException
cipherName - the full name of the cipher (algorithm/mode/padding)algorithm - the base algorithm namekeySize - keySize (in bytes) for the cipher key.isEncrypting - true if the cipher is for encryption, false otherwise.java.security.GeneralSecurityException - in case of failure.protected TlsBlockCipherImpl createBlockCipherWithCBCImplicitIV(java.lang.String cipherName, java.lang.String algorithm, int keySize, boolean isEncrypting) throws java.security.GeneralSecurityException
cipherName - the full name of the cipher (algorithm/mode/padding)algorithm - the base algorithm namekeySize - keySize (in bytes) for the cipher key.isEncrypting - true if the cipher is for encryption, false otherwise.java.security.GeneralSecurityException - in case of failure.protected TlsHash createHash(java.lang.String digestName) throws java.security.GeneralSecurityException
digestName - the name of the Hash function required.java.security.GeneralSecurityException - in case of failure.protected TlsNullCipher createNullCipher(TlsCryptoParameters cryptoParams, int macAlgorithm) throws java.io.IOException, java.security.GeneralSecurityException
macAlgorithm - the name of the algorithm supporting the MAC.java.io.IOException - in case of failure.java.security.GeneralSecurityException - in case of a specific failure in the JCA/JCE layer.protected TlsStreamSigner createStreamSigner(SignatureAndHashAlgorithm algorithm, java.security.PrivateKey privateKey, boolean needsRandom) throws java.io.IOException
java.io.IOExceptionprotected TlsStreamSigner createStreamSigner(java.lang.String algorithmName, java.security.spec.AlgorithmParameterSpec parameter, java.security.PrivateKey privateKey, boolean needsRandom) throws java.io.IOException
java.io.IOExceptionprotected TlsStreamVerifier createStreamVerifier(DigitallySigned digitallySigned, java.security.PublicKey publicKey) throws java.io.IOException
java.io.IOExceptionprotected TlsStreamVerifier createStreamVerifier(java.lang.String algorithmName, java.security.spec.AlgorithmParameterSpec parameter, byte[] signature, java.security.PublicKey publicKey) throws java.io.IOException
java.io.IOExceptionprotected Tls13Verifier createTls13Verifier(java.lang.String algorithmName, java.security.spec.AlgorithmParameterSpec parameter, java.security.PublicKey publicKey) throws java.io.IOException
java.io.IOExceptionprotected TlsStreamSigner createVerifyingStreamSigner(SignatureAndHashAlgorithm algorithm, java.security.PrivateKey privateKey, boolean needsRandom, java.security.PublicKey publicKey) throws java.io.IOException
java.io.IOExceptionprotected TlsStreamSigner createVerifyingStreamSigner(java.lang.String algorithmName, java.security.spec.AlgorithmParameterSpec parameter, java.security.PrivateKey privateKey, boolean needsRandom, java.security.PublicKey publicKey) throws java.io.IOException
java.io.IOExceptionprotected java.lang.Boolean isSupportedEncryptionAlgorithm(int encryptionAlgorithm)
protected java.lang.Boolean isSupportedNamedGroup(int namedGroup)
protected boolean isUsableCipher(java.lang.String cipherAlgorithm,
int keySize)
protected boolean isUsableMAC(java.lang.String macAlgorithm)
public org.bouncycastle.jcajce.util.JcaJceHelper getHelper()
protected TlsBlockCipherImpl createCBCBlockCipherImpl(TlsCryptoParameters cryptoParams, java.lang.String algorithm, int cipherKeySize, boolean forEncryption) throws java.security.GeneralSecurityException
java.security.GeneralSecurityExceptionprotected TlsCipher createCipher_CBC(TlsCryptoParameters cryptoParams, java.lang.String algorithm, int cipherKeySize, int macAlgorithm) throws java.security.GeneralSecurityException, java.io.IOException
java.security.GeneralSecurityExceptionjava.io.IOException