Class SSLUtil

java.lang.Object
org.globus.gsi.gssapi.SSLUtil

public class SSLUtil extends Object
A collection of SSL-protocol related functions.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static final boolean
    isSSLPacket(byte[] header)
    Determines if a given header is a SSL packet (has a SSL header)
    static final boolean
    isSSLv2HelloPacket(byte[] header)
    Determines if a given header is a SSLv2 client or server hello packet
    static final boolean
    isSSLv3Packet(byte[] header)
    Determines if a given header is a SSLv3 packet (has a SSL header) or a backward compatible version of TLS using the same header format.
    static int
    read(InputStream in, byte[] buf, int off, int len)
    Reads some number of bytes from the input stream.
    static void
    readFully(InputStream in, byte[] buf, int off, int len)
    Reads some number of bytes from the input stream.
    static byte[]
    Reads an entire SSL message from the specified input stream.
    static int
    toInt(byte[] buf, int off)
    Converts 4 bytes to an int at the specified offset in the given byte array.
    static long
    toLong(byte[] buf, int off)
    Converts 8 bytes to a long at the specified offset in the given byte array.
    static short
    toShort(byte a, byte b)
    Converts 2 bytes to a short.
    static int
    toUnsignedShort(byte a, byte b)
    Converts 2 bytes to a unsigned short.
    static void
    writeInt(int v, byte[] buf, int off)
    Converts the specified int value into 4 bytes.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SSLUtil

      public SSLUtil()
  • Method Details

    • read

      public static int read(InputStream in, byte[] buf, int off, int len) throws IOException
      Reads some number of bytes from the input stream. This function reads maximum data available on the stream.
      Parameters:
      in - the input stream to read the bytes from.
      buf - the buffer into which read the data is read.
      off - the start offset in array b at which the data is written.
      len - the maximum number of bytes to read.
      Throws:
      IOException - if I/O error occurs.
    • readFully

      public static void readFully(InputStream in, byte[] buf, int off, int len) throws IOException
      Reads some number of bytes from the input stream. This function blocks until all data is read or an I/O error occurs.
      Parameters:
      in - the input stream to read the bytes from.
      buf - the buffer into which read the data is read.
      off - the start offset in array b at which the data is written.
      len - the maximum number of bytes to read.
      Throws:
      IOException - if I/O error occurs.
    • readSslMessage

      public static byte[] readSslMessage(InputStream in) throws IOException
      Reads an entire SSL message from the specified input stream.
      Parameters:
      in - the input stream to read the SSL message from.
      Returns:
      the byte array containing the SSL message
      Throws:
      IOException - if I/O error occurs.
    • isSSLPacket

      public static final boolean isSSLPacket(byte[] header)
      Determines if a given header is a SSL packet (has a SSL header)
      Returns:
      true if the header is a SSL header. False, otherwise.
    • isSSLv3Packet

      public static final boolean isSSLv3Packet(byte[] header)
      Determines if a given header is a SSLv3 packet (has a SSL header) or a backward compatible version of TLS using the same header format.
      Returns:
      true if the header is a SSLv3 header. False, otherwise.
    • isSSLv2HelloPacket

      public static final boolean isSSLv2HelloPacket(byte[] header)
      Determines if a given header is a SSLv2 client or server hello packet
      Returns:
      true if the header is such a SSLv2 client or server hello packet. False, otherwise.
    • toShort

      public static short toShort(byte a, byte b)
      Converts 2 bytes to a short.
      Parameters:
      a - byte 1
      b - byte 2
      Returns:
      the short value of the 2 bytes
    • toUnsignedShort

      public static int toUnsignedShort(byte a, byte b)
      Converts 2 bytes to a unsigned short.
      Parameters:
      a - byte 1
      b - byte 2
      Returns:
      the unsigned short value of the 2 bytes
    • toInt

      public static int toInt(byte[] buf, int off)
      Converts 4 bytes to an int at the specified offset in the given byte array.
      Parameters:
      buf - the byte array containing the 4 bytes to be converted to an int.
      off - offset in the byte array
      Returns:
      the int value of the 4 bytes.
    • writeInt

      public static void writeInt(int v, byte[] buf, int off)
      Converts the specified int value into 4 bytes. The bytes are put into the specified byte array at a given offset location.
      Parameters:
      v - the int value to convert into 4 bytes.
      buf - the byte array to put the resulting 4 bytes.
      off - offset in the byte array
    • toLong

      public static long toLong(byte[] buf, int off)
      Converts 8 bytes to a long at the specified offset in the given byte array.
      Parameters:
      buf - the byte array containing the 8 bytes to be converted to a long.
      off - offset in the byte array
      Returns:
      the long value of the 8 bytes.