org.red5.server.net.rtmp
Class RTMPHandshake

java.lang.Object
  extended by org.red5.server.net.rtmp.RTMPHandshake
All Implemented Interfaces:
IHandshake
Direct Known Subclasses:
InboundHandshake

public abstract 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 ([email protected]), Steven Zimmer ([email protected]), Gavriloaie Eugen-Andrei, Ari-Pekka Viitanen, Paul Gregoire, Tiago Jacobs

Field Summary
protected  Cipher cipherIn
           
protected  Cipher cipherOut
           
protected static BigInteger DH_BASE
           
protected static BigInteger DH_MODULUS
           
protected static byte[] DH_MODULUS_BYTES
          Modulus bytes from flazr
protected static int DIGEST_LENGTH
           
protected static byte[] GENUINE_FMS_KEY
           
protected static byte[] GENUINE_FP_KEY
           
static byte[] HANDSHAKE_PAD_BYTES
           
protected static int HANDSHAKE_SIZE_SERVER
           
protected  byte[] handshakeBytes
           
protected  byte handshakeType
           
protected  byte[] incomingPublicKey
           
protected static int KEY_LENGTH
           
protected  KeyAgreement keyAgreement
           
protected static Logger log
           
protected  byte[] outgoingPublicKey
           
protected static Random random
           
protected  byte[] swfVerificationBytes
           
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 abstract  void createHandshakeBytes()
          Create the initial bytes for a request / response.
protected  KeyPair generateKeyPair()
          Creates a Diffie-Hellman key pair.
 Cipher getCipherIn()
          Returns the contained handshake bytes.
 Cipher getCipherOut()
          Gets the DH offset in the handshake bytes array based on validation scheme Generates DH keypair Adds public key to handshake bytes
protected  int getDHOffset(byte[] bytes)
          Returns the DH offset from an array of bytes.
protected  int getDHOffset0(byte[] bytes)
          Returns the DH byte offset.
protected  int getDHOffset1(byte[] bytes)
          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()
          Creates the servers handshake bytes
 byte getHandshakeType()
          Returns the handshake type.
protected static byte[] getPublicKey(KeyPair keyPair)
          Returns the public key for a given key pair.
protected static byte[] getSharedSecret(byte[] otherPublicKeyBytes, KeyAgreement agreement)
          Determines the validation scheme for given input.
 byte[] getSwfVerificationBytes()
          Returns the SWF verification bytes.
 void setHandshakeType(byte handshakeType)
          Sets the handshake type.
abstract  boolean validate(IoBuffer input)
          Determines the validation scheme for given input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.red5.server.net.IHandshake
doHandshake
 

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

HANDSHAKE_SIZE_SERVER

protected static final int HANDSHAKE_SIZE_SERVER
See Also:
Constant Field Values

DIGEST_LENGTH

protected static final int DIGEST_LENGTH
See Also:
Constant Field Values

KEY_LENGTH

protected static final int KEY_LENGTH
See Also:
Constant Field Values

random

protected static final Random random

keyAgreement

protected KeyAgreement keyAgreement

cipherOut

protected Cipher cipherOut

cipherIn

protected Cipher cipherIn

handshakeType

protected byte handshakeType

handshakeBytes

protected byte[] handshakeBytes

validationScheme

protected int validationScheme

incomingPublicKey

protected byte[] incomingPublicKey

outgoingPublicKey

protected byte[] outgoingPublicKey

swfVerificationBytes

protected byte[] swfVerificationBytes
Constructor Detail

RTMPHandshake

public RTMPHandshake()
Method Detail

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

getSharedSecret

protected static byte[] getSharedSecret(byte[] otherPublicKeyBytes,
                                        KeyAgreement agreement)
Determines the validation scheme for given input.

Parameters:
otherPublicKeyBytes -
agreement -
Returns:
shared secret bytes if client used a supported validation scheme

createHandshakeBytes

protected abstract void createHandshakeBytes()
Create the initial bytes for a request / response.


validate

public abstract boolean validate(IoBuffer input)
Determines the validation scheme for given input.

Specified by:
validate in interface IHandshake
Parameters:
input -
Returns:
true if its a supported validation scheme, false if unsupported

getDHOffset

protected int getDHOffset(byte[] bytes)
Returns the DH offset from an array of bytes.

Parameters:
bytes -
Returns:
DH offset

getDHOffset0

protected int getDHOffset0(byte[] bytes)
Returns the DH byte offset.

Returns:
dh offset

getDHOffset1

protected int getDHOffset1(byte[] bytes)
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

getHandshakeBytes

public byte[] getHandshakeBytes()
Creates the servers handshake bytes


setHandshakeType

public void setHandshakeType(byte handshakeType)
Sets the handshake type. Currently only two types are supported, plain and encrypted.

Parameters:
handshakeType -

getHandshakeType

public byte getHandshakeType()
Returns the handshake type.

Returns:
handshakeType

getCipherOut

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


getCipherIn

public Cipher getCipherIn()
Returns the contained handshake bytes. These are just random bytes if the player is using an non-versioned player.

Returns:
handshake bytes

getSwfVerificationBytes

public byte[] getSwfVerificationBytes()
Returns the SWF verification bytes.

Returns:
swf verification bytes


Copyright © 2006-2012 The Red5 Project