Skip to content
Snippets Groups Projects
Commit e3a1764d authored by amine.chbari.etu's avatar amine.chbari.etu
Browse files

declarer une fonction encrypt_rtmpe() pour regrouper le code dupliqué

parent cb7f8f67
No related branches found
No related tags found
No related merge requests found
......@@ -63,6 +63,35 @@ public class InboundHandshake extends RTMPHandshake {
return decodeClientRequest1(in);
}
/**
* encrypts the response to the client request C1
* this was duplicated code 176 - 195 and 241 - 259 from original file
* regroup it in one method
*/
public void encrypt_rtmpe(byte handshaketype, int DIGEST_LENGTH, byte[] signatureResp, byte[] digestresp){
switch (handshakeType) {
case RTMPConnection.RTMP_ENCRYPTED_XTEA:
log.debug("RTMPE type 8 XTEA");
// encrypt signatureResp
for (int i = 0; i < DIGEST_LENGTH; i += 8) {
encryptXtea(signatureResp, i, digestresp[i] % 15);
}
break;
case RTMPConnection.RTMP_ENCRYPTED_BLOWFISH:
log.debug("RTMPE type 9 Blowfish");
// encrypt signatureResp
for (int i = 0; i < DIGEST_LENGTH; i += 8) {
encryptBlowfish(signatureResp, i, digestresp[i] % 15);
}
break;
}
}
/**
* Decodes the first client request (C1) and returns a server response (S0S1).
*
......@@ -173,26 +202,8 @@ public class InboundHandshake extends RTMPHandshake {
calculateHMAC_SHA256(c1, 0, (Constants.HANDSHAKE_SIZE - DIGEST_LENGTH), digestResp, DIGEST_LENGTH, signatureResponse, 0);
log.debug("Signature response: {}", Hex.encodeHexString(signatureResponse));
if (useEncryption()) {
switch (handshakeType) {
case RTMPConnection.RTMP_ENCRYPTED:
log.debug("RTMPE type 6");
// we dont encrypt signatureResp for type 6
break;
case RTMPConnection.RTMP_ENCRYPTED_XTEA:
log.debug("RTMPE type 8 XTEA");
// encrypt signatureResp
for (int i = 0; i < DIGEST_LENGTH; i += 8) {
encryptXtea(signatureResponse, i, digestResp[i] % 15);
}
break;
case RTMPConnection.RTMP_ENCRYPTED_BLOWFISH:
log.debug("RTMPE type 9 Blowfish");
// encrypt signatureResp
for (int i = 0; i < DIGEST_LENGTH; i += 8) {
encryptBlowfish(signatureResponse, i, digestResp[i] % 15);
}
break;
}
// replace the switch block with called function
encrypt_rtmpe(handshakeType, DIGEST_LENGTH, signatureResponse, digestResp);
}
// copy signature into C1 as S2
System.arraycopy(signatureResponse, 0, c1, (Constants.HANDSHAKE_SIZE - DIGEST_LENGTH), DIGEST_LENGTH);
......@@ -238,25 +249,9 @@ public class InboundHandshake extends RTMPHandshake {
calculateHMAC_SHA256(s1, digestPosServer, DIGEST_LENGTH, GENUINE_FP_KEY, GENUINE_FP_KEY.length, digest, 0);
calculateHMAC_SHA256(c2, 0, Constants.HANDSHAKE_SIZE - DIGEST_LENGTH, digest, DIGEST_LENGTH, signature, 0);
if (useEncryption()) {
switch (handshakeType) {
case RTMPConnection.RTMP_ENCRYPTED:
log.debug("RTMPE type 6");
break;
case RTMPConnection.RTMP_ENCRYPTED_XTEA:
log.debug("RTMPE type 8 XTEA");
// encrypt signature
for (int i = 0; i < DIGEST_LENGTH; i += 8) {
encryptXtea(signature, i, digest[i] % 15);
}
break;
case RTMPConnection.RTMP_ENCRYPTED_BLOWFISH:
log.debug("RTMPE type 9 Blowfish");
// encrypt signature
for (int i = 0; i < DIGEST_LENGTH; i += 8) {
encryptBlowfish(signature, i, digest[i] % 15);
}
break;
}
// replace the switch block with called function
encrypt_rtmpe(handshakeType, DIGEST_LENGTH, signature, digest);
// update 'encoder / decoder state' for the RC4 keys both parties *pretend* as if handshake part 2 (1536 bytes) was encrypted
// effectively this hides / discards the first few bytes of encrypted session which is known to increase the secure-ness of RC4
// RC4 state is just a function of number of bytes processed so far that's why we just run 1536 arbitrary bytes through the keys below
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment