Package org.bouncycastle.crypto.tls
Class TlsUtils
- java.lang.Object
-
- org.bouncycastle.crypto.tls.TlsUtils
-
public class TlsUtils extends java.lang.ObjectSome helper functions for MicroTLS.
-
-
Field Summary
Fields Modifier and Type Field Description static byte[]EMPTY_BYTESstatic int[]EMPTY_INTSstatic long[]EMPTY_LONGSstatic short[]EMPTY_SHORTSstatic java.lang.IntegerEXT_signature_algorithms
-
Constructor Summary
Constructors Constructor Description TlsUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddSignatureAlgorithmsExtension(java.util.Hashtable extensions, java.util.Vector supportedSignatureAlgorithms)Add a 'signature_algorithms' extension to existing extensions.static voidcheckUint16(int i)static voidcheckUint16(long i)static voidcheckUint24(int i)static voidcheckUint24(long i)static voidcheckUint32(long i)static voidcheckUint48(long i)static voidcheckUint64(long i)static voidcheckUint8(int i)static voidcheckUint8(long i)static voidcheckUint8(short i)static DigestcloneHash(short hashAlgorithm, Digest hash)static DigestclonePRFHash(int prfAlgorithm, Digest hash)static DigestcreateHash(short hashAlgorithm)static DigestcreateHash(SignatureAndHashAlgorithm signatureAndHashAlgorithm)static DigestcreatePRFHash(int prfAlgorithm)static byte[]createSignatureAlgorithmsExtension(java.util.Vector supportedSignatureAlgorithms)Create a 'signature_algorithms' extension value.static TlsSignercreateTlsSigner(short clientCertificateType)static byte[]encodeOpaque8(byte[] buf)static voidencodeSupportedSignatureAlgorithms(java.util.Vector supportedSignatureAlgorithms, boolean allowAnonymous, java.io.OutputStream output)static byte[]encodeUint16ArrayWithUint16Length(int[] uints)static byte[]encodeUint8ArrayWithUint8Length(short[] uints)static java.util.VectorgetAllSignatureAlgorithms()static intgetCipherType(int ciphersuite)static java.util.VectorgetDefaultDSSSignatureAlgorithms()static java.util.VectorgetDefaultECDSASignatureAlgorithms()static java.util.VectorgetDefaultRSASignatureAlgorithms()static java.util.VectorgetDefaultSupportedSignatureAlgorithms()static intgetEncryptionAlgorithm(int ciphersuite)static byte[]getExtensionData(java.util.Hashtable extensions, java.lang.Integer extensionType)static shortgetHashAlgorithmForPRFAlgorithm(int prfAlgorithm)static intgetKeyExchangeAlgorithm(int ciphersuite)static intgetMACAlgorithm(int ciphersuite)static ProtocolVersiongetMinimumVersion(int ciphersuite)static ASN1ObjectIdentifiergetOIDForHashAlgorithm(short hashAlgorithm)static java.util.VectorgetSignatureAlgorithmsExtension(java.util.Hashtable extensions)Get a 'signature_algorithms' extension from extensions.static SignatureAndHashAlgorithmgetSignatureAndHashAlgorithm(TlsContext context, TlsSignerCredentials signerCredentials)static java.util.VectorgetUsableSignatureAlgorithms(java.util.Vector sigHashAlgs)static booleanhasExpectedEmptyExtensionData(java.util.Hashtable extensions, java.lang.Integer extensionType, short alertDescription)static booleanhasSigningCapability(short clientCertificateType)static TlsSessionimportSession(byte[] sessionID, SessionParameters sessionParameters)static booleanisAEADCipherSuite(int ciphersuite)static booleanisBlockCipherSuite(int ciphersuite)static booleanisSignatureAlgorithmsExtensionAllowed(ProtocolVersion clientVersion)static booleanisSSL(TlsContext context)static booleanisStreamCipherSuite(int ciphersuite)static booleanisTLSv11(ProtocolVersion version)static booleanisTLSv11(TlsContext context)static booleanisTLSv12(ProtocolVersion version)static booleanisTLSv12(TlsContext context)static booleanisValidCipherSuiteForSignatureAlgorithms(int cipherSuite, java.util.Vector sigAlgs)static booleanisValidCipherSuiteForVersion(int cipherSuite, ProtocolVersion serverVersion)static booleanisValidUint16(int i)static booleanisValidUint16(long i)static booleanisValidUint24(int i)static booleanisValidUint24(long i)static booleanisValidUint32(long i)static booleanisValidUint48(long i)static booleanisValidUint64(long i)static booleanisValidUint8(int i)static booleanisValidUint8(long i)static booleanisValidUint8(short i)static java.util.VectorparseSupportedSignatureAlgorithms(boolean allowAnonymous, java.io.InputStream input)static byte[]PRF(TlsContext context, byte[] secret, java.lang.String asciiLabel, byte[] seed, int size)static byte[]PRF_legacy(byte[] secret, java.lang.String asciiLabel, byte[] seed, int size)static byte[]readAllOrNothing(int length, java.io.InputStream input)static ASN1PrimitivereadASN1Object(byte[] encoding)static ASN1PrimitivereadDERObject(byte[] encoding)static voidreadFully(byte[] buf, java.io.InputStream input)static byte[]readFully(int length, java.io.InputStream input)static byte[]readOpaque16(java.io.InputStream input)static byte[]readOpaque24(java.io.InputStream input)static byte[]readOpaque8(java.io.InputStream input)static java.util.VectorreadSignatureAlgorithmsExtension(byte[] extensionData)Read 'signature_algorithms' extension data.static intreadUint16(byte[] buf, int offset)static intreadUint16(java.io.InputStream input)static int[]readUint16Array(int count, java.io.InputStream input)static intreadUint24(byte[] buf, int offset)static intreadUint24(java.io.InputStream input)static longreadUint32(byte[] buf, int offset)static longreadUint32(java.io.InputStream input)static longreadUint48(byte[] buf, int offset)static longreadUint48(java.io.InputStream input)static shortreadUint8(byte[] buf, int offset)static shortreadUint8(java.io.InputStream input)static short[]readUint8Array(int count, java.io.InputStream input)static ProtocolVersionreadVersion(byte[] buf, int offset)static ProtocolVersionreadVersion(java.io.InputStream input)static intreadVersionRaw(byte[] buf, int offset)static intreadVersionRaw(java.io.InputStream input)static voidverifySupportedSignatureAlgorithm(java.util.Vector supportedSignatureAlgorithms, SignatureAndHashAlgorithm signatureAlgorithm)static voidwriteGMTUnixTime(byte[] buf, int offset)static voidwriteOpaque16(byte[] buf, java.io.OutputStream output)static voidwriteOpaque24(byte[] buf, java.io.OutputStream output)static voidwriteOpaque8(byte[] buf, java.io.OutputStream output)static voidwriteUint16(int i, byte[] buf, int offset)static voidwriteUint16(int i, java.io.OutputStream output)static voidwriteUint16Array(int[] uints, byte[] buf, int offset)static voidwriteUint16Array(int[] uints, java.io.OutputStream output)static voidwriteUint16ArrayWithUint16Length(int[] uints, byte[] buf, int offset)static voidwriteUint16ArrayWithUint16Length(int[] uints, java.io.OutputStream output)static voidwriteUint24(int i, byte[] buf, int offset)static voidwriteUint24(int i, java.io.OutputStream output)static voidwriteUint32(long i, byte[] buf, int offset)static voidwriteUint32(long i, java.io.OutputStream output)static voidwriteUint48(long i, byte[] buf, int offset)static voidwriteUint48(long i, java.io.OutputStream output)static voidwriteUint64(long i, byte[] buf, int offset)static voidwriteUint64(long i, java.io.OutputStream output)static voidwriteUint8(int i, byte[] buf, int offset)static voidwriteUint8(int i, java.io.OutputStream output)static voidwriteUint8(short i, byte[] buf, int offset)static voidwriteUint8(short i, java.io.OutputStream output)static voidwriteUint8Array(short[] uints, byte[] buf, int offset)static voidwriteUint8Array(short[] uints, java.io.OutputStream output)static voidwriteUint8ArrayWithUint8Length(short[] uints, byte[] buf, int offset)static voidwriteUint8ArrayWithUint8Length(short[] uints, java.io.OutputStream output)static voidwriteVersion(ProtocolVersion version, byte[] buf, int offset)static voidwriteVersion(ProtocolVersion version, java.io.OutputStream output)
-
-
-
Field Detail
-
EMPTY_BYTES
public static final byte[] EMPTY_BYTES
-
EMPTY_SHORTS
public static final short[] EMPTY_SHORTS
-
EMPTY_INTS
public static final int[] EMPTY_INTS
-
EMPTY_LONGS
public static final long[] EMPTY_LONGS
-
EXT_signature_algorithms
public static final java.lang.Integer EXT_signature_algorithms
-
-
Method Detail
-
checkUint8
public static void checkUint8(short i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint8
public static void checkUint8(int i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint8
public static void checkUint8(long i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint16
public static void checkUint16(int i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint16
public static void checkUint16(long i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint24
public static void checkUint24(int i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint24
public static void checkUint24(long i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint32
public static void checkUint32(long i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint48
public static void checkUint48(long i) throws java.io.IOException- Throws:
java.io.IOException
-
checkUint64
public static void checkUint64(long i) throws java.io.IOException- Throws:
java.io.IOException
-
isValidUint8
public static boolean isValidUint8(short i)
-
isValidUint8
public static boolean isValidUint8(int i)
-
isValidUint8
public static boolean isValidUint8(long i)
-
isValidUint16
public static boolean isValidUint16(int i)
-
isValidUint16
public static boolean isValidUint16(long i)
-
isValidUint24
public static boolean isValidUint24(int i)
-
isValidUint24
public static boolean isValidUint24(long i)
-
isValidUint32
public static boolean isValidUint32(long i)
-
isValidUint48
public static boolean isValidUint48(long i)
-
isValidUint64
public static boolean isValidUint64(long i)
-
isSSL
public static boolean isSSL(TlsContext context)
-
isTLSv11
public static boolean isTLSv11(ProtocolVersion version)
-
isTLSv11
public static boolean isTLSv11(TlsContext context)
-
isTLSv12
public static boolean isTLSv12(ProtocolVersion version)
-
isTLSv12
public static boolean isTLSv12(TlsContext context)
-
writeUint8
public static void writeUint8(short i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint8
public static void writeUint8(int i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint8
public static void writeUint8(short i, byte[] buf, int offset)
-
writeUint8
public static void writeUint8(int i, byte[] buf, int offset)
-
writeUint16
public static void writeUint16(int i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint16
public static void writeUint16(int i, byte[] buf, int offset)
-
writeUint24
public static void writeUint24(int i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint24
public static void writeUint24(int i, byte[] buf, int offset)
-
writeUint32
public static void writeUint32(long i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint32
public static void writeUint32(long i, byte[] buf, int offset)
-
writeUint48
public static void writeUint48(long i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint48
public static void writeUint48(long i, byte[] buf, int offset)
-
writeUint64
public static void writeUint64(long i, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint64
public static void writeUint64(long i, byte[] buf, int offset)
-
writeOpaque8
public static void writeOpaque8(byte[] buf, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeOpaque16
public static void writeOpaque16(byte[] buf, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeOpaque24
public static void writeOpaque24(byte[] buf, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint8Array
public static void writeUint8Array(short[] uints, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint8Array
public static void writeUint8Array(short[] uints, byte[] buf, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint8ArrayWithUint8Length
public static void writeUint8ArrayWithUint8Length(short[] uints, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint8ArrayWithUint8Length
public static void writeUint8ArrayWithUint8Length(short[] uints, byte[] buf, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint16Array
public static void writeUint16Array(int[] uints, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint16Array
public static void writeUint16Array(int[] uints, byte[] buf, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint16ArrayWithUint16Length
public static void writeUint16ArrayWithUint16Length(int[] uints, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
writeUint16ArrayWithUint16Length
public static void writeUint16ArrayWithUint16Length(int[] uints, byte[] buf, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
encodeOpaque8
public static byte[] encodeOpaque8(byte[] buf) throws java.io.IOException- Throws:
java.io.IOException
-
encodeUint8ArrayWithUint8Length
public static byte[] encodeUint8ArrayWithUint8Length(short[] uints) throws java.io.IOException- Throws:
java.io.IOException
-
encodeUint16ArrayWithUint16Length
public static byte[] encodeUint16ArrayWithUint16Length(int[] uints) throws java.io.IOException- Throws:
java.io.IOException
-
readUint8
public static short readUint8(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint8
public static short readUint8(byte[] buf, int offset)
-
readUint16
public static int readUint16(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint16
public static int readUint16(byte[] buf, int offset)
-
readUint24
public static int readUint24(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint24
public static int readUint24(byte[] buf, int offset)
-
readUint32
public static long readUint32(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint32
public static long readUint32(byte[] buf, int offset)
-
readUint48
public static long readUint48(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint48
public static long readUint48(byte[] buf, int offset)
-
readAllOrNothing
public static byte[] readAllOrNothing(int length, java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readFully
public static byte[] readFully(int length, java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readFully
public static void readFully(byte[] buf, java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readOpaque8
public static byte[] readOpaque8(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readOpaque16
public static byte[] readOpaque16(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readOpaque24
public static byte[] readOpaque24(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint8Array
public static short[] readUint8Array(int count, java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readUint16Array
public static int[] readUint16Array(int count, java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readVersion
public static ProtocolVersion readVersion(byte[] buf, int offset) throws java.io.IOException
- Throws:
java.io.IOException
-
readVersion
public static ProtocolVersion readVersion(java.io.InputStream input) throws java.io.IOException
- Throws:
java.io.IOException
-
readVersionRaw
public static int readVersionRaw(byte[] buf, int offset) throws java.io.IOException- Throws:
java.io.IOException
-
readVersionRaw
public static int readVersionRaw(java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
readASN1Object
public static ASN1Primitive readASN1Object(byte[] encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
readDERObject
public static ASN1Primitive readDERObject(byte[] encoding) throws java.io.IOException
- Throws:
java.io.IOException
-
writeGMTUnixTime
public static void writeGMTUnixTime(byte[] buf, int offset)
-
writeVersion
public static void writeVersion(ProtocolVersion version, java.io.OutputStream output) throws java.io.IOException
- Throws:
java.io.IOException
-
writeVersion
public static void writeVersion(ProtocolVersion version, byte[] buf, int offset)
-
getAllSignatureAlgorithms
public static java.util.Vector getAllSignatureAlgorithms()
-
getDefaultDSSSignatureAlgorithms
public static java.util.Vector getDefaultDSSSignatureAlgorithms()
-
getDefaultECDSASignatureAlgorithms
public static java.util.Vector getDefaultECDSASignatureAlgorithms()
-
getDefaultRSASignatureAlgorithms
public static java.util.Vector getDefaultRSASignatureAlgorithms()
-
getDefaultSupportedSignatureAlgorithms
public static java.util.Vector getDefaultSupportedSignatureAlgorithms()
-
getSignatureAndHashAlgorithm
public static SignatureAndHashAlgorithm getSignatureAndHashAlgorithm(TlsContext context, TlsSignerCredentials signerCredentials) throws java.io.IOException
- Throws:
java.io.IOException
-
getExtensionData
public static byte[] getExtensionData(java.util.Hashtable extensions, java.lang.Integer extensionType)
-
hasExpectedEmptyExtensionData
public static boolean hasExpectedEmptyExtensionData(java.util.Hashtable extensions, java.lang.Integer extensionType, short alertDescription) throws java.io.IOException- Throws:
java.io.IOException
-
importSession
public static TlsSession importSession(byte[] sessionID, SessionParameters sessionParameters)
-
isSignatureAlgorithmsExtensionAllowed
public static boolean isSignatureAlgorithmsExtensionAllowed(ProtocolVersion clientVersion)
-
addSignatureAlgorithmsExtension
public static void addSignatureAlgorithmsExtension(java.util.Hashtable extensions, java.util.Vector supportedSignatureAlgorithms) throws java.io.IOExceptionAdd a 'signature_algorithms' extension to existing extensions.- Parameters:
extensions- AHashtableto add the extension to.supportedSignatureAlgorithms-Vectorcontaining at least 1SignatureAndHashAlgorithm.- Throws:
java.io.IOException
-
getSignatureAlgorithmsExtension
public static java.util.Vector getSignatureAlgorithmsExtension(java.util.Hashtable extensions) throws java.io.IOExceptionGet a 'signature_algorithms' extension from extensions.- Parameters:
extensions- AHashtableto get the extension from, if it is present.- Returns:
- A
Vectorcontaining at least 1SignatureAndHashAlgorithm, or null. - Throws:
java.io.IOException
-
createSignatureAlgorithmsExtension
public static byte[] createSignatureAlgorithmsExtension(java.util.Vector supportedSignatureAlgorithms) throws java.io.IOExceptionCreate a 'signature_algorithms' extension value.- Parameters:
supportedSignatureAlgorithms- AVectorcontaining at least 1SignatureAndHashAlgorithm.- Returns:
- A byte array suitable for use as an extension value.
- Throws:
java.io.IOException
-
readSignatureAlgorithmsExtension
public static java.util.Vector readSignatureAlgorithmsExtension(byte[] extensionData) throws java.io.IOExceptionRead 'signature_algorithms' extension data.- Parameters:
extensionData- The extension data.- Returns:
- A
Vectorcontaining at least 1SignatureAndHashAlgorithm. - Throws:
java.io.IOException
-
encodeSupportedSignatureAlgorithms
public static void encodeSupportedSignatureAlgorithms(java.util.Vector supportedSignatureAlgorithms, boolean allowAnonymous, java.io.OutputStream output) throws java.io.IOException- Throws:
java.io.IOException
-
parseSupportedSignatureAlgorithms
public static java.util.Vector parseSupportedSignatureAlgorithms(boolean allowAnonymous, java.io.InputStream input) throws java.io.IOException- Throws:
java.io.IOException
-
verifySupportedSignatureAlgorithm
public static void verifySupportedSignatureAlgorithm(java.util.Vector supportedSignatureAlgorithms, SignatureAndHashAlgorithm signatureAlgorithm) throws java.io.IOException- Throws:
java.io.IOException
-
PRF
public static byte[] PRF(TlsContext context, byte[] secret, java.lang.String asciiLabel, byte[] seed, int size)
-
PRF_legacy
public static byte[] PRF_legacy(byte[] secret, java.lang.String asciiLabel, byte[] seed, int size)
-
createHash
public static Digest createHash(short hashAlgorithm)
-
createHash
public static Digest createHash(SignatureAndHashAlgorithm signatureAndHashAlgorithm)
-
createPRFHash
public static Digest createPRFHash(int prfAlgorithm)
-
getHashAlgorithmForPRFAlgorithm
public static short getHashAlgorithmForPRFAlgorithm(int prfAlgorithm)
-
getOIDForHashAlgorithm
public static ASN1ObjectIdentifier getOIDForHashAlgorithm(short hashAlgorithm)
-
hasSigningCapability
public static boolean hasSigningCapability(short clientCertificateType)
-
createTlsSigner
public static TlsSigner createTlsSigner(short clientCertificateType)
-
getCipherType
public static int getCipherType(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
getEncryptionAlgorithm
public static int getEncryptionAlgorithm(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
getKeyExchangeAlgorithm
public static int getKeyExchangeAlgorithm(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
getMACAlgorithm
public static int getMACAlgorithm(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
getMinimumVersion
public static ProtocolVersion getMinimumVersion(int ciphersuite)
-
isAEADCipherSuite
public static boolean isAEADCipherSuite(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
isBlockCipherSuite
public static boolean isBlockCipherSuite(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
isStreamCipherSuite
public static boolean isStreamCipherSuite(int ciphersuite) throws java.io.IOException- Throws:
java.io.IOException
-
isValidCipherSuiteForSignatureAlgorithms
public static boolean isValidCipherSuiteForSignatureAlgorithms(int cipherSuite, java.util.Vector sigAlgs)
-
isValidCipherSuiteForVersion
public static boolean isValidCipherSuiteForVersion(int cipherSuite, ProtocolVersion serverVersion)
-
getUsableSignatureAlgorithms
public static java.util.Vector getUsableSignatureAlgorithms(java.util.Vector sigHashAlgs)
-
-