Package org.red5.server.net.rtmp
Class RTMPHandshake
java.lang.Object
org.red5.server.net.rtmp.RTMPHandshake
- All Implemented Interfaces:
IHandshake
- Direct Known Subclasses:
InboundHandshake
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
FieldsModifier and TypeFieldDescriptionprotected intprotected static final byte[][]Blowfish keys for RTMPE (RTMP type 0x09) - 16 x 24protected org.apache.mina.core.buffer.IoBufferprotected Cipherprotected Cipherprotected static final BigIntegerprotected static final BigIntegerprotected static final byte[]"Second Oakley Default Group" from RFC2409, section 6.2.protected static final intprotected booleanstatic final byte[]static final byte[]static final String[]protected byte[]protected byteprotected byte[]protected static final intprotected KeyAgreementprotected org.slf4j.Loggerprotected byte[]protected static final Randomprotected intprotected byte[]protected static final int[][]XTEA keys for RTMPE (RTMP type 0x08) - 16 x 4 -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddBuffer(byte[] in) Add a byte array to the buffer.voidaddBuffer(org.apache.mina.core.buffer.IoBuffer in) Add a IoBuffer to the buffer.voidcalculateDigest(int digestPos, byte[] handshakeMessage, int handshakeOffset, byte[] key, int keyLen, byte[] digest, int digestOffset) Calculates the digest given the its offset in the handshake data.voidcalculateHMAC_SHA256(byte[] message, int messageOffset, int messageLen, byte[] key, int keyLen, byte[] digest, int digestOffset) Calculates an HMAC SHA256 hash into the digest at the given offset.voidcalculateSwfVerification(byte[] handshakeMessage, byte[] swfHash, int swfSize) Calculates the swf verification token.protected abstract voidCreate the initial bytes for a request / response.protected KeyPairCreates a Diffie-Hellman key pair.static final voidgetBlowfishSignature(byte[] array, int offset, int keyid) RTMPE type 9 uses Blowfish on the regular signature http://en.wikipedia.org/wiki/Blowfish_(cipher)byte[]Returns buffered byte array.org.apache.mina.core.buffer.IoBufferReturns buffered IoBuffer itself.intReturns the buffer size.Returns the contained handshake bytes.Gets the DH offset in the handshake bytes array based on validation scheme Generates DH keypair Adds public key to handshake bytesintgetDHOffset(int algorithm, byte[] handshake, int bufferOffset) Returns the DH offset from an array of bytes.protected intgetDHOffset1(byte[] handshake, int bufferOffset) Returns the DH byte offset.protected intgetDHOffset2(byte[] handshake, int bufferOffset) Returns the DH byte offset.intgetDigestOffset(int algorithm, byte[] handshake, int bufferOffset) Returns the digest offset using current validation scheme.protected intgetDigestOffset1(byte[] handshake, int bufferOffset) Returns a digest byte offset.protected intgetDigestOffset2(byte[] handshake, int bufferOffset) Returns a digest byte offset.byteReturns the handshake type.protected byte[]getPublicKey(KeyPair keyPair) Returns the public key for a given key pair.protected byte[]getSharedSecret(byte[] publicKeyBytes, KeyAgreement agreement) Determines the validation scheme for given input.byte[]Returns the SWF verification bytes.static final voidgetXteaSignature(byte[] array, int offset, int keyid) RTMPE type 8 uses XTEA on the regular signature http://en.wikipedia.org/wiki/XTEAprotected voidinitRC4Encryption(byte[] sharedSecret) Prepare the ciphers.voidsetHandshakeType(byte handshakeType) Sets the handshake type.booleanWhether or not encryptions is in use.abstract booleanvalidate(byte[] handshake) Determines the validation scheme for given input.static final booleanvalidHandshakeType(byte handshakeType) Returns whether or not a given handshake type is valid.booleanverifyDigest(int digestPos, byte[] handshakeMessage, byte[] key, int keyLen) Verifies the digest.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.red5.server.net.IHandshake
doHandshake
-
Field Details
-
log
protected org.slf4j.Logger log -
HANDSHAKE_TYPES
-
GENUINE_FMS_KEY
public static final byte[] GENUINE_FMS_KEY -
GENUINE_FP_KEY
public static final byte[] GENUINE_FP_KEY -
DH_MODULUS_BYTES
protected static final byte[] DH_MODULUS_BYTES"Second Oakley Default Group" from RFC2409, section 6.2. -
XTEA_KEYS
protected static final int[][] XTEA_KEYSXTEA keys for RTMPE (RTMP type 0x08) - 16 x 4 -
BLOWFISH_KEYS
protected static final byte[][] BLOWFISH_KEYSBlowfish keys for RTMPE (RTMP type 0x09) - 16 x 24 -
DH_MODULUS
-
DH_BASE
-
DIGEST_LENGTH
protected static final int DIGEST_LENGTH- See Also:
-
KEY_LENGTH
protected static final int KEY_LENGTH- See Also:
-
random
-
keyAgreement
-
cipherOut
-
cipherIn
-
handshakeType
protected byte handshakeType -
handshakeBytes
protected byte[] handshakeBytes -
incomingPublicKey
protected byte[] incomingPublicKey -
outgoingPublicKey
protected byte[] outgoingPublicKey -
swfSize
protected int swfSize -
swfVerificationBytes
protected byte[] swfVerificationBytes -
algorithm
protected int algorithm -
fp9Handshake
protected boolean fp9Handshake -
buffer
protected org.apache.mina.core.buffer.IoBuffer buffer
-
-
Constructor Details
-
RTMPHandshake
public RTMPHandshake() -
RTMPHandshake
public RTMPHandshake(byte handshakeType)
-
-
Method Details
-
initRC4Encryption
protected void initRC4Encryption(byte[] sharedSecret) Prepare the ciphers.- Parameters:
sharedSecret- shared secret byte sequence
-
generateKeyPair
Creates a Diffie-Hellman key pair.- Returns:
- dh keypair
-
getPublicKey
Returns the public key for a given key pair.- Parameters:
keyPair- key pair- Returns:
- public key
-
createHandshakeBytes
protected abstract void createHandshakeBytes()Create the initial bytes for a request / response. -
validate
public abstract boolean validate(byte[] handshake) Determines the validation scheme for given input.- Specified by:
validatein interfaceIHandshake- Parameters:
handshake- handshake byte sequence- Returns:
- true if its a supported validation scheme, false if unsupported
-
calculateDigest
public void calculateDigest(int digestPos, byte[] handshakeMessage, int handshakeOffset, byte[] key, int keyLen, byte[] digest, int digestOffset) Calculates the digest given the its offset in the handshake data.- Parameters:
digestPos- digest positionhandshakeMessage- handshake messagehandshakeOffset- handshake message offsetkey- contains the keykeyLen- the length of the keydigest- contains the calculated digestdigestOffset- digest offset
-
verifyDigest
public boolean verifyDigest(int digestPos, byte[] handshakeMessage, byte[] key, int keyLen) Verifies the digest.- Parameters:
digestPos- digest positionhandshakeMessage- handshake messagekey- contains the keykeyLen- the length of the key- Returns:
- true if valid and false otherwise
-
calculateHMAC_SHA256
public void calculateHMAC_SHA256(byte[] message, int messageOffset, int messageLen, byte[] key, int keyLen, byte[] digest, int digestOffset) Calculates an HMAC SHA256 hash into the digest at the given offset.- Parameters:
message- incoming bytesmessageOffset- message offsetmessageLen- message lengthkey- incoming key byteskeyLen- the length of the keydigest- contains the calculated digestdigestOffset- digest offset
-
calculateSwfVerification
public void calculateSwfVerification(byte[] handshakeMessage, byte[] swfHash, int swfSize) Calculates the swf verification token.- Parameters:
handshakeMessage- servers handshake bytesswfHash- hash of swfswfSize- size of swf
-
getDHOffset
public int getDHOffset(int algorithm, byte[] handshake, int bufferOffset) Returns the DH offset from an array of bytes.- Parameters:
algorithm- validation algorithmhandshake- handshake sequencebufferOffset- buffer offset- Returns:
- DH offset
-
getDHOffset1
protected int getDHOffset1(byte[] handshake, int bufferOffset) Returns the DH byte offset.- Parameters:
handshake- handshake sequencebufferOffset- buffer offset- Returns:
- dh offset
-
getDHOffset2
protected int getDHOffset2(byte[] handshake, int bufferOffset) Returns the DH byte offset.- Parameters:
handshake- handshake sequencebufferOffset- buffer offset- Returns:
- dh offset
-
getDigestOffset
public int getDigestOffset(int algorithm, byte[] handshake, int bufferOffset) Returns the digest offset using current validation scheme.- Parameters:
algorithm- validation algorithmhandshake- handshake sequencebufferOffset- buffer offset- Returns:
- digest offset
-
getDigestOffset1
protected int getDigestOffset1(byte[] handshake, int bufferOffset) Returns a digest byte offset.- Parameters:
handshake- handshake sequencebufferOffset- buffer offset- Returns:
- digest offset
-
getDigestOffset2
protected int getDigestOffset2(byte[] handshake, int bufferOffset) Returns a digest byte offset.- Parameters:
handshake- handshake sequencebufferOffset- buffer offset- Returns:
- digest offset
-
getXteaSignature
public static final void getXteaSignature(byte[] array, int offset, int keyid) RTMPE type 8 uses XTEA on the regular signature http://en.wikipedia.org/wiki/XTEA- Parameters:
array- array to get signatureoffset- offset to start fromkeyid- ID of XTEA key
-
getBlowfishSignature
public static final void getBlowfishSignature(byte[] array, int offset, int keyid) RTMPE type 9 uses Blowfish on the regular signature http://en.wikipedia.org/wiki/Blowfish_(cipher)- Parameters:
array- array to get signatureoffset- offset to start fromkeyid- ID of XTEA key
-
validHandshakeType
public static final boolean validHandshakeType(byte handshakeType) Returns whether or not a given handshake type is valid.- Parameters:
handshakeType- the type of handshake- Returns:
- true if valid and supported, false otherwise
-
useEncryption
public boolean useEncryption()Whether or not encryptions is in use.- Specified by:
useEncryptionin interfaceIHandshake- Returns:
- true if handshake type is an encrypted type, false otherwise
-
setHandshakeType
public void setHandshakeType(byte handshakeType) Sets the handshake type. Currently only two types are supported, plain and encrypted.- Parameters:
handshakeType- handshake type
-
getHandshakeType
public byte getHandshakeType()Returns the handshake type.- Returns:
- handshakeType
-
getCipherOut
Gets the DH offset in the handshake bytes array based on validation scheme Generates DH keypair Adds public key to handshake bytes- Returns:
- cipher
-
getCipherIn
Returns the contained handshake bytes. These are just random bytes if the player is using an non-versioned player.- Returns:
- cipher
-
getSwfVerificationBytes
public byte[] getSwfVerificationBytes()Returns the SWF verification bytes.- Returns:
- swf verification bytes
-
getBufferSize
public int getBufferSize()Returns the buffer size.- Returns:
- buffer remaining
-
addBuffer
public void addBuffer(byte[] in) Add a byte array to the buffer.- Parameters:
in- incoming bytes
-
addBuffer
public void addBuffer(org.apache.mina.core.buffer.IoBuffer in) Add a IoBuffer to the buffer.- Parameters:
in- incoming IoBuffer
-
getBufferAsIoBuffer
public org.apache.mina.core.buffer.IoBuffer getBufferAsIoBuffer()Returns buffered IoBuffer itself.- Returns:
- IoBuffer
-
getBuffer
public byte[] getBuffer()Returns buffered byte array.- Returns:
- bytes
-