## org.red5.server.net.rtmp
Class RTMPHandshake

    java.lang.Object
      org.red5.server.net.rtmp.RTMPHandshake

All Implemented Interfaces:
  IHandshake

    public class RTMPHandshake

extends Object
implements IHandshake

Generates and validates the RTMP handshake response for Flash Players. Client versions equal to or greater than Flash 9,0,124,0 require a nonzero value as the fifth byte of the handshake request.

Author:
  Jacinto Shy II (jacinto.m.shy@ieee.org), Steven Zimmer (stevenlzimmer@gmail.com), Gavriloaie Eugen-Andrei, Ari-Pekka Viitanen, Paul Gregoire, Tiago Jacobs

Field Summary
`protected static BigInteger` `DH_BASE`
`protected static BigInteger` `DH_MODULUS`
`protected static byte[]` `DH_MODULUS_BYTES` Modulus bytes from flazr
`protected static byte[]` `GENUINE_FMS_KEY`
`protected static byte[]` `GENUINE_FP_KEY`
`static byte[]` `HANDSHAKE_PAD_BYTES`
`protected byte[]` `handshakeBytes`
`protected KeyAgreement` `keyAgreement`
`protected static Logger` `log`
`protected static Random` `random`
`protected int` `validationScheme`

Constructor Summary
`RTMPHandshake()`

Method Summary
`byte[]` `calculateHMAC_SHA256(byte[] input, byte[] key)` Calculates an HMAC SHA256 hash using a default key length.
`byte[]` `calculateHMAC_SHA256(byte[] input, byte[] key, int length)` Calculates an HMAC SHA256 hash using a set key length.
`protected KeyPair` `generateKeyPair()` Creates a Diffie-Hellman key pair.
`IoBuffer` `generateResponse(IoBuffer input)` Generates response for versioned connections.
`protected int` `getDHOffset0()` Returns the DH byte offset.
`protected int` `getDHOffset1()` Returns the DH byte offset.
`protected int` `getDigestOffset(byte[] pBuffer)` Returns the digest offset using current validation scheme.
`protected int` `getDigestOffset0(byte[] pBuffer)` Returns a digest byte offset.
`protected int` `getDigestOffset1(byte[] pBuffer)` Returns a digest byte offset.
`byte[]` `getHandshakeBytes()` Returns the contained handshake bytes.
`protected static byte[]` `getPublicKey(KeyPair keyPair)` Returns the public key for a given key pair.
`protected void` `prepareResponse()` Gets the DH offset in the handshake bytes array based on validation scheme Generates DH keypair Adds public key to handshake bytes
`protected boolean` `validateClient(IoBuffer input)` Determines the validation scheme for given input.
`protected boolean` `validateClientScheme(byte[] pBuffer, int scheme)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### log

    protected static Logger log

### HANDSHAKE_PAD_BYTES

    public static byte[] HANDSHAKE_PAD_BYTES

### GENUINE_FMS_KEY

    protected static final byte[] GENUINE_FMS_KEY

### GENUINE_FP_KEY

    protected static final byte[] GENUINE_FP_KEY

### DH_MODULUS_BYTES

    protected static final byte[] DH_MODULUS_BYTES

  Modulus bytes from flazr

### DH_MODULUS

    protected static final BigInteger DH_MODULUS

### DH_BASE

    protected static final BigInteger DH_BASE

### random

    protected static final Random random

### keyAgreement

    protected KeyAgreement keyAgreement

### handshakeBytes

    protected byte[] handshakeBytes

### validationScheme

    protected int validationScheme

Constructor Detail

### RTMPHandshake

    public RTMPHandshake()

Method Detail

### generateResponse

    public IoBuffer generateResponse(IoBuffer input)

  Generates response for versioned connections.

  Specified by:
    `generateResponse` in interface `IHandshake`
  Parameters:
    `input` - incoming RTMP bytes
  Returns:
    outgoing handshake

### calculateHMAC_SHA256

    public byte[] calculateHMAC_SHA256(byte[] input,
                                       byte[] key)

  Calculates an HMAC SHA256 hash using a default key length.

  Parameters:
    `input` -
    `key` -
  Returns:
    hmac hashed bytes

### calculateHMAC_SHA256

    public byte[] calculateHMAC_SHA256(byte[] input,
                                       byte[] key,
                                       int length)

  Calculates an HMAC SHA256 hash using a set key length.

  Parameters:
    `input` -
    `key` -
    `length` -
  Returns:
    hmac hashed bytes

### generateKeyPair

    protected KeyPair generateKeyPair()

  Creates a Diffie-Hellman key pair.

  Returns:
    dh keypair

### getPublicKey

    protected static byte[] getPublicKey(KeyPair keyPair)

  Returns the public key for a given key pair.

  Parameters:
    `keyPair` -
  Returns:
    public key

### validateClient

    protected boolean validateClient(IoBuffer input)

  Determines the validation scheme for given input.

  Parameters:
    `input` -
  Returns:
    true if client used a supported validation scheme, false if unsupported

### validateClientScheme

    protected boolean validateClientScheme(byte[] pBuffer,
                                           int scheme)

### getDHOffset0

    protected int getDHOffset0()

  Returns the DH byte offset.

  Returns:
    dh offset

### getDHOffset1

    protected int getDHOffset1()

  Returns the DH byte offset.

  Returns:
    dh offset

### getDigestOffset

    protected int getDigestOffset(byte[] pBuffer)

  Returns the digest offset using current validation scheme.

  Parameters:
    `pBuffer` -
  Returns:
    digest offset

### getDigestOffset0

    protected int getDigestOffset0(byte[] pBuffer)

  Returns a digest byte offset.

  Parameters:
    `pBuffer` - source for digest data
  Returns:
    digest offset

### getDigestOffset1

    protected int getDigestOffset1(byte[] pBuffer)

  Returns a digest byte offset.

  Parameters:
    `pBuffer` - source for digest data
  Returns:
    digest offset

### prepareResponse

    protected void prepareResponse()

  Gets the DH offset in the handshake bytes array based on validation scheme Generates DH keypair Adds public key to handshake bytes

### getHandshakeBytes

    public byte[] getHandshakeBytes()

  Returns the contained handshake bytes. These are just random bytes if the player is using an non-versioned player.

  Returns:
    handshake bytes

Copyright © 2006-2010 The Red5 Project