Bouncy Castle Cryptography 1.50

org.bouncycastle.crypto.tls
Class TlsUtils

java.lang.Object
  extended by org.bouncycastle.crypto.tls.TlsUtils

public class TlsUtils
extends java.lang.Object

Some helper functions for MicroTLS.


Field Summary
static byte[] EMPTY_BYTES
           
static java.lang.Integer EXT_signature_algorithms
           
 
Constructor Summary
TlsUtils()
           
 
Method Summary
static void addSignatureAlgorithmsExtension(java.util.Hashtable extensions, java.util.Vector supportedSignatureAlgorithms)
          Add a 'signature_algorithms' extension to existing extensions.
static void checkUint16(int i)
           
static void checkUint24(int i)
           
static void checkUint32(long i)
           
static void checkUint48(long i)
           
static void checkUint64(long i)
           
static void checkUint8(int i)
           
static void checkUint8(short i)
           
static Digest cloneHash(short hashAlgorithm, Digest hash)
           
static Digest clonePRFHash(int prfAlgorithm, Digest hash)
           
static Digest createHash(short hashAlgorithm)
           
static Digest createPRFHash(int prfAlgorithm)
           
static byte[] createSignatureAlgorithmsExtension(java.util.Vector supportedSignatureAlgorithms)
          Create a 'signature_algorithms' extension value.
static TlsSigner createTlsSigner(short clientCertificateType)
           
static byte[] encodeOpaque8(byte[] buf)
           
static void encodeSupportedSignatureAlgorithms(java.util.Vector supportedSignatureAlgorithms, boolean allowAnonymous, java.io.OutputStream output)
           
static byte[] encodeUint16ArrayWithUint16Length(int[] uints)
           
static byte[] encodeUint8ArrayWithUint8Length(short[] uints)
           
static java.util.Vector getDefaultDSSSignatureAlgorithms()
           
static java.util.Vector getDefaultECDSASignatureAlgorithms()
           
static java.util.Vector getDefaultRSASignatureAlgorithms()
           
static byte[] getExtensionData(java.util.Hashtable extensions, java.lang.Integer extensionType)
           
static short getHashAlgorithmForPRFAlgorithm(int prfAlgorithm)
           
static ASN1ObjectIdentifier getOIDForHashAlgorithm(short hashAlgorithm)
           
static java.util.Vector getSignatureAlgorithmsExtension(java.util.Hashtable extensions)
          Get a 'signature_algorithms' extension from extensions.
static boolean hasExpectedEmptyExtensionData(java.util.Hashtable extensions, java.lang.Integer extensionType, short alertDescription)
           
static boolean hasSigningCapability(short clientCertificateType)
           
static TlsSession importSession(byte[] sessionID, SessionParameters sessionParameters)
           
static boolean isSignatureAlgorithmsExtensionAllowed(ProtocolVersion clientVersion)
           
static boolean isSSL(TlsContext context)
           
static boolean isTLSv11(TlsContext context)
           
static boolean isTLSv12(TlsContext context)
           
static boolean isValidUint16(int i)
           
static boolean isValidUint24(int i)
           
static boolean isValidUint32(long i)
           
static boolean isValidUint48(long i)
           
static boolean isValidUint64(long i)
           
static boolean isValidUint8(int i)
           
static boolean isValidUint8(short i)
           
static java.util.Vector parseSupportedSignatureAlgorithms(boolean allowAnonymous, java.io.InputStream input)
           
static byte[] PRF(TlsContext context, byte[] secret, java.lang.String asciiLabel, byte[] seed, int size)
           
static byte[] readAllOrNothing(int length, java.io.InputStream input)
           
static ASN1Primitive readASN1Object(byte[] encoding)
           
static ASN1Primitive readDERObject(byte[] encoding)
           
