1717import org .bouncycastle .util .BigIntegers ;
1818import org .red5 .server .api .Red5 ;
1919import org .red5 .server .net .rtmp .message .Constants ;
20- import org .slf4j .LoggerFactory ;
2120
2221/**
2322 * Performs handshaking for server connections.
@@ -39,12 +38,10 @@ public class InboundHandshake extends RTMPHandshake {
3938
4039 public InboundHandshake () {
4140 super (RTMPConnection .RTMP_NON_ENCRYPTED );
42- log = LoggerFactory .getLogger (InboundHandshake .class );
4341 }
4442
4543 public InboundHandshake (byte handshakeType ) {
4644 super (handshakeType );
47- log = LoggerFactory .getLogger (InboundHandshake .class );
4845 }
4946
5047 public InboundHandshake (byte handshakeType , int algorithm ) {
@@ -184,14 +181,14 @@ public IoBuffer decodeClientRequest1(IoBuffer in) {
184181 log .debug ("RTMPE type 8 XTEA" );
185182 // encrypt signatureResp
186183 for (int i = 0 ; i < DIGEST_LENGTH ; i += 8 ) {
187- // encryptXtea(signatureResp , i, digestResp[i] % 15);
184+ encryptXtea (signatureResponse , i , digestResp [i ] % 15 );
188185 }
189186 break ;
190187 case RTMPConnection .RTMP_ENCRYPTED_BLOWFISH :
191188 log .debug ("RTMPE type 9 Blowfish" );
192189 // encrypt signatureResp
193190 for (int i = 0 ; i < DIGEST_LENGTH ; i += 8 ) {
194- // encryptBlowfish(signatureResp , i, digestResp[i] % 15);
191+ encryptBlowfish (signatureResponse , i , digestResp [i ] % 15 );
195192 }
196193 break ;
197194 }
@@ -250,14 +247,14 @@ public boolean decodeClientRequest2(IoBuffer in) {
250247 log .debug ("RTMPE type 8 XTEA" );
251248 // encrypt signature
252249 for (int i = 0 ; i < DIGEST_LENGTH ; i += 8 ) {
253- // encryptXtea(signature, i, digest[i] % 15);
250+ encryptXtea (signature , i , digest [i ] % 15 );
254251 }
255252 break ;
256253 case RTMPConnection .RTMP_ENCRYPTED_BLOWFISH :
257254 log .debug ("RTMPE type 9 Blowfish" );
258255 // encrypt signature
259256 for (int i = 0 ; i < DIGEST_LENGTH ; i += 8 ) {
260- // encryptBlowfish(signature, i, digest[i] % 15);
257+ encryptBlowfish (signature , i , digest [i ] % 15 );
261258 }
262259 break ;
263260 }
@@ -408,6 +405,33 @@ private boolean validateScheme(byte[] handshake, int scheme) {
408405 return result ;
409406 }
410407
408+ /**
409+ * Encrypt via xtea.
410+ *
411+ * @param in
412+ * @param index
413+ * @param keyId
414+ */
415+ private void encryptXtea (byte [] in , int index , int keyId ) {
416+ //xtea_le_init(XTEA_KEYS[keyId]);
417+ //xtea_le_crypt(out, in, 1, NULL, 0);
418+ }
419+
420+ /**
421+ * Encrypt via blowfish.
422+ *
423+ * @param in
424+ * @param index
425+ * @param keyId
426+ */
427+ private void encryptBlowfish (byte [] in , int index , int keyId ) {
428+ if (blowfish == null ) {
429+ initBlowfishEncryption (keyId );
430+ }
431+ // overwrite in as out using same array
432+ blowfish .processBlock (in , index , in , index );
433+ }
434+
411435 public void setHandshakeBytes (byte [] handshake ) {
412436 this .handshakeBytes = handshake ;
413437 }
0 commit comments