static void readFully(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.Vector readSignatureAlgorithmsExtension(byte[] extensionData)
          Read 'signature_algorithms' extension data.
static int readUint16(byte[] buf, int offset)
           
static int readUint16(java.io.InputStream input)
           
static int[] readUint16Array(int count, java.io.InputStream input)
           
static int readUint24(byte[] buf, int offset)
           
static int readUint24(java.io.InputStream input)
           
static long readUint32(java.io.InputStream input)
           
static long readUint48(byte[] buf, int offset)
           
static long readUint48(java.io.InputStream input)
           
static short readUint8(byte[] buf, int offset)
           
static short readUint8(java.io.InputStream input)
           
static short[] readUint8Array(int count, java.io.InputStream input)
           
static ProtocolVersion readVersion(byte[] buf, int offset)
           
static ProtocolVersion readVersion(java.io.InputStream input)
           
static int readVersionRaw(byte[] buf, int offset)
           
static int readVersionRaw(java.io.InputStream input)
           
static void writeGMTUnixTime(byte[] buf, int offset)
           
static void writeOpaque16(byte[] buf, java.io.OutputStream output)
           
static void writeOpaque24(byte[] buf, java.io.OutputStream output)
           
static void writeOpaque8(byte[] buf, java.io.OutputStream output)
           
static void writeUint16(int i, byte[] buf, int offset)
           
static void writeUint16(int i, java.io.OutputStream output)
           
static void writeUint16Array(int[] uints, byte[] buf, int offset)
           
static void writeUint16Array(int[] uints, java.io.OutputStream output)
           
static void writeUint16ArrayWithUint16Length(int[] uints, byte[] buf, int offset)
           
static void writeUint16ArrayWithUint16Length(int[] uints, java.io.OutputStream output)
           
static void writeUint24(int i, byte[] buf, int offset)
           
static void writeUint24(int i, java.io.OutputStream output)
           
static void writeUint32(long i, byte[] buf, int offset)
           
static void writeUint32(long i, java.io.OutputStream output)
           
static void writeUint48(long i, byte[] buf, int offset)
           
static void writeUint48(long i, java.io.OutputStream output)
           
static void writeUint64(long i, byte[] buf, int offset)
           
static void writeUint64(long i, java.io.OutputStream output)
           
static void writeUint8(int i, byte[] buf, int offset)
           
static void writeUint8(int i, java.io.OutputStream output)
           
static void writeUint8(short i, byte[] buf, int offset)
           
static void writeUint8(short i, java.io.OutputStream output)
           
static void writeUint8Array(short[] uints, byte[] buf, int offset)
           
static void writeUint8Array(short[] uints, java.io.OutputStream output)
           
static void writeUint8ArrayWithUint8Length(short[] uints, byte[] buf, int offset)
           
static void writeUint8ArrayWithUint8Length(short[] uints, java.io.OutputStream output)
           
static void writeVersion(ProtocolVersion version, byte[] buf, int offset)
           
static void writeVersion(ProtocolVersion version, java.io.OutputStream output)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_BYTES

public static byte[] EMPTY_BYTES

EXT_signature_algorithms

public static final java.lang.Integer EXT_signature_algorithms
Constructor Detail

TlsUtils

public TlsUtils()
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

checkUint16

public static void checkUint16(int i)
                        throws java.io.IOException
Throws:
java.io.IOException

checkUint24

public static void checkUint24(int 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)

isValidUint16

public static boolean isValidUint16(int i)

isValidUint24

public static boolean isValidUint24(int 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(TlsContext context)

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

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)

getDefaultDSSSignatureAlgorithms

public static java.util.Vector getDefaultDSSSignatureAlgorithms()

getDefaultECDSASignatureAlgorithms

public static java.util.Vector getDefaultECDSASignatureAlgorithms()

getDefaultRSASignatureAlgorithms

public static java.util.Vector getDefaultRSASignatureAlgorithms()

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.IOException
Add a 'signature_algorithms' extension to existing extensions.

Parameters:
extensions - A Hashtable to add the extension to.
supportedSignatureAlgorithms - Vector containing at least 1 SignatureAndHashAlgorithm.
Throws:
java.io.IOException

getSignatureAlgorithmsExtension

public static java.util.Vector getSignatureAlgorithmsExtension(java.util.Hashtable extensions)
                                                        throws java.io.IOException
Get a 'signature_algorithms' extension from extensions.

Parameters:
extensions - A Hashtable to get the extension from, if it is present.
Returns:
A Vector containing at least 1 SignatureAndHashAlgorithm, or null.
Throws:
java.io.IOException

createSignatureAlgorithmsExtension

public static byte[] createSignatureAlgorithmsExtension(java.util.Vector supportedSignatureAlgorithms)
                                                 throws java.io.IOException
Create a 'signature_algorithms' extension value.

Parameters:
supportedSignatureAlgorithms - A Vector containing at least 1 SignatureAndHashAlgorithm.
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.IOException
Read 'signature_algorithms' extension data.

Parameters:
extensionData - The extension data.
Returns:
A Vector containing at least 1 SignatureAndHashAlgorithm.
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

PRF

public static byte[] PRF(TlsContext context,
                         byte[] secret,
                         java.lang.String asciiLabel,
                         byte[] seed,
                         int size)

createHash

public static final Digest createHash(short hashAlgorithm)

cloneHash

public static final Digest cloneHash(short hashAlgorithm,
                                     Digest hash)

createPRFHash

public static final Digest createPRFHash(int prfAlgorithm)

clonePRFHash

public static final Digest clonePRFHash(int prfAlgorithm,
                                        Digest hash)

getHashAlgorithmForPRFAlgorithm

public static final 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)

Bouncy Castle Cryptography 1.50